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",
107 [ warningMessages.missingDescription,
108 warningMessages.missingRepository,
109 warningMessages.nonUrlBugsUrlField,
110 warningMessages.nonEmailBugsEmailField,
111 warningMessages.emptyNormalizedBugs,
112 warningMessages.missingReadme,
113 warningMessages.missingLicense,
114 warningMessages.nonEmailUrlBugsString,
115 warningMessages.emptyNormalizedBugs,
116 warningMessages.nonUrlHomepage,
117 warningMessages.missingLicense]
118 t.same(warnings, expect)
122 tap.test("homepage field must start with a protocol.", function(t) {
129 homepage: 'example.org'
135 [ warningMessages.missingDescription,
136 warningMessages.missingRepository,
137 warningMessages.missingReadme,
138 warningMessages.missingProtocolHomepage,
139 warningMessages.missingLicense]
140 t.same(warnings, expect)
141 t.same(a.homepage, 'http://example.org')
145 tap.test("license field should be a valid SPDX expression", function(t) {
158 [ warningMessages.missingDescription,
159 warningMessages.missingRepository,
160 warningMessages.missingReadme,
161 warningMessages.invalidLicense]
162 t.same(warnings, expect)
166 tap.test("gist bugs url", function(t) {
168 repository: "git@gist.github.com:123456.git"
171 t.same(d.repository, { type: 'git', url: 'git+ssh://git@gist.github.com/123456.git' })
172 t.same(d.bugs, { url: 'https://gist.github.com/123456' })
176 tap.test("singularize repositories", function(t) {
177 var d = {repositories:["git@gist.github.com:123456.git"]}
179 t.same(d.repository, { type: 'git', url: 'git+ssh://git@gist.github.com/123456.git' })
183 tap.test("treat visionmedia/express as github repo", function(t) {
184 var d = {repository: {type: "git", url: "visionmedia/express"}}
186 t.same(d.repository, { type: "git", url: "git+https://github.com/visionmedia/express.git" })
190 tap.test("treat isaacs/node-graceful-fs as github repo", function(t) {
191 var d = {repository: {type: "git", url: "isaacs/node-graceful-fs"}}
193 t.same(d.repository, { type: "git", url: "git+https://github.com/isaacs/node-graceful-fs.git" })
197 tap.test("homepage field will set to github url if repository is a github repo", function(t) {
200 repository: { type: "git", url: "https://github.com/isaacs/node-graceful-fs" }
202 t.same(a.homepage, 'https://github.com/isaacs/node-graceful-fs#readme')
206 tap.test("homepage field will set to github gist url if repository is a gist", function(t) {
209 repository: { type: "git", url: "git@gist.github.com:123456.git" }
211 t.same(a.homepage, 'https://gist.github.com/123456')
215 tap.test("homepage field will set to github gist url if repository is a shorthand reference", function(t) {
218 repository: { type: "git", url: "sindresorhus/chalk" }
220 t.same(a.homepage, 'https://github.com/sindresorhus/chalk#readme')
224 tap.test("don't mangle github shortcuts in dependencies", function(t) {
225 var d = {dependencies: {"node-graceful-fs": "isaacs/node-graceful-fs"}}
227 t.same(d.dependencies, {"node-graceful-fs": "github:isaacs/node-graceful-fs" })
231 tap.test("deprecation warning for array in dependencies fields", function(t) {
240 optionalDependencies: []
242 t.ok(~warnings.indexOf(safeFormat(warningMessages.deprecatedArrayDependencies, 'dependencies')), "deprecation warning")
243 t.ok(~warnings.indexOf(safeFormat(warningMessages.deprecatedArrayDependencies, 'devDependencies')), "deprecation warning")
244 t.ok(~warnings.indexOf(safeFormat(warningMessages.deprecatedArrayDependencies, 'optionalDependencies')), "deprecation warning")