Initial commit
[yaffs-website] / node_modules / normalize-package-data / test / consistency.js
1 var tap = require("tap")
2 var normalize = require("../lib/normalize")
3 var path = require("path")
4 var fs = require("fs")
5 var _ = require("underscore")
6 var async = require("async")
7
8 var data, clonedData
9 var warn
10
11 tap.test("consistent normalization", function(t) {
12   path.resolve(__dirname, "./fixtures/read-package-json.json")
13   fs.readdir (__dirname + "/fixtures", function (err, entries) {
14     // entries = ['coffee-script.json'] // uncomment to limit to a specific file
15     verifyConsistency = function(entryName, next) {
16       warn = function(msg) {
17         // t.equal("",msg) // uncomment to have some kind of logging of warnings
18       }
19       filename = __dirname + "/fixtures/" + entryName
20       fs.readFile(filename, function(err, contents) {
21         if (err) return next(err)
22         data = JSON.parse(contents.toString())
23         normalize(data, warn)
24         clonedData = _.clone(data)
25         normalize(data, warn)
26         t.deepEqual(clonedData, data,
27           "Normalization of " + entryName + " is consistent.")
28         next(null)
29       }) // fs.readFile
30     } // verifyConsistency
31     async.forEach(entries, verifyConsistency, function(err) {
32       if (err) throw err
33       t.end()
34     })
35   }) // fs.readdir
36 }) // tap.test