consistency.js 1.2 KB

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