1 var tap = require("tap")
3 var path = require("path")
5 var normalize = require("../lib/normalize")
6 var warningMessages = require("../lib/warning_messages.json")
7 var safeFormat = require("../lib/safe_format")
9 var rpjPath = path.resolve(__dirname,"./fixtures/read-package-json.json")
11 tap.test("normalize some package data", function(t) {
12 var packageData = require(rpjPath)
14 normalize(packageData, function(warning) {
15 warnings.push(warning)
17 // there's no readme data in this particular object
18 t.equal( warnings.length, 1, "There's exactly one warning.")
19 fs.readFile(rpjPath, function(err, data) {
21 // Various changes have been made
22 t.notEqual(packageData, JSON.parse(data), "Output is different from input.")
27 tap.test("runs without passing warning function", function(t) {
28 var packageData = require(rpjPath)
29 fs.readFile(rpjPath, function(err, data) {
31 normalize(JSON.parse(data))
32 t.ok(true, "If you read this, this means I'm still alive.")
37 tap.test("empty object", function(t) {
42 readme: 'ERROR: No README data found!',
49 normalize(packageData, warn)
50 t.same(packageData, expect)
52 warningMessages.missingDescription,
53 warningMessages.missingRepository,
54 warningMessages.missingReadme,
55 warningMessages.missingLicense
60 tap.test("core module name", function(t) {
68 readme: "read yourself how about",
70 bugs: "what is this i don't even",
75 safeFormat(warningMessages.conflictingName, 'http'),
76 warningMessages.nonEmailUrlBugsString,
77 warningMessages.emptyNormalizedBugs,
78 warningMessages.nonUrlHomepage,
79 warningMessages.missingLicense
81 t.same(warnings, expect)
85 tap.test("urls required", function(t) {
93 email: "not an email address"
98 readme: "read yourself how about",
100 bugs: "what is this i don't even",
105 [ warningMessages.missingDescription,
106 warningMessages.missingRepository,
107 warningMessages.nonUrlBugsUrlField,
108 warningMessages.nonEmailBugsEmailField,
109 warningMessages.emptyNormalizedBugs,
110 warningMessages.missingReadme,
111 warningMessages.missingLicense,
112 warningMessages.nonEmailUrlBugsString,
113 warningMessages.emptyNormalizedBugs,
114 warningMessages.nonUrlHomepage,
115 warningMessages.missingLicense]
116 t.same(warnings, expect)
120 tap.test("homepage field must start with a protocol.", function(t) {
127 homepage: 'example.org'
131 [ warningMessages.missingDescription,
132 warningMessages.missingRepository,
133 warningMessages.missingReadme,
134 warningMessages.missingProtocolHomepage,
135 warningMessages.missingLicense]
136 t.same(warnings, expect)
137 t.same(a.homepage, 'http://example.org')
141 tap.test("license field should be a valid SPDX expression", function(t) {
152 [ warningMessages.missingDescription,
153 warningMessages.missingRepository,
154 warningMessages.missingReadme,
155 warningMessages.invalidLicense]
156 t.same(warnings, expect)
160 tap.test("gist bugs url", function(t) {
162 repository: "git@gist.github.com:123456.git"
165 t.same(d.repository, { type: 'git', url: 'git+ssh://git@gist.github.com/123456.git' })
166 t.same(d.bugs, { url: 'https://gist.github.com/123456' })
170 tap.test("singularize repositories", function(t) {
171 var d = {repositories:["git@gist.github.com:123456.git"]}
173 t.same(d.repository, { type: 'git', url: 'git+ssh://git@gist.github.com/123456.git' })
177 tap.test("treat visionmedia/express as github repo", function(t) {
178 var d = {repository: {type: "git", url: "visionmedia/express"}}
180 t.same(d.repository, { type: "git", url: "git+https://github.com/visionmedia/express.git" })
184 tap.test("treat isaacs/node-graceful-fs as github repo", function(t) {
185 var d = {repository: {type: "git", url: "isaacs/node-graceful-fs"}}
187 t.same(d.repository, { type: "git", url: "git+https://github.com/isaacs/node-graceful-fs.git" })
191 tap.test("homepage field will set to github url if repository is a github repo", function(t) {
194 repository: { type: "git", url: "https://github.com/isaacs/node-graceful-fs" }
196 t.same(a.homepage, 'https://github.com/isaacs/node-graceful-fs#readme')
200 tap.test("homepage field will set to github gist url if repository is a gist", function(t) {
203 repository: { type: "git", url: "git@gist.github.com:123456.git" }
205 t.same(a.homepage, 'https://gist.github.com/123456')
209 tap.test("homepage field will set to github gist url if repository is a shorthand reference", function(t) {
212 repository: { type: "git", url: "sindresorhus/chalk" }
214 t.same(a.homepage, 'https://github.com/sindresorhus/chalk#readme')
218 tap.test("don't mangle github shortcuts in dependencies", function(t) {
219 var d = {dependencies: {"node-graceful-fs": "isaacs/node-graceful-fs"}}
221 t.same(d.dependencies, {"node-graceful-fs": "github:isaacs/node-graceful-fs" })
225 tap.test("deprecation warning for array in dependencies fields", function(t) {
234 optionalDependencies: []
236 t.ok(~warnings.indexOf(safeFormat(warningMessages.deprecatedArrayDependencies, 'dependencies')), "deprecation warning")
237 t.ok(~warnings.indexOf(safeFormat(warningMessages.deprecatedArrayDependencies, 'devDependencies')), "deprecation warning")
238 t.ok(~warnings.indexOf(safeFormat(warningMessages.deprecatedArrayDependencies, 'optionalDependencies')), "deprecation warning")