basic.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334
  1. var tap = require("tap")
  2. var normalize = require("../lib/normalize")
  3. var path = require("path")
  4. var fs = require("fs")
  5. tap.test("basic test", function (t) {
  6. var p = path.resolve(__dirname, "./fixtures/read-package-json.json")
  7. fs.readFile (p, function (err, contents) {
  8. if (err) throw err;
  9. var originalData = JSON.parse(contents.toString())
  10. var data = JSON.parse(contents.toString())
  11. normalize(data)
  12. t.ok(data)
  13. verifyFields(t, data, originalData)
  14. t.end()
  15. })
  16. })
  17. function verifyFields (t, normalized, original) {
  18. t.equal(normalized.version, original.version, "Version field stays same")
  19. t.equal(normalized._id, normalized.name + "@" + normalized.version, "It gets good id.")
  20. t.equal(normalized.name, original.name, "Name stays the same.")
  21. t.type(normalized.author, "object", "author field becomes object")
  22. t.deepEqual(normalized.scripts, original.scripts, "scripts field (object) stays same")
  23. t.equal(normalized.main, original.main)
  24. // optional deps are folded in.
  25. t.deepEqual(normalized.optionalDependencies,
  26. original.optionalDependencies)
  27. t.has(normalized.dependencies, original.optionalDependencies, "opt depedencies are copied into dependencies")
  28. t.has(normalized.dependencies, original.dependencies, "regular depedencies stay in place")
  29. t.deepEqual(normalized.devDependencies, original.devDependencies)
  30. t.type(normalized.bugs, "object", "bugs should become object")
  31. t.equal(normalized.bugs.url, "https://github.com/isaacs/read-package-json/issues")
  32. }