diff options
Diffstat (limited to 'test/tap')
94 files changed, 2646 insertions, 2650 deletions
diff --git a/test/tap/00-check-mock-dep.js b/test/tap/00-check-mock-dep.js index 1c862317c..cdc7af852 100644 --- a/test/tap/00-check-mock-dep.js +++ b/test/tap/00-check-mock-dep.js @@ -1,17 +1,17 @@ -console.log("TAP Version 13") +console.log('TAP Version 13') -process.on("uncaughtException", function (er) { +process.on('uncaughtException', function (er) { if (er) { throw er } - console.log("not ok - Failed checking mock registry dep. Expect much fail!") - console.log("1..1") + console.log('not ok - Failed checking mock registry dep. Expect much fail!') + console.log('1..1') process.exit(1) }) -var assert = require("assert") -var semver = require("semver") -var mock = require("npm-registry-mock/package.json").version -var req = require("../../package.json").devDependencies["npm-registry-mock"] +var assert = require('assert') +var semver = require('semver') +var mock = require('npm-registry-mock/package.json').version +var req = require('../../package.json').devDependencies['npm-registry-mock'] assert(semver.satisfies(mock, req)) -console.log("ok") -console.log("1..1") +console.log('ok') +console.log('1..1') diff --git a/test/tap/00-config-setup.js b/test/tap/00-config-setup.js index 33581eb13..a6687d116 100644 --- a/test/tap/00-config-setup.js +++ b/test/tap/00-config-setup.js @@ -1,32 +1,32 @@ -var path = require("path") -var userconfigSrc = path.resolve(__dirname, "..", "fixtures", "config", "userconfig") -exports.userconfig = userconfigSrc + "-with-gc" -exports.globalconfig = path.resolve(__dirname, "..", "fixtures", "config", "globalconfig") -exports.builtin = path.resolve(__dirname, "..", "fixtures", "config", "builtin") -exports.malformed = path.resolve(__dirname, "..", "fixtures", "config", "malformed") +var path = require('path') +var userconfigSrc = path.resolve(__dirname, '..', 'fixtures', 'config', 'userconfig') +exports.userconfig = userconfigSrc + '-with-gc' +exports.globalconfig = path.resolve(__dirname, '..', 'fixtures', 'config', 'globalconfig') +exports.builtin = path.resolve(__dirname, '..', 'fixtures', 'config', 'builtin') +exports.malformed = path.resolve(__dirname, '..', 'fixtures', 'config', 'malformed') exports.ucData = { globalconfig: exports.globalconfig, - email: "i@izs.me", - "env-thing": "asdf", - "init.author.name": "Isaac Z. Schlueter", - "init.author.email": "i@izs.me", - "init.author.url": "http://blog.izs.me/", - "init.version": "1.2.3", - "proprietary-attribs": false, - "npm:publishtest": true, - "_npmjs.org:couch": "https://admin:password@localhost:5984/registry", - "npm-www:nocache": "1", - nodedir: "/Users/isaacs/dev/js/node-v0.8", - "sign-git-tag": true, - message: "v%s", - "strict-ssl": false, - "tmp": process.env.HOME + "/.tmp", - _auth: "dXNlcm5hbWU6cGFzc3dvcmQ=", + email: 'i@izs.me', + 'env-thing': 'asdf', + 'init.author.name': 'Isaac Z. Schlueter', + 'init.author.email': 'i@izs.me', + 'init.author.url': 'http://blog.izs.me/', + 'init.version': '1.2.3', + 'proprietary-attribs': false, + 'npm:publishtest': true, + '_npmjs.org:couch': 'https://admin:password@localhost:5984/registry', + 'npm-www:nocache': '1', + nodedir: '/Users/isaacs/dev/js/node-v0.8', + 'sign-git-tag': true, + message: 'v%s', + 'strict-ssl': false, + 'tmp': process.env.HOME + '/.tmp', + _auth: 'dXNlcm5hbWU6cGFzc3dvcmQ=', _token: - { AuthSession: "yabba-dabba-doodle", - version: "1", - expires: "1345001053415", - path: "/", + { AuthSession: 'yabba-dabba-doodle', + version: '1', + expires: '1345001053415', + path: '/', httponly: true } } // set the userconfig in the env @@ -38,31 +38,30 @@ Object.keys(process.env).forEach(function (k) { }) process.env.npm_config_userconfig = exports.userconfig process.env.npm_config_other_env_thing = 1000 -process.env.random_env_var = "asdf" -process.env.npm_config__underbar_env_thing = "underful" +process.env.random_env_var = 'asdf' +process.env.npm_config__underbar_env_thing = 'underful' process.env.NPM_CONFIG_UPPERCASE_ENV_THING = 42 exports.envData = { userconfig: exports.userconfig, - "_underbar-env-thing": "underful", - "uppercase-env-thing": "42", - "other-env-thing": "1000" + '_underbar-env-thing': 'underful', + 'uppercase-env-thing': '42', + 'other-env-thing': '1000' } exports.envDataFix = { userconfig: exports.userconfig, - "_underbar-env-thing": "underful", - "uppercase-env-thing": 42, - "other-env-thing": 1000 + '_underbar-env-thing': 'underful', + 'uppercase-env-thing': 42, + 'other-env-thing': 1000 } - if (module === require.main) { // set the globalconfig in the userconfig - var fs = require("fs") + var fs = require('fs') var uc = fs.readFileSync(userconfigSrc) - var gcini = "globalconfig = " + exports.globalconfig + "\n" + var gcini = 'globalconfig = ' + exports.globalconfig + '\n' fs.writeFileSync(exports.userconfig, gcini + uc) - console.log("1..1") - console.log("ok 1 setup done") + console.log('1..1') + console.log('ok 1 setup done') } diff --git a/test/tap/00-verify-bundle-deps.js b/test/tap/00-verify-bundle-deps.js index 92818142a..75ea81c59 100644 --- a/test/tap/00-verify-bundle-deps.js +++ b/test/tap/00-verify-bundle-deps.js @@ -1,17 +1,14 @@ -var fs = require("fs") -var path = require("path") -var test = require("tap").test +var test = require('tap').test -var manifest = require("../../package.json") +var manifest = require('../../package.json') var deps = Object.keys(manifest.dependencies) -var dev = Object.keys(manifest.devDependencies) var bundled = manifest.bundleDependencies -test("all deps are bundled deps or dev deps", function (t) { +test('all deps are bundled deps or dev deps', function (t) { deps.forEach(function (name) { t.assert( bundled.indexOf(name) !== -1, - name + " is in bundledDependencies" + name + ' is in bundledDependencies' ) }) diff --git a/test/tap/00-verify-ls-ok.js b/test/tap/00-verify-ls-ok.js index aa6acdbc5..2d20e500b 100644 --- a/test/tap/00-verify-ls-ok.js +++ b/test/tap/00-verify-ls-ok.js @@ -1,18 +1,18 @@ -var common = require("../common-tap") -var test = require("tap").test -var path = require("path") -var cwd = path.resolve(__dirname, "..", "..") -var fs = require("fs") +var common = require('../common-tap') +var test = require('tap').test +var path = require('path') +var cwd = path.resolve(__dirname, '..', '..') +var fs = require('fs') -test("npm ls in npm", function (t) { - t.ok(fs.existsSync(cwd), "ensure that the path we are calling ls within exists") +test('npm ls in npm', function (t) { + t.ok(fs.existsSync(cwd), 'ensure that the path we are calling ls within exists') var files = fs.readdirSync(cwd) - t.notEqual(files.length, 0, "ensure there are files in the directory we are to ls") + t.notEqual(files.length, 0, 'ensure there are files in the directory we are to ls') - var opt = { cwd: cwd, stdio: [ "ignore", "ignore", 2 ] } - common.npm(["ls"], opt, function (err, code) { - t.ifError(err, "error should not exist") - t.equal(code, 0, "npm ls exited with code") + var opt = { cwd: cwd, stdio: [ 'ignore', 'ignore', 2 ] } + common.npm(['ls'], opt, function (err, code) { + t.ifError(err, 'error should not exist') + t.equal(code, 0, 'npm ls exited with code') t.end() }) }) diff --git a/test/tap/404-parent.js b/test/tap/404-parent.js index e3f49f7ba..a8bd95163 100644 --- a/test/tap/404-parent.js +++ b/test/tap/404-parent.js @@ -1,52 +1,52 @@ -var common = require("../common-tap.js") -var test = require("tap").test -var npm = require("../../") -var osenv = require("osenv") -var path = require("path") -var fs = require("fs") -var rimraf = require("rimraf") -var mkdirp = require("mkdirp") -var pkg = path.resolve(__dirname, "404-parent") -var mr = require("npm-registry-mock") +var common = require('../common-tap.js') +var test = require('tap').test +var npm = require('../../') +var osenv = require('osenv') +var path = require('path') +var fs = require('fs') +var rimraf = require('rimraf') +var mkdirp = require('mkdirp') +var pkg = path.resolve(__dirname, '404-parent') +var mr = require('npm-registry-mock') -test("404-parent: if parent exists, specify parent in error message", function (t) { +test('404-parent: if parent exists, specify parent in error message', function (t) { setup() - rimraf.sync(path.resolve(pkg, "node_modules")) + rimraf.sync(path.resolve(pkg, 'node_modules')) performInstall(function (err) { - t.ok(err instanceof Error, "error was returned") - t.ok(err.parent === "404-parent-test", "error's parent set") + t.ok(err instanceof Error, 'error was returned') + t.ok(err.parent === '404-parent-test', "error's parent set") t.end() }) }) -test("cleanup", function (t) { +test('cleanup', function (t) { process.chdir(osenv.tmpdir()) rimraf.sync(pkg) t.end() }) -function setup() { +function setup () { mkdirp.sync(pkg) - mkdirp.sync(path.resolve(pkg, "cache")) - fs.writeFileSync(path.resolve(pkg, "package.json"), JSON.stringify({ - author: "Evan Lucas", - name: "404-parent-test", - version: "0.0.0", - description: "Test for 404-parent", + mkdirp.sync(path.resolve(pkg, 'cache')) + fs.writeFileSync(path.resolve(pkg, 'package.json'), JSON.stringify({ + author: 'Evan Lucas', + name: '404-parent-test', + version: '0.0.0', + description: 'Test for 404-parent', dependencies: { - "test-npm-404-parent-test": "*" + 'test-npm-404-parent-test': '*' } - }), "utf8") + }), 'utf8') process.chdir(pkg) } function plugin (server) { - server.get("/test-npm-404-parent-test") - .reply(404, {"error": "version not found"}) + server.get('/test-npm-404-parent-test') + .reply(404, {'error': 'version not found'}) } function performInstall (cb) { - mr({port : common.port, plugin : plugin}, function (er, s) { // create mock registry. + mr({port: common.port, plugin: plugin}, function (er, s) { // create mock registry. npm.load({registry: common.registry}, function () { var pwd = process.cwd() process.chdir(pkg) diff --git a/test/tap/access.js b/test/tap/access.js index 5ac1d6138..833a874a1 100644 --- a/test/tap/access.js +++ b/test/tap/access.js @@ -1,43 +1,43 @@ -var fs = require("fs") -var path = require("path") -var mkdirp = require("mkdirp") -var rimraf = require("rimraf") -var mr = require("npm-registry-mock") +var fs = require('fs') +var path = require('path') +var mkdirp = require('mkdirp') +var rimraf = require('rimraf') +var mr = require('npm-registry-mock') -var test = require("tap").test -var common = require("../common-tap.js") +var test = require('tap').test +var common = require('../common-tap.js') -var pkg = path.resolve(__dirname, "access") +var pkg = path.resolve(__dirname, 'access') var server var scoped = { - name : "@scoped/pkg", - version : "1.1.1" + name: '@scoped/pkg', + version: '1.1.1' } var body = { - access : "public" + access: 'public' } function mocks (server) { - server.post("/-/package/@scoped%2fpkg/access", JSON.stringify(body)) - .reply(200, { "access" : "public" }) - server.post("/-/package/@scoped%2fanother/access", JSON.stringify(body)) - .reply(200, { "access" : "public" }) + server.post('/-/package/@scoped%2fpkg/access', JSON.stringify(body)) + .reply(200, { 'access': 'public' }) + server.post('/-/package/@scoped%2fanother/access', JSON.stringify(body)) + .reply(200, { 'access': 'public' }) } -test("setup", function (t) { +test('setup', function (t) { mkdirp(pkg, function (er) { - t.ifError(er, pkg + " made successfully") + t.ifError(er, pkg + ' made successfully') - mr({port : common.port, plugin : mocks}, function (err, s) { + mr({port: common.port, plugin: mocks}, function (er, s) { server = s fs.writeFile( - path.join(pkg, "package.json"), + path.join(pkg, 'package.json'), JSON.stringify(scoped), function (er) { - t.ifError(er, "wrote package.json") + t.ifError(er, 'wrote package.json') t.end() } ) @@ -45,52 +45,52 @@ test("setup", function (t) { }) }) -test("npm access on current package", function (t) { +test('npm access on current package', function (t) { common.npm( [ - "access", - "public", - "--registry", common.registry, - "--loglevel", "silent" + 'access', + 'public', + '--registry', common.registry, + '--loglevel', 'silent' ], - { cwd : pkg }, + { cwd: pkg }, function (er, code, stdout, stderr) { - t.ifError(er, "npm access") - t.notOk(code, "exited OK") - t.notOk(stderr, "no error output") + t.ifError(er, 'npm access') + t.notOk(code, 'exited OK') + t.notOk(stderr, 'no error output') t.end() } ) }) -test("npm access on named package", function (t) { +test('npm access on named package', function (t) { common.npm( [ - "access", - "public", "@scoped/another", - "--registry", common.registry, - "--loglevel", "silent" + 'access', + 'public', '@scoped/another', + '--registry', common.registry, + '--loglevel', 'silent' ], - { cwd : pkg }, + { cwd: pkg }, function (er, code, stdout, stderr) { - t.ifError(er, "npm access") - t.notOk(code, "exited OK") - t.notOk(stderr, "no error output") + t.ifError(er, 'npm access') + t.notOk(code, 'exited OK') + t.notOk(stderr, 'no error output') t.end() } ) }) -test("npm change access on unscoped package", function (t) { +test('npm change access on unscoped package', function (t) { common.npm( [ - "access", - "restricted", "yargs", - "--registry", common.registry + 'access', + 'restricted', 'yargs', + '--registry', common.registry ], - { cwd : pkg }, + { cwd: pkg }, function (er, code, stdout, stderr) { t.ok(code, 'exited with Error') t.ok(stderr.match(/you can't change the access level of unscoped packages/)) @@ -102,11 +102,11 @@ test("npm change access on unscoped package", function (t) { test('npm access add', function (t) { common.npm( [ - "access", - "add", "@scoped/another", - "--registry", common.registry + 'access', + 'add', '@scoped/another', + '--registry', common.registry ], - { cwd : pkg }, + { cwd: pkg }, function (er, code, stdout, stderr) { t.ok(code, 'exited with Error') t.ok(stderr.match(/npm access add isn't implemented yet!/)) @@ -118,11 +118,11 @@ test('npm access add', function (t) { test('npm access rm', function (t) { common.npm( [ - "access", - "rm", "@scoped/another", - "--registry", common.registry + 'access', + 'rm', '@scoped/another', + '--registry', common.registry ], - { cwd : pkg }, + { cwd: pkg }, function (er, code, stdout, stderr) { t.ok(code, 'exited with Error') t.ok(stderr.match(/npm access rm isn't implemented yet!/)) @@ -134,11 +134,11 @@ test('npm access rm', function (t) { test('npm access ls', function (t) { common.npm( [ - "access", - "ls", "@scoped/another", - "--registry", common.registry + 'access', + 'ls', '@scoped/another', + '--registry', common.registry ], - { cwd : pkg }, + { cwd: pkg }, function (er, code, stdout, stderr) { t.ok(code, 'exited with Error') t.ok(stderr.match(/npm access ls isn't implemented yet!/)) @@ -150,11 +150,11 @@ test('npm access ls', function (t) { test('npm access edit', function (t) { common.npm( [ - "access", - "edit", "@scoped/another", - "--registry", common.registry + 'access', + 'edit', '@scoped/another', + '--registry', common.registry ], - { cwd : pkg }, + { cwd: pkg }, function (er, code, stdout, stderr) { t.ok(code, 'exited with Error') t.ok(stderr.match(/npm access edit isn't implemented yet!/)) @@ -166,11 +166,11 @@ test('npm access edit', function (t) { test('npm access blerg', function (t) { common.npm( [ - "access", - "blerg", "@scoped/another", - "--registry", common.registry + 'access', + 'blerg', '@scoped/another', + '--registry', common.registry ], - { cwd : pkg }, + { cwd: pkg }, function (er, code, stdout, stderr) { t.ok(code, 'exited with Error') t.ok(stderr.match(/Usage:/)) @@ -179,8 +179,8 @@ test('npm access blerg', function (t) { ) }) -test("cleanup", function (t) { - t.pass("cleaned up") +test('cleanup', function (t) { + t.pass('cleaned up') rimraf.sync(pkg) server.close() t.end() diff --git a/test/tap/add-remote-git-fake-windows.js b/test/tap/add-remote-git-fake-windows.js index c9c9dd446..33b38781a 100644 --- a/test/tap/add-remote-git-fake-windows.js +++ b/test/tap/add-remote-git-fake-windows.js @@ -29,7 +29,6 @@ var pjChild = JSON.stringify({ version: '1.0.3' }, null, 2) + '\n' - test('setup', function (t) { bootstrap() setup(function (er, r) { diff --git a/test/tap/adduser-always-auth.js b/test/tap/adduser-always-auth.js index 6a451b451..3ec819000 100644 --- a/test/tap/adduser-always-auth.js +++ b/test/tap/adduser-always-auth.js @@ -1,142 +1,147 @@ -var fs = require("fs") -var path = require("path") -var rimraf = require("rimraf") -var mr = require("npm-registry-mock") +var fs = require('fs') +var path = require('path') +var rimraf = require('rimraf') +var mr = require('npm-registry-mock') -var test = require("tap").test -var common = require("../common-tap.js") +var test = require('tap').test +var common = require('../common-tap.js') -var opts = {cwd : __dirname} -var outfile = path.resolve(__dirname, "_npmrc") +var opts = {cwd: __dirname} +var outfile = path.resolve(__dirname, '_npmrc') var responses = { - "Username" : "u\n", - "Password" : "p\n", - "Email" : "u@p.me\n" + 'Username': 'u\n', + 'Password': 'p\n', + 'Email': 'u@p.me\n' } -function mocks(server) { +function mocks (server) { server.filteringRequestBody(function (r) { if (r.match(/\"_id\":\"org\.couchdb\.user:u\"/)) { - return "auth" + return 'auth' } }) - server.put("/-/user/org.couchdb.user:u", "auth") - .reply(201, {username : "u", password : "p", email : "u@p.me"}) + server.put('/-/user/org.couchdb.user:u', 'auth') + .reply(201, { username: 'u', password: 'p', email: 'u@p.me' }) } -test("npm login", function (t) { - mr({port : common.port, plugin : mocks}, function (er, s) { +test('npm login', function (t) { + mr({ port: common.port, plugin: mocks }, function (er, s) { var runner = common.npm( [ - "login", - "--registry", common.registry, - "--loglevel", "silent", - "--userconfig", outfile + 'login', + '--registry', common.registry, + '--loglevel', 'silent', + '--userconfig', outfile ], opts, function (err, code) { - t.notOk(code, "exited OK") - t.notOk(err, "no error output") - var config = fs.readFileSync(outfile, "utf8") - t.like(config, /:always-auth=false/, "always-auth is scoped and false (by default)") + t.notOk(code, 'exited OK') + t.notOk(err, 'no error output') + var config = fs.readFileSync(outfile, 'utf8') + t.like(config, /:always-auth=false/, 'always-auth is scoped and false (by default)') s.close() rimraf(outfile, function (err) { - t.ifError(err, "removed config file OK") + t.ifError(err, 'removed config file OK') t.end() }) }) - var o = "", e = "", remaining = Object.keys(responses).length - runner.stdout.on("data", function (chunk) { + var o = '' + var e = '' + var remaining = Object.keys(responses).length + runner.stdout.on('data', function (chunk) { remaining-- o += chunk - var label = chunk.toString("utf8").split(":")[0] + var label = chunk.toString('utf8').split(':')[0] runner.stdin.write(responses[label]) if (remaining === 0) runner.stdin.end() }) - runner.stderr.on("data", function (chunk) { e += chunk }) + runner.stderr.on('data', function (chunk) { e += chunk }) }) }) -test("npm login --always-auth", function (t) { - mr({port : common.port, plugin : mocks}, function (er, s) { +test('npm login --always-auth', function (t) { + mr({ port: common.port, plugin: mocks }, function (er, s) { var runner = common.npm( [ - "login", - "--registry", common.registry, - "--loglevel", "silent", - "--userconfig", outfile, - "--always-auth" + 'login', + '--registry', common.registry, + '--loglevel', 'silent', + '--userconfig', outfile, + '--always-auth' ], opts, function (err, code) { - t.notOk(code, "exited OK") - t.notOk(err, "no error output") - var config = fs.readFileSync(outfile, "utf8") - t.like(config, /:always-auth=true/, "always-auth is scoped and true") + t.notOk(code, 'exited OK') + t.notOk(err, 'no error output') + var config = fs.readFileSync(outfile, 'utf8') + t.like(config, /:always-auth=true/, 'always-auth is scoped and true') s.close() rimraf(outfile, function (err) { - t.ifError(err, "removed config file OK") + t.ifError(err, 'removed config file OK') t.end() }) }) - var o = "", e = "", remaining = Object.keys(responses).length - runner.stdout.on("data", function (chunk) { + var o = '' + var e = '' + var remaining = Object.keys(responses).length + runner.stdout.on('data', function (chunk) { remaining-- o += chunk - var label = chunk.toString("utf8").split(":")[0] + var label = chunk.toString('utf8').split(':')[0] runner.stdin.write(responses[label]) if (remaining === 0) runner.stdin.end() }) - runner.stderr.on("data", function (chunk) { e += chunk }) + runner.stderr.on('data', function (chunk) { e += chunk }) }) }) -test("npm login --no-always-auth", function (t) { - mr({port : common.port, plugin : mocks}, function (er, s) { +test('npm login --no-always-auth', function (t) { + mr({ port: common.port, plugin: mocks }, function (er, s) { var runner = common.npm( [ - "login", - "--registry", common.registry, - "--loglevel", "silent", - "--userconfig", outfile, - "--no-always-auth" + 'login', + '--registry', common.registry, + '--loglevel', 'silent', + '--userconfig', outfile, + '--no-always-auth' ], opts, function (err, code) { - t.notOk(code, "exited OK") - t.notOk(err, "no error output") - var config = fs.readFileSync(outfile, "utf8") - t.like(config, /:always-auth=false/, "always-auth is scoped and false") + t.notOk(code, 'exited OK') + t.notOk(err, 'no error output') + var config = fs.readFileSync(outfile, 'utf8') + t.like(config, /:always-auth=false/, 'always-auth is scoped and false') s.close() rimraf(outfile, function (err) { - t.ifError(err, "removed config file OK") + t.ifError(err, 'removed config file OK') t.end() }) }) - var o = "", e = "", remaining = Object.keys(responses).length - runner.stdout.on("data", function (chunk) { + var o = '' + var e = '' + var remaining = Object.keys(responses).length + runner.stdout.on('data', function (chunk) { remaining-- o += chunk - var label = chunk.toString("utf8").split(":")[0] + var label = chunk.toString('utf8').split(':')[0] runner.stdin.write(responses[label]) if (remaining === 0) runner.stdin.end() }) - runner.stderr.on("data", function (chunk) { e += chunk }) + runner.stderr.on('data', function (chunk) { e += chunk }) }) }) - -test("cleanup", function (t) { +test('cleanup', function (t) { rimraf.sync(outfile) - t.pass("cleaned up") + t.pass('cleaned up') t.end() }) diff --git a/test/tap/adduser-legacy-auth.js b/test/tap/adduser-legacy-auth.js index f9829c618..885a685b9 100644 --- a/test/tap/adduser-legacy-auth.js +++ b/test/tap/adduser-legacy-auth.js @@ -73,7 +73,9 @@ test('npm login', function (t) { }) }) - var o = '', e = '', remaining = Object.keys(responses).length + var o = '' + var e = '' + var remaining = Object.keys(responses).length runner.stdout.on('data', function (chunk) { remaining-- o += chunk diff --git a/test/tap/bin.js b/test/tap/bin.js index ee4e1ff28..55ca894bb 100644 --- a/test/tap/bin.js +++ b/test/tap/bin.js @@ -1,17 +1,17 @@ -var path = require("path") -var test = require("tap").test -var common = require("../common-tap.js") +var path = require('path') +var test = require('tap').test +var common = require('../common-tap.js') var opts = { cwd: __dirname } -var binDir = "../../node_modules/.bin" +var binDir = '../../node_modules/.bin' var fixture = path.resolve(__dirname, binDir) test('npm bin', function (t) { - common.npm(["bin"], opts, function (err, code, stdout, stderr) { - t.ifError(err, "bin ran without issue") - t.notOk(stderr, "should have no stderr") - t.equal(code, 0, "exit ok") + common.npm(['bin'], opts, function (err, code, stdout, stderr) { + t.ifError(err, 'bin ran without issue') + t.notOk(stderr, 'should have no stderr') + t.equal(code, 0, 'exit ok') var res = path.resolve(stdout) - t.equal(res, fixture + "\n") + t.equal(res, fixture + '\n') t.end() }) }) diff --git a/test/tap/bugs.js b/test/tap/bugs.js index 51ba5d3fe..a0a3be1b8 100644 --- a/test/tap/bugs.js +++ b/test/tap/bugs.js @@ -1,151 +1,151 @@ -if (process.platform === "win32") { - console.error("skipping test, because windows and shebangs") - return +if (process.platform === 'win32') { + console.error('skipping test, because windows and shebangs') + process.exit(0) } -var common = require("../common-tap.js") -var mr = require("npm-registry-mock") +var common = require('../common-tap.js') +var mr = require('npm-registry-mock') -var test = require("tap").test -var rimraf = require("rimraf") -var fs = require("fs") -var path = require("path") +var test = require('tap').test +var rimraf = require('rimraf') +var fs = require('fs') +var path = require('path') var join = path.join -var outFile = path.join(__dirname, "/_output") +var outFile = path.join(__dirname, '/_output') var opts = { cwd: __dirname } -test("setup", function (t) { - var s = "#!/usr/bin/env bash\n" + - "echo \"$@\" > " + JSON.stringify(__dirname) + "/_output\n" - fs.writeFileSync(join(__dirname, "/_script.sh"), s, "ascii") - fs.chmodSync(join(__dirname, "/_script.sh"), "0755") - t.pass("made script") +test('setup', function (t) { + var s = '#!/usr/bin/env bash\n' + + 'echo \"$@\" > ' + JSON.stringify(__dirname) + '/_output\n' + fs.writeFileSync(join(__dirname, '/_script.sh'), s, 'ascii') + fs.chmodSync(join(__dirname, '/_script.sh'), '0755') + t.pass('made script') t.end() }) -test("npm bugs underscore", function (t) { - mr({port : common.port}, function (er, s) { +test('npm bugs underscore', function (t) { + mr({ port: common.port }, function (er, s) { common.npm([ - "bugs", "underscore", - "--registry=" + common.registry, - "--loglevel=silent", - "--browser=" + join(__dirname, "/_script.sh") + 'bugs', 'underscore', + '--registry=' + common.registry, + '--loglevel=silent', + '--browser=' + join(__dirname, '/_script.sh') ], opts, function (err, code, stdout, stderr) { - t.ifError(err, "bugs ran without issue") - t.notOk(stderr, "should have no stderr") - t.equal(code, 0, "exit ok") - var res = fs.readFileSync(outFile, "ascii") + t.ifError(err, 'bugs ran without issue') + t.notOk(stderr, 'should have no stderr') + t.equal(code, 0, 'exit ok') + var res = fs.readFileSync(outFile, 'ascii') s.close() - t.equal(res, "https://github.com/jashkenas/underscore/issues\n") + t.equal(res, 'https://github.com/jashkenas/underscore/issues\n') rimraf.sync(outFile) t.end() }) }) }) -test("npm bugs optimist - github (https://)", function (t) { - mr({port : common.port}, function (er, s) { +test('npm bugs optimist - github (https://)', function (t) { + mr({ port: common.port }, function (er, s) { common.npm([ - "bugs", "optimist", - "--registry=" + common.registry, - "--loglevel=silent", - "--browser=" + join(__dirname, "/_script.sh") + 'bugs', 'optimist', + '--registry=' + common.registry, + '--loglevel=silent', + '--browser=' + join(__dirname, '/_script.sh') ], opts, function (err, code, stdout, stderr) { - t.ifError(err, "bugs ran without issue") - t.notOk(stderr, "should have no stderr") - t.equal(code, 0, "exit ok") - var res = fs.readFileSync(outFile, "ascii") + t.ifError(err, 'bugs ran without issue') + t.notOk(stderr, 'should have no stderr') + t.equal(code, 0, 'exit ok') + var res = fs.readFileSync(outFile, 'ascii') s.close() - t.equal(res, "https://github.com/substack/node-optimist/issues\n") + t.equal(res, 'https://github.com/substack/node-optimist/issues\n') rimraf.sync(outFile) t.end() }) }) }) -test("npm bugs npm-test-peer-deps - no repo", function (t) { - mr({port : common.port}, function (er, s) { +test('npm bugs npm-test-peer-deps - no repo', function (t) { + mr({ port: common.port }, function (er, s) { common.npm([ - "bugs", "npm-test-peer-deps", - "--registry=" + common.registry, - "--loglevel=silent", - "--browser=" + join(__dirname, "/_script.sh") + 'bugs', 'npm-test-peer-deps', + '--registry=' + common.registry, + '--loglevel=silent', + '--browser=' + join(__dirname, '/_script.sh') ], opts, function (err, code, stdout, stderr) { - t.ifError(err, "bugs ran without issue") - t.notOk(stderr, "should have no stderr") - t.equal(code, 0, "exit ok") - var res = fs.readFileSync(outFile, "ascii") + t.ifError(err, 'bugs ran without issue') + t.notOk(stderr, 'should have no stderr') + t.equal(code, 0, 'exit ok') + var res = fs.readFileSync(outFile, 'ascii') s.close() - t.equal(res, "https://www.npmjs.org/package/npm-test-peer-deps\n") + t.equal(res, 'https://www.npmjs.org/package/npm-test-peer-deps\n') rimraf.sync(outFile) t.end() }) }) }) -test("npm bugs test-repo-url-http - non-github (http://)", function (t) { - mr({port : common.port}, function (er, s) { +test('npm bugs test-repo-url-http - non-github (http://)', function (t) { + mr({ port: common.port }, function (er, s) { common.npm([ - "bugs", "test-repo-url-http", - "--registry=" + common.registry, - "--loglevel=silent", - "--browser=" + join(__dirname, "/_script.sh") + 'bugs', 'test-repo-url-http', + '--registry=' + common.registry, + '--loglevel=silent', + '--browser=' + join(__dirname, '/_script.sh') ], opts, function (err, code, stdout, stderr) { - t.ifError(err, "bugs ran without issue") - t.notOk(stderr, "should have no stderr") - t.equal(code, 0, "exit ok") - var res = fs.readFileSync(outFile, "ascii") + t.ifError(err, 'bugs ran without issue') + t.notOk(stderr, 'should have no stderr') + t.equal(code, 0, 'exit ok') + var res = fs.readFileSync(outFile, 'ascii') s.close() - t.equal(res, "https://www.npmjs.org/package/test-repo-url-http\n") + t.equal(res, 'https://www.npmjs.org/package/test-repo-url-http\n') rimraf.sync(outFile) t.end() }) }) }) -test("npm bugs test-repo-url-https - non-github (https://)", function (t) { - mr({port : common.port}, function (er, s) { +test('npm bugs test-repo-url-https - non-github (https://)', function (t) { + mr({ port: common.port }, function (er, s) { common.npm([ - "bugs", "test-repo-url-https", - "--registry=" + common.registry, - "--loglevel=silent", - "--browser=" + join(__dirname, "/_script.sh") + 'bugs', 'test-repo-url-https', + '--registry=' + common.registry, + '--loglevel=silent', + '--browser=' + join(__dirname, '/_script.sh') ], opts, function (err, code, stdout, stderr) { - t.ifError(err, "bugs ran without issue") - t.notOk(stderr, "should have no stderr") - t.equal(code, 0, "exit ok") - var res = fs.readFileSync(outFile, "ascii") + t.ifError(err, 'bugs ran without issue') + t.notOk(stderr, 'should have no stderr') + t.equal(code, 0, 'exit ok') + var res = fs.readFileSync(outFile, 'ascii') s.close() - t.equal(res, "https://www.npmjs.org/package/test-repo-url-https\n") + t.equal(res, 'https://www.npmjs.org/package/test-repo-url-https\n') rimraf.sync(outFile) t.end() }) }) }) -test("npm bugs test-repo-url-ssh - non-github (ssh://)", function (t) { - mr({port : common.port}, function (er, s) { +test('npm bugs test-repo-url-ssh - non-github (ssh://)', function (t) { + mr({ port: common.port }, function (er, s) { common.npm([ - "bugs", "test-repo-url-ssh", - "--registry=" + common.registry, - "--loglevel=silent", - "--browser=" + join(__dirname, "/_script.sh") + 'bugs', 'test-repo-url-ssh', + '--registry=' + common.registry, + '--loglevel=silent', + '--browser=' + join(__dirname, '/_script.sh') ], opts, function (err, code, stdout, stderr) { - t.ifError(err, "bugs ran without issue") - t.notOk(stderr, "should have no stderr") - t.equal(code, 0, "exit ok") - var res = fs.readFileSync(outFile, "ascii") + t.ifError(err, 'bugs ran without issue') + t.notOk(stderr, 'should have no stderr') + t.equal(code, 0, 'exit ok') + var res = fs.readFileSync(outFile, 'ascii') s.close() - t.equal(res, "https://www.npmjs.org/package/test-repo-url-ssh\n") + t.equal(res, 'https://www.npmjs.org/package/test-repo-url-ssh\n') rimraf.sync(outFile) t.end() }) }) }) -test("cleanup", function (t) { - fs.unlinkSync(join(__dirname, "/_script.sh")) - t.pass("cleaned up") +test('cleanup', function (t) { + fs.unlinkSync(join(__dirname, '/_script.sh')) + t.pass('cleaned up') t.end() }) diff --git a/test/tap/build-already-built.js b/test/tap/build-already-built.js index 8e5546fe4..45aa1ba1c 100644 --- a/test/tap/build-already-built.js +++ b/test/tap/build-already-built.js @@ -1,64 +1,64 @@ // if "npm rebuild" is run with bundled dependencies, // message "already built" should not be error -var test = require("tap").test -var path = require("path") -var osenv = require("osenv") -var rimraf = require("rimraf") -var npmlog = require("npmlog") -var mkdirp = require("mkdirp") -var requireInject = require("require-inject") +var test = require('tap').test +var path = require('path') +var osenv = require('osenv') +var rimraf = require('rimraf') +var npmlog = require('npmlog') +var mkdirp = require('mkdirp') +var requireInject = require('require-inject') -var npm = require("../../lib/npm.js") +var npm = require('../../lib/npm.js') -var PKG_DIR = path.resolve(__dirname, "build-already-built") -var fakePkg = "foo" +var PKG_DIR = path.resolve(__dirname, 'build-already-built') +var fakePkg = 'foo' -test("setup", function (t) { +test('setup', function (t) { cleanup() t.end() }) test("issue #6735 build 'already built' message", function (t) { - npm.load({loglevel : "warn"}, function () { + npm.load({ loglevel: 'warn' }, function () { // capture log messages with level - var log = "" - npmlog.on("log", function (chunk) { - log += chunk.level + " " + chunk.message + "\n" + var log = '' + npmlog.on('log', function (chunk) { + log += chunk.level + ' ' + chunk.message + '\n' }) mkdirp.sync(fakePkg) var folder = path.resolve(fakePkg) - var global = npm.config.get("global") + var global = npm.config.get('global') - var build = requireInject("../../lib/build", { + var build = requireInject('../../lib/build', { }) - t.test("pin previous behavior", function (t) { + t.test('pin previous behavior', function (t) { build([fakePkg], global, false, false, function (err) { - t.ok(err, "build failed as expected") - t.similar(err.message, /package.json/, "missing package.json as expected") - t.notSimilar(log, /already built/, "no already built message written") + t.ok(err, 'build failed as expected') + t.similar(err.message, /package.json/, 'missing package.json as expected') + t.notSimilar(log, /already built/, 'no already built message written') t.end() }) }) - t.test("simulate rebuild of bundledDependency", function (t) { + t.test('simulate rebuild of bundledDependency', function (t) { - log = "" + log = '' build._didBuild[folder] = true build([fakePkg], global, false, false, function (err) { - t.ok(err, "build failed as expected") - t.similar(err.message, /package.json/, "missing package.json as expected") + t.ok(err, 'build failed as expected') + t.similar(err.message, /package.json/, 'missing package.json as expected') - t.similar(log, /already built/, "already built message written") - t.notSimilar(log, /ERR! already built/, "already built message written is not error") - t.similar(log, /info already built/, "already built message written is info") + t.similar(log, /already built/, 'already built message written') + t.notSimilar(log, /ERR! already built/, 'already built message written is not error') + t.similar(log, /info already built/, 'already built message written is info') t.end() }) @@ -68,8 +68,7 @@ test("issue #6735 build 'already built' message", function (t) { }) }) - -test("cleanup", function (t) { +test('cleanup', function (t) { cleanup() t.end() diff --git a/test/tap/builtin-config.js b/test/tap/builtin-config.js index eb5bb2a16..333282e68 100644 --- a/test/tap/builtin-config.js +++ b/test/tap/builtin-config.js @@ -1,60 +1,58 @@ -var fs = require("fs") +var fs = require('fs') -if (process.argv[2] === "write-builtin") { +if (process.argv[2] === 'write-builtin') { var pid = process.argv[3] - fs.writeFileSync("npmrc", "foo=bar\npid=" + pid + "\n") - return + fs.writeFileSync('npmrc', 'foo=bar\npid=' + pid + '\n') + process.exit(0) } -var rcdata = "foo=bar\npid=" + process.pid + "\n" -var common = require("../common-tap.js") -var path = require("path") -var rimraf = require("rimraf") -var mkdirp = require("mkdirp") -var folder = path.resolve(__dirname, "builtin-config") -var test = require("tap").test -var npm = path.resolve(__dirname, "../..") -var spawn = require("child_process").spawn +var common = require('../common-tap.js') +var path = require('path') +var rimraf = require('rimraf') +var mkdirp = require('mkdirp') +var folder = path.resolve(__dirname, 'builtin-config') +var test = require('tap').test +var npm = path.resolve(__dirname, '../..') +var spawn = require('child_process').spawn var node = process.execPath -test("setup", function (t) { +test('setup', function (t) { t.plan(1) rimraf.sync(folder) - mkdirp.sync(folder + "/first") - mkdirp.sync(folder + "/second") - mkdirp.sync(folder + "/cache") - mkdirp.sync(folder + "/tmp") + mkdirp.sync(folder + '/first') + mkdirp.sync(folder + '/second') + mkdirp.sync(folder + '/cache') + mkdirp.sync(folder + '/tmp') - t.pass("finished setup") + t.pass('finished setup') t.end() }) - -test("install npm into first folder", function (t) { +test('install npm into first folder', function (t) { t.plan(1) - var args = ["install", npm, "-g", - "--prefix=" + folder + "/first", - "--ignore-scripts", - "--cache=" + folder + "/cache", - "--loglevel=silent", - "--tmp=" + folder + "/tmp"] - common.npm(args, {stdio: "inherit"}, function (er, code) { + var args = ['install', npm, '-g', + '--prefix=' + folder + '/first', + '--ignore-scripts', + '--cache=' + folder + '/cache', + '--loglevel=silent', + '--tmp=' + folder + '/tmp'] + common.npm(args, {stdio: 'inherit'}, function (er, code) { if (er) throw er t.equal(code, 0) t.end() }) }) -test("write npmrc file", function (t) { +test('write npmrc file', function (t) { t.plan(1) - common.npm(["explore", "npm", "-g", - "--prefix=" + folder + "/first", - "--cache=" + folder + "/cache", - "--tmp=" + folder + "/tmp", - "--", - node, __filename, "write-builtin", process.pid + common.npm(['explore', 'npm', '-g', + '--prefix=' + folder + '/first', + '--cache=' + folder + '/cache', + '--tmp=' + folder + '/tmp', + '--', + node, __filename, 'write-builtin', process.pid ], - {"stdio": "inherit"}, + {'stdio': 'inherit'}, function (er, code) { if (er) throw er t.equal(code, 0) @@ -62,66 +60,73 @@ test("write npmrc file", function (t) { }) }) -test("use first npm to install second npm", function (t) { +test('use first npm to install second npm', function (t) { t.plan(3) // get the root location - common.npm([ "root", "-g", - "--prefix=" + folder + "/first", - "--cache=" + folder + "/cache", - "--tmp=" + folder + "/tmp", - ], {}, function (er, code, so) { - if (er) throw er - t.equal(code, 0) - var root = so.trim() - t.ok(fs.statSync(root).isDirectory()) + common.npm( + [ + 'root', '-g', + '--prefix=' + folder + '/first', + '--cache=' + folder + '/cache', + '--tmp=' + folder + '/tmp' + ], + {}, + function (er, code, so) { + if (er) throw er + t.equal(code, 0) + var root = so.trim() + t.ok(fs.statSync(root).isDirectory()) - var bin = path.resolve(root, "npm/bin/npm-cli.js") - spawn( node - , [ bin - , "install", npm - , "-g" - , "--prefix=" + folder + "/second" - , "--cache=" + folder + "/cache" - , "--tmp=" + folder + "/tmp" - ]) - .on("error", function (er) { throw er }) - .on("close", function (code) { - t.equal(code, 0, "code is zero") - t.end() - }) - }) + var bin = path.resolve(root, 'npm/bin/npm-cli.js') + spawn( + node, + [ + bin, + 'install', npm, + '-g', + '--prefix=' + folder + '/second', + '--cache=' + folder + '/cache', + '--tmp=' + folder + '/tmp' + ] + ) + .on('error', function (er) { throw er }) + .on('close', function (code) { + t.equal(code, 0, 'code is zero') + t.end() + }) + } + ) }) -test("verify that the builtin config matches", function (t) { +test('verify that the builtin config matches', function (t) { t.plan(3) - common.npm([ "root", "-g", - "--prefix=" + folder + "/first", - "--cache=" + folder + "/cache", - "--tmp=" + folder + "/tmp" + common.npm([ 'root', '-g', + '--prefix=' + folder + '/first', + '--cache=' + folder + '/cache', + '--tmp=' + folder + '/tmp' ], {}, function (er, code, so) { if (er) throw er t.equal(code, 0) var firstRoot = so.trim() - common.npm([ "root", "-g", - "--prefix=" + folder + "/second", - "--cache=" + folder + "/cache", - "--tmp=" + folder + "/tmp" + common.npm([ 'root', '-g', + '--prefix=' + folder + '/second', + '--cache=' + folder + '/cache', + '--tmp=' + folder + '/tmp' ], {}, function (er, code, so) { if (er) throw er t.equal(code, 0) var secondRoot = so.trim() - var firstRc = path.resolve(firstRoot, "npm", "npmrc") - var secondRc = path.resolve(secondRoot, "npm", "npmrc") - var firstData = fs.readFileSync(firstRc, "utf8") - var secondData = fs.readFileSync(secondRc, "utf8") + var firstRc = path.resolve(firstRoot, 'npm', 'npmrc') + var secondRc = path.resolve(secondRoot, 'npm', 'npmrc') + var firstData = fs.readFileSync(firstRc, 'utf8') + var secondData = fs.readFileSync(secondRc, 'utf8') t.equal(firstData, secondData) t.end() }) }) }) - -test("clean", function (t) { +test('clean', function (t) { rimraf.sync(folder) t.end() }) diff --git a/test/tap/cache-add-localdir-fallback.js b/test/tap/cache-add-localdir-fallback.js index facd95c3a..ca8696d22 100644 --- a/test/tap/cache-add-localdir-fallback.js +++ b/test/tap/cache-add-localdir-fallback.js @@ -1,84 +1,84 @@ -var path = require("path") -var test = require("tap").test -var npm = require("../../lib/npm.js") -var requireInject = require("require-inject") +var path = require('path') +var test = require('tap').test +var npm = require('../../lib/npm.js') +var requireInject = require('require-inject') -var realizePackageSpecifier = requireInject("realize-package-specifier", { - "fs": { +var realizePackageSpecifier = requireInject('realize-package-specifier', { + 'fs': { stat: function (file, cb) { process.nextTick(function () { switch (file) { - case path.resolve("named"): - cb(new Error("ENOENT")) + case path.resolve('named'): + cb(new Error('ENOENT')) break - case path.resolve("file.tgz"): + case path.resolve('file.tgz'): cb(null, { isDirectory: function () { return false } }) break - case path.resolve("dir-no-package"): + case path.resolve('dir-no-package'): cb(null, { isDirectory: function () { return true } }) break - case path.resolve("dir-no-package/package.json"): - cb(new Error("ENOENT")) + case path.resolve('dir-no-package/package.json'): + cb(new Error('ENOENT')) break - case path.resolve("dir-with-package"): + case path.resolve('dir-with-package'): cb(null, { isDirectory: function () { return true } }) break - case path.resolve("dir-with-package/package.json"): + case path.resolve('dir-with-package/package.json'): cb(null, {}) break - case path.resolve(__dirname, "dir-with-package"): + case path.resolve(__dirname, 'dir-with-package'): cb(null, { isDirectory: function () { return true } }) break - case path.join(__dirname, "dir-with-package", "package.json"): + case path.join(__dirname, 'dir-with-package', 'package.json'): cb(null, {}) break - case path.resolve(__dirname, "file.tgz"): + case path.resolve(__dirname, 'file.tgz'): cb(null, { isDirectory: function () { return false } }) break default: - throw new Error("Unknown test file passed to stat: " + file) + throw new Error('Unknown test file passed to stat: ' + file) } }) } } }) -npm.load({loglevel : "silent"}, function () { - var cache = requireInject("../../lib/cache.js", { - "realize-package-specifier": realizePackageSpecifier, - "../../lib/cache/add-named.js": function addNamed (name, version, data, cb) { - cb(null, "addNamed") +npm.load({ loglevel: 'silent' }, function () { + var cache = requireInject('../../lib/cache.js', { + 'realize-package-specifier': realizePackageSpecifier, + '../../lib/cache/add-named.js': function addNamed (name, version, data, cb) { + cb(null, 'addNamed') }, - "../../lib/cache/add-local.js": function addLocal (name, data, cb) { - cb(null, "addLocal") + '../../lib/cache/add-local.js': function addLocal (name, data, cb) { + cb(null, 'addLocal') } }) - test("npm install localdir fallback", function (t) { + test('npm install localdir fallback', function (t) { t.plan(12) - cache.add("named", null, null, false, function (er, which) { - t.ifError(er, "named was cached") - t.is(which, "addNamed", "registry package name") + cache.add('named', null, null, false, function (er, which) { + t.ifError(er, 'named was cached') + t.is(which, 'addNamed', 'registry package name') }) - cache.add("file.tgz", null, null, false, function (er, which) { - t.ifError(er, "file.tgz was cached") - t.is(which, "addLocal", "local file") + cache.add('file.tgz', null, null, false, function (er, which) { + t.ifError(er, 'file.tgz was cached') + t.is(which, 'addLocal', 'local file') }) - cache.add("dir-no-package", null, null, false, function (er, which) { - t.ifError(er, "local directory was cached") - t.is(which, "addNamed", "local directory w/o package.json") + cache.add('dir-no-package', null, null, false, function (er, which) { + t.ifError(er, 'local directory was cached') + t.is(which, 'addNamed', 'local directory w/o package.json') }) - cache.add("dir-with-package", null, null, false, function (er, which) { - t.ifError(er, "local directory with package was cached") - t.is(which,"addLocal", "local directory with package.json") + cache.add('dir-with-package', null, null, false, function (er, which) { + t.ifError(er, 'local directory with package was cached') + t.is(which, 'addLocal', 'local directory with package.json') }) - cache.add("file:./dir-with-package", null, __dirname, false, function (er, which) { - t.ifError(er, "local directory (as URI) with package was cached") - t.is(which, "addLocal", "file: URI to local directory with package.json") + cache.add('file:./dir-with-package', null, __dirname, false, function (er, which) { + t.ifError(er, 'local directory (as URI) with package was cached') + t.is(which, 'addLocal', 'file: URI to local directory with package.json') }) - cache.add("file:./file.tgz", null, __dirname, false, function (er, which) { - t.ifError(er, "local file (as URI) with package was cached") - t.is(which, "addLocal", "file: URI to local file with package.json") + cache.add('file:./file.tgz', null, __dirname, false, function (er, which) { + t.ifError(er, 'local file (as URI) with package was cached') + t.is(which, 'addLocal', 'file: URI to local file with package.json') }) }) }) diff --git a/test/tap/cache-add-unpublished.js b/test/tap/cache-add-unpublished.js index fe26929fc..fe6807f19 100644 --- a/test/tap/cache-add-unpublished.js +++ b/test/tap/cache-add-unpublished.js @@ -1,22 +1,21 @@ -var common = require("../common-tap.js") -var test = require("tap").test -var mr = require("npm-registry-mock") +var common = require('../common-tap.js') +var test = require('tap').test -test("cache add", function (t) { +test('cache add', function (t) { setup(function (er, s) { if (er) { throw er } common.npm([ - "cache", - "add", - "superfoo", - "--registry=http://localhost:1337/" + 'cache', + 'add', + 'superfoo', + '--registry=http://localhost:1337/' ], {}, function (er, c, so, se) { if (er) throw er - t.ok(c, "got non-zero exit code") - t.equal(so, "", "nothing printed to stdout") - t.similar(se, /404 Not Found: superfoo/, "got expected error") + t.ok(c, 'got non-zero exit code') + t.equal(so, '', 'nothing printed to stdout') + t.similar(se, /404 Not Found: superfoo/, 'got expected error') s.close() t.end() }) @@ -24,9 +23,9 @@ test("cache add", function (t) { }) function setup (cb) { - var s = require("http").createServer(function (req, res) { + var s = require('http').createServer(function (req, res) { res.statusCode = 404 - res.end("{\"error\":\"not_found\"}\n") + res.end('{\"error\":\"not_found\"}\n') }) s.listen(1337, function () { cb(null, s) diff --git a/test/tap/cache-shasum-fork.js b/test/tap/cache-shasum-fork.js index c87e8c10a..01c2f68fb 100644 --- a/test/tap/cache-shasum-fork.js +++ b/test/tap/cache-shasum-fork.js @@ -18,8 +18,8 @@ var pkg = path.resolve(__dirname, 'cache-shasum-fork') var cache = path.join(pkg, 'cache') var server -var installed_output = path.join(__dirname,"cache-shasum-fork") + - "\n`-- underscore@1.5.1 \n\n" +var installed_output = path.join(__dirname, 'cache-shasum-fork') + + '\n`-- underscore@1.5.1 \n\n' test('setup', function (t) { setup() diff --git a/test/tap/cache-shasum.js b/test/tap/cache-shasum.js index f86037cc8..90915ed85 100644 --- a/test/tap/cache-shasum.js +++ b/test/tap/cache-shasum.js @@ -1,58 +1,57 @@ -var npm = require.resolve("../../") -var test = require("tap").test -var path = require("path") -var rimraf = require("rimraf") -var mkdirp = require("mkdirp") -var mr = require("npm-registry-mock") -var common = require("../common-tap.js") -var cache = path.resolve(__dirname, "cache-shasum") -var spawn = require("child_process").spawn -var sha = require("sha") +var npm = require.resolve('../../') +var test = require('tap').test +var path = require('path') +var rimraf = require('rimraf') +var mkdirp = require('mkdirp') +var mr = require('npm-registry-mock') +var common = require('../common-tap.js') +var cache = path.resolve(__dirname, 'cache-shasum') +var spawn = require('child_process').spawn +var sha = require('sha') var server -test("mock reg", function (t) { +test('mock reg', function (t) { rimraf.sync(cache) mkdirp.sync(cache) - mr({port : common.port}, function (er, s) { + mr({ port: common.port }, function (er, s) { server = s - t.pass("ok") + t.pass('ok') t.end() }) }) -test("npm cache add request", function (t) { +test('npm cache add request', function (t) { var c = spawn(process.execPath, [ - npm, "cache", "add", "request@2.27.0", - "--cache=" + cache, - "--registry=" + common.registry, - "--loglevel=quiet" + npm, 'cache', 'add', 'request@2.27.0', + '--cache=' + cache, + '--registry=' + common.registry, + '--loglevel=quiet' ]) c.stderr.pipe(process.stderr) - c.stdout.on("data", function (d) { - t.fail("Should not get data on stdout: " + d) + c.stdout.on('data', function (d) { + t.fail('Should not get data on stdout: ' + d) }) - c.on("close", function (code) { - t.notOk(code, "exit ok") + c.on('close', function (code) { + t.notOk(code, 'exit ok') t.end() }) }) -test("compare", function (t) { - var d = path.resolve(__dirname, "cache-shasum/request") - var p = path.resolve(d, "2.27.0/package.tgz") - var r = require("./cache-shasum/localhost_1337/request/.cache.json") - var rshasum = r.versions["2.27.0"].dist.shasum +test('compare', function (t) { + var d = path.resolve(__dirname, 'cache-shasum/request') + var p = path.resolve(d, '2.27.0/package.tgz') + var r = require('./cache-shasum/localhost_1337/request/.cache.json') + var rshasum = r.versions['2.27.0'].dist.shasum sha.get(p, function (er, pshasum) { - if (er) - throw er + if (er) throw er t.equal(pshasum, rshasum) t.end() }) }) -test("cleanup", function (t) { +test('cleanup', function (t) { server.close() rimraf.sync(cache) t.end() diff --git a/test/tap/config-basic.js b/test/tap/config-basic.js index d5a950a8e..82fa8ab58 100644 --- a/test/tap/config-basic.js +++ b/test/tap/config-basic.js @@ -1,57 +1,58 @@ -var test = require("tap").test -var npmconf = require("../../lib/config/core.js") -var common = require("./00-config-setup.js") -var path = require("path") +var test = require('tap').test +var npmconf = require('../../lib/config/core.js') +var common = require('./00-config-setup.js') +var path = require('path') var projectData = { - "save-prefix": "~", - "proprietary-attribs": false + 'save-prefix': '~', + 'proprietary-attribs': false } var ucData = common.ucData var envData = common.envData var envDataFix = common.envDataFix -var gcData = { "package-config:foo": "boo" } +var gcData = { 'package-config:foo': 'boo' } var biData = {} -var cli = { foo: "bar", umask: 022 } +var cli = { foo: 'bar', umask: parseInt('022', 8) } -var expectList = -[ cli, +var expectList = [ + cli, envDataFix, projectData, ucData, gcData, - biData ] + biData +] var expectSources = { cli: { data: cli }, env: { data: envDataFix, source: envData, - prefix: "" + prefix: '' }, project: { - path: path.resolve(__dirname, "..", "..", ".npmrc"), - type: "ini", + path: path.resolve(__dirname, '..', '..', '.npmrc'), + type: 'ini', data: projectData }, user: { path: common.userconfig, - type: "ini", + type: 'ini', data: ucData }, global: { path: common.globalconfig, - type: "ini", + type: 'ini', data: gcData }, builtin: { data: biData } } -test("no builtin", function (t) { +test('no builtin', function (t) { npmconf.load(cli, function (er, conf) { if (er) throw er t.same(conf.list, expectList) @@ -59,8 +60,8 @@ test("no builtin", function (t) { t.same(npmconf.rootConf.list, []) t.equal(npmconf.rootConf.root, npmconf.defs.defaults) t.equal(conf.root, npmconf.defs.defaults) - t.equal(conf.get("umask"), 022) - t.equal(conf.get("heading"), "npm") + t.equal(conf.get('umask'), parseInt('022', 8)) + t.equal(conf.get('heading'), 'npm') t.end() }) }) diff --git a/test/tap/config-builtin.js b/test/tap/config-builtin.js index 5a1589ff6..708eb3056 100644 --- a/test/tap/config-builtin.js +++ b/test/tap/config-builtin.js @@ -1,22 +1,22 @@ -var test = require("tap").test -var npmconf = require("../../lib/config/core.js") -var common = require("./00-config-setup.js") -var path = require("path") +var test = require('tap').test +var npmconf = require('../../lib/config/core.js') +var common = require('./00-config-setup.js') +var path = require('path') var ucData = common.ucData var envData = common.envData var envDataFix = common.envDataFix -var gcData = { "package-config:foo": "boo" } +var gcData = { 'package-config:foo': 'boo' } -var biData = { "builtin-config": true } +var biData = { 'builtin-config': true } -var cli = { foo: "bar", heading: "foo", "git-tag-version": false } +var cli = { foo: 'bar', heading: 'foo', 'git-tag-version': false } var projectData = { - "save-prefix": "~", - "proprietary-attribs": false + 'save-prefix': '~', + 'proprietary-attribs': false } var expectList = [ @@ -33,27 +33,27 @@ var expectSources = { env: { data: envDataFix, source: envData, - prefix: "" + prefix: '' }, project: { - path: path.resolve(__dirname, "..", "..", ".npmrc"), - type: "ini", + path: path.resolve(__dirname, '..', '..', '.npmrc'), + type: 'ini', data: projectData }, user: { path: common.userconfig, - type: "ini", + type: 'ini', data: ucData }, global: { path: common.globalconfig, - type: "ini", + type: 'ini', data: gcData }, builtin: { data: biData } } -test("with builtin", function (t) { +test('with builtin', function (t) { npmconf.load(cli, common.builtin, function (er, conf) { if (er) throw er t.same(conf.list, expectList) @@ -61,8 +61,8 @@ test("with builtin", function (t) { t.same(npmconf.rootConf.list, []) t.equal(npmconf.rootConf.root, npmconf.defs.defaults) t.equal(conf.root, npmconf.defs.defaults) - t.equal(conf.get("heading"), "foo") - t.equal(conf.get("git-tag-version"), false) + t.equal(conf.get('heading'), 'foo') + t.equal(conf.get('git-tag-version'), false) t.end() }) }) diff --git a/test/tap/config-certfile.js b/test/tap/config-certfile.js index 25de9963a..223ff3419 100644 --- a/test/tap/config-certfile.js +++ b/test/tap/config-certfile.js @@ -1,18 +1,18 @@ -require("./00-config-setup.js") +require('./00-config-setup.js') -var path = require("path") -var fs = require("fs") -var test = require("tap").test -var npmconf = require("../../lib/config/core.js") +var path = require('path') +var fs = require('fs') +var test = require('tap').test +var npmconf = require('../../lib/config/core.js') -test("cafile loads as ca", function (t) { - var cafile = path.join(__dirname, "..", "fixtures", "config", "multi-ca") +test('cafile loads as ca', function (t) { + var cafile = path.join(__dirname, '..', 'fixtures', 'config', 'multi-ca') npmconf.load({cafile: cafile}, function (er, conf) { if (er) throw er - t.same(conf.get("cafile"), cafile) - t.same(conf.get("ca").join("\n"), fs.readFileSync(cafile, "utf8").trim()) + t.same(conf.get('cafile'), cafile) + t.same(conf.get('ca').join('\n'), fs.readFileSync(cafile, 'utf8').trim()) t.end() }) }) diff --git a/test/tap/config-credentials.js b/test/tap/config-credentials.js index 1cb2a7eb4..c1b981d0a 100644 --- a/test/tap/config-credentials.js +++ b/test/tap/config-credentials.js @@ -1,350 +1,350 @@ -var test = require("tap").test +var test = require('tap').test -var npmconf = require("../../lib/config/core.js") -var common = require("./00-config-setup.js") +var npmconf = require('../../lib/config/core.js') +var common = require('./00-config-setup.js') -var URI = "https://registry.lvh.me:8661/" +var URI = 'https://registry.lvh.me:8661/' -test("getting scope with no credentials set", function (t) { +test('getting scope with no credentials set', function (t) { npmconf.load({}, function (er, conf) { - t.ifError(er, "configuration loaded") + t.ifError(er, 'configuration loaded') var basic = conf.getCredentialsByURI(URI) - t.equal(basic.scope, "//registry.lvh.me:8661/", "nerfed URL extracted") + t.equal(basic.scope, '//registry.lvh.me:8661/', 'nerfed URL extracted') t.end() }) }) -test("trying to set credentials with no URI", function (t) { +test('trying to set credentials with no URI', function (t) { npmconf.load(common.builtin, function (er, conf) { - t.ifError(er, "configuration loaded") + t.ifError(er, 'configuration loaded') t.throws(function () { conf.setCredentialsByURI() - }, "enforced missing URI") + }, 'enforced missing URI') t.end() }) }) -test("trying to clear credentials with no URI", function (t) { +test('trying to clear credentials with no URI', function (t) { npmconf.load(common.builtin, function (er, conf) { - t.ifError(er, "configuration loaded") + t.ifError(er, 'configuration loaded') t.throws(function () { conf.clearCredentialsByURI() - }, "enforced missing URI") + }, 'enforced missing URI') t.end() }) }) -test("set with missing credentials object", function (t) { +test('set with missing credentials object', function (t) { npmconf.load(common.builtin, function (er, conf) { - t.ifError(er, "configuration loaded") + t.ifError(er, 'configuration loaded') t.throws(function () { conf.setCredentialsByURI(URI) - }, "enforced missing credentials") + }, 'enforced missing credentials') t.end() }) }) -test("set with empty credentials object", function (t) { +test('set with empty credentials object', function (t) { npmconf.load(common.builtin, function (er, conf) { - t.ifError(er, "configuration loaded") + t.ifError(er, 'configuration loaded') t.throws(function () { conf.setCredentialsByURI(URI, {}) - }, "enforced missing credentials") + }, 'enforced missing credentials') t.end() }) }) -test("set with token", function (t) { +test('set with token', function (t) { npmconf.load(common.builtin, function (er, conf) { - t.ifError(er, "configuration loaded") + t.ifError(er, 'configuration loaded') t.doesNotThrow(function () { - conf.setCredentialsByURI(URI, {token : "simple-token"}) - }, "needs only token") + conf.setCredentialsByURI(URI, { token: 'simple-token' }) + }, 'needs only token') var expected = { - scope : "//registry.lvh.me:8661/", - token : "simple-token", - username : undefined, - password : undefined, - email : undefined, - auth : undefined, - alwaysAuth : undefined + scope: '//registry.lvh.me:8661/', + token: 'simple-token', + username: undefined, + password: undefined, + email: undefined, + auth: undefined, + alwaysAuth: undefined } - t.same(conf.getCredentialsByURI(URI), expected, "got bearer token and scope") + t.same(conf.getCredentialsByURI(URI), expected, 'got bearer token and scope') t.end() }) }) -test("clear with token", function (t) { +test('clear with token', function (t) { npmconf.load(common.builtin, function (er, conf) { - t.ifError(er, "configuration loaded") + t.ifError(er, 'configuration loaded') t.doesNotThrow(function () { - conf.setCredentialsByURI(URI, {token : "simple-token"}) - }, "needs only token") + conf.setCredentialsByURI(URI, { token: 'simple-token' }) + }, 'needs only token') t.doesNotThrow(function () { conf.clearCredentialsByURI(URI) - }, "needs only URI") + }, 'needs only URI') - t.notOk(conf.getCredentialsByURI(URI).token, "token all gone") + t.notOk(conf.getCredentialsByURI(URI).token, 'token all gone') t.end() }) }) -test("set with missing username", function (t) { +test('set with missing username', function (t) { npmconf.load(common.builtin, function (er, conf) { - t.ifError(er, "configuration loaded") + t.ifError(er, 'configuration loaded') var credentials = { - password : "password", - email : "ogd@aoaioxxysz.net" + password: 'password', + email: 'ogd@aoaioxxysz.net' } t.throws(function () { conf.setCredentialsByURI(URI, credentials) - }, "enforced missing email") + }, 'enforced missing email') t.end() }) }) -test("set with missing password", function (t) { +test('set with missing password', function (t) { npmconf.load(common.builtin, function (er, conf) { - t.ifError(er, "configuration loaded") + t.ifError(er, 'configuration loaded') var credentials = { - username : "username", - email : "ogd@aoaioxxysz.net" + username: 'username', + email: 'ogd@aoaioxxysz.net' } t.throws(function () { conf.setCredentialsByURI(URI, credentials) - }, "enforced missing email") + }, 'enforced missing email') t.end() }) }) -test("set with missing email", function (t) { +test('set with missing email', function (t) { npmconf.load(common.builtin, function (er, conf) { - t.ifError(er, "configuration loaded") + t.ifError(er, 'configuration loaded') var credentials = { - username : "username", - password : "password" + username: 'username', + password: 'password' } t.throws(function () { conf.setCredentialsByURI(URI, credentials) - }, "enforced missing email") + }, 'enforced missing email') t.end() }) }) -test("set with old-style credentials", function (t) { +test('set with old-style credentials', function (t) { npmconf.load(common.builtin, function (er, conf) { - t.ifError(er, "configuration loaded") + t.ifError(er, 'configuration loaded') var credentials = { - username : "username", - password : "password", - email : "ogd@aoaioxxysz.net" + username: 'username', + password: 'password', + email: 'ogd@aoaioxxysz.net' } t.doesNotThrow(function () { conf.setCredentialsByURI(URI, credentials) - }, "requires all of username, password, and email") + }, 'requires all of username, password, and email') var expected = { - scope : "//registry.lvh.me:8661/", - token : undefined, - username : "username", - password : "password", - email : "ogd@aoaioxxysz.net", - auth : "dXNlcm5hbWU6cGFzc3dvcmQ=", - alwaysAuth : false + scope: '//registry.lvh.me:8661/', + token: undefined, + username: 'username', + password: 'password', + email: 'ogd@aoaioxxysz.net', + auth: 'dXNlcm5hbWU6cGFzc3dvcmQ=', + alwaysAuth: false } - t.same(conf.getCredentialsByURI(URI), expected, "got credentials") + t.same(conf.getCredentialsByURI(URI), expected, 'got credentials') t.end() }) }) -test("clear with old-style credentials", function (t) { +test('clear with old-style credentials', function (t) { npmconf.load(common.builtin, function (er, conf) { - t.ifError(er, "configuration loaded") + t.ifError(er, 'configuration loaded') var credentials = { - username : "username", - password : "password", - email : "ogd@aoaioxxysz.net" + username: 'username', + password: 'password', + email: 'ogd@aoaioxxysz.net' } t.doesNotThrow(function () { conf.setCredentialsByURI(URI, credentials) - }, "requires all of username, password, and email") + }, 'requires all of username, password, and email') t.doesNotThrow(function () { conf.clearCredentialsByURI(URI) - }, "clearing only required URI") + }, 'clearing only required URI') - t.notOk(conf.getCredentialsByURI(URI).username, "username cleared") - t.notOk(conf.getCredentialsByURI(URI).password, "password cleared") + t.notOk(conf.getCredentialsByURI(URI).username, 'username cleared') + t.notOk(conf.getCredentialsByURI(URI).password, 'password cleared') t.end() }) }) -test("get old-style credentials for default registry", function (t) { +test('get old-style credentials for default registry', function (t) { npmconf.load(common.builtin, function (er, conf) { - var actual = conf.getCredentialsByURI(conf.get("registry")) + var actual = conf.getCredentialsByURI(conf.get('registry')) var expected = { - scope : "//registry.npmjs.org/", - token : undefined, - password : "password", - username : "username", - email : "i@izs.me", - auth : "dXNlcm5hbWU6cGFzc3dvcmQ=", - alwaysAuth : false + scope: '//registry.npmjs.org/', + token: undefined, + password: 'password', + username: 'username', + email: 'i@izs.me', + auth: 'dXNlcm5hbWU6cGFzc3dvcmQ=', + alwaysAuth: false } t.same(actual, expected) t.end() }) }) -test("set with always-auth enabled", function (t) { +test('set with always-auth enabled', function (t) { npmconf.load(common.builtin, function (er, conf) { - t.ifError(er, "configuration loaded") + t.ifError(er, 'configuration loaded') var credentials = { - username : "username", - password : "password", - email : "ogd@aoaioxxysz.net", - alwaysAuth : true + username: 'username', + password: 'password', + email: 'ogd@aoaioxxysz.net', + alwaysAuth: true } conf.setCredentialsByURI(URI, credentials) var expected = { - scope : "//registry.lvh.me:8661/", - token : undefined, - username : "username", - password : "password", - email : "ogd@aoaioxxysz.net", - auth : "dXNlcm5hbWU6cGFzc3dvcmQ=", - alwaysAuth : true + scope: '//registry.lvh.me:8661/', + token: undefined, + username: 'username', + password: 'password', + email: 'ogd@aoaioxxysz.net', + auth: 'dXNlcm5hbWU6cGFzc3dvcmQ=', + alwaysAuth: true } - t.same(conf.getCredentialsByURI(URI), expected, "got credentials") + t.same(conf.getCredentialsByURI(URI), expected, 'got credentials') t.end() }) }) -test("set with always-auth disabled", function (t) { +test('set with always-auth disabled', function (t) { npmconf.load(common.builtin, function (er, conf) { - t.ifError(er, "configuration loaded") + t.ifError(er, 'configuration loaded') var credentials = { - username : "username", - password : "password", - email : "ogd@aoaioxxysz.net", - alwaysAuth : false + username: 'username', + password: 'password', + email: 'ogd@aoaioxxysz.net', + alwaysAuth: false } conf.setCredentialsByURI(URI, credentials) var expected = { - scope : "//registry.lvh.me:8661/", - token : undefined, - username : "username", - password : "password", - email : "ogd@aoaioxxysz.net", - auth : "dXNlcm5hbWU6cGFzc3dvcmQ=", - alwaysAuth : false + scope: '//registry.lvh.me:8661/', + token: undefined, + username: 'username', + password: 'password', + email: 'ogd@aoaioxxysz.net', + auth: 'dXNlcm5hbWU6cGFzc3dvcmQ=', + alwaysAuth: false } - t.same(conf.getCredentialsByURI(URI), expected, "got credentials") + t.same(conf.getCredentialsByURI(URI), expected, 'got credentials') t.end() }) }) -test("set with global always-auth enabled", function (t) { +test('set with global always-auth enabled', function (t) { npmconf.load(common.builtin, function (er, conf) { - t.ifError(er, "configuration loaded") - var original = conf.get("always-auth") - conf.set("always-auth", true) + t.ifError(er, 'configuration loaded') + var original = conf.get('always-auth') + conf.set('always-auth', true) var credentials = { - username : "username", - password : "password", - email : "ogd@aoaioxxysz.net" + username: 'username', + password: 'password', + email: 'ogd@aoaioxxysz.net' } conf.setCredentialsByURI(URI, credentials) var expected = { - scope : "//registry.lvh.me:8661/", - token : undefined, - username : "username", - password : "password", - email : "ogd@aoaioxxysz.net", - auth : "dXNlcm5hbWU6cGFzc3dvcmQ=", - alwaysAuth : true + scope: '//registry.lvh.me:8661/', + token: undefined, + username: 'username', + password: 'password', + email: 'ogd@aoaioxxysz.net', + auth: 'dXNlcm5hbWU6cGFzc3dvcmQ=', + alwaysAuth: true } - t.same(conf.getCredentialsByURI(URI), expected, "got credentials") + t.same(conf.getCredentialsByURI(URI), expected, 'got credentials') - conf.set("always-auth", original) + conf.set('always-auth', original) t.end() }) }) -test("set with global always-auth disabled", function (t) { +test('set with global always-auth disabled', function (t) { npmconf.load(common.builtin, function (er, conf) { - t.ifError(er, "configuration loaded") - var original = conf.get("always-auth") - conf.set("always-auth", false) + t.ifError(er, 'configuration loaded') + var original = conf.get('always-auth') + conf.set('always-auth', false) var credentials = { - username : "username", - password : "password", - email : "ogd@aoaioxxysz.net" + username: 'username', + password: 'password', + email: 'ogd@aoaioxxysz.net' } conf.setCredentialsByURI(URI, credentials) var expected = { - scope : "//registry.lvh.me:8661/", - token : undefined, - username : "username", - password : "password", - email : "ogd@aoaioxxysz.net", - auth : "dXNlcm5hbWU6cGFzc3dvcmQ=", - alwaysAuth : false + scope: '//registry.lvh.me:8661/', + token: undefined, + username: 'username', + password: 'password', + email: 'ogd@aoaioxxysz.net', + auth: 'dXNlcm5hbWU6cGFzc3dvcmQ=', + alwaysAuth: false } - t.same(conf.getCredentialsByURI(URI), expected, "got credentials") + t.same(conf.getCredentialsByURI(URI), expected, 'got credentials') - conf.set("always-auth", original) + conf.set('always-auth', original) t.end() }) }) diff --git a/test/tap/config-edit.js b/test/tap/config-edit.js index 97a54d2ec..f9e09aba3 100644 --- a/test/tap/config-edit.js +++ b/test/tap/config-edit.js @@ -1,39 +1,39 @@ -var fs = require("fs") -var path = require("path") +var fs = require('fs') +var path = require('path') -var mkdirp = require("mkdirp") -var rimraf = require("rimraf") -var test = require("tap").test -var common = require("../common-tap.js") +var mkdirp = require('mkdirp') +var rimraf = require('rimraf') +var test = require('tap').test +var common = require('../common-tap.js') -var pkg = path.resolve(__dirname, "npm-global-edit") +var pkg = path.resolve(__dirname, 'npm-global-edit') var editorSrc = function () {/* #!/usr/bin/env node -var fs = require("fs") +var fs = require('fs') if (fs.existsSync(process.argv[2])) { - console.log("success") + console.log('success') } else { - console.log("error") + console.log('error') process.exit(1) } -*/}.toString().split("\n").slice(1, -1).join("\n") -var editorPath = path.join(pkg, "editor") +*/}.toString().split('\n').slice(1, -1).join('\n') +var editorPath = path.join(pkg, 'editor') -test("setup", function (t) { +test('setup', function (t) { cleanup(function (er) { - t.ifError(er, "old directory removed") + t.ifError(er, 'old directory removed') - mkdirp(pkg, "0777", function (er) { + mkdirp(pkg, '0777', function (er) { fs.writeFileSync(editorPath, editorSrc) - fs.chmodSync(editorPath, "0777") - t.ifError(er, "created package directory correctly") + fs.chmodSync(editorPath, '0777') + t.ifError(er, 'created package directory correctly') t.end() }) }) }) -test("saving configs", function (t) { +test('saving configs', function (t) { var opts = { cwd: pkg, env: { @@ -43,26 +43,26 @@ test("saving configs", function (t) { } common.npm( [ - "config", - "--prefix", pkg, - "--global", - "edit" + 'config', + '--prefix', pkg, + '--global', + 'edit' ], opts, function (err, code, stdout, stderr) { - t.ifError(err, "command ran without issue") + t.ifError(err, 'command ran without issue') - t.equal(stderr, "", "got nothing on stderr") - t.equal(code, 0, "exit ok") - t.equal(stdout, "success\n", "got success message") + t.equal(stderr, '', 'got nothing on stderr') + t.equal(code, 0, 'exit ok') + t.equal(stdout, 'success\n', 'got success message') t.end() } ) }) -test("cleanup", function (t) { +test('cleanup', function (t) { cleanup(function (er) { - t.ifError(er, "test directory removed OK") + t.ifError(er, 'test directory removed OK') t.end() }) }) diff --git a/test/tap/config-malformed.js b/test/tap/config-malformed.js index 045022146..4f74ea538 100644 --- a/test/tap/config-malformed.js +++ b/test/tap/config-malformed.js @@ -1,7 +1,7 @@ var test = require('tap').test -var npmconf = require("../../lib/config/core.js") -var common = require("./00-config-setup.js") +var npmconf = require('../../lib/config/core.js') +var common = require('./00-config-setup.js') test('with malformed', function (t) { npmconf.load({}, common.malformed, function (er, conf) { diff --git a/test/tap/config-meta.js b/test/tap/config-meta.js index 3da27a872..bb40e2038 100644 --- a/test/tap/config-meta.js +++ b/test/tap/config-meta.js @@ -4,34 +4,34 @@ // b) Documented // c) Defined in the `npmconf` package. -var test = require("tap").test -var fs = require("fs") -var path = require("path") -var root = path.resolve(__dirname, "..", "..") -var lib = path.resolve(root, "lib") -var nm = path.resolve(root, "node_modules") -var doc = path.resolve(root, "doc/misc/npm-config.md") +var test = require('tap').test +var fs = require('fs') +var path = require('path') +var root = path.resolve(__dirname, '..', '..') +var lib = path.resolve(root, 'lib') +var nm = path.resolve(root, 'node_modules') +var doc = path.resolve(root, 'doc/misc/npm-config.md') var FILES = [] var CONFS = {} var DOC = {} var exceptions = [ - path.resolve(lib, "adduser.js"), - path.resolve(lib, "config.js"), - path.resolve(lib, "publish.js"), - path.resolve(lib, "utils", "lifecycle.js"), - path.resolve(lib, "utils", "map-to-registry.js"), - path.resolve(nm, "npm-registry-client", "lib", "publish.js"), - path.resolve(nm, "npm-registry-client", "lib", "request.js") + path.resolve(lib, 'adduser.js'), + path.resolve(lib, 'config.js'), + path.resolve(lib, 'publish.js'), + path.resolve(lib, 'utils', 'lifecycle.js'), + path.resolve(lib, 'utils', 'map-to-registry.js'), + path.resolve(nm, 'npm-registry-client', 'lib', 'publish.js'), + path.resolve(nm, 'npm-registry-client', 'lib', 'request.js') ] -test("get files", function (t) { +test('get files', function (t) { walk(nm) walk(lib) - t.pass("got files") + t.pass('got files') t.end() - function walk(lib) { + function walk (lib) { var files = fs.readdirSync(lib).map(function (f) { return path.resolve(lib, f) }) @@ -41,86 +41,89 @@ test("get files", function (t) { } catch (er) { return } - if (s.isDirectory()) + if (s.isDirectory()) { walk(f) - else if (f.match(/\.js$/)) + } else if (f.match(/\.js$/)) { FILES.push(f) + } }) } }) -test("get lines", function (t) { +test('get lines', function (t) { FILES.forEach(function (f) { - var lines = fs.readFileSync(f, "utf8").split(/\r|\n/) + var lines = fs.readFileSync(f, 'utf8').split(/\r|\n/) lines.forEach(function (l, i) { var matches = l.split(/conf(?:ig)?\.get\(/g) matches.shift() matches.forEach(function (m) { - m = m.split(")").shift() - var literal = m.match(/^['"].+?['"]/) + m = m.split(')').shift() + var literal = m.match(/^[''].+?['']/) if (literal) { m = literal[0].slice(1, -1) - if (!m.match(/^\_/) && m !== "argv") + if (!m.match(/^\_/) && m !== 'argv') { CONFS[m] = { file: f, line: i } + } } else if (exceptions.indexOf(f) === -1) { - t.fail("non-string-literal config used in " + f + ":" + i) + t.fail('non-string-literal config used in ' + f + ':' + i) } }) }) }) - t.pass("got lines") + t.pass('got lines') t.end() }) -test("get docs", function (t) { - var d = fs.readFileSync(doc, "utf8").split(/\r|\n/) - // walk down until the "## Config Settings" section - for (var i = 0; i < d.length && d[i] !== "## Config Settings"; i++); +test('get docs', function (t) { + var d = fs.readFileSync(doc, 'utf8').split(/\r|\n/) + // walk down until the '## Config Settings' section + for (var i = 0; i < d.length && d[i] !== '## Config Settings'; i++); i++ // now gather up all the ^###\s lines until the next ^##\s for (; i < d.length && !d[i].match(/^## /); i++) { - if (d[i].match(/^### /)) - DOC[ d[i].replace(/^### /, "").trim() ] = true + if (d[i].match(/^### /)) { + DOC[ d[i].replace(/^### /, '').trim() ] = true + } } - t.pass("read the docs") + t.pass('read the docs') t.end() }) -test("check configs", function (t) { - var defs = require("../../lib/config/defaults.js") +test('check configs', function (t) { + var defs = require('../../lib/config/defaults.js') var types = Object.keys(defs.types) var defaults = Object.keys(defs.defaults) for (var c1 in CONFS) { if (CONFS[c1].file.indexOf(lib) === 0) { - t.ok(DOC[c1], "should be documented " + c1 + " " - + CONFS[c1].file + ":" + CONFS[c1].line) - t.ok(types.indexOf(c1) !== -1, "should be defined in npmconf " + c1) - t.ok(defaults.indexOf(c1) !== -1, "should have default in npmconf " + c1) + t.ok(DOC[c1], 'should be documented ' + c1 + ' ' + + CONFS[c1].file + ':' + CONFS[c1].line) + t.ok(types.indexOf(c1) !== -1, 'should be defined in npmconf ' + c1) + t.ok(defaults.indexOf(c1) !== -1, 'should have default in npmconf ' + c1) } } for (var c2 in DOC) { - if (c2 !== "versions" && c2 !== "version" && c2 !== "init.version") { - t.ok(CONFS[c2], "config in doc should be used somewhere " + c2) - t.ok(types.indexOf(c2) !== -1, "should be defined in npmconf " + c2) - t.ok(defaults.indexOf(c2) !== -1, "should have default in npmconf " + c2) + if (c2 !== 'versions' && c2 !== 'version' && c2 !== 'init.version') { + t.ok(CONFS[c2], 'config in doc should be used somewhere ' + c2) + t.ok(types.indexOf(c2) !== -1, 'should be defined in npmconf ' + c2) + t.ok(defaults.indexOf(c2) !== -1, 'should have default in npmconf ' + c2) } } types.forEach(function (c) { - if (!c.match(/^\_/) && c !== "argv" && !c.match(/^versions?$/)) { - t.ok(DOC[c], "defined type should be documented " + c) - t.ok(CONFS[c], "defined type should be used " + c) + if (!c.match(/^\_/) && c !== 'argv' && !c.match(/^versions?$/)) { + t.ok(DOC[c], 'defined type should be documented ' + c) + t.ok(CONFS[c], 'defined type should be used ' + c) } }) defaults.forEach(function (c) { - if (!c.match(/^\_/) && c !== "argv" && !c.match(/^versions?$/)) { - t.ok(DOC[c], "defaulted type should be documented " + c) - t.ok(CONFS[c], "defaulted type should be used " + c) + if (!c.match(/^\_/) && c !== 'argv' && !c.match(/^versions?$/)) { + t.ok(DOC[c], 'defaulted type should be documented ' + c) + t.ok(CONFS[c], 'defaulted type should be used ' + c) } }) diff --git a/test/tap/config-private.js b/test/tap/config-private.js index 37e283eec..97c6a73f1 100644 --- a/test/tap/config-private.js +++ b/test/tap/config-private.js @@ -1,81 +1,81 @@ -var fs = require("fs") -var path = require("path") -var test = require("tap").test -var rimraf = require("rimraf") -var mkdirp = require("mkdirp") -var common = require("../common-tap.js") +var fs = require('fs') +var path = require('path') +var test = require('tap').test +var rimraf = require('rimraf') +var mkdirp = require('mkdirp') +var common = require('../common-tap.js') -var pkg = path.resolve(__dirname, "config-private") +var pkg = path.resolve(__dirname, 'config-private') var opts = { cwd: pkg } -test("setup", function (t) { +test('setup', function (t) { rimraf.sync(pkg) mkdirp.sync(pkg) t.end() }) -test("config get private var (old auth)", function (t) { +test('config get private var (old auth)', function (t) { common.npm([ - "config", - "get", - "_auth" + 'config', + 'get', + '_auth' ], opts, function (err, code, stdout, stderr) { t.ifError(err) - t.similar(stderr, /sekretz/, "password blocked on stderr") - t.equal(stdout, "", "no output") + t.similar(stderr, /sekretz/, 'password blocked on stderr') + t.equal(stdout, '', 'no output') t.end() } ) }) -test("config get private var (new auth)", function (t) { +test('config get private var (new auth)', function (t) { common.npm([ - "config", - "get", - "//registry.npmjs.org/:_password" + 'config', + 'get', + '//registry.npmjs.org/:_password' ], opts, function (err, code, stdout, stderr) { t.ifError(err) - t.similar(stderr, /sekretz/, "password blocked on stderr") - t.equal(stdout, "", "no output") + t.similar(stderr, /sekretz/, 'password blocked on stderr') + t.equal(stdout, '', 'no output') t.end() } ) }) -test("config get public var (new username)", function (t) { - var FIXTURE_PATH = path.resolve(pkg, "fixture_npmrc") - var s = "//registry.lvh.me/:username = wombat\n" + - "//registry.lvh.me/:_password = YmFkIHBhc3N3b3Jk\n" + - "//registry.lvh.me/:email = lindsay@wdu.org.au\n" - fs.writeFileSync(FIXTURE_PATH, s, "ascii") - fs.chmodSync(FIXTURE_PATH, "0444") +test('config get public var (new username)', function (t) { + var FIXTURE_PATH = path.resolve(pkg, 'fixture_npmrc') + var s = '//registry.lvh.me/:username = wombat\n' + + '//registry.lvh.me/:_password = YmFkIHBhc3N3b3Jk\n' + + '//registry.lvh.me/:email = lindsay@wdu.org.au\n' + fs.writeFileSync(FIXTURE_PATH, s, 'ascii') + fs.chmodSync(FIXTURE_PATH, '0444') common.npm( [ - "config", - "get", - "//registry.lvh.me/:username", - "--userconfig=" + FIXTURE_PATH, - "--registry=http://registry.lvh.me/" + 'config', + 'get', + '//registry.lvh.me/:username', + '--userconfig=' + FIXTURE_PATH, + '--registry=http://registry.lvh.me/' ], opts, function (err, code, stdout, stderr) { t.ifError(err) - t.equal(stderr, "", "stderr is empty") - t.equal(stdout, "wombat\n", "got usename is output") + t.equal(stderr, '', 'stderr is empty') + t.equal(stdout, 'wombat\n', 'got usename is output') t.end() } ) }) -test("clean", function (t) { +test('clean', function (t) { rimraf.sync(pkg) t.end() }) diff --git a/test/tap/config-project.js b/test/tap/config-project.js index 337355bf2..b9e8b7ac0 100644 --- a/test/tap/config-project.js +++ b/test/tap/config-project.js @@ -1,21 +1,21 @@ -var test = require("tap").test -var path = require("path") -var fix = path.resolve(__dirname, "..", "fixtures", "config") -var projectRc = path.resolve(fix, ".npmrc") -var npmconf = require("../../lib/config/core.js") -var common = require("./00-config-setup.js") +var test = require('tap').test +var path = require('path') +var fix = path.resolve(__dirname, '..', 'fixtures', 'config') +var projectRc = path.resolve(fix, '.npmrc') +var npmconf = require('../../lib/config/core.js') +var common = require('./00-config-setup.js') -var projectData = { just: "testing" } +var projectData = { just: 'testing' } var ucData = common.ucData var envData = common.envData var envDataFix = common.envDataFix -var gcData = { "package-config:foo": "boo" } +var gcData = { 'package-config:foo': 'boo' } var biData = {} -var cli = { foo: "bar", umask: 022, prefix: fix } +var cli = { foo: 'bar', umask: parseInt('022', 8), prefix: fix } var expectList = [ cli, @@ -31,27 +31,27 @@ var expectSources = { env: { data: envDataFix, source: envData, - prefix: "" + prefix: '' }, project: { path: projectRc, - type: "ini", + type: 'ini', data: projectData }, user: { path: common.userconfig, - type: "ini", + type: 'ini', data: ucData }, global: { path: common.globalconfig, - type: "ini", + type: 'ini', data: gcData }, builtin: { data: biData } } -test("no builtin", function (t) { +test('no builtin', function (t) { npmconf.load(cli, function (er, conf) { if (er) throw er t.same(conf.list, expectList) @@ -59,8 +59,8 @@ test("no builtin", function (t) { t.same(npmconf.rootConf.list, []) t.equal(npmconf.rootConf.root, npmconf.defs.defaults) t.equal(conf.root, npmconf.defs.defaults) - t.equal(conf.get("umask"), 022) - t.equal(conf.get("heading"), "npm") + t.equal(conf.get('umask'), parseInt('022', 8)) + t.equal(conf.get('heading'), 'npm') t.end() }) }) diff --git a/test/tap/config-save.js b/test/tap/config-save.js index 88526a38a..903bac7ae 100644 --- a/test/tap/config-save.js +++ b/test/tap/config-save.js @@ -1,88 +1,87 @@ -var fs = require("fs") -var ini = require("ini") -var test = require("tap").test -var npmconf = require("../../lib/config/core.js") -var common = require("./00-config-setup.js") +var fs = require('fs') +var ini = require('ini') +var test = require('tap').test +var npmconf = require('../../lib/config/core.js') +var common = require('./00-config-setup.js') var expectConf = [ - "globalconfig = " + common.globalconfig, - "email = i@izs.me", - "env-thing = asdf", - "init.author.name = Isaac Z. Schlueter", - "init.author.email = i@izs.me", - "init.author.url = http://blog.izs.me/", - "init.version = 1.2.3", - "proprietary-attribs = false", - "npm:publishtest = true", - "_npmjs.org:couch = https://admin:password@localhost:5984/registry", - "npm-www:nocache = 1", - "sign-git-tag = false", - "message = v%s", - "strict-ssl = false", - "_auth = dXNlcm5hbWU6cGFzc3dvcmQ=", - "", - "[_token]", - "AuthSession = yabba-dabba-doodle", - "version = 1", - "expires = 1345001053415", - "path = /", - "httponly = true", - "" -].join("\n") + 'globalconfig = ' + common.globalconfig, + 'email = i@izs.me', + 'env-thing = asdf', + 'init.author.name = Isaac Z. Schlueter', + 'init.author.email = i@izs.me', + 'init.author.url = http://blog.izs.me/', + 'init.version = 1.2.3', + 'proprietary-attribs = false', + 'npm:publishtest = true', + '_npmjs.org:couch = https://admin:password@localhost:5984/registry', + 'npm-www:nocache = 1', + 'sign-git-tag = false', + 'message = v%s', + 'strict-ssl = false', + '_auth = dXNlcm5hbWU6cGFzc3dvcmQ=', + '', + '[_token]', + 'AuthSession = yabba-dabba-doodle', + 'version = 1', + 'expires = 1345001053415', + 'path = /', + 'httponly = true', + '' +].join('\n') var expectFile = [ - "globalconfig = " + common.globalconfig, - "email = i@izs.me", - "env-thing = asdf", - "init.author.name = Isaac Z. Schlueter", - "init.author.email = i@izs.me", - "init.author.url = http://blog.izs.me/", - "init.version = 1.2.3", - "proprietary-attribs = false", - "npm:publishtest = true", - "_npmjs.org:couch = https://admin:password@localhost:5984/registry", - "npm-www:nocache = 1", - "sign-git-tag = false", - "message = v%s", - "strict-ssl = false", - "_auth = dXNlcm5hbWU6cGFzc3dvcmQ=", - "", - "[_token]", - "AuthSession = yabba-dabba-doodle", - "version = 1", - "expires = 1345001053415", - "path = /", - "httponly = true", - "" -].join("\n") + 'globalconfig = ' + common.globalconfig, + 'email = i@izs.me', + 'env-thing = asdf', + 'init.author.name = Isaac Z. Schlueter', + 'init.author.email = i@izs.me', + 'init.author.url = http://blog.izs.me/', + 'init.version = 1.2.3', + 'proprietary-attribs = false', + 'npm:publishtest = true', + '_npmjs.org:couch = https://admin:password@localhost:5984/registry', + 'npm-www:nocache = 1', + 'sign-git-tag = false', + 'message = v%s', + 'strict-ssl = false', + '_auth = dXNlcm5hbWU6cGFzc3dvcmQ=', + '', + '[_token]', + 'AuthSession = yabba-dabba-doodle', + 'version = 1', + 'expires = 1345001053415', + 'path = /', + 'httponly = true', + '' +].join('\n') -test("saving configs", function (t) { +test('saving configs', function (t) { npmconf.load(function (er, conf) { - if (er) - throw er - conf.set("sign-git-tag", false, "user") - conf.del("nodedir") - conf.del("tmp") + if (er) throw er + + conf.set('sign-git-tag', false, 'user') + conf.del('nodedir') + conf.del('tmp') var foundConf = ini.stringify(conf.sources.user.data) t.same(ini.parse(foundConf), ini.parse(expectConf)) fs.unlinkSync(common.userconfig) - conf.save("user", function (er) { - if (er) - throw er - var uc = fs.readFileSync(conf.get("userconfig"), "utf8") + conf.save('user', function (er) { + if (er) throw er + + var uc = fs.readFileSync(conf.get('userconfig'), 'utf8') t.same(ini.parse(uc), ini.parse(expectFile)) t.end() }) }) }) -test("setting prefix", function (t) { +test('setting prefix', function (t) { npmconf.load(function (er, conf) { - if (er) - throw er + if (er) throw er - conf.prefix = "newvalue" - t.same(conf.prefix, "newvalue") + conf.prefix = 'newvalue' + t.same(conf.prefix, 'newvalue') t.end() }) }) diff --git a/test/tap/dedupe-scoped.js b/test/tap/dedupe-scoped.js index 355fc138a..27e27d39d 100644 --- a/test/tap/dedupe-scoped.js +++ b/test/tap/dedupe-scoped.js @@ -60,7 +60,6 @@ var secondUnique = { 'version': '1.2.0' } - test('setup', function (t) { setup() t.end() diff --git a/test/tap/dedupe.js b/test/tap/dedupe.js index c6106f814..4c3424818 100644 --- a/test/tap/dedupe.js +++ b/test/tap/dedupe.js @@ -25,32 +25,31 @@ var json = { } var shrinkwrap = { - name: "dedupe", - version: "0.0.0", + name: 'dedupe', + version: '0.0.0', dependencies: { clean: { - version: "2.1.6", + version: '2.1.6', dependencies: { checker: { - version: "0.5.2", + version: '0.5.2', dependencies: { - async: { version: "0.2.10" } + async: { version: '0.2.10' } } }, - minimist: { version: "0.0.5" } + minimist: { version: '0.0.5' } } }, optimist: { - version: "0.6.0", + version: '0.6.0', dependencies: { - wordwrap: { version: "0.0.2" }, - minimist: { version: "0.0.5" } + wordwrap: { version: '0.0.2' }, + minimist: { version: '0.0.5' } } } } } - test('setup', function (t) { t.comment('test for https://github.com/npm/npm/issues/4675') setup(function () { @@ -78,8 +77,14 @@ test('dedupe finds the common module and moves it up one level', function (t) { t.notOk(code, 'npm dedupe exited with code') t.ok(existsSync(path.join(pkg, 'node_modules', 'minimist')), 'minimist module exists') - t.notOk(existsSync(path.join(pkg, 'node_modules', 'clean','node_modules','minimist')), 'no clean/minimist') - t.notOk(existsSync(path.join(pkg, 'node_modules', 'optimist','node_modules','minimist')), 'no optmist/minimist') + t.notOk( + existsSync(path.join(pkg, 'node_modules', 'clean', 'node_modules', 'minimist')), + 'no clean/minimist' + ) + t.notOk( + existsSync(path.join(pkg, 'node_modules', 'optimist', 'node_modules', 'minimist')), + 'no optmist/minimist' + ) t.end() } ) diff --git a/test/tap/dist-tag.js b/test/tap/dist-tag.js index 08a5ca438..62ecab2c0 100644 --- a/test/tap/dist-tag.js +++ b/test/tap/dist-tag.js @@ -1,62 +1,62 @@ -var fs = require("fs") -var path = require("path") -var mkdirp = require("mkdirp") -var rimraf = require("rimraf") -var mr = require("npm-registry-mock") +var fs = require('fs') +var path = require('path') +var mkdirp = require('mkdirp') +var rimraf = require('rimraf') +var mr = require('npm-registry-mock') -var test = require("tap").test -var common = require("../common-tap.js") +var test = require('tap').test +var common = require('../common-tap.js') -var pkg = path.resolve(__dirname, "dist-tag") +var pkg = path.resolve(__dirname, 'dist-tag') var server var scoped = { - name : "@scoped/pkg", - version : "1.1.1" + name: '@scoped/pkg', + version: '1.1.1' } function mocks (server) { // ls current package - server.get("/-/package/@scoped%2fpkg/dist-tags") - .reply(200, { latest : "1.0.0", a : "0.0.1", b : "0.5.0" }) + server.get('/-/package/@scoped%2fpkg/dist-tags') + .reply(200, { latest: '1.0.0', a: '0.0.1', b: '0.5.0' }) // ls named package - server.get("/-/package/@scoped%2fanother/dist-tags") - .reply(200, { latest : "2.0.0", a : "0.0.2", b : "0.6.0" }) + server.get('/-/package/@scoped%2fanother/dist-tags') + .reply(200, { latest: '2.0.0', a: '0.0.2', b: '0.6.0' }) // add c - server.get("/-/package/@scoped%2fanother/dist-tags") - .reply(200, { latest : "2.0.0", a : "0.0.2", b : "0.6.0" }) - server.put("/-/package/@scoped%2fanother/dist-tags/c", "\"7.7.7\"") - .reply(200, { latest : "7.7.7", a : "0.0.2", b : "0.6.0", c : "7.7.7" }) + server.get('/-/package/@scoped%2fanother/dist-tags') + .reply(200, { latest: '2.0.0', a: '0.0.2', b: '0.6.0' }) + server.put('/-/package/@scoped%2fanother/dist-tags/c', '\"7.7.7\"') + .reply(200, { latest: '7.7.7', a: '0.0.2', b: '0.6.0', c: '7.7.7' }) // set same version - server.get("/-/package/@scoped%2fanother/dist-tags") - .reply(200, { latest : "2.0.0", b : "0.6.0" }) + server.get('/-/package/@scoped%2fanother/dist-tags') + .reply(200, { latest: '2.0.0', b: '0.6.0' }) // rm - server.get("/-/package/@scoped%2fanother/dist-tags") - .reply(200, { latest : "2.0.0", a : "0.0.2", b : "0.6.0", c : "7.7.7" }) - server.delete("/-/package/@scoped%2fanother/dist-tags/c") - .reply(200, { c : "7.7.7" }) + server.get('/-/package/@scoped%2fanother/dist-tags') + .reply(200, { latest: '2.0.0', a: '0.0.2', b: '0.6.0', c: '7.7.7' }) + server.delete('/-/package/@scoped%2fanother/dist-tags/c') + .reply(200, { c: '7.7.7' }) // rm - server.get("/-/package/@scoped%2fanother/dist-tags") - .reply(200, { latest : "4.0.0" }) + server.get('/-/package/@scoped%2fanother/dist-tags') + .reply(200, { latest: '4.0.0' }) } -test("setup", function (t) { +test('setup', function (t) { mkdirp(pkg, function (er) { - t.ifError(er, pkg + " made successfully") + t.ifError(er, pkg + ' made successfully') - mr({port : common.port, plugin : mocks}, function (er, s) { + mr({ port: common.port, plugin: mocks }, function (er, s) { server = s fs.writeFile( - path.join(pkg, "package.json"), + path.join(pkg, 'package.json'), JSON.stringify(scoped), function (er) { - t.ifError(er, "wrote package.json") + t.ifError(er, 'wrote package.json') t.end() } ) @@ -64,131 +64,131 @@ test("setup", function (t) { }) }) -test("npm dist-tags ls in current package", function (t) { +test('npm dist-tags ls in current package', function (t) { common.npm( [ - "dist-tags", "ls", - "--registry", common.registry, - "--loglevel", "silent" + 'dist-tags', 'ls', + '--registry', common.registry, + '--loglevel', 'silent' ], - { cwd : pkg }, + { cwd: pkg }, function (er, code, stdout, stderr) { - t.ifError(er, "npm access") - t.notOk(code, "exited OK") - t.notOk(stderr, "no error output") - t.equal(stdout, "a: 0.0.1\nb: 0.5.0\nlatest: 1.0.0\n") + t.ifError(er, 'npm access') + t.notOk(code, 'exited OK') + t.notOk(stderr, 'no error output') + t.equal(stdout, 'a: 0.0.1\nb: 0.5.0\nlatest: 1.0.0\n') t.end() } ) }) -test("npm dist-tags ls on named package", function (t) { +test('npm dist-tags ls on named package', function (t) { common.npm( [ - "dist-tags", - "ls", "@scoped/another", - "--registry", common.registry, - "--loglevel", "silent" + 'dist-tags', + 'ls', '@scoped/another', + '--registry', common.registry, + '--loglevel', 'silent' ], - { cwd : pkg }, + { cwd: pkg }, function (er, code, stdout, stderr) { - t.ifError(er, "npm access") - t.notOk(code, "exited OK") - t.notOk(stderr, "no error output") - t.equal(stdout, "a: 0.0.2\nb: 0.6.0\nlatest: 2.0.0\n") + t.ifError(er, 'npm access') + t.notOk(code, 'exited OK') + t.notOk(stderr, 'no error output') + t.equal(stdout, 'a: 0.0.2\nb: 0.6.0\nlatest: 2.0.0\n') t.end() } ) }) -test("npm dist-tags add @scoped/another@7.7.7 c", function (t) { +test('npm dist-tags add @scoped/another@7.7.7 c', function (t) { common.npm( [ - "dist-tags", - "add", "@scoped/another@7.7.7", "c", - "--registry", common.registry, - "--loglevel", "silent" + 'dist-tags', + 'add', '@scoped/another@7.7.7', 'c', + '--registry', common.registry, + '--loglevel', 'silent' ], - { cwd : pkg }, + { cwd: pkg }, function (er, code, stdout, stderr) { - t.ifError(er, "npm access") - t.notOk(code, "exited OK") - t.notOk(stderr, "no error output") - t.equal(stdout, "+c: @scoped/another@7.7.7\n") + t.ifError(er, 'npm access') + t.notOk(code, 'exited OK') + t.notOk(stderr, 'no error output') + t.equal(stdout, '+c: @scoped/another@7.7.7\n') t.end() } ) }) -test("npm dist-tags set same version", function (t) { +test('npm dist-tags set same version', function (t) { common.npm( [ - "dist-tag", - "set", "@scoped/another@0.6.0", "b", - "--registry", common.registry, - "--loglevel", "warn" + 'dist-tag', + 'set', '@scoped/another@0.6.0', 'b', + '--registry', common.registry, + '--loglevel', 'warn' ], - { cwd : pkg }, + { cwd: pkg }, function (er, code, stdout, stderr) { - t.ifError(er, "npm access") - t.notOk(code, "exited OK") + t.ifError(er, 'npm access') + t.notOk(code, 'exited OK') t.equal( stderr, - "npm WARN dist-tag add b is already set to version 0.6.0\n", - "warned about setting same version" + 'npm WARN dist-tag add b is already set to version 0.6.0\n', + 'warned about setting same version' ) - t.notOk(stdout, "only expecting warning message") + t.notOk(stdout, 'only expecting warning message') t.end() } ) }) -test("npm dist-tags rm @scoped/another c", function (t) { +test('npm dist-tags rm @scoped/another c', function (t) { common.npm( [ - "dist-tags", - "rm", "@scoped/another", "c", - "--registry", common.registry, - "--loglevel", "silent" + 'dist-tags', + 'rm', '@scoped/another', 'c', + '--registry', common.registry, + '--loglevel', 'silent' ], - { cwd : pkg }, + { cwd: pkg }, function (er, code, stdout, stderr) { - t.ifError(er, "npm access") - t.notOk(code, "exited OK") - t.notOk(stderr, "no error output") - t.equal(stdout, "-c: @scoped/another@7.7.7\n") + t.ifError(er, 'npm access') + t.notOk(code, 'exited OK') + t.notOk(stderr, 'no error output') + t.equal(stdout, '-c: @scoped/another@7.7.7\n') t.end() } ) }) -test("npm dist-tags rm @scoped/another nonexistent", function (t) { +test('npm dist-tags rm @scoped/another nonexistent', function (t) { common.npm( [ - "dist-tags", - "rm", "@scoped/another", "nonexistent", - "--registry", common.registry, - "--loglevel", "silent" + 'dist-tags', + 'rm', '@scoped/another', 'nonexistent', + '--registry', common.registry, + '--loglevel', 'silent' ], - { cwd : pkg }, + { cwd: pkg }, function (er, code, stdout, stderr) { - t.ifError(er, "npm dist-tag") - t.ok(code, "expecting nonzero exit code") - t.notOk(stderr, "no error output") - t.notOk(stdout, "not expecting output") + t.ifError(er, 'npm dist-tag') + t.ok(code, 'expecting nonzero exit code') + t.notOk(stderr, 'no error output') + t.notOk(stdout, 'not expecting output') t.end() } ) }) -test("cleanup", function (t) { - t.pass("cleaned up") +test('cleanup', function (t) { + t.pass('cleaned up') rimraf.sync(pkg) server.close() t.end() diff --git a/test/tap/false-name.js b/test/tap/false-name.js index 89e890e37..1e2a4d43d 100644 --- a/test/tap/false-name.js +++ b/test/tap/false-name.js @@ -54,14 +54,14 @@ test('not every pkg.name can be required', function (t) { function (err, code) { t.ifErr(err, 'install finished without error') t.equal(code, 0, 'install exited ok') - t.ok(existsSync(path.join( - pkg, - 'node_modules','test-package-with-one-dep' - )), 'test-package-with-one-dep installed OK') - t.ok(existsSync(path.join( - pkg, - 'node_modules','test-package' - )), 'test-pacakge subdep installed OK') + t.ok( + existsSync(path.join(pkg, 'node_modules', 'test-package-with-one-dep')), + 'test-package-with-one-dep installed OK' + ) + t.ok( + existsSync(path.join(pkg, 'node_modules', 'test-package')), + 'test-pacakge subdep installed OK' + ) t.end() } ) diff --git a/test/tap/gently-rm-overeager.js b/test/tap/gently-rm-overeager.js index 35f46cc21..c266f1c4d 100644 --- a/test/tap/gently-rm-overeager.js +++ b/test/tap/gently-rm-overeager.js @@ -1,53 +1,50 @@ -var resolve = require("path").resolve -var fs = require("graceful-fs") -var test = require("tap").test -var mkdirp = require("mkdirp") -var rimraf = require("rimraf") +var resolve = require('path').resolve +var fs = require('graceful-fs') +var test = require('tap').test +var mkdirp = require('mkdirp') +var rimraf = require('rimraf') -var common = require("../common-tap.js") +var common = require('../common-tap.js') -var pkg = resolve(__dirname, "gently-rm-overeager") -var dep = resolve(__dirname, "test-whoops") +var pkg = resolve(__dirname, 'gently-rm-overeager') +var dep = resolve(__dirname, 'test-whoops') -var EXEC_OPTS = { - cwd : pkg -} +var EXEC_OPTS = { cwd: pkg } var fixture = { - name: "@test/whoops", - version: "1.0.0", + name: '@test/whoops', + version: '1.0.0', scripts: { - postinstall: "echo \"nope\" && exit 1" + postinstall: 'echo \'nope\' && exit 1' } } -test("setup", function (t) { +test('setup', function (t) { cleanup() setup() t.end() }) -test("cache add", function (t) { - common.npm(["install", "../test-whoops"], EXEC_OPTS, function (er, c) { +test('cache add', function (t) { + common.npm(['install', '../test-whoops'], EXEC_OPTS, function (er, c) { t.ifError(er, "test-whoops install didn't explode") - t.ok(c, "test-whoops install also failed") + t.ok(c, 'test-whoops install also failed') fs.readdir(pkg, function (er, files) { - t.ifError(er, "package directory is still there") - t.deepEqual(files, ["npm-debug.log"], "only debug log remains") + t.ifError(er, 'package directory is still there') + t.deepEqual(files, ['npm-debug.log'], 'only debug log remains') t.end() }) }) }) -test("cleanup", function (t) { +test('cleanup', function (t) { cleanup() t.end() }) - function cleanup () { rimraf.sync(pkg) rimraf.sync(dep) @@ -56,7 +53,7 @@ function cleanup () { function setup () { mkdirp.sync(pkg) // so it doesn't try to install into npm's own node_modules - mkdirp.sync(resolve(pkg, "node_modules")) + mkdirp.sync(resolve(pkg, 'node_modules')) mkdirp.sync(dep) - fs.writeFileSync(resolve(dep, "package.json"), JSON.stringify(fixture)) + fs.writeFileSync(resolve(dep, 'package.json'), JSON.stringify(fixture)) } diff --git a/test/tap/gently-rm-symlink.js b/test/tap/gently-rm-symlink.js index 3a743c894..93ed3edaa 100644 --- a/test/tap/gently-rm-symlink.js +++ b/test/tap/gently-rm-symlink.js @@ -1,73 +1,70 @@ -var resolve = require("path").resolve -var fs = require("graceful-fs") -var test = require("tap").test -var mkdirp = require("mkdirp") -var rimraf = require("rimraf") +var resolve = require('path').resolve +var fs = require('graceful-fs') +var test = require('tap').test +var mkdirp = require('mkdirp') +var rimraf = require('rimraf') -var common = require("../common-tap.js") +var common = require('../common-tap.js') -var pkg = resolve(__dirname, "gently-rm-linked") -var dep = resolve(__dirname, "test-linked") -var glb = resolve(__dirname, "test-global") -var lnk = resolve(__dirname, "test-global-link") - -var EXEC_OPTS = { - cwd : pkg -} +var pkg = resolve(__dirname, 'gently-rm-linked') +var dep = resolve(__dirname, 'test-linked') +var glb = resolve(__dirname, 'test-global') +var lnk = resolve(__dirname, 'test-global-link') +var EXEC_OPTS = { cwd: pkg } var index = "module.exports = function () { console.log('whoop whoop') }" var fixture = { - name: "@test/linked", - version: "1.0.0", + name: '@test/linked', + version: '1.0.0', bin: { - linked: "./index.js" + linked: './index.js' } } -test("setup", function (t) { +test('setup', function (t) { cleanup() setup() t.end() }) -test("install and link", function (t) { +test('install and link', function (t) { common.npm( [ - "--global", - "--prefix", lnk, - "--loglevel", "silent", - "install", "../test-linked" + '--global', + '--prefix', lnk, + '--loglevel', 'silent', + 'install', '../test-linked' ], EXEC_OPTS, function (er, code, stdout, stderr) { t.ifError(er, "test-linked install didn't explode") - t.notOk(code, "test-linked install also failed") - t.notOk(stderr, "no log output") + t.notOk(code, 'test-linked install also failed') + t.notOk(stderr, 'no log output') verify(t, stdout) // again, to make sure unlinking works properlyt common.npm( [ - "--global", - "--prefix", lnk, - "--loglevel", "silent", - "install", "../test-linked" + '--global', + '--prefix', lnk, + '--loglevel', 'silent', + 'install', '../test-linked' ], EXEC_OPTS, function (er, code, stdout, stderr) { t.ifError(er, "test-linked install didn't explode") - t.notOk(code, "test-linked install also failed") - t.notOk(stderr, "no log output") + t.notOk(code, 'test-linked install also failed') + t.notOk(stderr, 'no log output') verify(t, stdout) fs.readdir(pkg, function (er, files) { - t.ifError(er, "package directory is still there") - t.deepEqual(files, ["node_modules"], "only stub modules dir remains") + t.ifError(er, 'package directory is still there') + t.deepEqual(files, ['node_modules'], 'only stub modules dir remains') t.end() }) @@ -77,7 +74,7 @@ test("install and link", function (t) { ) }) -test("cleanup", function (t) { +test('cleanup', function (t) { cleanup() t.end() @@ -88,16 +85,16 @@ function removeBlank (line) { } function verify (t, stdout) { - var binPath = resolve(lnk, "bin", "linked") - var pkgPath = resolve(lnk, "lib", "node_modules", "@test", "linked") - var trgPath = resolve(pkgPath, "index.js") + var binPath = resolve(lnk, 'bin', 'linked') + var pkgPath = resolve(lnk, 'lib', 'node_modules', '@test', 'linked') + var trgPath = resolve(pkgPath, 'index.js') t.deepEqual( stdout.split('\n').filter(removeBlank), - [ binPath+" -> "+trgPath, + [ binPath + ' -> ' + trgPath, resolve(lnk, 'lib'), '└── @test/linked@1.0.0 ' ], - "got expected install output" + 'got expected install output' ) } @@ -113,8 +110,8 @@ function setup () { mkdirp.sync(glb) fs.symlinkSync(glb, lnk) // so it doesn't try to install into npm's own node_modules - mkdirp.sync(resolve(pkg, "node_modules")) + mkdirp.sync(resolve(pkg, 'node_modules')) mkdirp.sync(dep) - fs.writeFileSync(resolve(dep, "package.json"), JSON.stringify(fixture)) - fs.writeFileSync(resolve(dep, "index.js"), index) + fs.writeFileSync(resolve(dep, 'package.json'), JSON.stringify(fixture)) + fs.writeFileSync(resolve(dep, 'index.js'), index) } diff --git a/test/tap/get.js b/test/tap/get.js index 983243025..62bb05fda 100644 --- a/test/tap/get.js +++ b/test/tap/get.js @@ -1,52 +1,50 @@ -var common = require("../common-tap.js") -var test = require("tap").test -var cacheFile = require("npm-cache-filename") -var npm = require("../../") -var mkdirp = require("mkdirp") -var rimraf = require("rimraf") -var path = require("path") -var mr = require("npm-registry-mock") -var fs = require("graceful-fs") +var common = require('../common-tap.js') +var test = require('tap').test +var cacheFile = require('npm-cache-filename') +var npm = require('../../') +var mkdirp = require('mkdirp') +var rimraf = require('rimraf') +var path = require('path') +var mr = require('npm-registry-mock') +var fs = require('graceful-fs') function nop () {} -var URI = "https://npm.registry:8043/rewrite" -var TIMEOUT = 3600 -var FOLLOW = false +var URI = 'https://npm.registry:8043/rewrite' +var TIMEOUT = 3600 +var FOLLOW = false var STALE_OK = true -var TOKEN = "lolbutts" -var AUTH = { - token : TOKEN +var TOKEN = 'lolbutts' +var AUTH = { token: TOKEN } +var PARAMS = { + timeout: TIMEOUT, + follow: FOLLOW, + staleOk: STALE_OK, + auth: AUTH } -var PARAMS = { - timeout : TIMEOUT, - follow : FOLLOW, - staleOk : STALE_OK, - auth : AUTH -} -var PKG_DIR = path.resolve(__dirname, "get-basic") -var CACHE_DIR = path.resolve(PKG_DIR, "cache") +var PKG_DIR = path.resolve(__dirname, 'get-basic') +var CACHE_DIR = path.resolve(PKG_DIR, 'cache') var BIGCO_SAMPLE = { - name : "@bigco/sample", - version : "1.2.3" + name: '@bigco/sample', + version: '1.2.3' } // mock server reference var server var mocks = { - "get": { - "/@bigco%2fsample/1.2.3" : [200, BIGCO_SAMPLE] + 'get': { + '/@bigco%2fsample/1.2.3': [200, BIGCO_SAMPLE] } } var mapper = cacheFile(CACHE_DIR) function getCachePath (uri) { - return path.join(mapper(uri), ".cache.json") + return path.join(mapper(uri), '.cache.json') } -test("setup", function (t) { +test('setup', function (t) { mkdirp.sync(CACHE_DIR) mr({port: common.port, mocks: mocks}, function (er, s) { @@ -59,66 +57,66 @@ test("setup", function (t) { }) }) -test("get call contract", function (t) { +test('get call contract', function (t) { t.throws(function () { npm.registry.get(undefined, PARAMS, nop) - }, "requires a URI") + }, 'requires a URI') t.throws(function () { npm.registry.get([], PARAMS, nop) - }, "requires URI to be a string") + }, 'requires URI to be a string') t.throws(function () { npm.registry.get(URI, undefined, nop) - }, "requires params object") + }, 'requires params object') t.throws(function () { - npm.registry.get(URI, "", nop) - }, "params must be object") + npm.registry.get(URI, '', nop) + }, 'params must be object') t.throws(function () { npm.registry.get(URI, PARAMS, undefined) - }, "requires callback") + }, 'requires callback') t.throws(function () { - npm.registry.get(URI, PARAMS, "callback") - }, "callback must be function") + npm.registry.get(URI, PARAMS, 'callback') + }, 'callback must be function') t.end() }) -test("basic request", function (t) { +test('basic request', function (t) { t.plan(9) - var versioned = common.registry + "/underscore/1.3.3" + var versioned = common.registry + '/underscore/1.3.3' npm.registry.get(versioned, PARAMS, function (er, data) { - t.ifError(er, "loaded specified version underscore data") - t.equal(data.version, "1.3.3") + t.ifError(er, 'loaded specified version underscore data') + t.equal(data.version, '1.3.3') fs.stat(getCachePath(versioned), function (er) { - t.ifError(er, "underscore 1.3.3 cache data written") + t.ifError(er, 'underscore 1.3.3 cache data written') }) }) - var rollup = common.registry + "/underscore" + var rollup = common.registry + '/underscore' npm.registry.get(rollup, PARAMS, function (er, data) { - t.ifError(er, "loaded all metadata") - t.deepEqual(data.name, "underscore") + t.ifError(er, 'loaded all metadata') + t.deepEqual(data.name, 'underscore') fs.stat(getCachePath(rollup), function (er) { - t.ifError(er, "underscore rollup cache data written") + t.ifError(er, 'underscore rollup cache data written') }) }) - var scoped = common.registry + "/@bigco%2fsample/1.2.3" + var scoped = common.registry + '/@bigco%2fsample/1.2.3' npm.registry.get(scoped, PARAMS, function (er, data) { - t.ifError(er, "loaded all metadata") - t.equal(data.name, "@bigco/sample") + t.ifError(er, 'loaded all metadata') + t.equal(data.name, '@bigco/sample') fs.stat(getCachePath(scoped), function (er) { - t.ifError(er, "scoped cache data written") + t.ifError(er, 'scoped cache data written') }) }) }) -test("cleanup", function (t) { +test('cleanup', function (t) { server.close() rimraf.sync(PKG_DIR) diff --git a/test/tap/git-cache-no-hooks.js b/test/tap/git-cache-no-hooks.js index 32731fa1b..e5d862919 100644 --- a/test/tap/git-cache-no-hooks.js +++ b/test/tap/git-cache-no-hooks.js @@ -1,63 +1,63 @@ -var test = require("tap").test - , fs = require("fs") - , path = require("path") - , rimraf = require("rimraf") - , mkdirp = require("mkdirp") - , spawn = require("child_process").spawn - , npmCli = require.resolve("../../bin/npm-cli.js") - , node = process.execPath - , pkg = path.resolve(__dirname, "git-cache-no-hooks") - , tmp = path.join(pkg, "tmp") - , cache = path.join(pkg, "cache") - - -test("setup", function (t) { +var test = require('tap').test +var fs = require('fs') +var path = require('path') +var rimraf = require('rimraf') +var mkdirp = require('mkdirp') +var spawn = require('child_process').spawn +var npmCli = require.resolve('../../bin/npm-cli.js') +var node = process.execPath +var pkg = path.resolve(__dirname, 'git-cache-no-hooks') +var tmp = path.join(pkg, 'tmp') +var cache = path.join(pkg, 'cache') + +test('setup', function (t) { rimraf.sync(pkg) mkdirp.sync(pkg) mkdirp.sync(cache) mkdirp.sync(tmp) - mkdirp.sync(path.resolve(pkg, "node_modules")) + mkdirp.sync(path.resolve(pkg, 'node_modules')) t.end() }) -test("git-cache-no-hooks: install a git dependency", function (t) { +test('git-cache-no-hooks: install a git dependency', function (t) { // disable git integration tests on Travis. if (process.env.TRAVIS) return t.end() - var command = [ npmCli - , "install" - , "git://github.com/nigelzor/npm-4503-a.git" - ] + var command = [ + npmCli, + 'install', + 'git://github.com/nigelzor/npm-4503-a.git' + ] var child = spawn(node, command, { cwd: pkg, env: { - "npm_config_cache" : cache, - "npm_config_tmp" : tmp, - "npm_config_prefix" : pkg, - "npm_config_global" : "false", - "npm_config_umask" : "00", - HOME : process.env.HOME, - Path : process.env.PATH, - PATH : process.env.PATH + 'npm_config_cache': cache, + 'npm_config_tmp': tmp, + 'npm_config_prefix': pkg, + 'npm_config_global': 'false', + 'npm_config_umask': '00', + HOME: process.env.HOME, + Path: process.env.PATH, + PATH: process.env.PATH }, - stdio: "inherit" + stdio: 'inherit' }) - child.on("close", function (code) { - t.equal(code, 0, "npm install should succeed") + child.on('close', function (code) { + t.equal(code, 0, 'npm install should succeed') // verify permissions on git hooks - var repoDir = "git-github-com-nigelzor-npm-4503-a-git-40c5cb24" - var hooksPath = path.join(cache, "_git-remotes", repoDir, "hooks") + var repoDir = 'git-github-com-nigelzor-npm-4503-a-git-40c5cb24' + var hooksPath = path.join(cache, '_git-remotes', repoDir, 'hooks') fs.readdir(hooksPath, function (err) { - t.equal(err && err.code, "ENOENT", "hooks are not brought along with repo") + t.equal(err && err.code, 'ENOENT', 'hooks are not brought along with repo') t.end() }) }) }) -test("cleanup", function (t) { +test('cleanup', function (t) { rimraf.sync(pkg) t.end() }) diff --git a/test/tap/git-dependency-install-link.js b/test/tap/git-dependency-install-link.js index cbb256d98..1eba7ff85 100644 --- a/test/tap/git-dependency-install-link.js +++ b/test/tap/git-dependency-install-link.js @@ -39,7 +39,6 @@ var pjChild = JSON.stringify({ version: '1.0.3' }, null, 2) + '\n' - test('setup', function (t) { bootstrap() setup(function (er, r) { diff --git a/test/tap/git-npmignore.js b/test/tap/git-npmignore.js index 5e915a706..4cd989872 100644 --- a/test/tap/git-npmignore.js +++ b/test/tap/git-npmignore.js @@ -1,62 +1,59 @@ -var cat = require("graceful-fs").writeFileSync -var exec = require("child_process").exec -var readdir = require("graceful-fs").readdirSync -var resolve = require("path").resolve - -var mkdirp = require("mkdirp") -var rimraf = require("rimraf") -var test = require("tap").test -var tmpdir = require("osenv").tmpdir -var which = require("which") - -var common = require("../common-tap.js") - -var pkg = resolve(__dirname, "git-npmignore") -var dep = resolve(pkg, "deps", "gitch") -var packname = "gitch-1.0.0.tgz" +var cat = require('graceful-fs').writeFileSync +var exec = require('child_process').exec +var readdir = require('graceful-fs').readdirSync +var resolve = require('path').resolve + +var mkdirp = require('mkdirp') +var rimraf = require('rimraf') +var test = require('tap').test +var tmpdir = require('osenv').tmpdir +var which = require('which') + +var common = require('../common-tap.js') + +var pkg = resolve(__dirname, 'git-npmignore') +var dep = resolve(pkg, 'deps', 'gitch') +var packname = 'gitch-1.0.0.tgz' var packed = resolve(pkg, packname) -var modules = resolve(pkg, "node_modules") -var installed = resolve(modules, "gitch") +var modules = resolve(pkg, 'node_modules') +var installed = resolve(modules, 'gitch') var expected = [ - "a.js", - "package.json", - ".npmignore" + 'a.js', + 'package.json', + '.npmignore' ].sort() -var EXEC_OPTS = { - cwd : pkg -} +var EXEC_OPTS = { cwd: pkg } -var gitignore = "node_modules/\n" -var npmignore = "t.js\n" +var gitignore = 'node_modules/\n' +var npmignore = 't.js\n' var a = "console.log('hi');" var t = "require('tap').test(function (t) { t.pass('I am a test!'); t.end(); });" var fixture = { - "name" : "gitch", - "version" : "1.0.0", - "private" : true, - "main" : "a.js" + 'name': 'gitch', + 'version': '1.0.0', + 'private': true, + 'main': 'a.js' } - -test("setup", function (t) { +test('setup', function (t) { setup(function (er) { - t.ifError(er, "setup ran OK") + t.ifError(er, 'setup ran OK') t.end() }) }) -test("npm pack directly from directory", function (t) { +test('npm pack directly from directory', function (t) { packInstallTest(dep, t) }) -test("npm pack via git", function (t) { - packInstallTest("git+file://"+dep, t) +test('npm pack via git', function (t) { + packInstallTest('git+file://' + dep, t) }) -test("cleanup", function (t) { +test('cleanup', function (t) { cleanup() t.end() @@ -65,29 +62,29 @@ test("cleanup", function (t) { function packInstallTest (spec, t) { common.npm( [ - "--loglevel", "silent", - "pack", spec + '--loglevel', 'silent', + 'pack', spec ], EXEC_OPTS, function (err, code, stdout, stderr) { - t.ifError(err, "npm pack ran without error") - t.notOk(code, "npm pack exited cleanly") - t.notOk(stderr, "npm pack ran silently") - t.equal(stdout.trim(), packname, "got expected package name") + t.ifError(err, 'npm pack ran without error') + t.notOk(code, 'npm pack exited cleanly') + t.notOk(stderr, 'npm pack ran silently') + t.equal(stdout.trim(), packname, 'got expected package name') common.npm( [ - "--loglevel", "silent", - "install", packed + '--loglevel', 'silent', + 'install', packed ], EXEC_OPTS, function (err, code, stdout, stderr) { - t.ifError(err, "npm install ran without error") - t.notOk(code, "npm install exited cleanly") - t.notOk(stderr, "npm install ran silently") + t.ifError(err, 'npm install ran without error') + t.notOk(code, 'npm install exited cleanly') + t.notOk(stderr, 'npm install ran silently') var actual = readdir(installed).sort() - t.same(actual, expected, "no unexpected files in packed directory") + t.same(actual, expected, 'no unexpected files in packed directory') rimraf(packed, function () { t.end() @@ -111,59 +108,59 @@ function setup (cb) { process.chdir(dep) - cat(resolve(dep, ".npmignore"), npmignore) - cat(resolve(dep, ".gitignore"), gitignore) - cat(resolve(dep, "a.js"), a) - cat(resolve(dep, "t.js"), t) - cat(resolve(dep, "package.json"), JSON.stringify(fixture)) + cat(resolve(dep, '.npmignore'), npmignore) + cat(resolve(dep, '.gitignore'), gitignore) + cat(resolve(dep, 'a.js'), a) + cat(resolve(dep, 't.js'), t) + cat(resolve(dep, 'package.json'), JSON.stringify(fixture)) common.npm( [ - "--loglevel", "silent", - "cache", "clean" + '--loglevel', 'silent', + 'cache', 'clean' ], EXEC_OPTS, function (er, code, _, stderr) { if (er) return cb(er) - if (code) return cb(new Error("npm cache nonzero exit: "+code)) - if (stderr) return cb(new Error("npm cache clean error: "+stderr)) + if (code) return cb(new Error('npm cache nonzero exit: ' + code)) + if (stderr) return cb(new Error('npm cache clean error: ' + stderr)) - which("git", function found (er, git) { + which('git', function found (er, git) { if (er) return cb(er) - exec(git+" init", init) + exec(git + ' init', init) function init (er, _, stderr) { if (er) return cb(er) - if (stderr) return cb(new Error("git init error: "+stderr)) + if (stderr) return cb(new Error('git init error: ' + stderr)) - exec(git+" config user.name 'Phantom Faker'", user) + exec(git + " config user.name 'Phantom Faker'", user) } function user (er, _, stderr) { if (er) return cb(er) - if (stderr) return cb(new Error("git config error: "+stderr)) + if (stderr) return cb(new Error('git config error: ' + stderr)) - exec(git+" config user.email nope@not.real", email) + exec(git + ' config user.email nope@not.real', email) } function email (er, _, stderr) { if (er) return cb(er) - if (stderr) return cb(new Error("git config error: "+stderr)) + if (stderr) return cb(new Error('git config error: ' + stderr)) - exec(git+" add .", addAll) + exec(git + ' add .', addAll) } function addAll (er, _, stderr) { if (er) return cb(er) - if (stderr) return cb(new Error("git add . error: "+stderr)) + if (stderr) return cb(new Error('git add . error: ' + stderr)) - exec(git+" commit -m boot", commit) + exec(git + ' commit -m boot', commit) } function commit (er, _, stderr) { if (er) return cb(er) - if (stderr) return cb(new Error("git commit error: "+stderr)) + if (stderr) return cb(new Error('git commit error: ' + stderr)) cb() } diff --git a/test/tap/global-prefix-set-in-userconfig.js b/test/tap/global-prefix-set-in-userconfig.js index f820a2772..422bcb247 100644 --- a/test/tap/global-prefix-set-in-userconfig.js +++ b/test/tap/global-prefix-set-in-userconfig.js @@ -1,36 +1,36 @@ -var common = require("../common-tap.js") -var test = require("tap").test -var rimraf = require("rimraf") -var prefix = __filename.replace(/\.js$/, "") -var rcfile = __filename.replace(/\.js$/, ".npmrc") -var fs = require("fs") -var conf = "prefix = " + prefix + "\n" +var common = require('../common-tap.js') +var test = require('tap').test +var rimraf = require('rimraf') +var prefix = __filename.replace(/\.js$/, '') +var rcfile = __filename.replace(/\.js$/, '.npmrc') +var fs = require('fs') +var conf = 'prefix = ' + prefix + '\n' -test("setup", function (t) { +test('setup', function (t) { rimraf.sync(prefix) fs.writeFileSync(rcfile, conf) - t.pass("ready") + t.pass('ready') t.end() }) -test("run command", function (t) { - var args = ["prefix", "-g", "--userconfig=" + rcfile] +test('run command', function (t) { + var args = ['prefix', '-g', '--userconfig=' + rcfile] common.npm(args, {env: {}}, function (er, code, so) { if (er) throw er - t.notOk(code, "npm prefix exited with code 0") + t.notOk(code, 'npm prefix exited with code 0') t.equal(so.trim(), prefix) t.end() }) }) -test("made dir", function (t) { +test('made dir', function (t) { t.ok(fs.statSync(prefix).isDirectory()) t.end() }) -test("cleanup", function (t) { +test('cleanup', function (t) { rimraf.sync(prefix) rimraf.sync(rcfile) - t.pass("clean") + t.pass('clean') t.end() }) diff --git a/test/tap/graceful-restart.js b/test/tap/graceful-restart.js index 532647480..21da0d990 100644 --- a/test/tap/graceful-restart.js +++ b/test/tap/graceful-restart.js @@ -107,8 +107,9 @@ function createChild (args, cb) { 'npm_config_loglevel': 'silent' } - if (process.platform === 'win32') + if (process.platform === 'win32') { env.npm_config_cache = '%APPDATA%\\npm-cache' + } return common.npm(args, { cwd: pkg, diff --git a/test/tap/ignore-install-link.js b/test/tap/ignore-install-link.js index 45db51d30..684c6a05b 100644 --- a/test/tap/ignore-install-link.js +++ b/test/tap/ignore-install-link.js @@ -1,68 +1,73 @@ -if (process.platform === "win32") { - console.log("ok - symlinks are weird on windows, skip this test") - return +if (process.platform === 'win32') { + console.log('ok - symlinks are weird on windows, skip this test') + process.exit(0) } -var common = require("../common-tap.js") -var test = require("tap").test -var path = require("path") -var fs = require("fs") -var rimraf = require("rimraf") -var mkdirp = require("mkdirp") +var common = require('../common-tap.js') +var test = require('tap').test +var path = require('path') +var fs = require('fs') +var rimraf = require('rimraf') +var mkdirp = require('mkdirp') -var root = path.resolve(__dirname, "ignore-install-link") -var pkg = path.resolve(root, "pkg") -var dep = path.resolve(root, "dep") -var target = path.resolve(pkg, "node_modules", "dep") -var cache = path.resolve(root, "cache") -var globalPath = path.resolve(root, "global") +var root = path.resolve(__dirname, 'ignore-install-link') +var pkg = path.resolve(root, 'pkg') +var dep = path.resolve(root, 'dep') +var target = path.resolve(pkg, 'node_modules', 'dep') +var cache = path.resolve(root, 'cache') +var globalPath = path.resolve(root, 'global') -var pkgj = { "name":"pkg", "version": "1.2.3" - , "dependencies": { "dep": "1.2.3" } } -var depj = { "name": "dep", "version": "1.2.3" } +var pkgj = { + 'name': 'pkg', + 'version': '1.2.3', + 'dependencies': { + 'dep': '1.2.3' + } +} +var depj = { 'name': 'dep', 'version': '1.2.3' } -var myreg = require("http").createServer(function (q, s) { +var myreg = require('http').createServer(function (q, s) { s.statusCode = 403 - s.end(JSON.stringify({"error":"forbidden"}) + "\n") + s.end(JSON.stringify({'error': 'forbidden'}) + '\n') }).listen(common.port) -test("setup", function (t) { +test('setup', function (t) { rimraf.sync(root) mkdirp.sync(root) - mkdirp.sync(path.resolve(pkg, "node_modules")) + mkdirp.sync(path.resolve(pkg, 'node_modules')) mkdirp.sync(dep) mkdirp.sync(cache) mkdirp.sync(globalPath) - fs.writeFileSync(path.resolve(pkg, "package.json"), JSON.stringify(pkgj)) - fs.writeFileSync(path.resolve(dep, "package.json"), JSON.stringify(depj)) - fs.symlinkSync(dep, target, "dir") + fs.writeFileSync(path.resolve(pkg, 'package.json'), JSON.stringify(pkgj)) + fs.writeFileSync(path.resolve(dep, 'package.json'), JSON.stringify(depj)) + fs.symlinkSync(dep, target, 'dir') t.end() }) -test("ignore install if package is linked", function (t) { - common.npm(["install"], { +test('ignore install if package is linked', function (t) { + common.npm(['install'], { cwd: pkg, env: { PATH: process.env.PATH || process.env.Path, HOME: process.env.HOME, - "npm_config_prefix": globalPath, - "npm_config_cache": cache, - "npm_config_registry": common.registry, - "npm_config_loglevel": "silent" + 'npm_config_prefix': globalPath, + 'npm_config_cache': cache, + 'npm_config_registry': common.registry, + 'npm_config_loglevel': 'silent' }, - stdio: "inherit" + stdio: 'inherit' }, function (er, code) { if (er) throw er - t.equal(code, 0, "npm install exited with code") + t.equal(code, 0, 'npm install exited with code') t.end() }) }) -test("still a symlink", function (t) { +test('still a symlink', function (t) { t.equal(true, fs.lstatSync(target).isSymbolicLink()) t.end() }) -test("cleanup", function (t) { +test('cleanup', function (t) { rimraf.sync(root) myreg.close() t.end() diff --git a/test/tap/init-interrupt.js b/test/tap/init-interrupt.js index 962ab7244..2e85a5d1b 100644 --- a/test/tap/init-interrupt.js +++ b/test/tap/init-interrupt.js @@ -1,52 +1,52 @@ -// if "npm init" is interrupted with ^C, don't report -// "init written successfully" -var test = require("tap").test -var path = require("path") -var osenv = require("osenv") -var rimraf = require("rimraf") -var npmlog = require("npmlog") -var requireInject = require("require-inject") +// if 'npm init' is interrupted with ^C, don't report +// 'init written successfully' +var test = require('tap').test +var path = require('path') +var osenv = require('osenv') +var rimraf = require('rimraf') +var npmlog = require('npmlog') +var requireInject = require('require-inject') -var npm = require("../../lib/npm.js") +var npm = require('../../lib/npm.js') -var PKG_DIR = path.resolve(__dirname, "init-interrupt") +var PKG_DIR = path.resolve(__dirname, 'init-interrupt') -test("setup", function (t) { +test('setup', function (t) { cleanup() t.end() }) -test("issue #6684 remove confusing message", function (t) { +test('issue #6684 remove confusing message', function (t) { var initJsonMock = function (dir, input, config, cb) { process.nextTick(function () { - cb({message : "canceled"}) + cb({ message: 'canceled' }) }) } initJsonMock.yes = function () { return true } - npm.load({loglevel : "silent"}, function () { - var log = "" - var init = requireInject("../../lib/init", { - "init-package-json": initJsonMock + npm.load({ loglevel: 'silent' }, function () { + var log = '' + var init = requireInject('../../lib/init', { + 'init-package-json': initJsonMock }) // capture log messages - npmlog.on("log", function (chunk) { log += chunk.message + "\n" } ) + npmlog.on('log', function (chunk) { log += chunk.message + '\n' }) init([], function (err, code) { - t.ifError(err, "init ran successfully") - t.notOk(code, "exited without issue") - t.notSimilar(log, /written successfully/, "no success message written") - t.similar(log, /canceled/, "alerted that init was canceled") + t.ifError(err, 'init ran successfully') + t.notOk(code, 'exited without issue') + t.notSimilar(log, /written successfully/, 'no success message written') + t.similar(log, /canceled/, 'alerted that init was canceled') t.end() }) }) }) -test("cleanup", function (t) { +test('cleanup', function (t) { cleanup() t.end() diff --git a/test/tap/install-bad-man.js b/test/tap/install-bad-man.js index 9ec8a8473..756b4a590 100644 --- a/test/tap/install-bad-man.js +++ b/test/tap/install-bad-man.js @@ -1,53 +1,52 @@ -var fs = require("fs") -var resolve = require("path").resolve +var fs = require('fs') +var resolve = require('path').resolve -var osenv = require("osenv") -var mkdirp = require("mkdirp") -var rimraf = require("rimraf") -var test = require("tap").test +var osenv = require('osenv') +var mkdirp = require('mkdirp') +var rimraf = require('rimraf') +var test = require('tap').test -var common = require("../common-tap.js") +var common = require('../common-tap.js') -var pkg = resolve(__dirname, "install-bad-man") -var target = resolve(__dirname, "install-bad-man-target") +var pkg = resolve(__dirname, 'install-bad-man') +var target = resolve(__dirname, 'install-bad-man-target') var EXEC_OPTS = { cwd: target } var json = { - name : "install-bad-man", - version : "1.2.3", - man : [ "./install-bad-man.1.lol" ] + name: 'install-bad-man', + version: '1.2.3', + man: [ './install-bad-man.1.lol' ] } - -test("setup", function (t) { +test('setup', function (t) { setup() - t.pass("setup ran") + t.pass('setup ran') t.end() }) test("install from repo on 'OS X'", function (t) { common.npm( [ - "install", - "--prefix", target, - "--global", + 'install', + '--prefix', target, + '--global', pkg ], EXEC_OPTS, function (err, code, stdout, stderr) { - t.ifError(err, "npm command ran from test") - t.equals(code, 1, "install exited with failure (1)") - t.notOk(stdout, "no output indicating success") + t.ifError(err, 'npm command ran from test') + t.equals(code, 1, 'install exited with failure (1)') + t.notOk(stdout, 'no output indicating success') t.notOk( stderr.match(/Cannot read property '1' of null/), - "no longer has cryptic error output" + 'no longer has cryptic error output' ) t.ok( stderr.match(/install-bad-man\.1\.lol is not a valid name/), - "got expected error output" + 'got expected error output' ) t.end() @@ -55,9 +54,9 @@ test("install from repo on 'OS X'", function (t) { ) }) -test("clean", function (t) { +test('clean', function (t) { cleanup() - t.pass("cleaned up") + t.pass('cleaned up') t.end() }) @@ -65,12 +64,12 @@ function setup () { cleanup() mkdirp.sync(pkg) // make sure it installs locally - mkdirp.sync(resolve(target, "node_modules")) + mkdirp.sync(resolve(target, 'node_modules')) fs.writeFileSync( - resolve(pkg, "package.json"), - JSON.stringify(json, null, 2)+"\n" + resolve(pkg, 'package.json'), + JSON.stringify(json, null, 2) + '\n' ) - fs.writeFileSync(resolve(pkg, "install-bad-man.1.lol"), "lol\n") + fs.writeFileSync(resolve(pkg, 'install-bad-man.1.lol'), 'lol\n') } function cleanup () { diff --git a/test/tap/install-man.js b/test/tap/install-man.js index ebba5d87b..d309788b2 100644 --- a/test/tap/install-man.js +++ b/test/tap/install-man.js @@ -1,48 +1,48 @@ -var fs = require("fs") -var resolve = require("path").resolve +var fs = require('fs') +var resolve = require('path').resolve -var osenv = require("osenv") -var mkdirp = require("mkdirp") -var rimraf = require("rimraf") -var test = require("tap").test +var osenv = require('osenv') +var mkdirp = require('mkdirp') +var rimraf = require('rimraf') +var test = require('tap').test -var common = require("../common-tap.js") +var common = require('../common-tap.js') -var pkg = resolve(__dirname, "install-man") -var target = resolve(__dirname, "install-man-target") +var pkg = resolve(__dirname, 'install-man') +var target = resolve(__dirname, 'install-man-target') var EXEC_OPTS = { cwd: target } var json = { - name : "install-man", - version : "1.2.3", - man : [ "./install-man.1" ] + name: 'install-man', + version: '1.2.3', + man: [ './install-man.1' ] } -test("setup", function (t) { +test('setup', function (t) { setup() - t.pass("setup ran") + t.pass('setup ran') t.end() }) -test("install man page", function (t) { +test('install man page', function (t) { common.npm( [ - "install", - "--prefix", target, - "--global", + 'install', + '--prefix', target, + '--global', pkg ], EXEC_OPTS, function (err, code, stdout, stderr) { - t.ifError(err, "npm command ran from test") - t.equals(code, 0, "install exited with success (0)") - t.ok(stdout, "output indicating success") + t.ifError(err, 'npm command ran from test') + t.equals(code, 0, 'install exited with success (0)') + t.ok(stdout, 'output indicating success') t.ok( - fs.existsSync(resolve(target, "share", "man", "man1", "install-man.1")), - "man page link was created" + fs.existsSync(resolve(target, 'share', 'man', 'man1', 'install-man.1')), + 'man page link was created' ) t.end() @@ -50,9 +50,9 @@ test("install man page", function (t) { ) }) -test("clean", function (t) { +test('clean', function (t) { cleanup() - t.pass("cleaned up") + t.pass('cleaned up') t.end() }) @@ -60,12 +60,12 @@ function setup () { cleanup() mkdirp.sync(pkg) // make sure it installs locally - mkdirp.sync(resolve(target, "node_modules")) + mkdirp.sync(resolve(target, 'node_modules')) fs.writeFileSync( - resolve(pkg, "package.json"), - JSON.stringify(json, null, 2)+"\n" + resolve(pkg, 'package.json'), + JSON.stringify(json, null, 2) + '\n' ) - fs.writeFileSync(resolve(pkg, "install-man.1"), "THIS IS A MANPAGE\n") + fs.writeFileSync(resolve(pkg, 'install-man.1'), 'THIS IS A MANPAGE\n') } function cleanup () { diff --git a/test/tap/install-scoped-already-installed.js b/test/tap/install-scoped-already-installed.js index 412d06940..f3c191ddb 100644 --- a/test/tap/install-scoped-already-installed.js +++ b/test/tap/install-scoped-already-installed.js @@ -125,7 +125,7 @@ test('cleanup', function (t) { }) function contains (list, element) { - var matcher = new RegExp(element+'$') + var matcher = new RegExp(element + '$') for (var i = 0; i < list.length; ++i) { if (matcher.test(list[i])) { return true diff --git a/test/tap/invalid-cmd-exit-code.js b/test/tap/invalid-cmd-exit-code.js index c9918e5a7..f4bb444a1 100644 --- a/test/tap/invalid-cmd-exit-code.js +++ b/test/tap/invalid-cmd-exit-code.js @@ -1,28 +1,28 @@ -var test = require("tap").test -var common = require("../common-tap.js") +var test = require('tap').test +var common = require('../common-tap.js') var opts = { cwd: process.cwd() } -test("npm asdf should return exit code 1", function (t) { - common.npm(["asdf"], opts, function (er, c) { +test('npm asdf should return exit code 1', function (t) { + common.npm(['asdf'], opts, function (er, c) { if (er) throw er - t.ok(c, "exit code should not be zero") + t.ok(c, 'exit code should not be zero') t.end() }) }) -test("npm help should return exit code 0", function (t) { - common.npm(["help"], opts, function (er, c) { +test('npm help should return exit code 0', function (t) { + common.npm(['help'], opts, function (er, c) { if (er) throw er - t.equal(c, 0, "exit code should be 0") + t.equal(c, 0, 'exit code should be 0') t.end() }) }) -test("npm help fadf should return exit code 0", function (t) { - common.npm(["help", "fadf"], opts, function (er, c) { +test('npm help fadf should return exit code 0', function (t) { + common.npm(['help', 'fadf'], opts, function (er, c) { if (er) throw er - t.equal(c, 0, "exit code should be 0") + t.equal(c, 0, 'exit code should be 0') t.end() }) }) diff --git a/test/tap/lifecycle.js b/test/tap/lifecycle.js index aa0efc526..1bd77c383 100644 --- a/test/tap/lifecycle.js +++ b/test/tap/lifecycle.js @@ -1,12 +1,12 @@ -var test = require("tap").test -var npm = require("../../") -var lifecycle = require("../../lib/utils/lifecycle") +var test = require('tap').test +var npm = require('../../') +var lifecycle = require('../../lib/utils/lifecycle') -test("lifecycle: make env correctly", function (t) { +test('lifecycle: make env correctly', function (t) { npm.load({enteente: Infinity}, function () { var env = lifecycle.makeEnv({}, null, process.env) - t.equal("Infinity", env.npm_config_enteente) + t.equal('Infinity', env.npm_config_enteente) t.end() }) }) diff --git a/test/tap/link.js b/test/tap/link.js index ea47e8296..684fcf7e1 100644 --- a/test/tap/link.js +++ b/test/tap/link.js @@ -44,7 +44,6 @@ var installJSON = { license: 'ISC' } - test('setup', function (t) { setup() common.npm(['ls', '-g', '--depth=0'], OPTS, function (err, c, out) { diff --git a/test/tap/locker.js b/test/tap/locker.js index bc43c30e9..8c548095f 100644 --- a/test/tap/locker.js +++ b/test/tap/locker.js @@ -1,54 +1,54 @@ -var test = require("tap").test - , path = require("path") - , fs = require("graceful-fs") - , crypto = require("crypto") - , rimraf = require("rimraf") - , osenv = require("osenv") - , mkdirp = require("mkdirp") - , npm = require("../../") - , locker = require("../../lib/utils/locker.js") - , lock = locker.lock - , unlock = locker.unlock +var test = require('tap').test +var path = require('path') +var fs = require('graceful-fs') +var crypto = require('crypto') +var rimraf = require('rimraf') +var osenv = require('osenv') +var mkdirp = require('mkdirp') +var npm = require('../../') +var locker = require('../../lib/utils/locker.js') +var lock = locker.lock +var unlock = locker.unlock -var pkg = path.join(__dirname, "/locker") - , cache = path.join(pkg, "/cache") - , tmp = path.join(pkg, "/tmp") - , nm = path.join(pkg, "/node_modules") +var pkg = path.join(__dirname, '/locker') +var cache = path.join(pkg, '/cache') +var tmp = path.join(pkg, '/tmp') +var nm = path.join(pkg, '/node_modules') function cleanup () { process.chdir(osenv.tmpdir()) rimraf.sync(pkg) } -test("setup", function (t) { +test('setup', function (t) { cleanup() mkdirp.sync(cache) mkdirp.sync(tmp) t.end() }) -test("locking file puts lock in correct place", function (t) { +test('locking file puts lock in correct place', function (t) { npm.load({cache: cache, tmpdir: tmp}, function (er) { - t.ifError(er, "npm bootstrapped OK") + t.ifError(er, 'npm bootstrapped OK') - var n = "correct" - , c = n.replace(/[^a-zA-Z0-9]+/g, "-").replace(/^-+|-+$/g, "") - , p = path.resolve(nm, n) - , h = crypto.createHash("sha1").update(p).digest("hex") - , l = c.substr(0, 24)+"-"+h.substr(0, 16)+".lock" - , v = path.join(cache, "_locks", l) + var n = 'correct' + var c = n.replace(/[^a-zA-Z0-9]+/g, '-').replace(/^-+|-+$/g, '') + var p = path.resolve(nm, n) + var h = crypto.createHash('sha1').update(p).digest('hex') + var l = c.substr(0, 24) + '-' + h.substr(0, 16) + '.lock' + var v = path.join(cache, '_locks', l) lock(nm, n, function (er) { - t.ifError(er, "locked path") + t.ifError(er, 'locked path') fs.exists(v, function (found) { - t.ok(found, "lock found OK") + t.ok(found, 'lock found OK') unlock(nm, n, function (er) { - t.ifError(er, "unlocked path") + t.ifError(er, 'unlocked path') fs.exists(v, function (found) { - t.notOk(found, "lock deleted OK") + t.notOk(found, 'lock deleted OK') t.end() }) }) @@ -57,33 +57,33 @@ test("locking file puts lock in correct place", function (t) { }) }) -test("unlocking out of order errors out", function (t) { +test('unlocking out of order errors out', function (t) { npm.load({cache: cache, tmpdir: tmp}, function (er) { - t.ifError(er, "npm bootstrapped OK") + t.ifError(er, 'npm bootstrapped OK') - var n = "busted" - , c = n.replace(/[^a-zA-Z0-9]+/g, "-").replace(/^-+|-+$/g, "") - , p = path.resolve(nm, n) - , h = crypto.createHash("sha1").update(p).digest("hex") - , l = c.substr(0, 24)+"-"+h.substr(0, 16)+".lock" - , v = path.join(cache, "_locks", l) + var n = 'busted' + var c = n.replace(/[^a-zA-Z0-9]+/g, '-').replace(/^-+|-+$/g, '') + var p = path.resolve(nm, n) + var h = crypto.createHash('sha1').update(p).digest('hex') + var l = c.substr(0, 24) + '-' + h.substr(0, 16) + '.lock' + var v = path.join(cache, '_locks', l) fs.exists(v, function (found) { - t.notOk(found, "no lock to unlock") + t.notOk(found, 'no lock to unlock') t.throws(function () { unlock(nm, n, function () { t.fail("shouldn't get here") t.end() }) - }, "blew up as expected") + }, 'blew up as expected') t.end() }) }) }) -test("cleanup", function (t) { +test('cleanup', function (t) { cleanup() t.end() }) diff --git a/test/tap/logout.js b/test/tap/logout.js index 1d9392ad1..3a62cc273 100644 --- a/test/tap/logout.js +++ b/test/tap/logout.js @@ -1,58 +1,58 @@ -var fs = require("fs") -var path = require("path") +var fs = require('fs') +var path = require('path') -var mkdirp = require("mkdirp") -var mr = require("npm-registry-mock") -var rimraf = require("rimraf") -var test = require("tap").test +var mkdirp = require('mkdirp') +var mr = require('npm-registry-mock') +var rimraf = require('rimraf') +var test = require('tap').test -var common = require("../common-tap.js") +var common = require('../common-tap.js') -var pkg = path.resolve(__dirname, "logout") -var outfile = path.join(pkg, "_npmrc") +var pkg = path.resolve(__dirname, 'logout') +var outfile = path.join(pkg, '_npmrc') var opts = { cwd: pkg } var contents = function () {/* foo=boo //localhost:1337/:_authToken=glarb -*/}.toString().split("\n").slice(1, -1).join("\n") +*/}.toString().split('\n').slice(1, -1).join('\n') function mocks (server) { - server.delete("/-/user/token/glarb") + server.delete('/-/user/token/glarb') .reply(200, {}) } -test("setup", function (t) { +test('setup', function (t) { cleanup() setup() t.end() }) -test("npm logout", function (t) { +test('npm logout', function (t) { mr({ port: common.port, plugin: mocks }, function (err, s) { if (err) throw err common.npm( [ - "logout", - "--registry", common.registry, - "--loglevel", "silent", - "--userconfig", outfile + 'logout', + '--registry', common.registry, + '--loglevel', 'silent', + '--userconfig', outfile ], opts, function (err, code) { - t.ifError(err, "no error output") - t.notOk(code, "exited OK") + t.ifError(err, 'no error output') + t.notOk(code, 'exited OK') - var config = fs.readFileSync(outfile, "utf8") - t.equal(config, "foo=boo\n", "creds gone") + var config = fs.readFileSync(outfile, 'utf8') + t.equal(config, 'foo=boo\n', 'creds gone') s.close() t.end() }) }) }) -test("cleanup", function (t) { +test('cleanup', function (t) { cleanup() t.end() }) diff --git a/test/tap/ls-l-depth-0.js b/test/tap/ls-l-depth-0.js index d723b9c92..ab3189f2e 100644 --- a/test/tap/ls-l-depth-0.js +++ b/test/tap/ls-l-depth-0.js @@ -62,7 +62,9 @@ test('#6311: npm ll --depth=0 duplicates listing', function (t) { t.notOk(stderr, 'npm install ran silently') t.equal( stdout.trim(), - resolve(__dirname,'ls-l-depth-0')+'\n└─┬ glock@1.8.7 \n └── underscore@1.5.1', + resolve(__dirname, 'ls-l-depth-0') + + '\n└─┬ glock@1.8.7 ' + + '\n └── underscore@1.5.1', 'got expected install output' ) diff --git a/test/tap/ls-no-results.js b/test/tap/ls-no-results.js index 10f3ce001..9792774c6 100644 --- a/test/tap/ls-no-results.js +++ b/test/tap/ls-no-results.js @@ -1,11 +1,11 @@ -var test = require("tap").test -var spawn = require("child_process").spawn +var test = require('tap').test +var spawn = require('child_process').spawn var node = process.execPath -var npm = require.resolve("../../") -var args = [ npm, "ls", "ceci n’est pas une package" ] -test("ls exits non-zero when nothing found", function (t) { +var npm = require.resolve('../../') +var args = [ npm, 'ls', 'ceci n’est pas une package' ] +test('ls exits non-zero when nothing found', function (t) { var child = spawn(node, args) - child.on("exit", function (code) { + child.on('exit', function (code) { t.notEqual(code, 0) t.end() }) diff --git a/test/tap/nerf-dart.js b/test/tap/nerf-dart.js index 157f6c7df..a6df7272c 100644 --- a/test/tap/nerf-dart.js +++ b/test/tap/nerf-dart.js @@ -1,32 +1,32 @@ // taken from https://raw.githubusercontent.com/indexzero/npm/bd3cad01fbd3ab481d2f5da441b9eead16029123/test/tap/config-nerf-dart.js // originally written by Charlie Robbins, https://github.com/indexzero -var test = require("tap").test -var toNerfDart = require("../../lib/config/nerf-dart.js") +var test = require('tap').test +var toNerfDart = require('../../lib/config/nerf-dart.js') function validNerfDart (uri, valid) { - if (!valid) valid = "//registry.npmjs.org/" + if (!valid) valid = '//registry.npmjs.org/' test(uri, function (t) { t.equal(toNerfDart(uri), valid) t.end() }) } -validNerfDart("http://registry.npmjs.org") -validNerfDart("http://registry.npmjs.org/some-package") -validNerfDart("http://registry.npmjs.org/some-package?write=true") -validNerfDart("http://user:pass@registry.npmjs.org/some-package?write=true") -validNerfDart("http://registry.npmjs.org/#random-hash") -validNerfDart("http://registry.npmjs.org/some-package#random-hash") +validNerfDart('http://registry.npmjs.org') +validNerfDart('http://registry.npmjs.org/some-package') +validNerfDart('http://registry.npmjs.org/some-package?write=true') +validNerfDart('http://user:pass@registry.npmjs.org/some-package?write=true') +validNerfDart('http://registry.npmjs.org/#random-hash') +validNerfDart('http://registry.npmjs.org/some-package#random-hash') validNerfDart( - "http://relative.couchapp.npm/design/-/rewrite/", - "//relative.couchapp.npm/design/-/rewrite/" + 'http://relative.couchapp.npm/design/-/rewrite/', + '//relative.couchapp.npm/design/-/rewrite/' ) validNerfDart( - "http://relative.couchapp.npm:8080/design/-/rewrite/", - "//relative.couchapp.npm:8080/design/-/rewrite/" + 'http://relative.couchapp.npm:8080/design/-/rewrite/', + '//relative.couchapp.npm:8080/design/-/rewrite/' ) validNerfDart( - "http://relative.couchapp.npm:8080/design/-/rewrite/some-package", - "//relative.couchapp.npm:8080/design/-/rewrite/" + 'http://relative.couchapp.npm:8080/design/-/rewrite/some-package', + '//relative.couchapp.npm:8080/design/-/rewrite/' ) diff --git a/test/tap/nested-extraneous.js b/test/tap/nested-extraneous.js index fcba0418e..99d4bea5b 100644 --- a/test/tap/nested-extraneous.js +++ b/test/tap/nested-extraneous.js @@ -1,42 +1,42 @@ -var common = require("../common-tap.js") -var test = require("tap").test -var mkdirp = require("mkdirp") -var fs = require("fs") -var rimraf = require("rimraf") -var path = require("path") +var common = require('../common-tap.js') +var test = require('tap').test +var mkdirp = require('mkdirp') +var fs = require('fs') +var rimraf = require('rimraf') +var path = require('path') -var pkg = path.resolve(__dirname, "nested-extraneous") +var pkg = path.resolve(__dirname, 'nested-extraneous') var pj = { - name: "nested-extraneous", - version: "1.2.3" + name: 'nested-extraneous', + version: '1.2.3' } -var dep = path.resolve(pkg, "node_modules", "dep") +var dep = path.resolve(pkg, 'node_modules', 'dep') var deppj = { - name: "nested-extraneous-dep", - version: "1.2.3", + name: 'nested-extraneous-dep', + version: '1.2.3', dependencies: { - "nested-extra-depdep": "*" + 'nested-extra-depdep': '*' } } -var depdep = path.resolve(dep, "node_modules", "depdep") +var depdep = path.resolve(dep, 'node_modules', 'depdep') var depdeppj = { - name: "nested-extra-depdep", - version: "1.2.3" + name: 'nested-extra-depdep', + version: '1.2.3' } -test("setup", function (t) { +test('setup', function (t) { rimraf.sync(pkg) mkdirp.sync(depdep) - fs.writeFileSync(path.resolve(pkg, "package.json"), JSON.stringify(pj)) - fs.writeFileSync(path.resolve(dep, "package.json"), JSON.stringify(deppj)) - fs.writeFileSync(path.resolve(depdep, "package.json"), JSON.stringify(depdeppj)) + fs.writeFileSync(path.resolve(pkg, 'package.json'), JSON.stringify(pj)) + fs.writeFileSync(path.resolve(dep, 'package.json'), JSON.stringify(deppj)) + fs.writeFileSync(path.resolve(depdep, 'package.json'), JSON.stringify(depdeppj)) t.end() }) -test("test", function (t) { - common.npm(["ls"], { +test('test', function (t) { + common.npm(['ls'], { cwd: pkg }, function (er, code, sto, ste) { if (er) throw er @@ -47,7 +47,7 @@ test("test", function (t) { }) }) -test("clean", function (t) { +test('clean', function (t) { rimraf.sync(pkg) t.end() }) diff --git a/test/tap/noargs-install-config-save.js b/test/tap/noargs-install-config-save.js index b6900b431..81b23cca9 100644 --- a/test/tap/noargs-install-config-save.js +++ b/test/tap/noargs-install-config-save.js @@ -1,46 +1,47 @@ -var common = require("../common-tap.js") -var test = require("tap").test -var npm = require.resolve("../../bin/npm-cli.js") -var path = require("path") -var fs = require("fs") -var rimraf = require("rimraf") -var mkdirp = require("mkdirp") +var common = require('../common-tap.js') +var test = require('tap').test +var npm = require.resolve('../../bin/npm-cli.js') +var path = require('path') +var fs = require('fs') +var rimraf = require('rimraf') +var mkdirp = require('mkdirp') -var mr = require("npm-registry-mock") +var mr = require('npm-registry-mock') -var spawn = require("child_process").spawn +var spawn = require('child_process').spawn var node = process.execPath -var pkg = path.resolve(process.env.npm_config_tmp || "/tmp", - "noargs-install-config-save") +var pkg = path.resolve(process.env.npm_config_tmp || '/tmp', + 'noargs-install-config-save') -function writePackageJson() { +function writePackageJson () { rimraf.sync(pkg) mkdirp.sync(pkg) - mkdirp.sync(pkg + "/cache") + mkdirp.sync(pkg + '/cache') - fs.writeFileSync(pkg + "/package.json", JSON.stringify({ - "author": "Rocko Artischocko", - "name": "noargs", - "version": "0.0.0", - "devDependencies": { - "underscore": "1.3.1" + fs.writeFileSync(pkg + '/package.json', JSON.stringify({ + 'author': 'Rocko Artischocko', + 'name': 'noargs', + 'version': '0.0.0', + 'devDependencies': { + 'underscore': '1.3.1' } - }), "utf8") + }), 'utf8') } function createChild (args) { var env = { - "npm_config_save": true, - "npm_config_registry": common.registry, - "npm_config_cache": pkg + "/cache", + 'npm_config_save': true, + 'npm_config_registry': common.registry, + 'npm_config_cache': pkg + '/cache', HOME: process.env.HOME, Path: process.env.PATH, PATH: process.env.PATH } - if (process.platform === "win32") - env.npm_config_cache = "%APPDATA%\\npm-cache" + if (process.platform === 'win32') { + env.npm_config_cache = '%APPDATA%\\npm-cache' + } return spawn(node, args, { cwd: pkg, @@ -48,35 +49,35 @@ function createChild (args) { }) } -test("does not update the package.json with empty arguments", function (t) { +test('does not update the package.json with empty arguments', function (t) { writePackageJson() t.plan(1) - mr({port : common.port}, function (er, s) { - var child = createChild([npm, "install"]) - child.on("close", function () { - var text = JSON.stringify(fs.readFileSync(pkg + "/package.json", "utf8")) + mr({ port: common.port }, function (er, s) { + var child = createChild([npm, 'install']) + child.on('close', function () { + var text = JSON.stringify(fs.readFileSync(pkg + '/package.json', 'utf8')) s.close() - t.ok(text.indexOf("\"dependencies") === -1) + t.ok(text.indexOf('"dependencies') === -1) }) }) }) -test("updates the package.json (adds dependencies) with an argument", function (t) { +test('updates the package.json (adds dependencies) with an argument', function (t) { writePackageJson() t.plan(1) - mr({port : common.port}, function (er, s) { - var child = createChild([npm, "install", "underscore"]) - child.on("close", function () { + mr({ port: common.port }, function (er, s) { + var child = createChild([npm, 'install', 'underscore']) + child.on('close', function () { s.close() - var text = JSON.stringify(fs.readFileSync(pkg + "/package.json", "utf8")) - t.ok(text.indexOf("\"dependencies") !== -1) + var text = JSON.stringify(fs.readFileSync(pkg + '/package.json', 'utf8')) + t.ok(text.indexOf('"dependencies') !== -1) }) }) }) -test("cleanup", function (t) { - rimraf.sync(pkg + "/cache") +test('cleanup', function (t) { + rimraf.sync(pkg + '/cache') t.end() }) diff --git a/test/tap/npm-api-not-loaded-error.js b/test/tap/npm-api-not-loaded-error.js index afedfbcd0..48b71e521 100644 --- a/test/tap/npm-api-not-loaded-error.js +++ b/test/tap/npm-api-not-loaded-error.js @@ -1,47 +1,47 @@ -var test = require("tap").test -var npm = require("../..") -var path = require("path") -var rimraf = require("rimraf") -var npmrc = path.join(__dirname, "npmrc") -var fs = require("fs") +var test = require('tap').test +var npm = require('../..') +var path = require('path') +var rimraf = require('rimraf') +var npmrc = path.join(__dirname, 'npmrc') +var fs = require('fs') -test("setup", function (t) { - fs.writeFileSync(npmrc, "foo = bar\n", "ascii") +test('setup', function (t) { + fs.writeFileSync(npmrc, 'foo = bar\n', 'ascii') t.end() }) -test("calling set/get on config pre-load should throw", function (t) { +test('calling set/get on config pre-load should throw', function (t) { var threw = true try { - npm.config.get("foo") + npm.config.get('foo') threw = false } catch (er) { - t.equal(er.message, "npm.load() required") + t.equal(er.message, 'npm.load() required') } finally { - t.ok(threw, "get before load should throw") + t.ok(threw, 'get before load should throw') } threw = true try { - npm.config.set("foo", "bar") + npm.config.set('foo', 'bar') threw = false } catch (er) { - t.equal(er.message, "npm.load() required") + t.equal(er.message, 'npm.load() required') } finally { - t.ok(threw, "set before load should throw") + t.ok(threw, 'set before load should throw') } npm.load({ userconfig: npmrc }, function (er) { - if (er) - throw er - t.equal(npm.config.get("foo"), "bar") - npm.config.set("foo", "baz") - t.equal(npm.config.get("foo"), "baz") + if (er) throw er + + t.equal(npm.config.get('foo'), 'bar') + npm.config.set('foo', 'baz') + t.equal(npm.config.get('foo'), 'baz') t.end() }) }) -test("cleanup", function (t) { +test('cleanup', function (t) { rimraf.sync(npmrc) t.end() }) diff --git a/test/tap/optional-metadep-rollback-collision.js b/test/tap/optional-metadep-rollback-collision.js index 53befd593..10a33319d 100644 --- a/test/tap/optional-metadep-rollback-collision.js +++ b/test/tap/optional-metadep-rollback-collision.js @@ -63,7 +63,6 @@ var opdep = { } } - var badServer = function () {/* var createServer = require('http').createServer var spawn = require('child_process').spawn diff --git a/test/tap/outdated-depth-deep.js b/test/tap/outdated-depth-deep.js index 8d4a6428a..c39e029aa 100644 --- a/test/tap/outdated-depth-deep.js +++ b/test/tap/outdated-depth-deep.js @@ -1,26 +1,26 @@ -var common = require("../common-tap") - , path = require("path") - , test = require("tap").test - , rimraf = require("rimraf") - , npm = require("../../") - , mr = require("npm-registry-mock") - , pkg = path.resolve(__dirname, "outdated-depth-deep") - , cache = path.resolve(pkg, "cache") +var common = require('../common-tap') +var path = require('path') +var test = require('tap').test +var rimraf = require('rimraf') +var npm = require('../../') +var mr = require('npm-registry-mock') +var pkg = path.resolve(__dirname, 'outdated-depth-deep') +var cache = path.resolve(pkg, 'cache') -var osenv = require("osenv") -var mkdirp = require("mkdirp") -var fs = require("fs") +var osenv = require('osenv') +var mkdirp = require('mkdirp') +var fs = require('fs') var pj = JSON.stringify({ - "name": "whatever", - "description": "yeah idk", - "version": "1.2.3", - "main": "index.js", - "dependencies": { - "underscore": "1.3.1", - "npm-test-peer-deps": "0.0.0" + 'name': 'whatever', + 'description': 'yeah idk', + 'version': '1.2.3', + 'main': 'index.js', + 'dependencies': { + 'underscore': '1.3.1', + 'npm-test-peer-deps': '0.0.0' }, - "repository": "git://github.com/luk-/whatever" + 'repository': 'git://github.com/luk-/whatever' }, null, 2) function cleanup () { @@ -31,51 +31,49 @@ function cleanup () { function setup () { mkdirp.sync(pkg) process.chdir(pkg) - fs.writeFileSync(path.resolve(pkg, "package.json"), pj) + fs.writeFileSync(path.resolve(pkg, 'package.json'), pj) } -test("setup", function (t) { +test('setup', function (t) { cleanup() setup() t.end() }) -test("outdated depth deep (9999)", function (t) { - var underscoreOutdated = ["underscore", "1.3.1", "1.3.1", "1.5.1", "1.3.1"] - var childPkg = path.resolve(pkg, "node_modules", "npm-test-peer-deps") +test('outdated depth deep (9999)', function (t) { + var underscoreOutdated = ['underscore', '1.3.1', '1.3.1', '1.5.1', '1.3.1'] + var childPkg = path.resolve(pkg, 'node_modules', 'npm-test-peer-deps') var expected = [ [childPkg].concat(underscoreOutdated).concat([null]), [pkg].concat(underscoreOutdated).concat([null]) ] process.chdir(pkg) - mr({port : common.port}, function (er, s) { + mr({ port: common.port }, function (er, s) { npm.load({ - cache: cache - , loglevel: "silent" - , registry: common.registry - , depth: 9999 - } - , function () { - npm.install(".", function (er) { + cache: cache, + loglevel: 'silent', + registry: common.registry, + depth: 9999 + }, + function () { + npm.install('.', function (er) { + if (er) throw new Error(er) + npm.explore('npm-test-peer-deps', 'npm', 'install', 'underscore', function (er) { if (er) throw new Error(er) - npm.explore("npm-test-peer-deps", "npm", "install", "underscore", function (er) { - if (er) throw new Error(er) - npm.outdated(function (err, d) { - if (err) throw new Error(err) - t.deepEqual(d, expected) - s.close() - t.end() - }) + npm.outdated(function (err, d) { + if (err) throw new Error(err) + t.deepEqual(d, expected) + s.close() + t.end() }) }) - } - ) + }) + }) }) }) - -test("cleanup", function (t) { +test('cleanup', function (t) { cleanup() t.end() }) diff --git a/test/tap/outdated-depth-integer.js b/test/tap/outdated-depth-integer.js index 6bfb304b1..ddd2dd7c3 100644 --- a/test/tap/outdated-depth-integer.js +++ b/test/tap/outdated-depth-integer.js @@ -1,24 +1,24 @@ var common = require('../common-tap') - , test = require('tap').test - , rimraf = require('rimraf') - , npm = require('../../') - , mr = require('npm-registry-mock') - , pkg = __dirname + '/outdated-depth-integer' +var test = require('tap').test +var rimraf = require('rimraf') +var npm = require('../../') +var mr = require('npm-registry-mock') +var pkg = __dirname + '/outdated-depth-integer' -var osenv = require("osenv") -var mkdirp = require("mkdirp") -var fs = require("fs") +var osenv = require('osenv') +var mkdirp = require('mkdirp') +var fs = require('fs') var pj = JSON.stringify({ - "name": "whatever", - "description": "yeah idk", - "version": "1.2.3", - "main": "index.js", - "dependencies": { - "underscore": "1.3.1" + 'name': 'whatever', + 'description': 'yeah idk', + 'version': '1.2.3', + 'main': 'index.js', + 'dependencies': { + 'underscore': '1.3.1' }, - "repository": "git://github.com/luk-/whatever" -}, null, 2); + 'repository': 'git://github.com/luk-/whatever' +}, null, 2) function cleanup () { process.chdir(osenv.tmpdir()) @@ -28,10 +28,10 @@ function cleanup () { function setup () { mkdirp.sync(pkg) process.chdir(pkg) - fs.writeFileSync("package.json", pj) + fs.writeFileSync('package.json', pj) } -test("setup", function (t) { +test('setup', function (t) { cleanup() setup() t.end() @@ -50,12 +50,12 @@ test('outdated depth integer', function (t) { null ]] - mr({port : common.port}, function (er, s) { + mr({ port: common.port }, function (er, s) { npm.load({ - cache: pkg + '/cache' - , loglevel: 'silent' - , registry: common.registry - , depth: 5 + cache: pkg + '/cache', + loglevel: 'silent', + registry: common.registry, + depth: 5 } , function () { npm.install('request@0.9.0', function (er) { @@ -72,7 +72,7 @@ test('outdated depth integer', function (t) { }) }) -test("cleanup", function (t) { +test('cleanup', function (t) { cleanup() t.end() }) diff --git a/test/tap/outdated-git.js b/test/tap/outdated-git.js index 2162c743c..1a61a0c4d 100644 --- a/test/tap/outdated-git.js +++ b/test/tap/outdated-git.js @@ -2,7 +2,7 @@ var path = require('path') var test = require('tap').test var mkdirp = require('mkdirp') -var fs = require("graceful-fs") +var fs = require('graceful-fs') var rimraf = require('rimraf') var common = require('../common-tap.js') diff --git a/test/tap/outdated-local.js b/test/tap/outdated-local.js index f9b8af442..067696ca9 100644 --- a/test/tap/outdated-local.js +++ b/test/tap/outdated-local.js @@ -65,7 +65,6 @@ var pjLocalOptimistBumped = JSON.stringify({ version: '0.5.0' }, null, 2) + '\n' - function mocks (server) { server.get('/local-module') .reply(404) diff --git a/test/tap/outdated-notarget.js b/test/tap/outdated-notarget.js index 6058ddee4..5fd2b0634 100644 --- a/test/tap/outdated-notarget.js +++ b/test/tap/outdated-notarget.js @@ -1,23 +1,23 @@ // Fixes Issue #1770 -var common = require("../common-tap.js") -var test = require("tap").test -var npm = require("../../") -var osenv = require("osenv") -var path = require("path") -var fs = require("fs") -var rimraf = require("rimraf") -var mkdirp = require("mkdirp") -var pkg = path.resolve(__dirname, "outdated-notarget") -var cache = path.resolve(pkg, "cache") -var mr = require("npm-registry-mock") +var common = require('../common-tap.js') +var test = require('tap').test +var npm = require('../../') +var osenv = require('osenv') +var path = require('path') +var fs = require('fs') +var rimraf = require('rimraf') +var mkdirp = require('mkdirp') +var pkg = path.resolve(__dirname, 'outdated-notarget') +var cache = path.resolve(pkg, 'cache') +var mr = require('npm-registry-mock') -test("outdated-target: if no viable version is found, show error", function (t) { +test('outdated-target: if no viable version is found, show error', function (t) { t.plan(1) setup() - mr({port : common.port}, function (er, s) { + mr({ port: common.port }, function (er, s) { npm.load({ cache: cache, registry: common.registry}, function () { npm.commands.update(function (er) { - t.equal(er.code, "ETARGET") + t.equal(er.code, 'ETARGET') s.close() t.end() }) @@ -25,23 +25,23 @@ test("outdated-target: if no viable version is found, show error", function (t) }) }) -test("cleanup", function (t) { +test('cleanup', function (t) { process.chdir(osenv.tmpdir()) rimraf.sync(pkg) t.end() }) -function setup() { +function setup () { mkdirp.sync(pkg) mkdirp.sync(cache) - fs.writeFileSync(path.resolve(pkg, "package.json"), JSON.stringify({ - author: "Evan Lucas", - name: "outdated-notarget", - version: "0.0.0", - description: "Test for outdated-target", + fs.writeFileSync(path.resolve(pkg, 'package.json'), JSON.stringify({ + author: 'Evan Lucas', + name: 'outdated-notarget', + version: '0.0.0', + description: 'Test for outdated-target', dependencies: { - underscore: "~199.7.1" + underscore: '~199.7.1' } - }), "utf8") + }), 'utf8') process.chdir(pkg) } diff --git a/test/tap/outdated-private.js b/test/tap/outdated-private.js index f7fb47587..1d5e460c6 100644 --- a/test/tap/outdated-private.js +++ b/test/tap/outdated-private.js @@ -1,79 +1,79 @@ -var common = require("../common-tap.js") -var test = require("tap").test -var npm = require("../../") -var rimraf = require("rimraf") -var path = require("path") -var mr = require("npm-registry-mock") -var osenv = require("osenv") -var mkdirp = require("mkdirp") -var fs = require("graceful-fs") +var common = require('../common-tap.js') +var test = require('tap').test +var npm = require('../../') +var rimraf = require('rimraf') +var path = require('path') +var mr = require('npm-registry-mock') +var osenv = require('osenv') +var mkdirp = require('mkdirp') +var fs = require('graceful-fs') -var pkg = path.resolve(__dirname, "outdated-private") -var pkgLocalPrivate = path.resolve(pkg, "local-private") -var pkgScopedLocalPrivate = path.resolve(pkg, "another-local-private") -var pkgLocalUnderscore = path.resolve(pkg, "underscore") +var pkg = path.resolve(__dirname, 'outdated-private') +var pkgLocalPrivate = path.resolve(pkg, 'local-private') +var pkgScopedLocalPrivate = path.resolve(pkg, 'another-local-private') +var pkgLocalUnderscore = path.resolve(pkg, 'underscore') var pjParent = JSON.stringify({ - name : "outdated-private", - version : "1.0.0", - dependencies : { - "local-private" : "file:local-private", - "@scoped/another-local-private" : "file:another-local-private", - "underscore" : "file:underscore" + name: 'outdated-private', + version: '1.0.0', + dependencies: { + 'local-private': 'file:local-private', + '@scoped/another-local-private': 'file:another-local-private', + 'underscore': 'file:underscore' } -}, null, 2) + "\n" +}, null, 2) + '\n' var pjLocalPrivate = JSON.stringify({ - name : "local-private", - version : "1.0.0", - private : true -}, null, 2) + "\n" + name: 'local-private', + version: '1.0.0', + 'private': true +}, null, 2) + '\n' var pjLocalPrivateBumped = JSON.stringify({ - name : "local-private", - version : "1.1.0", - private : true -}, null, 2) + "\n" + name: 'local-private', + version: '1.1.0', + 'private': true +}, null, 2) + '\n' var pjScopedLocalPrivate = JSON.stringify({ - name : "@scoped/another-local-private", - version : "1.0.0", - private : true -}, null, 2) + "\n" + name: '@scoped/another-local-private', + version: '1.0.0', + 'private': true +}, null, 2) + '\n' var pjLocalUnderscore = JSON.stringify({ - name : "underscore", - version : "1.3.1" -}, null, 2) + "\n" + name: 'underscore', + version: '1.3.1' +}, null, 2) + '\n' -test("setup", function (t) { +test('setup', function (t) { bootstrap() t.end() }) -test("outdated ignores private modules", function (t) { +test('outdated ignores private modules', function (t) { t.plan(3) process.chdir(pkg) - mr({ port : common.port }, function (err, s) { + mr({ port: common.port }, function (er, s) { npm.load( { - loglevel : "silent", - parseable : true, - registry : common.registry + loglevel: 'silent', + parseable: true, + registry: common.registry }, function () { - npm.install(".", function (err) { - t.ifError(err, "install success") + npm.install('.', function (err) { + t.ifError(err, 'install success') bumpLocalPrivate() npm.outdated(function (er, d) { - t.ifError(er, "outdated success") + t.ifError(er, 'outdated success') t.deepEqual(d, [[ - path.resolve(__dirname, "outdated-private"), - "underscore", - "1.3.1", - "1.5.1", - "1.5.1", - "underscore@1.5.1", + path.resolve(__dirname, 'outdated-private'), + 'underscore', + '1.3.1', + '1.5.1', + '1.5.1', + 'underscore@1.5.1', null ]]) s.close() @@ -84,27 +84,27 @@ test("outdated ignores private modules", function (t) { }) }) -test("cleanup", function (t) { +test('cleanup', function (t) { cleanup() t.end() }) function bootstrap () { mkdirp.sync(pkg) - fs.writeFileSync(path.resolve(pkg, "package.json"), pjParent) + fs.writeFileSync(path.resolve(pkg, 'package.json'), pjParent) mkdirp.sync(pkgLocalPrivate) - fs.writeFileSync(path.resolve(pkgLocalPrivate, "package.json"), pjLocalPrivate) + fs.writeFileSync(path.resolve(pkgLocalPrivate, 'package.json'), pjLocalPrivate) mkdirp.sync(pkgScopedLocalPrivate) - fs.writeFileSync(path.resolve(pkgScopedLocalPrivate, "package.json"), pjScopedLocalPrivate) + fs.writeFileSync(path.resolve(pkgScopedLocalPrivate, 'package.json'), pjScopedLocalPrivate) mkdirp.sync(pkgLocalUnderscore) - fs.writeFileSync(path.resolve(pkgLocalUnderscore, "package.json"), pjLocalUnderscore) + fs.writeFileSync(path.resolve(pkgLocalUnderscore, 'package.json'), pjLocalUnderscore) } function bumpLocalPrivate () { - fs.writeFileSync(path.resolve(pkgLocalPrivate, "package.json"), pjLocalPrivateBumped) + fs.writeFileSync(path.resolve(pkgLocalPrivate, 'package.json'), pjLocalPrivateBumped) } function cleanup () { diff --git a/test/tap/owner.js b/test/tap/owner.js index 938c21665..4bef1a0d8 100644 --- a/test/tap/owner.js +++ b/test/tap/owner.js @@ -1,79 +1,79 @@ -var mr = require("npm-registry-mock") -var test = require("tap").test +var mr = require('npm-registry-mock') +var test = require('tap').test -var common = require("../common-tap.js") +var common = require('../common-tap.js') var server var EXEC_OPTS = {} var jashkenas = { - name : "jashkenas", - email : "jashkenas@gmail.com" + name: 'jashkenas', + email: 'jashkenas@gmail.com' } var othiym23 = { - name : "othiym23", - email : "forrest@npmjs.com" + name: 'othiym23', + email: 'forrest@npmjs.com' } var bcoe = { - name : "bcoe", - email : "ben@npmjs.com" + name: 'bcoe', + email: 'ben@npmjs.com' } function shrt (user) { - return user.name+" <"+user.email+">\n" + return user.name + ' <' + user.email + '>\n' } function mocks (server) { - server.get("/-/user/org.couchdb.user:othiym23") + server.get('/-/user/org.couchdb.user:othiym23') .many().reply(200, othiym23) // test 1 - server.get("/underscore") - .reply(200, {_id:"underscore",_rev:1,maintainers:[jashkenas]}) + server.get('/underscore') + .reply(200, { _id: 'underscore', _rev: 1, maintainers: [jashkenas] }) server.put( - "/underscore/-rev/1", - {_id:"underscore",_rev:1,maintainers:[jashkenas,othiym23]}, + '/underscore/-rev/1', + { _id: 'underscore', _rev: 1, maintainers: [jashkenas, othiym23] }, {} - ).reply(200, {_id:"underscore",_rev:2,maintainers:[jashkenas,othiym23]}) + ).reply(200, { _id: 'underscore', _rev: 2, maintainers: [jashkenas, othiym23] }) // test 2 - server.get("/@xxx%2fscoped") - .reply(200, {_id:"@xxx/scoped",_rev:1,maintainers:[bcoe]}) + server.get('/@xxx%2fscoped') + .reply(200, { _id: '@xxx/scoped', _rev: 1, maintainers: [bcoe] }) server.put( - "/@xxx%2fscoped/-rev/1", - {_id:"@xxx/scoped",_rev:1,maintainers:[bcoe,othiym23]}, + '/@xxx%2fscoped/-rev/1', + { _id: '@xxx/scoped', _rev: 1, maintainers: [bcoe, othiym23] }, {} - ).reply(200, {_id:"@xxx/scoped",_rev:2,maintainers:[bcoe,othiym23]}) + ).reply(200, { _id: '@xxx/scoped', _rev: 2, maintainers: [bcoe, othiym23] }) // test 3 - server.get("/underscore") - .reply(200, {_id:"underscore",_rev:2,maintainers:[jashkenas,othiym23]}) + server.get('/underscore') + .reply(200, { _id: 'underscore', _rev: 2, maintainers: [jashkenas, othiym23] }) // test 4 - server.get("/underscore") - .reply(200, {_id:"underscore",_rev:2,maintainers:[jashkenas,othiym23]}) + server.get('/underscore') + .reply(200, { _id: 'underscore', _rev: 2, maintainers: [jashkenas, othiym23] }) server.put( - "/underscore/-rev/2", - {_id:"underscore",_rev:2,maintainers:[jashkenas]}, + '/underscore/-rev/2', + { _id: 'underscore', _rev: 2, maintainers: [jashkenas] }, {} - ).reply(200, {_id:"underscore",_rev:3,maintainers:[jashkenas]}) + ).reply(200, { _id: 'underscore', _rev: 3, maintainers: [jashkenas] }) } -test("setup", function (t) { +test('setup', function (t) { common.npm( [ - "--loglevel", "silent", - "cache", "clean" + '--loglevel', 'silent', + 'cache', 'clean' ], EXEC_OPTS, function (err, code) { - t.ifError(err, "npm cache clean ran without error") - t.notOk(code, "npm cache clean exited cleanly") + t.ifError(err, 'npm cache clean ran without error') + t.notOk(code, 'npm cache clean exited cleanly') - mr({ port : common.port, plugin : mocks }, function (err, s) { + mr({ port: common.port, plugin: mocks }, function (er, s) { server = s t.end() }) @@ -81,83 +81,83 @@ test("setup", function (t) { ) }) -test("npm owner add", function (t) { +test('npm owner add', function (t) { common.npm( [ - "--loglevel", "silent", - "--registry", common.registry, - "owner", "add", "othiym23", "underscore" + '--loglevel', 'silent', + '--registry', common.registry, + 'owner', 'add', 'othiym23', 'underscore' ], EXEC_OPTS, function (err, code, stdout, stderr) { - t.ifError(err, "npm owner add ran without error") - t.notOk(code, "npm owner add exited cleanly") - t.notOk(stderr, "npm owner add ran silently") - t.equal(stdout, "+ othiym23 (underscore)\n", "got expected add output") + t.ifError(err, 'npm owner add ran without error') + t.notOk(code, 'npm owner add exited cleanly') + t.notOk(stderr, 'npm owner add ran silently') + t.equal(stdout, '+ othiym23 (underscore)\n', 'got expected add output') t.end() } ) }) -test("npm owner add (scoped)", function (t) { +test('npm owner add (scoped)', function (t) { common.npm( [ - "--loglevel", "silent", - "--registry", common.registry, - "owner", "add", "othiym23", "@xxx/scoped" + '--loglevel', 'silent', + '--registry', common.registry, + 'owner', 'add', 'othiym23', '@xxx/scoped' ], EXEC_OPTS, function (err, code, stdout, stderr) { - t.ifError(err, "npm owner add (scoped) ran without error") - t.notOk(code, "npm owner add (scoped) exited cleanly") - t.notOk(stderr, "npm owner add (scoped) ran silently") - t.equal(stdout, "+ othiym23 (@xxx/scoped)\n", "got expected scoped add output") + t.ifError(err, 'npm owner add (scoped) ran without error') + t.notOk(code, 'npm owner add (scoped) exited cleanly') + t.notOk(stderr, 'npm owner add (scoped) ran silently') + t.equal(stdout, '+ othiym23 (@xxx/scoped)\n', 'got expected scoped add output') t.end() } ) }) -test("npm owner ls", function (t) { +test('npm owner ls', function (t) { common.npm( [ - "--loglevel", "silent", - "--registry", common.registry, - "owner", "ls", "underscore" + '--loglevel', 'silent', + '--registry', common.registry, + 'owner', 'ls', 'underscore' ], EXEC_OPTS, function (err, code, stdout, stderr) { - t.ifError(err, "npm owner ls ran without error") - t.notOk(code, "npm owner ls exited cleanly") - t.notOk(stderr, "npm owner ls ran silently") - t.equal(stdout, shrt(jashkenas)+shrt(othiym23), "got expected ls output") + t.ifError(err, 'npm owner ls ran without error') + t.notOk(code, 'npm owner ls exited cleanly') + t.notOk(stderr, 'npm owner ls ran silently') + t.equal(stdout, shrt(jashkenas) + shrt(othiym23), 'got expected ls output') t.end() } ) }) -test("npm owner rm", function (t) { +test('npm owner rm', function (t) { common.npm( [ - "--loglevel", "silent", - "--registry", common.registry, - "owner", "rm", "othiym23", "underscore" + '--loglevel', 'silent', + '--registry', common.registry, + 'owner', 'rm', 'othiym23', 'underscore' ], EXEC_OPTS, function (err, code, stdout, stderr) { - t.ifError(err, "npm owner rm ran without error") - t.notOk(code, "npm owner rm exited cleanly") - t.notOk(stderr, "npm owner rm ran silently") - t.equal(stdout, "- othiym23 (underscore)\n", "got expected rm output") + t.ifError(err, 'npm owner rm ran without error') + t.notOk(code, 'npm owner rm exited cleanly') + t.notOk(stderr, 'npm owner rm ran silently') + t.equal(stdout, '- othiym23 (underscore)\n', 'got expected rm output') t.end() } ) }) -test("cleanup", function (t) { +test('cleanup', function (t) { server.close() t.end() }) diff --git a/test/tap/pack-scoped.js b/test/tap/pack-scoped.js index 5c351339c..05b9d12a8 100644 --- a/test/tap/pack-scoped.js +++ b/test/tap/pack-scoped.js @@ -1,29 +1,29 @@ // verify that prepublish runs on pack and publish -var test = require("tap").test -var common = require("../common-tap") -var fs = require("graceful-fs") -var join = require("path").join -var mkdirp = require("mkdirp") -var rimraf = require("rimraf") +var test = require('tap').test +var common = require('../common-tap') +var fs = require('graceful-fs') +var join = require('path').join +var mkdirp = require('mkdirp') +var rimraf = require('rimraf') -var pkg = join(__dirname, "scoped_package") -var manifest = join(pkg, "package.json") -var tmp = join(pkg, "tmp") -var cache = join(pkg, "cache") +var pkg = join(__dirname, 'scoped_package') +var manifest = join(pkg, 'package.json') +var tmp = join(pkg, 'tmp') +var cache = join(pkg, 'cache') var data = { - name : "@scope/generic-package", - version : "90000.100001.5" + name: '@scope/generic-package', + version: '90000.100001.5' } -test("setup", function (t) { +test('setup', function (t) { var n = 0 rimraf.sync(pkg) - mkdirp(pkg, then()) + mkdirp(pkg, then()) mkdirp(cache, then()) - mkdirp(tmp, then()) + mkdirp(tmp, then()) function then () { n++ @@ -34,23 +34,23 @@ test("setup", function (t) { } function next () { - fs.writeFile(manifest, JSON.stringify(data), "ascii", done) + fs.writeFile(manifest, JSON.stringify(data), 'ascii', done) } function done (er) { t.ifError(er) - t.pass("setup done") + t.pass('setup done') t.end() } }) -test("test", function (t) { +test('test', function (t) { var env = { - "npm_config_cache" : cache, - "npm_config_tmp" : tmp, - "npm_config_prefix" : pkg, - "npm_config_global" : "false" + 'npm_config_cache': cache, + 'npm_config_tmp': tmp, + 'npm_config_prefix': pkg, + 'npm_config_global': 'false' } for (var i in process.env) { @@ -58,24 +58,24 @@ test("test", function (t) { } common.npm([ - "pack", - "--loglevel", "warn" + 'pack', + '--loglevel', 'warn' ], { cwd: pkg, env: env - }, function(err, code, stdout, stderr) { - t.ifErr(err, "npm pack finished without error") - t.equal(code, 0, "npm pack exited ok") - t.notOk(stderr, "got stderr data: " + JSON.stringify("" + stderr)) + }, function (err, code, stdout, stderr) { + t.ifErr(err, 'npm pack finished without error') + t.equal(code, 0, 'npm pack exited ok') + t.notOk(stderr, 'got stderr data: ' + JSON.stringify('' + stderr)) stdout = stdout.trim() - var regex = new RegExp("scope-generic-package-90000.100001.5.tgz", "ig") - t.ok(stdout.match(regex), "found package") + var regex = new RegExp('scope-generic-package-90000.100001.5.tgz', 'ig') + t.ok(stdout.match(regex), 'found package') t.end() }) }) -test("cleanup", function (t) { +test('cleanup', function (t) { rimraf.sync(pkg) - t.pass("cleaned up") + t.pass('cleaned up') t.end() }) diff --git a/test/tap/peer-deps-toplevel.js b/test/tap/peer-deps-toplevel.js index bd2309912..3a8d3c722 100644 --- a/test/tap/peer-deps-toplevel.js +++ b/test/tap/peer-deps-toplevel.js @@ -53,7 +53,7 @@ var expected = { version: '*', peerMissing: true, dependencies: {} - }, + } } } } diff --git a/test/tap/peer-deps-without-package-json.js b/test/tap/peer-deps-without-package-json.js index f60c99232..781686f62 100644 --- a/test/tap/peer-deps-without-package-json.js +++ b/test/tap/peer-deps-without-package-json.js @@ -31,7 +31,7 @@ var fileJS = function () { test('setup', function (t) { t.comment('test for https://github.com/npm/npm/issues/3049') cleanup() - mkdirp.sync(cache) + mkdirp.sync(cache) mkdirp.sync(nodeModules) fs.writeFileSync(path.join(pkg, 'file-js.js'), fileJS) process.chdir(pkg) @@ -53,7 +53,7 @@ test('installing a peerDeps-using package without package.json', function (t) { }, function () { npm.install(common.registry + '/ok.js', function (err, result) { t.ifError(err, 'installed ok.js') - + t.ok( fs.existsSync(path.join(nodeModules, 'npm-test-peer-deps-file')), 'passive peer dep installed' diff --git a/test/tap/prepublish.js b/test/tap/prepublish.js index 36391beeb..f065a656a 100644 --- a/test/tap/prepublish.js +++ b/test/tap/prepublish.js @@ -1,16 +1,16 @@ // verify that prepublish runs on pack and publish -var common = require("../common-tap") -var test = require("tap").test -var fs = require("graceful-fs") -var join = require("path").join -var mkdirp = require("mkdirp") -var rimraf = require("rimraf") +var common = require('../common-tap') +var test = require('tap').test +var fs = require('graceful-fs') +var join = require('path').join +var mkdirp = require('mkdirp') +var rimraf = require('rimraf') -var pkg = join(__dirname, "prepublish_package") -var tmp = join(pkg, "tmp") -var cache = join(pkg, "cache") +var pkg = join(__dirname, 'prepublish_package') +var tmp = join(pkg, 'tmp') +var cache = join(pkg, 'cache') -test("setup", function (t) { +test('setup', function (t) { var n = 0 cleanup() mkdirp(pkg, then()) @@ -25,58 +25,60 @@ test("setup", function (t) { } function next () { - fs.writeFile(join(pkg, "package.json"), JSON.stringify({ - name: "npm-test-prepublish", - version: "1.2.5", - scripts: { prepublish: "echo ok" } - }), "ascii", function (er) { + fs.writeFile(join(pkg, 'package.json'), JSON.stringify({ + name: 'npm-test-prepublish', + version: '1.2.5', + scripts: { prepublish: 'echo ok' } + }), 'ascii', function (er) { if (er) throw er - t.pass("setup done") + t.pass('setup done') t.end() }) } }) -test("test", function (t) { +test('test', function (t) { var env = { - "npm_config_cache" : cache, - "npm_config_tmp" : tmp, - "npm_config_prefix" : pkg, - "npm_config_global" : "false" + 'npm_config_cache': cache, + 'npm_config_tmp': tmp, + 'npm_config_prefix': pkg, + 'npm_config_global': 'false' } + for (var i in process.env) { - if (!/^npm_config_/.test(i)) + if (!/^npm_config_/.test(i)) { env[i] = process.env[i] + } } common.npm([ - "pack", - "--loglevel", "warn" - ], { cwd: pkg, env: env }, function(err, code, stdout, stderr) { - t.equal(code, 0, "pack finished successfully") - t.ifErr(err, "pack finished successfully") + 'pack', + '--loglevel', 'warn' + ], { cwd: pkg, env: env }, function (err, code, stdout, stderr) { + t.equal(code, 0, 'pack finished successfully') + t.ifErr(err, 'pack finished successfully') - t.notOk(stderr, "got stderr data:" + JSON.stringify("" + stderr)) + t.notOk(stderr, 'got stderr data:' + JSON.stringify('' + stderr)) var c = stdout.trim() - var regex = new RegExp("" + - "> npm-test-prepublish@1.2.5 prepublish [^\\r\\n]+\\r?\\n" + - "> echo ok\\r?\\n" + - "\\r?\\n" + - "ok\\r?\\n" + - "npm-test-prepublish-1.2.5.tgz", "ig") + var regex = new RegExp('' + + '> npm-test-prepublish@1.2.5 prepublish [^\\r\\n]+\\r?\\n' + + '> echo ok\\r?\\n' + + '\\r?\\n' + + 'ok\\r?\\n' + + 'npm-test-prepublish-1.2.5.tgz', 'ig') t.ok(c.match(regex)) t.end() }) }) -test("cleanup", function (t) { +test('cleanup', function (t) { cleanup() - t.pass("cleaned up") + t.pass('cleaned up') t.end() }) -function cleanup() { +function cleanup () { rimraf.sync(pkg) } diff --git a/test/tap/publish-access-scoped.js b/test/tap/publish-access-scoped.js index e734ebfd7..adc67a48e 100644 --- a/test/tap/publish-access-scoped.js +++ b/test/tap/publish-access-scoped.js @@ -1,15 +1,15 @@ -var fs = require("fs") -var path = require("path") +var fs = require('fs') +var path = require('path') -var test = require("tap").test -var mkdirp = require("mkdirp") -var rimraf = require("rimraf") -var nock = require("nock") +var test = require('tap').test +var mkdirp = require('mkdirp') +var rimraf = require('rimraf') +var nock = require('nock') -var npm = require("../../") -var common = require("../common-tap.js") +var npm = require('../../') +var common = require('../common-tap.js') -var pkg = path.join(__dirname, "publish-access") +var pkg = path.join(__dirname, 'publish-access') // TODO: nock uses setImmediate, breaks 0.8: replace with mockRegistry if (!global.setImmediate) { @@ -19,46 +19,46 @@ if (!global.setImmediate) { } } -test("setup", function (t) { - mkdirp(path.join(pkg, "cache"), function () { +test('setup', function (t) { + mkdirp(path.join(pkg, 'cache'), function () { var configuration = { - cache : path.join(pkg, "cache"), - loglevel : "silent", - registry : common.registry + cache: path.join(pkg, 'cache'), + loglevel: 'silent', + registry: common.registry } npm.load(configuration, next) }) function next (er) { - t.ifError(er, "npm loaded successfully") + t.ifError(er, 'npm loaded successfully') process.chdir(pkg) fs.writeFile( - path.join(pkg, "package.json"), + path.join(pkg, 'package.json'), JSON.stringify({ - name: "@bigco/publish-access", - version: "1.2.5" + name: '@bigco/publish-access', + version: '1.2.5' }), - "ascii", + 'ascii', function (er) { t.ifError(er) - t.pass("setup done") + t.pass('setup done') t.end() } ) } }) -test("scoped packages pass public access if set", function (t) { +test('scoped packages pass public access if set', function (t) { var put = nock(common.registry) - .put("/@bigco%2fpublish-access") + .put('/@bigco%2fpublish-access') .reply(201, verify) - npm.config.set("access", "public") + npm.config.set('access', 'public') npm.commands.publish([], false, function (er) { - t.ifError(er, "published without error") + t.ifError(er, 'published without error') put.done() t.end() @@ -67,14 +67,14 @@ test("scoped packages pass public access if set", function (t) { function verify (_, body) { t.doesNotThrow(function () { var parsed = JSON.parse(body) - t.equal(parsed.access, "public", "access level is correct") - }, "converted body back into object") + t.equal(parsed.access, 'public', 'access level is correct') + }, 'converted body back into object') return {ok: true} } }) -test("cleanup", function (t) { +test('cleanup', function (t) { process.chdir(__dirname) rimraf(pkg, function (er) { t.ifError(er) diff --git a/test/tap/publish-access-unscoped-restricted-fails.js b/test/tap/publish-access-unscoped-restricted-fails.js index 4d39b00b1..b97539938 100644 --- a/test/tap/publish-access-unscoped-restricted-fails.js +++ b/test/tap/publish-access-unscoped-restricted-fails.js @@ -1,14 +1,14 @@ -var fs = require("fs") -var path = require("path") +var fs = require('fs') +var path = require('path') -var test = require("tap").test -var mkdirp = require("mkdirp") -var rimraf = require("rimraf") +var test = require('tap').test +var mkdirp = require('mkdirp') +var rimraf = require('rimraf') -var npm = require("../../") -var common = require("../common-tap.js") +var npm = require('../../') +var common = require('../common-tap.js') -var pkg = path.join(__dirname, "publish-access-unscoped") +var pkg = path.join(__dirname, 'publish-access-unscoped') // TODO: nock uses setImmediate, breaks 0.8: replace with mockRegistry if (!global.setImmediate) { @@ -18,49 +18,49 @@ if (!global.setImmediate) { } } -test("setup", function (t) { - mkdirp(path.join(pkg, "cache"), function () { +test('setup', function (t) { + mkdirp(path.join(pkg, 'cache'), function () { var configuration = { - cache : path.join(pkg, "cache"), - loglevel : "silent", - registry : common.registry + cache: path.join(pkg, 'cache'), + loglevel: 'silent', + registry: common.registry } npm.load(configuration, next) }) function next (er) { - t.ifError(er, "npm loaded successfully") + t.ifError(er, 'npm loaded successfully') process.chdir(pkg) fs.writeFile( - path.join(pkg, "package.json"), + path.join(pkg, 'package.json'), JSON.stringify({ - name: "publish-access", - version: "1.2.5" + name: 'publish-access', + version: '1.2.5' }), - "ascii", + 'ascii', function (er) { t.ifError(er) - t.pass("setup done") + t.pass('setup done') t.end() } ) } }) -test("unscoped packages cannot be restricted", function (t) { - npm.config.set("access", "restricted") +test('unscoped packages cannot be restricted', function (t) { + npm.config.set('access', 'restricted') npm.commands.publish([], false, function (er) { - t.ok(er, "got an error back") + t.ok(er, 'got an error back') t.equal(er.message, "Can't restrict access to unscoped packages.") t.end() }) }) -test("cleanup", function (t) { +test('cleanup', function (t) { process.chdir(__dirname) rimraf(pkg, function (er) { t.ifError(er) diff --git a/test/tap/publish-access-unscoped.js b/test/tap/publish-access-unscoped.js index 023bfba5f..48b12ed52 100644 --- a/test/tap/publish-access-unscoped.js +++ b/test/tap/publish-access-unscoped.js @@ -1,15 +1,15 @@ -var fs = require("fs") -var path = require("path") +var fs = require('fs') +var path = require('path') -var test = require("tap").test -var mkdirp = require("mkdirp") -var rimraf = require("rimraf") -var nock = require("nock") +var test = require('tap').test +var mkdirp = require('mkdirp') +var rimraf = require('rimraf') +var nock = require('nock') -var npm = require("../../") -var common = require("../common-tap.js") +var npm = require('../../') +var common = require('../common-tap.js') -var pkg = path.join(__dirname, "publish-access-unscoped") +var pkg = path.join(__dirname, 'publish-access-unscoped') // TODO: nock uses setImmediate, breaks 0.8: replace with mockRegistry if (!global.setImmediate) { @@ -19,46 +19,46 @@ if (!global.setImmediate) { } } -test("setup", function (t) { - mkdirp(path.join(pkg, "cache"), function () { +test('setup', function (t) { + mkdirp(path.join(pkg, 'cache'), function () { var configuration = { - cache : path.join(pkg, "cache"), - loglevel : "silent", - registry : common.registry + cache: path.join(pkg, 'cache'), + loglevel: 'silent', + registry: common.registry } npm.load(configuration, next) }) function next (er) { - t.ifError(er, "npm loaded successfully") + t.ifError(er, 'npm loaded successfully') process.chdir(pkg) fs.writeFile( - path.join(pkg, "package.json"), + path.join(pkg, 'package.json'), JSON.stringify({ - name: "publish-access", - version: "1.2.5" + name: 'publish-access', + version: '1.2.5' }), - "ascii", + 'ascii', function (er) { t.ifError(er) - t.pass("setup done") + t.pass('setup done') t.end() } ) } }) -test("unscoped packages can be explicitly set as public", function (t) { +test('unscoped packages can be explicitly set as public', function (t) { var put = nock(common.registry) - .put("/publish-access") + .put('/publish-access') .reply(201, verify) - npm.config.set("access", "public") + npm.config.set('access', 'public') npm.commands.publish([], false, function (er) { - t.ifError(er, "published without error") + t.ifError(er, 'published without error') put.done() t.end() @@ -67,14 +67,14 @@ test("unscoped packages can be explicitly set as public", function (t) { function verify (_, body) { t.doesNotThrow(function () { var parsed = JSON.parse(body) - t.equal(parsed.access, "public", "access level is correct") - }, "converted body back into object") + t.equal(parsed.access, 'public', 'access level is correct') + }, 'converted body back into object') return {ok: true} } }) -test("cleanup", function (t) { +test('cleanup', function (t) { process.chdir(__dirname) rimraf(pkg, function (er) { t.ifError(er) diff --git a/test/tap/publish-config.js b/test/tap/publish-config.js index 1d063535b..57070f78b 100644 --- a/test/tap/publish-config.js +++ b/test/tap/publish-config.js @@ -1,37 +1,37 @@ -var common = require("../common-tap.js") -var test = require("tap").test -var fs = require("fs") -var osenv = require("osenv") -var pkg = process.env.npm_config_tmp || "/tmp" -pkg += "/npm-test-publish-config" +var common = require('../common-tap.js') +var test = require('tap').test +var fs = require('fs') +var osenv = require('osenv') +var pkg = process.env.npm_config_tmp || '/tmp' +pkg += '/npm-test-publish-config' -require("mkdirp").sync(pkg) +require('mkdirp').sync(pkg) -fs.writeFileSync(pkg + "/package.json", JSON.stringify({ - name: "npm-test-publish-config", - version: "1.2.3", +fs.writeFileSync(pkg + '/package.json', JSON.stringify({ + name: 'npm-test-publish-config', + version: '1.2.3', publishConfig: { registry: common.registry } -}), "utf8") +}), 'utf8') -fs.writeFileSync(pkg + "/fixture_npmrc", - "//localhost:1337/:email = fancy@feast.net\n" + - "//localhost:1337/:username = fancy\n" + - "//localhost:1337/:_password = " + new Buffer("feast").toString("base64") + "\n" + - "registry = http://localhost:1337/") +fs.writeFileSync(pkg + '/fixture_npmrc', + '//localhost:1337/:email = fancy@feast.net\n' + + '//localhost:1337/:username = fancy\n' + + '//localhost:1337/:_password = ' + new Buffer('feast').toString('base64') + '\n' + + 'registry = http://localhost:1337/') test(function (t) { var child t.plan(4) - require("http").createServer(function (req, res) { - t.pass("got request on the fakey fake registry") + require('http').createServer(function (req, res) { + t.pass('got request on the fakey fake registry') this.close() res.statusCode = 500 res.end(JSON.stringify({ - error: "sshhh. naptime nao. \\^O^/ <(YAWWWWN!)" + error: 'sshhh. naptime nao. \\^O^/ <(YAWWWWN!)' })) child.kill('SIGHUP') }).listen(common.port, function () { - t.pass("server is listening") + t.pass('server is listening') // don't much care about listening to the child's results // just wanna make sure it hits the server we just set up. @@ -40,20 +40,20 @@ test(function (t) { // itself functions normally. // // Make sure that we don't sit around waiting for lock files - child = common.npm(["publish", "--userconfig=" + pkg + "/fixture_npmrc"], { + child = common.npm(['publish', '--userconfig=' + pkg + '/fixture_npmrc'], { cwd: pkg, - stdio: "inherit", + stdio: 'inherit', env: { - "npm_config_cache_lock_stale": 1000, - "npm_config_cache_lock_wait": 1000, + 'npm_config_cache_lock_stale': 1000, + 'npm_config_cache_lock_wait': 1000, HOME: process.env.HOME, Path: process.env.PATH, PATH: process.env.PATH, USERPROFILE: osenv.home() } }, function (err, code) { - t.ifError(err, "publish command finished successfully") - t.notOk(code, "npm install exited with code 0") + t.ifError(err, 'publish command finished successfully') + t.notOk(code, 'npm install exited with code 0') }) }) }) diff --git a/test/tap/publish-scoped.js b/test/tap/publish-scoped.js index f74ca2e61..eb14ae504 100644 --- a/test/tap/publish-scoped.js +++ b/test/tap/publish-scoped.js @@ -1,60 +1,60 @@ -var fs = require("fs") -var path = require("path") +var fs = require('fs') +var path = require('path') -var test = require("tap").test -var mkdirp = require("mkdirp") -var rimraf = require("rimraf") -var nock = require("nock") +var test = require('tap').test +var mkdirp = require('mkdirp') +var rimraf = require('rimraf') +var nock = require('nock') -var npm = require("../../") -var common = require("../common-tap.js") +var npm = require('../../') +var common = require('../common-tap.js') -var pkg = path.join(__dirname, "prepublish_package") +var pkg = path.join(__dirname, 'prepublish_package') -test("setup", function (t) { - mkdirp(path.join(pkg, "cache"), next) +test('setup', function (t) { + mkdirp(path.join(pkg, 'cache'), next) function next () { process.chdir(pkg) fs.writeFile( - path.join(pkg, "package.json"), + path.join(pkg, 'package.json'), JSON.stringify({ - name: "@bigco/publish-organized", - version: "1.2.5" + name: '@bigco/publish-organized', + version: '1.2.5' }), - "ascii", + 'ascii', function (er) { t.ifError(er) - t.pass("setup done") + t.pass('setup done') t.end() } ) } }) -test("npm publish should honor scoping", function (t) { +test('npm publish should honor scoping', function (t) { var put = nock(common.registry) - .put("/@bigco%2fpublish-organized") + .put('/@bigco%2fpublish-organized') .reply(201, verify) var configuration = { - cache : path.join(pkg, "cache"), - loglevel : "silent", - registry : "http://nonexistent.lvh.me", - "//localhost:1337/:username" : "username", - "//localhost:1337/:_password" : new Buffer("password").toString("base64"), - "//localhost:1337/:email" : "ogd@aoaioxxysz.net" + cache: path.join(pkg, 'cache'), + loglevel: 'silent', + registry: 'http://nonexistent.lvh.me', + '//localhost:1337/:username': 'username', + '//localhost:1337/:_password': new Buffer('password').toString('base64'), + '//localhost:1337/:email': 'ogd@aoaioxxysz.net' } npm.load(configuration, onload) function onload (er) { - t.ifError(er, "npm bootstrapped successfully") + t.ifError(er, 'npm bootstrapped successfully') - npm.config.set("@bigco:registry", common.registry) + npm.config.set('@bigco:registry', common.registry) npm.commands.publish([], false, function (er) { - t.ifError(er, "published without error") + t.ifError(er, 'published without error') put.done() @@ -65,25 +65,25 @@ test("npm publish should honor scoping", function (t) { function verify (_, body) { t.doesNotThrow(function () { var parsed = JSON.parse(body) - var current = parsed.versions["1.2.5"] + var current = parsed.versions['1.2.5'] t.equal( current._npmVersion, - require(path.resolve(__dirname, "../../package.json")).version, - "npm version is correct" + require(path.resolve(__dirname, '../../package.json')).version, + 'npm version is correct' ) t.equal( current._nodeVersion, process.versions.node, - "node version is correct" + 'node version is correct' ) - }, "converted body back into object") + }, 'converted body back into object') return {ok: true} } }) -test("cleanup", function (t) { +test('cleanup', function (t) { process.chdir(__dirname) rimraf(pkg, function (er) { t.ifError(er) diff --git a/test/tap/pwd-prefix.js b/test/tap/pwd-prefix.js index 237096e0a..1b59f5c83 100644 --- a/test/tap/pwd-prefix.js +++ b/test/tap/pwd-prefix.js @@ -2,31 +2,31 @@ // thing when the cwd is where package.json is, and when // the package.json is one level up. -var test = require("tap").test -var common = require("../common-tap.js") -var path = require("path") -var root = path.resolve(__dirname, "../..") -var lib = path.resolve(root, "lib") -var commands = ["run", "version"] +var test = require('tap').test +var common = require('../common-tap.js') +var path = require('path') +var root = path.resolve(__dirname, '../..') +var lib = path.resolve(root, 'lib') +var commands = ['run', 'version'] commands.forEach(function (cmd) { // Should get the same stdout and stderr each time var stdout, stderr - test(cmd + " in root", function (t) { + test(cmd + ' in root', function (t) { common.npm([cmd], {cwd: root}, function (er, code, so, se) { if (er) throw er - t.notOk(code, "npm " + cmd + " exited with code 0") + t.notOk(code, 'npm ' + cmd + ' exited with code 0') stdout = so stderr = se t.end() }) }) - test(cmd + " in lib", function (t) { + test(cmd + ' in lib', function (t) { common.npm([cmd], {cwd: lib}, function (er, code, so, se) { if (er) throw er - t.notOk(code, "npm " + cmd + " exited with code 0") + t.notOk(code, 'npm ' + cmd + ' exited with code 0') t.equal(so, stdout) t.equal(se, stderr) t.end() diff --git a/test/tap/referer.js b/test/tap/referer.js index c1b173d97..8c3dbed72 100644 --- a/test/tap/referer.js +++ b/test/tap/referer.js @@ -1,16 +1,16 @@ -var common = require("../common-tap.js") -var test = require("tap").test -var http = require("http") +var common = require('../common-tap.js') +var test = require('tap').test +var http = require('http') -test("should send referer http header", function (t) { +test('should send referer http header', function (t) { http.createServer(function (q, s) { - t.equal(q.headers.referer, "install foo") + t.equal(q.headers.referer, 'install foo') s.statusCode = 404 - s.end(JSON.stringify({error: "whatever"})) + s.end(JSON.stringify({error: 'whatever'})) this.close() }).listen(common.port, function () { - var reg = "http://localhost:" + common.port - var args = [ "install", "foo", "--registry", reg ] + var reg = 'http://localhost:' + common.port + var args = [ 'install', 'foo', '--registry', reg ] common.npm(args, {}, function (er, code) { if (er) { throw er diff --git a/test/tap/registry.js b/test/tap/registry.js index 060d9b67b..7ff4075bf 100644 --- a/test/tap/registry.js +++ b/test/tap/registry.js @@ -1,34 +1,31 @@ // Run all the tests in the `npm-registry-couchapp` suite // This verifies that the server-side stuff still works. -var common = require("../common-tap") -var test = require("tap").test +var common = require('../common-tap') +var test = require('tap').test -var npmExec = require.resolve("../../bin/npm-cli.js") -var path = require("path") -var ca = path.resolve(__dirname, "../../node_modules/npm-registry-couchapp") +var npmExec = require.resolve('../../bin/npm-cli.js') +var path = require('path') +var ca = path.resolve(__dirname, '../../node_modules/npm-registry-couchapp') -var which = require("which") +var which = require('which') -var v = process.versions.node.split(".").map(function (n) { return parseInt(n, 10) }) +var v = process.versions.node.split('.').map(function (n) { return parseInt(n, 10) }) if (v[0] === 0 && v[1] < 10) { console.error( - "WARNING: need a recent Node for npm-registry-couchapp tests to run, have", + 'WARNING: need a recent Node for npm-registry-couchapp tests to run, have', process.versions.node ) -} -else { - which("couchdb", function (er) { +} else { + which('couchdb', function (er) { if (er) { - console.error("WARNING: need couch to run test: " + er.message) - } - else { + console.error('WARNING: need couch to run test: ' + er.message) + } else { runTests() } }) } - function runTests () { var env = { TAP: 1 } for (var i in process.env) env[i] = process.env[i] @@ -36,13 +33,13 @@ function runTests () { var opts = { cwd: ca, - stdio: "inherit" + stdio: 'inherit' } - common.npm(["install"], opts, function (err, code) { + common.npm(['install'], opts, function (err, code) { if (err) { throw err } if (code) { - return test("need install to work", function (t) { - t.fail("install failed with: " + code) + return test('need install to work', function (t) { + t.fail('install failed with: ' + code) t.end() }) @@ -50,22 +47,22 @@ function runTests () { opts = { cwd: ca, env: env, - stdio: "inherit" + stdio: 'inherit' } - common.npm(["test", "--", "-Rtap"], opts, function (err, code) { + common.npm(['test', '--', '-Rtap'], opts, function (err, code) { if (err) { throw err } if (code) { - return test("need test to work", function (t) { - t.fail("test failed with: " + code) + return test('need test to work', function (t) { + t.fail('test failed with: ' + code) t.end() }) } opts = { cwd: ca, env: env, - stdio: "inherit" + stdio: 'inherit' } - common.npm(["prune", "--production"], opts, function (err, code) { + common.npm(['prune', '--production'], opts, function (err, code) { if (err) { throw err } process.exit(code || 0) }) diff --git a/test/tap/repo.js b/test/tap/repo.js index df4e67410..292415705 100644 --- a/test/tap/repo.js +++ b/test/tap/repo.js @@ -1,76 +1,75 @@ -if (process.platform === "win32") { - console.error("skipping test, because windows and shebangs") - return +if (process.platform === 'win32') { + console.error('skipping test, because windows and shebangs') + process.exit(0) } -var common = require("../common-tap.js") -var mr = require("npm-registry-mock") +var common = require('../common-tap.js') +var mr = require('npm-registry-mock') -var test = require("tap").test -var npm = require.resolve("../../bin/npm-cli.js") -var node = process.execPath -var rimraf = require("rimraf") -var spawn = require("child_process").spawn -var fs = require("fs") +var test = require('tap').test +var rimraf = require('rimraf') +var fs = require('fs') var path = require('path') var outFile = path.join(__dirname, '/_output') var opts = { cwd: __dirname } -test("setup", function (t) { - var s = "#!/usr/bin/env bash\n" + - "echo \"$@\" > " + JSON.stringify(__dirname) + "/_output\n" - fs.writeFileSync(__dirname + "/_script.sh", s, "ascii") - fs.chmodSync(__dirname + "/_script.sh", "0755") - t.pass("made script") +test('setup', function (t) { + var s = '#!/usr/bin/env bash\n' + + 'echo \"$@\" > ' + JSON.stringify(__dirname) + '/_output\n' + fs.writeFileSync(__dirname + '/_script.sh', s, 'ascii') + fs.chmodSync(__dirname + '/_script.sh', '0755') + t.pass('made script') t.end() }) -test("npm repo underscore", function (t) { - mr({port : common.port}, function (er, s) { +test('npm repo underscore', function (t) { + mr({ port: common.port }, function (er, s) { common.npm([ 'repo', 'underscore', '--registry=' + common.registry, '--loglevel=silent', '--browser=' + __dirname + '/_script.sh' ], opts, function (err, code, stdout, stderr) { + t.ifError(err, 'repo command ran without error') t.equal(code, 0, 'exit ok') var res = fs.readFileSync(outFile, 'ascii') s.close() - t.equal(res, "https://github.com/jashkenas/underscore\n") + t.equal(res, 'https://github.com/jashkenas/underscore\n') rimraf.sync(outFile) t.end() }) }) }) - test('npm repo optimist - github (https://)', function (t) { - mr({port : common.port}, function (er, s) { + mr({ port: common.port }, function (er, s) { common.npm([ 'repo', 'optimist', '--registry=' + common.registry, '--loglevel=silent', '--browser=' + __dirname + '/_script.sh' ], opts, function (err, code, stdout, stderr) { + t.ifError(err, 'repo command ran without error') t.equal(code, 0, 'exit ok') var res = fs.readFileSync(outFile, 'ascii') s.close() - t.equal(res, "https://github.com/substack/node-optimist\n") + t.equal(res, 'https://github.com/substack/node-optimist\n') rimraf.sync(outFile) t.end() }) }) }) -test("npm repo npm-test-peer-deps - no repo", function (t) { - mr({port : common.port}, function (er, s) { +test('npm repo npm-test-peer-deps - no repo', function (t) { + mr({ port: common.port }, function (er, s) { common.npm([ 'repo', 'npm-test-peer-deps', '--registry=' + common.registry, '--loglevel=silent', '--browser=' + __dirname + '/_script.sh' ], opts, function (err, code, stdout, stderr) { + t.ifError(err, 'repo command ran without error') t.equal(code, 1, 'exit not ok') s.close() t.end() @@ -78,62 +77,65 @@ test("npm repo npm-test-peer-deps - no repo", function (t) { }) }) -test("npm repo test-repo-url-http - non-github (http://)", function (t) { - mr({port : common.port}, function (er, s) { +test('npm repo test-repo-url-http - non-github (http://)', function (t) { + mr({ port: common.port }, function (er, s) { common.npm([ 'repo', 'test-repo-url-http', '--registry=' + common.registry, '--loglevel=silent', '--browser=' + __dirname + '/_script.sh' ], opts, function (err, code, stdout, stderr) { + t.ifError(err, 'repo command ran without error') t.equal(code, 0, 'exit ok') var res = fs.readFileSync(outFile, 'ascii') s.close() - t.equal(res, "http://gitlab.com/evanlucas/test-repo-url-http\n") + t.equal(res, 'http://gitlab.com/evanlucas/test-repo-url-http\n') rimraf.sync(outFile) t.end() }) }) }) -test("npm repo test-repo-url-https - non-github (https://)", function (t) { - mr({port : common.port}, function (er, s) { +test('npm repo test-repo-url-https - non-github (https://)', function (t) { + mr({ port: common.port }, function (er, s) { common.npm([ 'repo', 'test-repo-url-https', '--registry=' + common.registry, '--loglevel=silent', '--browser=' + __dirname + '/_script.sh' ], opts, function (err, code, stdout, stderr) { + t.ifError(err, 'repo command ran without error') t.equal(code, 0, 'exit ok') var res = fs.readFileSync(outFile, 'ascii') s.close() - t.equal(res, "https://gitlab.com/evanlucas/test-repo-url-https\n") + t.equal(res, 'https://gitlab.com/evanlucas/test-repo-url-https\n') rimraf.sync(outFile) t.end() }) }) }) -test("npm repo test-repo-url-ssh - non-github (ssh://)", function (t) { - mr({port : common.port}, function (er, s) { +test('npm repo test-repo-url-ssh - non-github (ssh://)', function (t) { + mr({ port: common.port }, function (er, s) { common.npm([ 'repo', 'test-repo-url-ssh', '--registry=' + common.registry, '--loglevel=silent', '--browser=' + __dirname + '/_script.sh' ], opts, function (err, code, stdout, stderr) { + t.ifError(err, 'repo command ran without error') t.equal(code, 0, 'exit ok') var res = fs.readFileSync(outFile, 'ascii') s.close() - t.equal(res, "https://gitlab.com/evanlucas/test-repo-url-ssh\n") + t.equal(res, 'https://gitlab.com/evanlucas/test-repo-url-ssh\n') rimraf.sync(outFile) t.end() }) }) }) -test("cleanup", function (t) { - fs.unlinkSync(__dirname + "/_script.sh") - t.pass("cleaned up") +test('cleanup', function (t) { + fs.unlinkSync(__dirname + '/_script.sh') + t.pass('cleaned up') t.end() }) diff --git a/test/tap/run-script.js b/test/tap/run-script.js index 8dfe574e1..9c1d5d1f5 100644 --- a/test/tap/run-script.js +++ b/test/tap/run-script.js @@ -54,15 +54,14 @@ var both = { } } - function testOutput (t, command, er, code, stdout, stderr) { var lines - if (er) - throw er + if (er) throw er - if (stderr) + if (stderr) { throw new Error('npm ' + command + ' stderr: ' + stderr.toString()) + } lines = stdout.trim().split('\n') stdout = lines.filter(function (line) { diff --git a/test/tap/semver-doc.js b/test/tap/semver-doc.js index 963cace10..31c75fffd 100644 --- a/test/tap/semver-doc.js +++ b/test/tap/semver-doc.js @@ -1,12 +1,12 @@ -var test = require("tap").test +var test = require('tap').test -test("semver doc is up to date", function (t) { - var path = require("path") - var moddoc = path.join(__dirname, "../../node_modules/semver/README.md") - var mydoc = path.join(__dirname, "../../doc/misc/semver.md") - var fs = require("fs") - var mod = fs.readFileSync(moddoc, "utf8").replace(/semver\(1\)/, "semver(7)") - var my = fs.readFileSync(mydoc, "utf8") +test('semver doc is up to date', function (t) { + var path = require('path') + var moddoc = path.join(__dirname, '../../node_modules/semver/README.md') + var mydoc = path.join(__dirname, '../../doc/misc/semver.md') + var fs = require('fs') + var mod = fs.readFileSync(moddoc, 'utf8').replace(/semver\(1\)/, 'semver(7)') + var my = fs.readFileSync(mydoc, 'utf8') t.equal(my, mod) t.end() }) diff --git a/test/tap/semver-tag.js b/test/tap/semver-tag.js index 03dcdf85b..b4feb7517 100644 --- a/test/tap/semver-tag.js +++ b/test/tap/semver-tag.js @@ -1,11 +1,11 @@ // should not allow tagging with a valid semver range -var common = require("../common-tap.js") -var test = require("tap").test +var common = require('../common-tap.js') +var test = require('tap').test -test("try to tag with semver range as tag name", function (t) { - var cmd = ["tag", "zzzz@1.2.3", "v2.x", "--registry=http://localhost"] +test('try to tag with semver range as tag name', function (t) { + var cmd = ['tag', 'zzzz@1.2.3', 'v2.x', '--registry=http://localhost'] common.npm(cmd, { - stdio: "pipe" + stdio: 'pipe' }, function (er, code, so, se) { if (er) throw er t.similar(se, /Tag name must not be a valid SemVer range: v2.x\n/) diff --git a/test/tap/shrinkwrap-local-dependency.js b/test/tap/shrinkwrap-local-dependency.js index ffbde6574..8d7c0712f 100644 --- a/test/tap/shrinkwrap-local-dependency.js +++ b/test/tap/shrinkwrap-local-dependency.js @@ -1,63 +1,62 @@ -var test = require("tap").test -var path = require("path") -var fs = require("fs") -var osenv = require("osenv") -var rimraf = require("rimraf") -var mkdirp = require("mkdirp") -var common = require("../common-tap.js") - -var PKG_DIR = path.resolve(__dirname, "shrinkwrap-local-dependency") -var CACHE_DIR = path.resolve(PKG_DIR, "cache") -var DEP_DIR = path.resolve(PKG_DIR, "dep") +var test = require('tap').test +var path = require('path') +var fs = require('fs') +var osenv = require('osenv') +var rimraf = require('rimraf') +var mkdirp = require('mkdirp') +var common = require('../common-tap.js') + +var PKG_DIR = path.resolve(__dirname, 'shrinkwrap-local-dependency') +var CACHE_DIR = path.resolve(PKG_DIR, 'cache') +var DEP_DIR = path.resolve(PKG_DIR, 'dep') var desired = { - "name": "npm-test-shrinkwrap-local-dependency", - "version": "0.0.0", - "dependencies": { - "npm-test-shrinkwrap-local-dependency-dep": { - "version": "0.0.0", - "from": "dep", - "resolved": "file:dep" + 'name': 'npm-test-shrinkwrap-local-dependency', + 'version': '0.0.0', + 'dependencies': { + 'npm-test-shrinkwrap-local-dependency-dep': { + 'version': '0.0.0', + 'from': 'dep', + 'resolved': 'file:dep' } } } var root = { - "author": "Thomas Torp", - "name": "npm-test-shrinkwrap-local-dependency", - "version": "0.0.0", - "dependencies": { - "npm-test-shrinkwrap-local-dependency-dep": "file:./dep" + 'author': 'Thomas Torp', + 'name': 'npm-test-shrinkwrap-local-dependency', + 'version': '0.0.0', + 'dependencies': { + 'npm-test-shrinkwrap-local-dependency-dep': 'file:./dep' } } var dependency = { - "author": "Thomas Torp", - "name": "npm-test-shrinkwrap-local-dependency-dep", - "version": "0.0.0" + 'author': 'Thomas Torp', + 'name': 'npm-test-shrinkwrap-local-dependency-dep', + 'version': '0.0.0' } - -test("shrinkwrap uses resolved with file: on local deps", function(t) { +test('shrinkwrap uses resolved with file: on local deps', function (t) { setup() common.npm( - ["--cache="+CACHE_DIR, "--loglevel=silent", "install", "."], + ['--cache=' + CACHE_DIR, '--loglevel=silent', 'install', '.'], {}, function (err, code) { - t.ifError(err, "npm install worked") - t.equal(code, 0, "npm exited normally") + t.ifError(err, 'npm install worked') + t.equal(code, 0, 'npm exited normally') common.npm( - ["--cache="+CACHE_DIR, "--loglevel=silent", "shrinkwrap"], + ['--cache=' + CACHE_DIR, '--loglevel=silent', 'shrinkwrap'], {}, function (err, code) { - t.ifError(err, "npm shrinkwrap worked") - t.equal(code, 0, "npm exited normally") + t.ifError(err, 'npm shrinkwrap worked') + t.equal(code, 0, 'npm exited normally') - fs.readFile("npm-shrinkwrap.json", { encoding : "utf8" }, function (err, data) { - t.ifError(err, "read file correctly") - t.deepEqual(JSON.parse(data), desired, "shrinkwrap looks correct") + fs.readFile('npm-shrinkwrap.json', { encoding: 'utf8' }, function (err, data) { + t.ifError(err, 'read file correctly') + t.deepEqual(JSON.parse(data), desired, 'shrinkwrap looks correct') t.end() }) @@ -67,22 +66,22 @@ test("shrinkwrap uses resolved with file: on local deps", function(t) { ) }) -test('"npm install" should install local packages from shrinkwrap', function (t) { +test("'npm install' should install local packages from shrinkwrap", function (t) { cleanNodeModules() common.npm( - ["--cache="+CACHE_DIR, "--loglevel=silent", "install", "."], + ['--cache=' + CACHE_DIR, '--loglevel=silent', 'install', '.'], {}, function (err, code) { - t.ifError(err, "install ran correctly") - t.notOk(code, "npm install exited with code 0") + t.ifError(err, 'install ran correctly') + t.notOk(code, 'npm install exited with code 0') var dependencyPackageJson = path.resolve( PKG_DIR, - "node_modules/npm-test-shrinkwrap-local-dependency-dep/package.json" + 'node_modules/npm-test-shrinkwrap-local-dependency-dep/package.json' ) t.ok( - JSON.parse(fs.readFileSync(dependencyPackageJson, "utf8")), - "package with local dependency installed from shrinkwrap" + JSON.parse(fs.readFileSync(dependencyPackageJson, 'utf8')), + 'package with local dependency installed from shrinkwrap' ) t.end() @@ -90,32 +89,32 @@ test('"npm install" should install local packages from shrinkwrap', function (t) ) }) -test("cleanup", function(t) { +test('cleanup', function (t) { cleanup() t.end() }) -function setup() { +function setup () { cleanup() mkdirp.sync(PKG_DIR) mkdirp.sync(CACHE_DIR) mkdirp.sync(DEP_DIR) fs.writeFileSync( - path.resolve(PKG_DIR, "package.json"), + path.resolve(PKG_DIR, 'package.json'), JSON.stringify(root, null, 2) ) fs.writeFileSync( - path.resolve(DEP_DIR, "package.json"), + path.resolve(DEP_DIR, 'package.json'), JSON.stringify(dependency, null, 2) ) process.chdir(PKG_DIR) } -function cleanNodeModules() { - rimraf.sync(path.resolve(PKG_DIR, "node_modules")) +function cleanNodeModules () { + rimraf.sync(path.resolve(PKG_DIR, 'node_modules')) } -function cleanup() { +function cleanup () { process.chdir(osenv.tmpdir()) cleanNodeModules() rimraf.sync(PKG_DIR) diff --git a/test/tap/shrinkwrap-scoped-auth.js b/test/tap/shrinkwrap-scoped-auth.js index 81b205d2e..8fe0d1e23 100644 --- a/test/tap/shrinkwrap-scoped-auth.js +++ b/test/tap/shrinkwrap-scoped-auth.js @@ -1,68 +1,66 @@ -var resolve = require("path").resolve -var writeFileSync = require("graceful-fs").writeFileSync - -var mkdirp = require("mkdirp") -var mr = require("npm-registry-mock") -var osenv = require("osenv") -var rimraf = require("rimraf") -var test = require("tap").test - -var common = require("../common-tap.js") -var toNerfDart = require("../../lib/config/nerf-dart.js") - -var pkg = resolve(__dirname, "shrinkwrap-scoped-auth") -var outfile = resolve(pkg, "_npmrc") -var modules = resolve(pkg, "node_modules") -var tarballPath = "/scoped-underscore/-/scoped-underscore-1.3.1.tgz" +var resolve = require('path').resolve +var writeFileSync = require('graceful-fs').writeFileSync + +var mkdirp = require('mkdirp') +var mr = require('npm-registry-mock') +var osenv = require('osenv') +var rimraf = require('rimraf') +var test = require('tap').test + +var common = require('../common-tap.js') +var toNerfDart = require('../../lib/config/nerf-dart.js') + +var pkg = resolve(__dirname, 'shrinkwrap-scoped-auth') +var outfile = resolve(pkg, '_npmrc') +var modules = resolve(pkg, 'node_modules') +var tarballPath = '/scoped-underscore/-/scoped-underscore-1.3.1.tgz' var tarballURL = common.registry + tarballPath -var tarball = resolve(__dirname, "../fixtures/scoped-underscore-1.3.1.tgz") +var tarball = resolve(__dirname, '../fixtures/scoped-underscore-1.3.1.tgz') var server -var EXEC_OPTS = { - cwd : pkg -} +var EXEC_OPTS = { cwd: pkg } function mocks (server) { - var auth = "Bearer 0xabad1dea" - server.get(tarballPath, { authorization : auth }).replyWithFile(200, tarball) + var auth = 'Bearer 0xabad1dea' + server.get(tarballPath, { authorization: auth }).replyWithFile(200, tarball) server.get(tarballPath).reply(401, { - error : "unauthorized", - reason : "You are not authorized to access this db." + error: 'unauthorized', + reason: 'You are not authorized to access this db.' }) } -test("setup", function (t) { - mr({ port : common.port, plugin : mocks }, function (err, s) { +test('setup', function (t) { + mr({ port: common.port, plugin: mocks }, function (er, s) { server = s - t.ok(s, "set up mock registry") + t.ok(s, 'set up mock registry') setup() t.end() }) }) -test("authed npm install with shrinkwrapped scoped package", function (t) { +test('authed npm install with shrinkwrapped scoped package', function (t) { common.npm( [ - "install", - "--loglevel", "silent", - "--json", - "--fetch-retries", 0, - "--userconfig", outfile + 'install', + '--loglevel', 'silent', + '--json', + '--fetch-retries', 0, + '--userconfig', outfile ], EXEC_OPTS, function (err, code, stdout, stderr) { console.error(stderr) - t.ifError(err, "test runner executed without error") - t.equal(code, 0, "npm install exited OK") - t.notOk(stderr, "no output on stderr") + t.ifError(err, 'test runner executed without error') + t.equal(code, 0, 'npm install exited OK') + t.notOk(stderr, 'no output on stderr') try { var results = JSON.parse(stdout) - } - catch (ex) { + } catch (ex) { console.error('#', ex) - t.ifError(ex, "stdout was valid JSON") + t.ifError(ex, 'stdout was valid JSON') } + if (results) { var installedversion = { 'version': '1.3.1', @@ -77,28 +75,28 @@ test("authed npm install with shrinkwrapped scoped package", function (t) { ) }) -test("cleanup", function (t) { +test('cleanup', function (t) { server.close() cleanup() t.end() }) -var contents = "@scoped:registry="+common.registry+"\n" + - toNerfDart(common.registry)+":_authToken=0xabad1dea\n" +var contents = '@scoped:registry=' + common.registry + '\n' + + toNerfDart(common.registry) + ':_authToken=0xabad1dea\n' var json = { - name : "test-package-install", - version : "1.0.0" + name: 'test-package-install', + version: '1.0.0' } var shrinkwrap = { - name : "test-package-install", - version : "1.0.0", - dependencies : { - "@scoped/underscore" : { - resolved : tarballURL, - from : ">=1.3.1 <2", - version : "1.3.1" + name: 'test-package-install', + version: '1.0.0', + dependencies: { + '@scoped/underscore': { + resolved: tarballURL, + from: '>=1.3.1 <2', + version: '1.3.1' } } } @@ -106,15 +104,15 @@ var shrinkwrap = { function setup () { cleanup() mkdirp.sync(modules) - writeFileSync(resolve(pkg, "package.json"), JSON.stringify(json, null, 2)+"\n") + writeFileSync(resolve(pkg, 'package.json'), JSON.stringify(json, null, 2) + '\n') writeFileSync(outfile, contents) writeFileSync( - resolve(pkg, "npm-shrinkwrap.json"), - JSON.stringify(shrinkwrap, null, 2)+"\n" + resolve(pkg, 'npm-shrinkwrap.json'), + JSON.stringify(shrinkwrap, null, 2) + '\n' ) } -function cleanup() { +function cleanup () { process.chdir(osenv.tmpdir()) rimraf.sync(pkg) } diff --git a/test/tap/sorted-package-json.js b/test/tap/sorted-package-json.js index 6853cf302..9b2e93592 100644 --- a/test/tap/sorted-package-json.js +++ b/test/tap/sorted-package-json.js @@ -1,21 +1,20 @@ -var test = require("tap").test - , path = require("path") - , rimraf = require("rimraf") - , mkdirp = require("mkdirp") - , spawn = require("child_process").spawn - , npm = require.resolve("../../bin/npm-cli.js") - , node = process.execPath - , pkg = path.resolve(__dirname, "sorted-package-json") - , tmp = path.join(pkg, "tmp") - , cache = path.join(pkg, "cache") - , fs = require("fs") - , common = require("../common-tap.js") - , mr = require("npm-registry-mock") - , osenv = require("osenv") +var test = require('tap').test +var path = require('path') +var rimraf = require('rimraf') +var mkdirp = require('mkdirp') +var spawn = require('child_process').spawn +var npm = require.resolve('../../bin/npm-cli.js') +var node = process.execPath +var pkg = path.resolve(__dirname, 'sorted-package-json') +var tmp = path.join(pkg, 'tmp') +var cache = path.join(pkg, 'cache') +var fs = require('fs') +var common = require('../common-tap.js') +var mr = require('npm-registry-mock') +var osenv = require('osenv') - -test("sorting dependencies", function (t) { - var packageJson = path.resolve(pkg, "package.json") +test('sorting dependencies', function (t) { + var packageJson = path.resolve(pkg, 'package.json') cleanup() mkdirp.sync(cache) @@ -24,27 +23,27 @@ test("sorting dependencies", function (t) { var before = JSON.parse(fs.readFileSync(packageJson).toString()) - mr({port : common.port}, function (er, s) { + mr({ port: common.port }, function (er, s) { // underscore is already in the package.json, // but --save will trigger a rewrite with sort - var child = spawn(node, [npm, "install", "--save", "underscore@1.3.3"], { + var child = spawn(node, [npm, 'install', '--save', 'underscore@1.3.3'], { cwd: pkg, env: { - "npm_config_registry": common.registry, - "npm_config_cache": cache, - "npm_config_tmp": tmp, - "npm_config_prefix": pkg, - "npm_config_global": "false", + 'npm_config_registry': common.registry, + 'npm_config_cache': cache, + 'npm_config_tmp': tmp, + 'npm_config_prefix': pkg, + 'npm_config_global': 'false', HOME: process.env.HOME, Path: process.env.PATH, PATH: process.env.PATH } }) - child.on("close", function (code) { - t.equal(code, 0, "npm install exited with code") + child.on('close', function (code) { + t.equal(code, 0, 'npm install exited with code') var result = fs.readFileSync(packageJson).toString() - , resultAsJson = JSON.parse(result) + var resultAsJson = JSON.parse(result) s.close() @@ -61,33 +60,33 @@ test("sorting dependencies", function (t) { }) }) -test("cleanup", function (t) { +test('cleanup', function (t) { cleanup() - t.pass("cleaned up") + t.pass('cleaned up') t.end() }) -function setup() { +function setup () { mkdirp.sync(pkg) - fs.writeFileSync(path.resolve(pkg, "package.json"), JSON.stringify({ - "name": "sorted-package-json", - "version": "0.0.0", - "description": "", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + fs.writeFileSync(path.resolve(pkg, 'package.json'), JSON.stringify({ + 'name': 'sorted-package-json', + 'version': '0.0.0', + 'description': '', + 'main': 'index.js', + 'scripts': { + 'test': 'echo \'Error: no test specified\' && exit 1' }, - "author": "Rocko Artischocko", - "license": "ISC", - "dependencies": { - "underscore": "^1.3.3", - "request": "^0.9.0" + 'author': 'Rocko Artischocko', + 'license': 'ISC', + 'dependencies': { + 'underscore': '^1.3.3', + 'request': '^0.9.0' } - }, null, 2), "utf8") + }, null, 2), 'utf8') } -function cleanup() { +function cleanup () { process.chdir(osenv.tmpdir()) rimraf.sync(cache) rimraf.sync(pkg) diff --git a/test/tap/spawn-enoent-help.js b/test/tap/spawn-enoent-help.js index 70fb078fa..716f6ebd1 100644 --- a/test/tap/spawn-enoent-help.js +++ b/test/tap/spawn-enoent-help.js @@ -1,25 +1,25 @@ -var path = require("path") -var test = require("tap").test -var rimraf = require("rimraf") -var mkdirp = require("mkdirp") -var common = require("../common-tap.js") +var path = require('path') +var test = require('tap').test +var rimraf = require('rimraf') +var mkdirp = require('mkdirp') +var common = require('../common-tap.js') -var pkg = path.resolve(__dirname, "spawn-enoent-help") +var pkg = path.resolve(__dirname, 'spawn-enoent-help') -test("setup", function (t) { +test('setup', function (t) { rimraf.sync(pkg) mkdirp.sync(pkg) t.end() }) -test("enoent help", function (t) { - common.npm(["help", "config"], { +test('enoent help', function (t) { + common.npm(['help', 'config'], { cwd: pkg, env: { - PATH: "", - Path: "", - "npm_config_loglevel": "warn", - "npm_config_viewer": "woman" + PATH: '', + Path: '', + 'npm_config_loglevel': 'warn', + 'npm_config_viewer': 'woman' } }, function (er, code, sout, serr) { t.similar(serr, /Check if the file 'emacsclient' is present./) @@ -28,7 +28,7 @@ test("enoent help", function (t) { }) }) -test("clean", function (t) { +test('clean', function (t) { rimraf.sync(pkg) t.end() }) diff --git a/test/tap/spawn-enoent.js b/test/tap/spawn-enoent.js index 29b70f6f8..320e477e0 100644 --- a/test/tap/spawn-enoent.js +++ b/test/tap/spawn-enoent.js @@ -1,32 +1,31 @@ -var path = require("path") -var test = require("tap").test -var fs = require("fs") -var rimraf = require("rimraf") -var mkdirp = require("mkdirp") -var common = require("../common-tap.js") +var path = require('path') +var test = require('tap').test +var fs = require('fs') +var rimraf = require('rimraf') +var mkdirp = require('mkdirp') +var common = require('../common-tap.js') -var pkg = path.resolve(__dirname, "spawn-enoent") +var pkg = path.resolve(__dirname, 'spawn-enoent') var pj = JSON.stringify({ - name:"x", - version: "1.2.3", - scripts: { start: "wharble-garble-blorst" } -}, null, 2) + "\n" + name: 'x', + version: '1.2.3', + scripts: { start: 'wharble-garble-blorst' } +}, null, 2) + '\n' - -test("setup", function (t) { +test('setup', function (t) { rimraf.sync(pkg) mkdirp.sync(pkg) - fs.writeFileSync(pkg + "/package.json", pj) + fs.writeFileSync(pkg + '/package.json', pj) t.end() }) -test("enoent script", function (t) { - common.npm(["start"], { +test('enoent script', function (t) { + common.npm(['start'], { cwd: pkg, env: { PATH: process.env.PATH, Path: process.env.Path, - "npm_config_loglevel": "warn" + 'npm_config_loglevel': 'warn' } }, function (er, code, sout, serr) { t.similar(serr, /npm ERR! Failed at the x@1\.2\.3 start script 'wharble-garble-blorst'\./) @@ -34,7 +33,7 @@ test("enoent script", function (t) { }) }) -test("clean", function (t) { +test('clean', function (t) { rimraf.sync(pkg) t.end() }) diff --git a/test/tap/tag-version-prefix.js b/test/tap/tag-version-prefix.js index efd2d14d4..e137c1771 100644 --- a/test/tap/tag-version-prefix.js +++ b/test/tap/tag-version-prefix.js @@ -19,70 +19,72 @@ var json = { name: 'blah', version: '0.1.2' } var configContents = 'sign-git-tag=false\nmessage=":bookmark: %s"\n' test('npm version <semver> with message config', function (t) { - setup() - - npm.load({ prefix: pkg, userconfig: npmrc }, function () { - var git = require('../../lib/utils/git.js') - - common.makeGitRepo({ path: pkg }, function (er) { - t.ifErr(er, 'git bootstrap ran without error') - - common.npm([ - 'config', - 'set', - 'tag-version-prefix', - 'q' - ], { cwd: pkg, env: { PATH: process.env.PATH } }, + setup() + + npm.load({ prefix: pkg, userconfig: npmrc }, function () { + var git = require('../../lib/utils/git.js') + + common.makeGitRepo({ path: pkg }, function (er) { + t.ifErr(er, 'git bootstrap ran without error') + + common.npm( + [ + 'config', + 'set', + 'tag-version-prefix', + 'q' + ], + { cwd: pkg, env: { PATH: process.env.PATH } }, + function (err, code, stdout, stderr) { + t.ifError(err, 'npm config ran without issue') + t.notOk(code, 'exited with a non-error code') + t.notOk(stderr, 'no error output') + + common.npm( + [ + 'version', + 'patch', + '--loglevel', 'silent' + // package config is picked up from env + ], + { cwd: pkg, env: { PATH: process.env.PATH } }, function (err, code, stdout, stderr) { - t.ifError(err, 'npm config ran without issue') - t.notOk(code, 'exited with a non-error code') - t.notOk(stderr, 'no error output') - - common.npm( - [ - 'version', - 'patch', - '--loglevel', 'silent' - // package config is picked up from env - ], - { cwd: pkg, env: { PATH: process.env.PATH } }, - function (err, code, stdout, stderr) { - t.ifError(err, 'npm version ran without issue') - t.notOk(code, 'exited with a non-error code') - t.notOk(stderr, 'no error output') - - git.whichAndExec( - ['tag'], - { cwd: pkg, env: process.env }, - function (er, tags, stderr) { - t.ok(tags.match(/q0\.1\.3/g), 'tag was created by version' + tags) - t.end() - } - ) - } - ) - }) + t.ifError(err, 'npm version ran without issue') + t.notOk(code, 'exited with a non-error code') + t.notOk(stderr, 'no error output') + + git.whichAndExec( + ['tag'], + { cwd: pkg, env: process.env }, + function (er, tags, stderr) { + t.ok(tags.match(/q0\.1\.3/g), 'tag was created by version' + tags) + t.end() + } + ) + } + ) }) }) + }) }) test('cleanup', function (t) { - cleanup() - t.end() + cleanup() + t.end() }) function cleanup () { - // windows fix for locked files - process.chdir(osenv.tmpdir()) + // windows fix for locked files + process.chdir(osenv.tmpdir()) - rimraf.sync(pkg) + rimraf.sync(pkg) } function setup () { - cleanup() - mkdirp.sync(cache) - process.chdir(pkg) + cleanup() + mkdirp.sync(cache) + process.chdir(pkg) - fs.writeFileSync(packagePath, JSON.stringify(json), 'utf8') - fs.writeFileSync(npmrc, configContents, 'ascii') + fs.writeFileSync(packagePath, JSON.stringify(json), 'utf8') + fs.writeFileSync(npmrc, configContents, 'ascii') } diff --git a/test/tap/test-run-ls.js b/test/tap/test-run-ls.js index 252c6e8f9..ea495879f 100644 --- a/test/tap/test-run-ls.js +++ b/test/tap/test-run-ls.js @@ -1,30 +1,30 @@ -var common = require("../common-tap.js") -var test = require("tap").test -var path = require("path") -var cwd = path.resolve(__dirname, "..", "..") -var testscript = require("../../package.json").scripts.test -var tsregexp = testscript.replace(/([\[\.\*\]])/g, "\\$1") +var common = require('../common-tap.js') +var test = require('tap').test +var path = require('path') +var cwd = path.resolve(__dirname, '..', '..') +var testscript = require('../../package.json').scripts.test +var tsregexp = testscript.replace(/([\[\.\*\]])/g, '\\$1') -test("default", function (t) { - common.npm(["run"], { cwd: cwd }, function (er, code, so) { +test('default', function (t) { + common.npm(['run'], { cwd: cwd }, function (er, code, so) { if (er) throw er t.notOk(code) - t.similar(so, new RegExp("\\n test\\n " + tsregexp + "\\n")) + t.similar(so, new RegExp('\\n test\\n ' + tsregexp + '\\n')) t.end() }) }) -test("parseable", function (t) { - common.npm(["run", "-p"], { cwd: cwd }, function (er, code, so) { +test('parseable', function (t) { + common.npm(['run', '-p'], { cwd: cwd }, function (er, code, so) { if (er) throw er t.notOk(code) - t.similar(so, new RegExp("\\ntest:" + tsregexp + "\\n")) + t.similar(so, new RegExp('\\ntest:' + tsregexp + '\\n')) t.end() }) }) -test("parseable", function (t) { - common.npm(["run", "--json"], { cwd: cwd }, function (er, code, so) { +test('parseable', function (t) { + common.npm(['run', '--json'], { cwd: cwd }, function (er, code, so) { if (er) throw er t.notOk(code) t.equal(JSON.parse(so).test, testscript) diff --git a/test/tap/update-examples.js b/test/tap/update-examples.js index f662e23d5..ae67e4a91 100644 --- a/test/tap/update-examples.js +++ b/test/tap/update-examples.js @@ -141,7 +141,7 @@ test('setup', function (t) { process.chdir(osenv.tmpdir()) mkdirp.sync(PKG_DIR) process.chdir(PKG_DIR) - t.pass('made '+PKG_DIR) + t.pass('made ' + PKG_DIR) resetPackage({}) diff --git a/test/tap/version-git-not-clean.js b/test/tap/version-git-not-clean.js index 1deae49f9..d770a86e6 100644 --- a/test/tap/version-git-not-clean.js +++ b/test/tap/version-git-not-clean.js @@ -1,60 +1,59 @@ -var common = require("../common-tap.js") -var test = require("tap").test -var npm = require("../../") -var osenv = require("osenv") -var path = require("path") -var fs = require("fs") -var rimraf = require("rimraf") -var mkdirp = require("mkdirp") -var which = require("which") -var spawn = require("child_process").spawn +var common = require('../common-tap.js') +var test = require('tap').test +var npm = require('../../') +var osenv = require('osenv') +var path = require('path') +var fs = require('fs') +var rimraf = require('rimraf') +var mkdirp = require('mkdirp') +var which = require('which') +var spawn = require('child_process').spawn -var pkg = path.resolve(__dirname, "version-git-not-clean") -var cache = path.resolve(pkg, "cache") +var pkg = path.resolve(__dirname, 'version-git-not-clean') +var cache = path.resolve(pkg, 'cache') -test("npm version <semver> with working directory not clean", function (t) { +test('npm version <semver> with working directory not clean', function (t) { setup() npm.load({ cache: cache, registry: common.registry, prefix: pkg }, function () { - which("git", function (err, git) { - t.ifError(err, "git found") + which('git', function (err, git) { + t.ifError(err, 'git found') - function gitInit(_cb) { - var child = spawn(git, ["init"]) - var out = "" - child.stdout.on("data", function (d) { + function gitInit (_cb) { + var child = spawn(git, ['init']) + var out = '' + child.stdout.on('data', function (d) { out += d.toString() }) - child.on("exit", function () { + child.on('exit', function () { return _cb(out) }) } - function addPackageJSON(_cb) { - var data = JSON.stringify({ name: "blah", version: "0.1.2" }) - fs.writeFile("package.json", data, function() { - var child = spawn(git, ["add", "package.json"]) - child.on("exit", function () { - var child2 = spawn(git, ["commit", "package.json", "-m", "init"]) - var out = "" - child2.stdout.on("data", function (d) { + function addPackageJSON (_cb) { + var data = JSON.stringify({ name: 'blah', version: '0.1.2' }) + fs.writeFile('package.json', data, function () { + var child = spawn(git, ['add', 'package.json']) + child.on('exit', function () { + var child2 = spawn(git, ['commit', 'package.json', '-m', 'init']) + var out = '' + child2.stdout.on('data', function (d) { out += d.toString() }) - child2.on("exit", function () { + child2.on('exit', function () { return _cb(out) }) }) }) } - gitInit(function() { - addPackageJSON(function() { - var data = JSON.stringify({ name: "blah", version: "0.1.3" }) - fs.writeFile("package.json", data, function() { - npm.commands.version(["patch"], function (err) { + gitInit(function () { + addPackageJSON(function () { + var data = JSON.stringify({ name: 'blah', version: '0.1.3' }) + fs.writeFile('package.json', data, function () { + npm.commands.version(['patch'], function (err) { if (!err) { - t.fail("should fail on non-clean working directory") - } - else { + t.fail('should fail on non-clean working directory') + } else { t.ok(err.message.match(/Git working directory not clean./)) t.ok(err.message.match(/M package.json/)) } @@ -67,7 +66,7 @@ test("npm version <semver> with working directory not clean", function (t) { }) }) -test("cleanup", function (t) { +test('cleanup', function (t) { // windows fix for locked files process.chdir(osenv.tmpdir()) @@ -75,7 +74,7 @@ test("cleanup", function (t) { t.end() }) -function setup() { +function setup () { mkdirp.sync(pkg) mkdirp.sync(cache) process.chdir(pkg) diff --git a/test/tap/version-no-git.js b/test/tap/version-no-git.js index 0acd0ab6a..0a859c7af 100644 --- a/test/tap/version-no-git.js +++ b/test/tap/version-no-git.js @@ -1,54 +1,54 @@ -var common = require("../common-tap.js") -var test = require("tap").test -var npm = require("../../") -var osenv = require("osenv") -var path = require("path") -var fs = require("fs") -var mkdirp = require("mkdirp") -var rimraf = require("rimraf") -var requireInject = require("require-inject") +var common = require('../common-tap.js') +var test = require('tap').test +var npm = require('../../') +var osenv = require('osenv') +var path = require('path') +var fs = require('fs') +var mkdirp = require('mkdirp') +var rimraf = require('rimraf') +var requireInject = require('require-inject') -var pkg = path.resolve(__dirname, "version-no-git") -var cache = path.resolve(pkg, "cache") -var gitDir = path.resolve(pkg, ".git") +var pkg = path.resolve(__dirname, 'version-no-git') +var cache = path.resolve(pkg, 'cache') +var gitDir = path.resolve(pkg, '.git') -test("npm version <semver> in a git repo without the git binary", function(t) { +test('npm version <semver> in a git repo without the git binary', function (t) { setup() - npm.load({cache: cache, registry: common.registry}, function() { - var version = requireInject("../../lib/version", { - which: function(cmd, cb) { - process.nextTick(function() { + npm.load({cache: cache, registry: common.registry}, function () { + var version = requireInject('../../lib/version', { + which: function (cmd, cb) { + process.nextTick(function () { cb(new Error('ENOGIT!')) }) } }) - version(["patch"], function(err) { - if (! t.error(err)) return t.end() - var p = path.resolve(pkg, "package") + version(['patch'], function (err) { + if (!t.error(err)) return t.end() + var p = path.resolve(pkg, 'package') var testPkg = require(p) - t.equal("0.0.1", testPkg.version, "\"" + testPkg.version+"\" === \"0.0.1\"") + t.equal('0.0.1', testPkg.version, '\'' + testPkg.version + '\' === \'0.0.1\'') t.end() }) }) }) -test("cleanup", function(t) { +test('cleanup', function (t) { process.chdir(osenv.tmpdir()) rimraf.sync(pkg) t.end() }) -function setup() { +function setup () { mkdirp.sync(pkg) mkdirp.sync(cache) mkdirp.sync(gitDir) - fs.writeFileSync(path.resolve(pkg, "package.json"), JSON.stringify({ - author: "Terin Stock", - name: "version-no-git-test", - version: "0.0.0", + fs.writeFileSync(path.resolve(pkg, 'package.json'), JSON.stringify({ + author: 'Terin Stock', + name: 'version-no-git-test', + version: '0.0.0', description: "Test for npm version if git binary doesn't exist" - }), "utf8") + }), 'utf8') process.chdir(pkg) } diff --git a/test/tap/version-no-package.js b/test/tap/version-no-package.js index 539f53feb..755f99317 100644 --- a/test/tap/version-no-package.js +++ b/test/tap/version-no-package.js @@ -1,45 +1,45 @@ -var common = require("../common-tap.js") -var test = require("tap").test -var osenv = require("osenv") -var path = require("path") -var mkdirp = require("mkdirp") -var rimraf = require("rimraf") +var common = require('../common-tap.js') +var test = require('tap').test +var osenv = require('osenv') +var path = require('path') +var mkdirp = require('mkdirp') +var rimraf = require('rimraf') -var pkg = path.resolve(__dirname, "version-no-package") +var pkg = path.resolve(__dirname, 'version-no-package') -test("setup", function (t) { +test('setup', function (t) { setup() t.end() }) -test("npm version in a prefix with no package.json", function(t) { +test('npm version in a prefix with no package.json', function (t) { setup() common.npm( - ["version", "--json", "--prefix", pkg], - { cwd : pkg }, + ['version', '--json', '--prefix', pkg], + { cwd: pkg }, function (er, code, stdout, stderr) { t.ifError(er, "npm version doesn't care that there's no package.json") - t.notOk(code, "npm version ran without barfing") - t.ok(stdout, "got version output") - t.notOk(stderr, "no error output") + t.notOk(code, 'npm version ran without barfing') + t.ok(stdout, 'got version output') + t.notOk(stderr, 'no error output') t.doesNotThrow(function () { var metadata = JSON.parse(stdout) - t.equal(metadata.node, process.versions.node, "node versions match") + t.equal(metadata.node, process.versions.node, 'node versions match') t.end() - }, "able to reconstitute version object from stdout") + }, 'able to reconstitute version object from stdout') } ) }) -test("cleanup", function(t) { +test('cleanup', function (t) { process.chdir(osenv.tmpdir()) rimraf.sync(pkg) t.end() }) -function setup() { +function setup () { mkdirp.sync(pkg) process.chdir(pkg) } diff --git a/test/tap/version-no-tags.js b/test/tap/version-no-tags.js index cb6f195f8..ed2bed32c 100644 --- a/test/tap/version-no-tags.js +++ b/test/tap/version-no-tags.js @@ -1,47 +1,47 @@ -var common = require("../common-tap.js") -var test = require("tap").test -var npm = require("../../") -var osenv = require("osenv") -var path = require("path") -var fs = require("fs") -var rimraf = require("rimraf") -var mkdirp = require("mkdirp") -var which = require("which") -var spawn = require("child_process").spawn +var common = require('../common-tap.js') +var test = require('tap').test +var npm = require('../../') +var osenv = require('osenv') +var path = require('path') +var fs = require('fs') +var rimraf = require('rimraf') +var mkdirp = require('mkdirp') +var which = require('which') +var spawn = require('child_process').spawn -var pkg = path.resolve(__dirname, "version-no-tags") -var cache = path.resolve(pkg, "cache") +var pkg = path.resolve(__dirname, 'version-no-tags') +var cache = path.resolve(pkg, 'cache') -test("npm version <semver> without git tag", function (t) { +test('npm version <semver> without git tag', function (t) { setup() npm.load({ cache: cache, registry: common.registry}, function () { - which("git", function (err, git) { - t.ifError(err, "git found on system") - function tagExists(tag, _cb) { - var child1 = spawn(git, ["tag", "-l", tag]) - var out = "" - child1.stdout.on("data", function (d) { + which('git', function (err, git) { + t.ifError(err, 'git found on system') + function tagExists (tag, _cb) { + var child1 = spawn(git, ['tag', '-l', tag]) + var out = '' + child1.stdout.on('data', function (d) { out += d.toString() }) - child1.on("exit", function () { + child1.on('exit', function () { return _cb(null, Boolean(~out.indexOf(tag))) }) } - var child2 = spawn(git, ["init"]) + var child2 = spawn(git, ['init']) child2.stdout.pipe(process.stdout) - child2.on("exit", function () { - npm.config.set("git-tag-version", false) - npm.commands.version(["patch"], function (err) { - if (err) return t.fail("Error perform version patch") - var p = path.resolve(pkg, "package") + child2.on('exit', function () { + npm.config.set('git-tag-version', false) + npm.commands.version(['patch'], function (err) { + if (err) return t.fail('Error perform version patch') + var p = path.resolve(pkg, 'package') var testPkg = require(p) - if (testPkg.version !== "0.0.1") t.fail(testPkg.version+" !== \"0.0.1\"") - t.equal("0.0.1", testPkg.version) - tagExists("v0.0.1", function (err, exists) { - t.ifError(err, "tag found to exist") - t.equal(exists, false, "git tag DOES exist") - t.pass("git tag does not exist") + if (testPkg.version !== '0.0.1') t.fail(testPkg.version + ' !== \'0.0.1\'') + t.equal('0.0.1', testPkg.version) + tagExists('v0.0.1', function (err, exists) { + t.ifError(err, 'tag found to exist') + t.equal(exists, false, 'git tag DOES exist') + t.pass('git tag does not exist') t.end() }) }) @@ -50,7 +50,7 @@ test("npm version <semver> without git tag", function (t) { }) }) -test("cleanup", function (t) { +test('cleanup', function (t) { // windows fix for locked files process.chdir(osenv.tmpdir()) @@ -58,14 +58,14 @@ test("cleanup", function (t) { t.end() }) -function setup() { +function setup () { mkdirp.sync(pkg) mkdirp.sync(cache) - fs.writeFileSync(path.resolve(pkg, "package.json"), JSON.stringify({ - author: "Evan Lucas", - name: "version-no-tags-test", - version: "0.0.0", - description: "Test for git-tag-version flag" - }), "utf8") + fs.writeFileSync(path.resolve(pkg, 'package.json'), JSON.stringify({ + author: 'Evan Lucas', + name: 'version-no-tags-test', + version: '0.0.0', + description: 'Test for git-tag-version flag' + }), 'utf8') process.chdir(pkg) } diff --git a/test/tap/view.js b/test/tap/view.js index 68583ba25..84a0a69d3 100644 --- a/test/tap/view.js +++ b/test/tap/view.js @@ -1,97 +1,97 @@ -var common = require("../common-tap.js") -var test = require("tap").test -var osenv = require("osenv") -var path = require("path") -var fs = require("fs") -var rimraf = require("rimraf") -var mkdirp = require("mkdirp") +var common = require('../common-tap.js') +var test = require('tap').test +var osenv = require('osenv') +var path = require('path') +var fs = require('fs') +var rimraf = require('rimraf') +var mkdirp = require('mkdirp') var tmp = osenv.tmpdir() -var t1dir = path.resolve(tmp, "view-local-no-pkg") -var t2dir = path.resolve(tmp, "view-local-notmine") -var t3dir = path.resolve(tmp, "view-local-mine") -var mr = require("npm-registry-mock") +var t1dir = path.resolve(tmp, 'view-local-no-pkg') +var t2dir = path.resolve(tmp, 'view-local-notmine') +var t3dir = path.resolve(tmp, 'view-local-mine') +var mr = require('npm-registry-mock') -test("setup", function (t) { +test('setup', function (t) { mkdirp.sync(t1dir) mkdirp.sync(t2dir) mkdirp.sync(t3dir) - fs.writeFileSync(t2dir + "/package.json", JSON.stringify({ - author: "Evan Lucas" - , name: "test-repo-url-https" - , version: "0.0.1" - }), "utf8") + fs.writeFileSync(t2dir + '/package.json', JSON.stringify({ + author: 'Evan Lucas', + name: 'test-repo-url-https', + version: '0.0.1' + }), 'utf8') - fs.writeFileSync(t3dir + "/package.json", JSON.stringify({ - author: "Evan Lucas" - , name: "biscuits" - , version: "0.0.1" - }), "utf8") + fs.writeFileSync(t3dir + '/package.json', JSON.stringify({ + author: 'Evan Lucas', + name: 'biscuits', + version: '0.0.1' + }), 'utf8') - t.pass("created fixtures") + t.pass('created fixtures') t.end() }) function plugin (server) { server - .get("/biscuits") + .get('/biscuits') .many() - .reply(404, {"error": "version not found"}) + .reply(404, {'error': 'version not found'}) } -test("npm view . in global mode", function (t) { +test('npm view . in global mode', function (t) { process.chdir(t1dir) common.npm([ - "view" - , "." - , "--registry=" + common.registry - , "--global" + 'view', + '.', + '--registry=' + common.registry, + '--global' ], { cwd: t1dir }, function (err, code, stdout, stderr) { - t.ifError(err, "view command finished successfully") - t.equal(code, 1, "exit not ok") + t.ifError(err, 'view command finished successfully') + t.equal(code, 1, 'exit not ok') t.similar(stderr, /Cannot use view command in global mode./m) t.end() }) }) -test("npm view --global", function(t) { +test('npm view --global', function (t) { process.chdir(t1dir) common.npm([ - "view" - , "--registry=" + common.registry - , "--global" - ], { cwd: t1dir }, function(err, code, stdout, stderr) { - t.ifError(err, "view command finished successfully") - t.equal(code, 1, "exit not ok") + 'view', + '--registry=' + common.registry, + '--global' + ], { cwd: t1dir }, function (err, code, stdout, stderr) { + t.ifError(err, 'view command finished successfully') + t.equal(code, 1, 'exit not ok') t.similar(stderr, /Cannot use view command in global mode./m) t.end() }) }) -test("npm view . with no package.json", function(t) { +test('npm view . with no package.json', function (t) { process.chdir(t1dir) common.npm([ - "view" - , "." - , "--registry=" + common.registry + 'view', + '.', + '--registry=' + common.registry ], { cwd: t1dir }, function (err, code, stdout, stderr) { - t.ifError(err, "view command finished successfully") - t.equal(code, 1, "exit not ok") + t.ifError(err, 'view command finished successfully') + t.equal(code, 1, 'exit not ok') t.similar(stderr, /Invalid package.json/m) t.end() }) }) -test("npm view . with no published package", function (t) { +test('npm view . with no published package', function (t) { process.chdir(t3dir) - mr({port : common.port, plugin : plugin}, function (er, s) { + mr({ port: common.port, plugin: plugin}, function (er, s) { common.npm([ - "view" - , "." - , "--registry=" + common.registry + 'view', + '.', + '--registry=' + common.registry ], { cwd: t3dir }, function (err, code, stdout, stderr) { - t.ifError(err, "view command finished successfully") - t.equal(code, 1, "exit not ok") + t.ifError(err, 'view command finished successfully') + t.equal(code, 1, 'exit not ok') t.similar(stderr, /version not found/m) s.close() t.end() @@ -99,16 +99,16 @@ test("npm view . with no published package", function (t) { }) }) -test("npm view .", function (t) { +test('npm view .', function (t) { process.chdir(t2dir) - mr({port : common.port, plugin : plugin}, function (er, s) { + mr({ port: common.port, plugin: plugin }, function (er, s) { common.npm([ - "view" - , "." - , "--registry=" + common.registry + 'view', + '.', + '--registry=' + common.registry ], { cwd: t2dir }, function (err, code, stdout) { - t.ifError(err, "view command finished successfully") - t.equal(code, 0, "exit ok") + t.ifError(err, 'view command finished successfully') + t.equal(code, 0, 'exit ok') var re = new RegExp("name: 'test-repo-url-https'") t.similar(stdout, re) s.close() @@ -117,161 +117,160 @@ test("npm view .", function (t) { }) }) -test("npm view . select fields", function (t) { +test('npm view . select fields', function (t) { process.chdir(t2dir) - mr({port : common.port, plugin : plugin}, function (er, s) { + mr({ port: common.port, plugin: plugin }, function (er, s) { common.npm([ - "view" - , "." - , "main" - , "--registry=" + common.registry + 'view', + '.', + 'main', + '--registry=' + common.registry ], { cwd: t2dir }, function (err, code, stdout) { - t.ifError(err, "view command finished successfully") - t.equal(code, 0, "exit ok") - t.equal(stdout.trim(), "index.js", "should print `index.js`") + t.ifError(err, 'view command finished successfully') + t.equal(code, 0, 'exit ok') + t.equal(stdout.trim(), 'index.js', 'should print `index.js`') s.close() t.end() }) }) }) -test("npm view .@<version>", function (t) { +test('npm view .@<version>', function (t) { process.chdir(t2dir) - mr({port : common.port, plugin : plugin}, function (er, s) { + mr({ port: common.port, plugin: plugin }, function (er, s) { common.npm([ - "view" - , ".@0.0.0" - , "version" - , "--registry=" + common.registry + 'view', + '.@0.0.0', + 'version', + '--registry=' + common.registry ], { cwd: t2dir }, function (err, code, stdout) { - t.ifError(err, "view command finished successfully") - t.equal(code, 0, "exit ok") - t.equal(stdout.trim(), "0.0.0", "should print `0.0.0`") + t.ifError(err, 'view command finished successfully') + t.equal(code, 0, 'exit ok') + t.equal(stdout.trim(), '0.0.0', 'should print `0.0.0`') s.close() t.end() }) }) }) -test("npm view .@<version> --json", function (t) { +test('npm view .@<version> --json', function (t) { process.chdir(t2dir) - mr({port : common.port, plugin : plugin}, function (er, s) { + mr({ port: common.port, plugin: plugin }, function (er, s) { common.npm([ - "view" - , ".@0.0.0" - , "version" - , "--json" - , "--registry=" + common.registry + 'view', + '.@0.0.0', + 'version', + '--json', + '--registry=' + common.registry ], { cwd: t2dir }, function (err, code, stdout) { - t.ifError(err, "view command finished successfully") - t.equal(code, 0, "exit ok") - t.equal(stdout.trim(), "\"0.0.0\"", "should print `\"0.0.0\"`") + t.ifError(err, 'view command finished successfully') + t.equal(code, 0, 'exit ok') + t.equal(stdout.trim(), '"0.0.0"', 'should print `"0.0.0"`') s.close() t.end() }) }) }) -test("npm view <package name>", function (t) { - mr({port : common.port, plugin : plugin}, function (er, s) { +test('npm view <package name>', function (t) { + mr({ port: common.port, plugin: plugin }, function (er, s) { common.npm([ - "view" - , "underscore" - , "--registry=" + common.registry + 'view', + 'underscore', + '--registry=' + common.registry ], { cwd: t2dir }, function (err, code, stdout) { - t.ifError(err, "view command finished successfully") - t.equal(code, 0, "exit ok") + t.ifError(err, 'view command finished successfully') + t.equal(code, 0, 'exit ok') var re = new RegExp("name: 'underscore'") - t.similar(stdout, re, "should have name `underscore`") + t.similar(stdout, re, 'should have name `underscore`') s.close() t.end() }) }) }) -test("npm view <package name> --global", function(t) { - mr({port : common.port, plugin : plugin}, function (er, s) { +test('npm view <package name> --global', function (t) { + mr({ port: common.port, plugin: plugin }, function (er, s) { common.npm([ - "view" - , "underscore" - , "--global" - , "--registry=" + common.registry - ], { cwd: t2dir }, function(err, code, stdout) { - t.ifError(err, "view command finished successfully") - t.equal(code, 0, "exit ok") + 'view', + 'underscore', + '--global', + '--registry=' + common.registry + ], { cwd: t2dir }, function (err, code, stdout) { + t.ifError(err, 'view command finished successfully') + t.equal(code, 0, 'exit ok') var re = new RegExp("name: 'underscore'") - t.similar(stdout, re, "should have name `underscore`") + t.similar(stdout, re, 'should have name `underscore`') s.close() t.end() }) }) }) -test("npm view <package name> --json", function(t) { +test('npm view <package name> --json', function (t) { t.plan(3) - mr({port : common.port, plugin : plugin}, function (er, s) { + mr({ port: common.port, plugin: plugin }, function (er, s) { common.npm([ - "view" - , "underscore" - , "--json" - , "--registry=" + common.registry + 'view', + 'underscore', + '--json', + '--registry=' + common.registry ], { cwd: t2dir }, function (err, code, stdout) { - t.ifError(err, "view command finished successfully") - t.equal(code, 0, "exit ok") + t.ifError(err, 'view command finished successfully') + t.equal(code, 0, 'exit ok') s.close() try { var out = JSON.parse(stdout.trim()) t.similar(out, { - maintainers: ["jashkenas <jashkenas@gmail.com>"] - }, "should have the same maintainer") - } - catch (er) { - t.fail("Unable to parse JSON") + maintainers: ['jashkenas <jashkenas@gmail.com>'] + }, 'should have the same maintainer') + } catch (er) { + t.fail('Unable to parse JSON') } }) }) }) -test("npm view <package name> <field>", function (t) { - mr({port : common.port, plugin : plugin}, function (er, s) { +test('npm view <package name> <field>', function (t) { + mr({ port: common.port, plugin: plugin }, function (er, s) { common.npm([ - "view" - , "underscore" - , "homepage" - , "--registry=" + common.registry + 'view', + 'underscore', + 'homepage', + '--registry=' + common.registry ], { cwd: t2dir }, function (err, code, stdout) { - t.ifError(err, "view command finished successfully") - t.equal(code, 0, "exit ok") - t.equal(stdout.trim(), "http://underscorejs.org", - "homepage should equal `http://underscorejs.org`") + t.ifError(err, 'view command finished successfully') + t.equal(code, 0, 'exit ok') + t.equal(stdout.trim(), 'http://underscorejs.org', + 'homepage should equal `http://underscorejs.org`') s.close() t.end() }) }) }) -test("npm view with invalid package name", function (t) { - var invalidName = "InvalidPackage" - obj = {} - obj["/" + invalidName] = [404, {"error": "not found"}] +test('npm view with invalid package name', function (t) { + var invalidName = 'InvalidPackage' + var obj = {} + obj['/' + invalidName] = [404, {'error': 'not found'}] - mr({port : common.port, mocks: {"get": obj}}, function (er, s) { + mr({ port: common.port, mocks: { 'get': obj } }, function (er, s) { common.npm([ - "view" - , invalidName - , "--registry=" + common.registry + 'view', + invalidName, + '--registry=' + common.registry ], {}, function (err, code, stdout, stderr) { - t.ifError(err, "view command finished successfully") - t.equal(code, 1, "exit not ok") + t.ifError(err, 'view command finished successfully') + t.equal(code, 1, 'exit not ok') - t.similar(stderr, new RegExp("is not in the npm registry"), - "Package should NOT be found") + t.similar(stderr, new RegExp('is not in the npm registry'), + 'Package should NOT be found') - t.dissimilar(stderr, new RegExp("use the name yourself!"), - "Suggestion should not be there") + t.dissimilar(stderr, new RegExp('use the name yourself!'), + 'Suggestion should not be there') - t.similar(stderr, new RegExp("name can no longer contain capital letters"), - "Suggestion about Capital letter should be there") + t.similar(stderr, new RegExp('name can no longer contain capital letters'), + 'Suggestion about Capital letter should be there') s.close() t.end() @@ -279,27 +278,26 @@ test("npm view with invalid package name", function (t) { }) }) - -test("npm view with valid but non existent package name", function (t) { - mr({port : common.port, mocks: { - "get": { - "/valid-but-non-existent-package" : [404, {"error": "not found"}] +test('npm view with valid but non existent package name', function (t) { + mr({ port: common.port, mocks: { + 'get': { + '/valid-but-non-existent-package': [404, {'error': 'not found'}] } }}, function (er, s) { common.npm([ - "view" - , "valid-but-non-existent-package" - , "--registry=" + common.registry + 'view', + 'valid-but-non-existent-package', + '--registry=' + common.registry ], {}, function (err, code, stdout, stderr) { - t.ifError(err, "view command finished successfully") - t.equal(code, 1, "exit not ok") + t.ifError(err, 'view command finished successfully') + t.equal(code, 1, 'exit not ok') t.similar(stderr, new RegExp("'valid-but-non-existent-package' is not in the npm registry\."), - "Package should NOT be found") + 'Package should NOT be found') - t.similar(stderr, new RegExp("use the name yourself!"), - "Suggestion should be there") + t.similar(stderr, new RegExp('use the name yourself!'), + 'Suggestion should be there') s.close() t.end() @@ -307,11 +305,11 @@ test("npm view with valid but non existent package name", function (t) { }) }) -test("cleanup", function (t) { +test('cleanup', function (t) { process.chdir(osenv.tmpdir()) rimraf.sync(t1dir) rimraf.sync(t2dir) rimraf.sync(t3dir) - t.pass("cleaned up") + t.pass('cleaned up') t.end() }) diff --git a/test/tap/whoami.js b/test/tap/whoami.js index 558d0db9a..268e0f94f 100644 --- a/test/tap/whoami.js +++ b/test/tap/whoami.js @@ -1,55 +1,55 @@ -var common = require("../common-tap.js") +var common = require('../common-tap.js') -var fs = require("fs") -var path = require("path") -var createServer = require("http").createServer +var fs = require('fs') +var path = require('path') +var createServer = require('http').createServer -var test = require("tap").test -var rimraf = require("rimraf") +var test = require('tap').test +var rimraf = require('rimraf') var opts = { cwd: __dirname } -var FIXTURE_PATH = path.resolve(__dirname, "fixture_npmrc") +var FIXTURE_PATH = path.resolve(__dirname, 'fixture_npmrc') -test("npm whoami with basic auth", function (t) { - var s = "//registry.lvh.me/:username = wombat\n" + - "//registry.lvh.me/:_password = YmFkIHBhc3N3b3Jk\n" + - "//registry.lvh.me/:email = lindsay@wdu.org.au\n" - fs.writeFileSync(FIXTURE_PATH, s, "ascii") - fs.chmodSync(FIXTURE_PATH, "0444") +test('npm whoami with basic auth', function (t) { + var s = '//registry.lvh.me/:username = wombat\n' + + '//registry.lvh.me/:_password = YmFkIHBhc3N3b3Jk\n' + + '//registry.lvh.me/:email = lindsay@wdu.org.au\n' + fs.writeFileSync(FIXTURE_PATH, s, 'ascii') + fs.chmodSync(FIXTURE_PATH, '0444') common.npm( [ - "whoami", - "--userconfig=" + FIXTURE_PATH, - "--registry=http://registry.lvh.me/" + 'whoami', + '--userconfig=' + FIXTURE_PATH, + '--registry=http://registry.lvh.me/' ], opts, function (err, code, stdout, stderr) { t.ifError(err) - t.equal(stderr, "", "got nothing on stderr") - t.equal(code, 0, "exit ok") - t.equal(stdout, "wombat\n", "got username") + t.equal(stderr, '', 'got nothing on stderr') + t.equal(code, 0, 'exit ok') + t.equal(stdout, 'wombat\n', 'got username') rimraf.sync(FIXTURE_PATH) t.end() } ) }) -test("npm whoami with bearer auth", {timeout : 2 * 1000}, function (t) { - var s = "//localhost:" + common.port + - "/:_authToken = wombat-developers-union\n" - fs.writeFileSync(FIXTURE_PATH, s, "ascii") - fs.chmodSync(FIXTURE_PATH, "0444") +test('npm whoami with bearer auth', { timeout: 2 * 1000 }, function (t) { + var s = '//localhost:' + common.port + + '/:_authToken = wombat-developers-union\n' + fs.writeFileSync(FIXTURE_PATH, s, 'ascii') + fs.chmodSync(FIXTURE_PATH, '0444') - function verify(req, res) { - t.equal(req.method, "GET") - t.equal(req.url, "/-/whoami") + function verify (req, res) { + t.equal(req.method, 'GET') + t.equal(req.url, '/-/whoami') - res.setHeader("content-type", "application/json") + res.setHeader('content-type', 'application/json') res.writeHeader(200) - res.end(JSON.stringify({username : "wombat"}), "utf8") + res.end(JSON.stringify({ username: 'wombat' }), 'utf8') } var server = createServer(verify) @@ -57,17 +57,17 @@ test("npm whoami with bearer auth", {timeout : 2 * 1000}, function (t) { server.listen(common.port, function () { common.npm( [ - "whoami", - "--userconfig=" + FIXTURE_PATH, - "--registry=http://localhost:" + common.port + "/" + 'whoami', + '--userconfig=' + FIXTURE_PATH, + '--registry=http://localhost:' + common.port + '/' ], opts, function (err, code, stdout, stderr) { t.ifError(err) - t.equal(stderr, "", "got nothing on stderr") - t.equal(code, 0, "exit ok") - t.equal(stdout, "wombat\n", "got username") + t.equal(stderr, '', 'got nothing on stderr') + t.equal(code, 0, 'exit ok') + t.equal(stdout, 'wombat\n', 'got username') rimraf.sync(FIXTURE_PATH) server.close() t.end() diff --git a/test/tap/zz-cleanup.js b/test/tap/zz-cleanup.js index c491cbf07..e1020aa3b 100644 --- a/test/tap/zz-cleanup.js +++ b/test/tap/zz-cleanup.js @@ -1,8 +1,8 @@ -var common = require("../common-tap") -var test = require("tap").test -var rimraf = require("rimraf") +var common = require('../common-tap') +var test = require('tap').test +var rimraf = require('rimraf') -test("cleanup", function (t) { +test('cleanup', function (t) { rimraf.sync(common.npm_config_cache) t.end() }) |