-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
57 additions
and
90 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,25 @@ | ||
var tap = require("tap") | ||
var normalize = require("../lib/normalize") | ||
var path = require("path") | ||
var fs = require("fs") | ||
var async = require("async") | ||
const t = require("tap") | ||
const normalize = require("../lib/normalize") | ||
const fs = require("fs") | ||
const { promisify } = require("util") | ||
const readFile = promisify(fs.readFile) | ||
const readdir = promisify(fs.readdir) | ||
|
||
var data, clonedData | ||
var warn | ||
|
||
tap.test("consistent normalization", function(t) { | ||
path.resolve(__dirname, "./fixtures/read-package-json.json") | ||
fs.readdir (__dirname + "/fixtures", function (err, entries) { | ||
// entries = ['coffee-script.json'] // uncomment to limit to a specific file | ||
verifyConsistency = function(entryName, next) { | ||
warn = function(msg) { | ||
// t.equal("",msg) // uncomment to have some kind of logging of warnings | ||
} | ||
filename = __dirname + "/fixtures/" + entryName | ||
fs.readFile(filename, function(err, contents) { | ||
if (err) return next(err) | ||
data = JSON.parse(contents.toString()) | ||
normalize(data, warn) | ||
clonedData = { ...data } | ||
normalize(data, warn) | ||
t.deepEqual(clonedData, data, | ||
"Normalization of " + entryName + " is consistent.") | ||
next(null) | ||
}) // fs.readFile | ||
} // verifyConsistency | ||
async.forEach(entries, verifyConsistency, function(err) { | ||
if (err) throw err | ||
t.end() | ||
}) | ||
}) // fs.readdir | ||
}) // tap.test | ||
t.test("consistent normalization", async t => { | ||
const entries = await readdir(__dirname + "/fixtures") | ||
const verifyConsistency = async (entryName) => { | ||
const warn = () => null | ||
const filename = __dirname + "/fixtures/" + entryName | ||
const contents = await readFile(filename) | ||
|
||
const data = JSON.parse(contents.toString()) | ||
normalize(data, warn) | ||
const clonedData = { ...data } | ||
normalize(data, warn) | ||
t.deepEqual(clonedData, data, | ||
"Normalization of " + entryName + " is consistent.") | ||
} | ||
|
||
return Promise.all(entries.map(i => verifyConsistency(i))) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,35 @@ | ||
var tap = require("tap") | ||
var normalize = require("../lib/normalize") | ||
var fs = require("fs") | ||
var async = require("async") | ||
const t = require("tap") | ||
const normalize = require("../lib/normalize") | ||
const fs = require("fs") | ||
const { promisify } = require("util") | ||
const readFile = promisify(fs.readFile) | ||
|
||
var data | ||
var warn | ||
|
||
tap.test("consistent normalization", function(t) { | ||
var entries = [ | ||
t.test("consistent normalization", async t => { | ||
const entries = [ | ||
'read-package-json.json', | ||
'http-server.json', | ||
"movefile.json", | ||
"node-module_exist.json" | ||
] | ||
var verifyConsistency = function(entryName, next) { | ||
warn = function(msg) { | ||
// t.equal("",msg) // uncomment to have some kind of logging of warnings | ||
const verifyConsistency = async (entryName) => { | ||
const warn = () => null | ||
const filename = __dirname + "/fixtures/" + entryName | ||
const contents = await readFile(filename) | ||
const data = JSON.parse(contents.toString()) | ||
normalize(data, warn) | ||
if(data.name == "node-module_exist") { | ||
t.same(data.bugs.url, "https://gist.github.com/3135914") | ||
} | ||
var filename = __dirname + "/fixtures/" + entryName | ||
fs.readFile(filename, function(err, contents) { | ||
if (err) return next(err) | ||
data = JSON.parse(contents.toString()) | ||
normalize(data, warn) | ||
if(data.name == "node-module_exist") { | ||
t.same(data.bugs.url, "https://gist.github.com/3135914") | ||
} | ||
if(data.name == "read-package-json") { | ||
t.same(data.bugs.url, "https://github.com/isaacs/read-package-json/issues") | ||
} | ||
if(data.name == "http-server") { | ||
t.same(data.bugs.url, "https://github.com/nodejitsu/http-server/issues") | ||
} | ||
if(data.name == "movefile") { | ||
t.same(data.bugs.url, "https://github.com/yazgazan/movefile/issues") | ||
} | ||
next(null) | ||
}) // fs.readFile | ||
} // verifyConsistency | ||
async.forEach(entries, verifyConsistency, function(err) { | ||
if (err) throw err | ||
t.end() | ||
}) | ||
}) // tap.test | ||
if(data.name == "read-package-json") { | ||
t.same(data.bugs.url, "https://github.com/isaacs/read-package-json/issues") | ||
} | ||
if(data.name == "http-server") { | ||
t.same(data.bugs.url, "https://github.com/nodejitsu/http-server/issues") | ||
} | ||
if(data.name == "movefile") { | ||
t.same(data.bugs.url, "https://github.com/yazgazan/movefile/issues") | ||
} | ||
} | ||
return Promise.all(entries.map(i => verifyConsistency(i))) | ||
}) |