Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorForrest L Norvell <forrest@npmjs.com>2015-04-12 01:18:24 +0300
committerForrest L Norvell <forrest@npmjs.com>2015-04-13 04:12:10 +0300
commited7e249d50444312cd266942ce3b89e1ca049bdf (patch)
treeef8ec74c7d4c3f6699fe35f6d5282426537bf6c3
parent4928d30140821c63e03fffed73f8d88ebdc43710 (diff)
test: eliminate fixture directories from test/tap
It's too difficult for npm contributors to figure out what the conventional style is for tests. Part of the problem is that the documentation in CONTRIBUTING.md is inadequate, but another important factor is that the tests themselves are written in a variety of styles. One of the most notable examples of this is the fact that many tests use fixture directories to store precooked test scenarios and package.json files. This had some negative consequences: * tests weren't idempotent * subtle dependencies between tests existed * new tests get written in this deprecated style because it's not obvious that the style is out of favor * it's hard to figure out why a lot of those directories existed, because they served a variety of purposes, so it was difficult to tell when it was safe to remove them All in all, the fixture directories were a major source of technical debt, and cleaning them up, while time-consuming, makes the whole test suite much more approachable, and makes it more likely that new tests written by outside contributors will follow a conventional style. To support that, all of the tests touched by this changed were cleaned up to pass the `standard` style checker.
-rw-r--r--test/tap/adduser-legacy-auth.js96
-rw-r--r--test/tap/circular-dep.js123
-rw-r--r--test/tap/circular-dep/minimist/package.json7
-rw-r--r--test/tap/dedupe.js111
-rw-r--r--test/tap/dedupe/package.json9
-rw-r--r--test/tap/false-name.js85
-rw-r--r--test/tap/false_name.js55
-rw-r--r--test/tap/false_name/index.js1
-rw-r--r--test/tap/false_name/package.json8
-rw-r--r--test/tap/ignore-scripts.js134
-rw-r--r--test/tap/ignore-scripts/binding.gyp1
-rw-r--r--test/tap/ignore-scripts/package.json28
-rw-r--r--test/tap/ignore-shrinkwrap.js164
-rw-r--r--test/tap/ignore-shrinkwrap/npm-shrinkwrap.json17
-rw-r--r--test/tap/ignore-shrinkwrap/package.json8
-rw-r--r--test/tap/install-at-locally.js85
-rw-r--r--test/tap/install-at-locally/package@1.2.3/package.json5
-rw-r--r--test/tap/install-cli-production.js108
-rw-r--r--test/tap/install-cli-production/dependency/package.json5
-rw-r--r--test/tap/install-cli-production/dev-dependency/package.json5
-rw-r--r--test/tap/install-cli-production/package.json14
-rw-r--r--test/tap/install-cli-unicode.js84
-rw-r--r--test/tap/install-cli/README.md1
-rw-r--r--test/tap/install-cli/index.js1
-rw-r--r--test/tap/install-cli/package.json10
-rw-r--r--test/tap/install-from-local.js117
-rw-r--r--test/tap/install-from-local/package-local-dependency/package.json5
-rw-r--r--test/tap/install-from-local/package-local-dev-dependency/package.json5
-rw-r--r--test/tap/install-from-local/package-scoped-dependency/package.json5
-rw-r--r--test/tap/install-from-local/package-with-local-paths/package.json10
-rw-r--r--test/tap/install-from-local/package-with-scoped-paths/package.json8
-rw-r--r--test/tap/install-save-exact.js186
-rw-r--r--test/tap/install-save-exact/README.md1
-rw-r--r--test/tap/install-save-exact/index.js1
-rw-r--r--test/tap/install-save-exact/package.json7
-rw-r--r--test/tap/install-save-local.js159
-rw-r--r--test/tap/install-save-local/package-local-dependency/package.json5
-rw-r--r--test/tap/install-save-local/package-local-dev-dependency/package.json5
-rw-r--r--test/tap/install-save-local/package/package.json4
-rw-r--r--test/tap/install-save-prefix.js289
-rw-r--r--test/tap/install-save-prefix/README.md1
-rw-r--r--test/tap/install-save-prefix/index.js1
-rw-r--r--test/tap/install-save-prefix/package.json7
-rw-r--r--test/tap/install-scoped-already-installed.js167
-rw-r--r--test/tap/install-scoped-link.js99
-rw-r--r--test/tap/install-scoped/package.json7
-rw-r--r--test/tap/install-scoped/world.js1
-rw-r--r--test/tap/lifecycle-path.js78
-rw-r--r--test/tap/lifecycle-path/package.json1
-rw-r--r--test/tap/lifecycle-path/print-path.js1
-rw-r--r--test/tap/lifecycle-signal.js57
-rw-r--r--test/tap/lifecycle-signal/package.json3
-rw-r--r--test/tap/ls-depth-cli.js161
-rw-r--r--test/tap/ls-depth-unmet.js230
-rw-r--r--test/tap/ls-depth-unmet/package.json10
-rw-r--r--test/tap/ls-depth/package.json8
-rw-r--r--test/tap/ls-env.js52
-rw-r--r--test/tap/optional-metadep-rollback-collision.js247
-rw-r--r--test/tap/optional-metadep-rollback-collision/deps/d1/package.json13
-rw-r--r--test/tap/optional-metadep-rollback-collision/deps/d2/blart.js52
-rw-r--r--test/tap/optional-metadep-rollback-collision/deps/d2/package.json15
-rw-r--r--test/tap/optional-metadep-rollback-collision/deps/opdep/bad-server.js35
-rw-r--r--test/tap/optional-metadep-rollback-collision/deps/opdep/package.json15
-rw-r--r--test/tap/optional-metadep-rollback-collision/package.json10
-rw-r--r--test/tap/outdated-color.js77
-rw-r--r--test/tap/outdated-depth.js81
-rw-r--r--test/tap/outdated-depth/README.md1
-rw-r--r--test/tap/outdated-depth/index.js1
-rw-r--r--test/tap/outdated-depth/package.json11
-rw-r--r--test/tap/outdated-include-devdependencies.js57
-rw-r--r--test/tap/outdated-include-devdependencies/package.json8
-rw-r--r--test/tap/outdated-json.js147
-rw-r--r--test/tap/outdated-long.js123
-rw-r--r--test/tap/outdated-new-versions.js62
-rw-r--r--test/tap/outdated-new-versions/package.json11
-rw-r--r--test/tap/outdated.js118
-rw-r--r--test/tap/outdated/README.md1
-rw-r--r--test/tap/outdated/index.js1
-rw-r--r--test/tap/outdated/package.json10
-rw-r--r--test/tap/package-with-peer-dep/package.json7
-rw-r--r--test/tap/peer-deps-invalid.js127
-rw-r--r--test/tap/peer-deps-invalid/file-fail.js10
-rw-r--r--test/tap/peer-deps-invalid/file-ok.js11
-rw-r--r--test/tap/peer-deps-invalid/package.json9
-rw-r--r--test/tap/peer-deps-without-package-json.js85
-rw-r--r--test/tap/peer-deps-without-package-json/.gitkeep0
-rw-r--r--test/tap/peer-deps-without-package-json/file-js.js11
-rw-r--r--test/tap/prune.js153
-rw-r--r--test/tap/prune/package.json13
-rw-r--r--test/tap/scripts-whitespace-windows.js109
-rw-r--r--test/tap/scripts-whitespace-windows/README.md1
-rw-r--r--test/tap/scripts-whitespace-windows/dep/README.md1
-rw-r--r--test/tap/scripts-whitespace-windows/dep/bin/foo4
-rw-r--r--test/tap/scripts-whitespace-windows/dep/package.json6
-rw-r--r--test/tap/scripts-whitespace-windows/package.json11
-rw-r--r--test/tap/search.js325
-rw-r--r--test/tap/shrinkwrap-empty-deps.js98
-rw-r--r--test/tap/shrinkwrap-empty-deps/package.json7
-rw-r--r--test/tap/startstop.js76
-rw-r--r--test/tap/startstop/package.json7
-rw-r--r--test/tap/uninstall-package.js103
-rw-r--r--test/tap/uninstall-package/package.json11
-rw-r--r--test/tap/update-save.js270
-rw-r--r--test/tap/update-save/README.md1
-rw-r--r--test/tap/update-save/index.js1
-rw-r--r--test/tap/update-save/package.json10
-rw-r--r--test/tap/url-dependencies.js131
-rw-r--r--test/tap/url-dependencies/package.json8
108 files changed, 3269 insertions, 2289 deletions
diff --git a/test/tap/adduser-legacy-auth.js b/test/tap/adduser-legacy-auth.js
index 9090c67b4..f9829c618 100644
--- a/test/tap/adduser-legacy-auth.js
+++ b/test/tap/adduser-legacy-auth.js
@@ -1,90 +1,94 @@
-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 opts = {cwd : __dirname}
-var pkg = path.resolve(__dirname, "adduser-legacy-auth")
-var outfile = path.resolve(pkg, "_npmrc")
+var opts = { cwd: __dirname }
+var pkg = path.resolve(__dirname, 'adduser-legacy-auth')
+var outfile = path.resolve(pkg, '_npmrc')
-var contents = "_auth=" + new Buffer("u:x").toString("base64") + "\n" +
- "registry=https://nonexistent.lvh.me/registry\n" +
- "email=u@p.me\n"
+var contents = '_auth=' + new Buffer('u:x').toString('base64') + '\n' +
+ 'registry=https://nonexistent.lvh.me/registry\n' +
+ 'email=u@p.me\n'
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) {
server.filteringRequestBody(function (r) {
- if (r.match(/\"_id\":\"org\.couchdb\.user:u\"/)) {
- return "auth"
+ if (r.match(/"_id":"org\.couchdb\.user:u"/)) {
+ return 'auth'
}
})
- server.put("/-/user/org.couchdb.user:u", "auth")
- .reply(409, {"error": "user exists"})
- server.get("/-/user/org.couchdb.user:u?write=true")
- .reply(200, {_rev : "3-deadcafebabebeef"})
- server.put("/-/user/org.couchdb.user:u/-rev/3-deadcafebabebeef", "auth", {"authorization" : "Basic dTpw"})
- .reply(201, {username : "u", password : "p", email : "u@p.me"})
+ server.put('/-/user/org.couchdb.user:u', 'auth')
+ .reply(409, { error: 'user exists' })
+ server.get('/-/user/org.couchdb.user:u?write=true')
+ .reply(200, { _rev: '3-deadcafebabebeef' })
+ server.put(
+ '/-/user/org.couchdb.user:u/-rev/3-deadcafebabebeef',
+ 'auth',
+ { authorization: 'Basic dTpw' }
+ ).reply(201, { username: 'u', password: 'p', email: 'u@p.me' })
}
-test("setup", function (t) {
+test('setup', function (t) {
mkdirp(pkg, function (er) {
- t.ifError(er, pkg + " made successfully")
+ t.ifError(er, pkg + ' made successfully')
fs.writeFile(outfile, contents, function (er) {
- t.ifError(er, "wrote legacy config")
+ t.ifError(er, 'wrote legacy config')
t.end()
})
})
})
-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", "silly",
- "--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)")
+ function (err, code, stdout, stderr) {
+ t.ifError(err, 'npm ran without issue')
+ t.notOk(code, 'exited OK')
+ t.notOk(stderr, '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 = '', e = '', 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) {
- rimraf.sync(outfile)
- t.pass("cleaned up")
+test('cleanup', function (t) {
+ rimraf.sync(pkg)
+ t.pass('cleaned up')
t.end()
})
diff --git a/test/tap/circular-dep.js b/test/tap/circular-dep.js
index fd5817dbc..002b30cd7 100644
--- a/test/tap/circular-dep.js
+++ b/test/tap/circular-dep.js
@@ -1,52 +1,99 @@
-var test = require("tap").test
- , fs = require("fs")
- , path = require("path")
- , existsSync = fs.existsSync || path.existsSync
- , npm = require("../../")
- , rimraf = require("rimraf")
- , osenv = require("osenv")
- , mr = require("npm-registry-mock")
- , common = require("../common-tap.js")
- , server
-
-var pkg = path.resolve(__dirname, "circular-dep")
-
-test("installing a package that depends on the current package", function (t) {
- t.plan(1)
+var fs = require('graceful-fs')
+var path = require('path')
+var existsSync = fs.existsSync || path.existsSync
+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 server
+
+var pkg = path.resolve(__dirname, 'circular-dep')
+var minimist = path.join(pkg, 'minimist')
+
+var EXEC_OPTS = {
+ cwd: path.join(pkg, 'minimist/node_modules'),
+ npm_config_cache: path.join(pkg, 'cache')
+}
+
+var json = {
+ name: 'minimist',
+ version: '0.0.5',
+ dependencies: {
+ optimist: '0.6.0'
+ }
+}
+
+test('setup', function (t) {
+ t.comment('test for https://github.com/npm/npm/issues/4312')
setup(function () {
- npm.install("optimist", function (err) {
- if (err) return t.fail(err)
- npm.dedupe(function (err) {
- if (err) return t.fail(err)
- t.ok(existsSync(path.resolve(pkg,
- "minimist", "node_modules", "optimist",
- "node_modules", "minimist"
- )), "circular dependency uncircled")
- cleanup()
- server.close()
- })
- })
+ t.end()
})
})
+test('installing a package that depends on the current package', function (t) {
+ common.npm(
+ [
+ '--registry', common.registry,
+ '--loglevel', 'silent',
+ 'install', 'optimist'
+ ],
+ EXEC_OPTS,
+ function (err, code, stdout, stderr) {
+ t.ifError(err, 'npm ran without issue')
+ t.notOk(code, 'npm ran without raising an error code')
+ t.notOk(stderr, 'no error output')
+
+ common.npm(
+ [
+ '--registry', common.registry,
+ '--loglevel', 'silent',
+ 'dedupe'
+ ],
+ EXEC_OPTS,
+ function (err, code, stdout, stderr) {
+ t.ifError(err, 'npm ran without issue')
+ t.notOk(code, 'npm ran without raising an error code')
+ t.notOk(stderr, 'no error output')
+
+ t.ok(existsSync(path.resolve(
+ minimist,
+ 'node_modules', 'optimist',
+ 'node_modules', 'minimist'
+ )), 'circular dependency uncircled')
+ t.end()
+ }
+ )
+ }
+ )
+})
+
+test('cleanup', function (t) {
+ cleanup()
+ server.close()
+ t.end()
+})
+
function setup (cb) {
cleanup()
- process.chdir(path.resolve(pkg, "minimist"))
+ mkdirp.sync(minimist)
+ fs.writeFileSync(
+ path.join(minimist, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+ process.chdir(path.resolve(pkg, 'minimist'))
- fs.mkdirSync(path.resolve(pkg, "minimist/node_modules"))
- mr({port : common.port}, function (er, s) {
+ fs.mkdirSync(path.resolve(pkg, 'minimist/node_modules'))
+ mr({ port: common.port }, function (er, s) {
server = s
- npm.load({
- loglevel: "silent",
- registry: common.registry,
- cache: path.resolve(pkg, "cache")
- }, cb)
+ cb()
})
}
-function cleanup() {
+function cleanup () {
process.chdir(osenv.tmpdir())
- rimraf.sync(path.resolve(pkg, "minimist/node_modules"))
- rimraf.sync(path.resolve(pkg, "cache"))
+ rimraf.sync(pkg)
}
diff --git a/test/tap/circular-dep/minimist/package.json b/test/tap/circular-dep/minimist/package.json
deleted file mode 100644
index cdaa1913b..000000000
--- a/test/tap/circular-dep/minimist/package.json
+++ /dev/null
@@ -1,7 +0,0 @@
-{
- "name": "minimist",
- "version": "0.0.5",
- "dependencies": {
- "optimist": "0.6.0"
- }
-}
diff --git a/test/tap/dedupe.js b/test/tap/dedupe.js
index b203e5e39..7b80102b3 100644
--- a/test/tap/dedupe.js
+++ b/test/tap/dedupe.js
@@ -1,41 +1,86 @@
-var test = require("tap").test
- , fs = require("fs")
- , path = require("path")
- , existsSync = fs.existsSync || path.existsSync
- , rimraf = require("rimraf")
- , mr = require("npm-registry-mock")
- , common = require("../common-tap.js")
-
-var EXEC_OPTS = {}
-
-test("dedupe finds the common module and moves it up one level", function (t) {
- setup(function (s) {
+var fs = require('graceful-fs')
+var path = require('path')
+var existsSync = fs.existsSync || path.existsSync
+
+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 server
+
+var pkg = path.join(__dirname, 'dedupe')
+
+var EXEC_OPTS = { cwd: pkg }
+
+var json = {
+ author: 'Dedupe tester',
+ name: 'dedupe',
+ version: '0.0.0',
+ dependencies: {
+ optimist: '0.6.0',
+ clean: '2.1.6'
+ }
+}
+
+test('setup', function (t) {
+ t.comment('test for https://github.com/npm/npm/issues/4675')
+ setup(function () {
+ t.end()
+ })
+})
+
+test('dedupe finds the common module and moves it up one level', function (t) {
+ common.npm(
+ [
+ '--registry', common.registry,
+ 'install', '.'
+ ],
+ EXEC_OPTS,
+ function (err, code) {
+ t.ifError(err, 'successfully installed directory')
+ t.equal(code, 0, 'npm install exited with code')
common.npm(
- [
- "install", ".",
- "--registry", common.registry
- ],
- EXEC_OPTS,
- function (err, code) {
- t.ifError(err, "successfully installed directory")
- t.equal(code, 0, "npm install exited with code")
- common.npm(["dedupe"], {}, function (err, code) {
- t.ifError(err, "successfully deduped against previous install")
- t.notOk(code, "npm dedupe exited with code")
- t.ok(existsSync(path.join(__dirname, "dedupe", "node_modules", "minimist")))
- t.ok(!existsSync(path.join(__dirname, "dedupe", "node_modules", "checker")))
- s.close() // shutdown mock registry.
+ [
+ 'dedupe'
+ ],
+ EXEC_OPTS,
+ function (err, code) {
+ t.ifError(err, 'successfully deduped against previous install')
+ t.notOk(code, 'npm dedupe exited with code')
+
+ t.ok(existsSync(path.join(pkg, 'node_modules', 'minimist')))
+ t.notOk(existsSync(path.join(pkg, 'node_modules', 'checker')))
+
t.end()
- })
- })
+ }
+ )
})
})
+test('cleanup', function (t) {
+ server.close()
+ cleanup()
+
+ t.end()
+})
+
+function cleanup () {
+ rimraf.sync(pkg)
+}
+
function setup (cb) {
- process.chdir(path.join(__dirname, "dedupe"))
- mr({port : common.port}, function (er, s) { // create mock registry.
- rimraf.sync(path.join(__dirname, "dedupe", "node_modules"))
- fs.mkdirSync(path.join(__dirname, "dedupe", "node_modules"))
- cb(s)
+ cleanup()
+ mkdirp.sync(path.join(pkg, 'node_modules'))
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+ process.chdir(pkg)
+
+ mr({ port: common.port }, function (er, s) {
+ server = s
+ cb()
})
}
diff --git a/test/tap/dedupe/package.json b/test/tap/dedupe/package.json
deleted file mode 100644
index 842d4b2b2..000000000
--- a/test/tap/dedupe/package.json
+++ /dev/null
@@ -1,9 +0,0 @@
-{
- "author": "Dedupe tester",
- "name": "dedupe",
- "version": "0.0.0",
- "dependencies": {
- "optimist": "0.6.0",
- "clean": "2.1.6"
- }
-}
diff --git a/test/tap/false-name.js b/test/tap/false-name.js
new file mode 100644
index 000000000..c98a5103b
--- /dev/null
+++ b/test/tap/false-name.js
@@ -0,0 +1,85 @@
+// this is a test for fix #2538
+
+// the false_name-test-package has the name property 'test-package' set
+// in the package.json and a dependency named 'test-package' is also a
+// defined dependency of 'test-package-with-one-dep'.
+//
+// this leads to a conflict during installation and the fix is covered
+// by this test
+
+var fs = require('graceful-fs')
+var path = require('path')
+var existsSync = fs.existsSync || path.existsSync
+
+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 pkg = path.join(__dirname, 'false-name')
+var cache = path.join(pkg, 'cache')
+var server
+
+var EXEC_OPTS = { cwd: pkg }
+
+var indexContent = 'module.exports = true\n'
+var json = {
+ name: 'test-package',
+ version: '0.0.0',
+ main: 'index.js',
+ dependencies: {
+ 'test-package-with-one-dep': '0.0.0'
+ }
+}
+
+test('setup', function (t) {
+ t.comment('test for https://github.com/npm/npm/issues/2538')
+ setup()
+ mr({ port: common.port }, function (er, s) {
+ server = s
+ t.end()
+ })
+})
+
+test('not every pkg.name can be required', function (t) {
+ common.npm(
+ [
+ 'install', '.',
+ '--cache', cache,
+ '--registry', common.registry
+ ],
+ EXEC_OPTS,
+ 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',
+ 'node_modules/test-package'
+ )), 'package installed OK')
+ t.end()
+ }
+ )
+})
+
+test('cleanup', function (t) {
+ server.close()
+ cleanup()
+ t.end()
+})
+
+function cleanup () {
+ rimraf.sync(pkg)
+}
+
+function setup () {
+ cleanup()
+ mkdirp.sync(cache)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+ fs.writeFileSync(path.join(pkg, 'index.js'), indexContent)
+}
diff --git a/test/tap/false_name.js b/test/tap/false_name.js
deleted file mode 100644
index 26ecb5b84..000000000
--- a/test/tap/false_name.js
+++ /dev/null
@@ -1,55 +0,0 @@
-// this is a test for fix #2538
-
-// the false_name-test-package has the name property "test-package" set
-// in the package.json and a dependency named "test-package" is also a
-// defined dependency of "test-package-with-one-dep".
-//
-// this leads to a conflict during installation and the fix is covered
-// by this test
-
-var test = require("tap").test
- , fs = require("fs")
- , path = require("path")
- , existsSync = fs.existsSync || path.existsSync
- , rimraf = require("rimraf")
- , common = require("../common-tap.js")
- , mr = require("npm-registry-mock")
- , pkg = path.resolve(__dirname, "false_name")
- , cache = path.resolve(pkg, "cache")
- , nodeModules = path.resolve(pkg, "node_modules")
-
-var EXEC_OPTS = { cwd: pkg }
-
-test("setup", function(t) {
- cleanup()
- fs.mkdirSync(nodeModules)
- t.end()
-})
-
-test("not every pkg.name can be required", function (t) {
- t.plan(3)
- mr({port : common.port}, function (er, s) {
- common.npm([
- "install", ".",
- "--cache", cache,
- "--registry", common.registry
- ], EXEC_OPTS, function (err, code) {
- s.close()
- t.ifErr(err, "install finished without error")
- t.equal(code, 0, "install exited ok")
- t.ok(existsSync(path.resolve(pkg,
- "node_modules/test-package-with-one-dep",
- "node_modules/test-package")))
- })
- })
-})
-
-function cleanup() {
- rimraf.sync(cache)
- rimraf.sync(nodeModules)
-}
-
-test("cleanup", function (t) {
- cleanup()
- t.end()
-})
diff --git a/test/tap/false_name/index.js b/test/tap/false_name/index.js
deleted file mode 100644
index 33c1891f8..000000000
--- a/test/tap/false_name/index.js
+++ /dev/null
@@ -1 +0,0 @@
-module.exports = true
diff --git a/test/tap/false_name/package.json b/test/tap/false_name/package.json
deleted file mode 100644
index 9c321e853..000000000
--- a/test/tap/false_name/package.json
+++ /dev/null
@@ -1,8 +0,0 @@
-{
- "name": "test-package",
- "version": "0.0.0",
- "main": "index.js",
- "dependencies": {
- "test-package-with-one-dep": "0.0.0"
- }
-}
diff --git a/test/tap/ignore-scripts.js b/test/tap/ignore-scripts.js
index 8b5291f78..a446579cd 100644
--- a/test/tap/ignore-scripts.js
+++ b/test/tap/ignore-scripts.js
@@ -1,72 +1,120 @@
-var common = require("../common-tap")
-var test = require("tap").test
-var path = require("path")
+var fs = require('graceful-fs')
+var path = require('path')
+
+var mkdirp = require('mkdirp')
+var rimraf = require('rimraf')
+var test = require('tap').test
+
+var common = require('../common-tap')
// ignore-scripts/package.json has scripts that always exit with non-zero error
-// codes. The "install" script is omitted so that npm tries to run node-gyp,
-// which should also fail.
-var pkg = path.resolve(__dirname, "ignore-scripts")
+// codes.
+var pkg = path.resolve(__dirname, 'ignore-scripts')
+
+var gypfile = 'bad_binding_file\n'
+var json = {
+ author: 'Milton the Aussie',
+ name: 'ignore-scripts',
+ version: '0.0.0',
+ scripts: {
+ prepublish: 'exit 123',
+ publish: 'exit 123',
+ postpublish: 'exit 123',
+ preinstall: 'exit 123',
+ install: 'exit 123',
+ postinstall: 'exit 123',
+ preuninstall: 'exit 123',
+ uninstall: 'exit 123',
+ postuninstall: 'exit 123',
+ pretest: 'exit 123',
+ test: 'exit 123',
+ posttest: 'exit 123',
+ prestop: 'exit 123',
+ stop: 'exit 123',
+ poststop: 'exit 123',
+ prestart: 'exit 123',
+ start: 'exit 123',
+ poststart: 'exit 123',
+ prerestart: 'exit 123',
+ restart: 'exit 123',
+ postrestart: 'exit 123'
+ }
+}
+
+test('setup', function (t) {
+ setup()
+ t.end()
+})
-test("ignore-scripts: install using the option", function (t) {
- createChild(["install", "--ignore-scripts"], function (err, code) {
- t.ifError(err, "install with scripts ignored finished successfully")
- t.equal(code, 0, "npm install exited with code")
+test('ignore-scripts: install using the option', function (t) {
+ createChild(['install', '--ignore-scripts'], function (err, code) {
+ t.ifError(err, 'install with scripts ignored finished successfully')
+ t.equal(code, 0, 'npm install exited with code')
t.end()
})
})
-test("ignore-scripts: install NOT using the option", function (t) {
- createChild(["install"], function (err, code) {
- t.ifError(err, "install with scripts successful")
- t.notEqual(code, 0, "npm install exited with code")
+test('ignore-scripts: install NOT using the option', function (t) {
+ createChild(['install'], function (err, code) {
+ t.ifError(err, 'install with scripts successful')
+ t.notEqual(code, 0, 'npm install exited with code')
t.end()
})
})
var scripts = [
- "prepublish", "publish", "postpublish",
- "preinstall", "install", "postinstall",
- "preuninstall", "uninstall", "postuninstall",
- "pretest", "test", "posttest",
- "prestop", "stop", "poststop",
- "prestart", "start", "poststart",
- "prerestart", "restart", "postrestart"
+ 'prepublish', 'publish', 'postpublish',
+ 'preinstall', 'install', 'postinstall',
+ 'preuninstall', 'uninstall', 'postuninstall',
+ 'pretest', 'test', 'posttest',
+ 'prestop', 'stop', 'poststop',
+ 'prestart', 'start', 'poststart',
+ 'prerestart', 'restart', 'postrestart'
]
scripts.forEach(function (script) {
- test("ignore-scripts: run-script "+script+" using the option", function (t) {
- createChild(["--ignore-scripts", "run-script", script], function (err, code) {
- t.ifError(err, "run-script " + script + " with ignore-scripts successful")
- t.equal(code, 0, "npm run-script exited with code")
+ test('ignore-scripts: run-script ' + script + ' using the option', function (t) {
+ createChild(['--ignore-scripts', 'run-script', script], function (err, code, stdout, stderr) {
+ t.ifError(err, 'run-script ' + script + ' with ignore-scripts successful')
+ t.equal(code, 0, 'npm run-script exited with code')
t.end()
})
})
})
scripts.forEach(function (script) {
- test("ignore-scripts: run-script "+script+" NOT using the option", function (t) {
- createChild(["run-script", script], function (err, code) {
- t.ifError(err, "run-script " + script + " finished successfully")
- t.notEqual(code, 0, "npm run-script exited with code")
+ test('ignore-scripts: run-script ' + script + ' NOT using the option', function (t) {
+ createChild(['run-script', script], function (err, code) {
+ t.ifError(err, 'run-script ' + script + ' finished successfully')
+ t.notEqual(code, 0, 'npm run-script exited with code')
t.end()
})
})
})
-function createChild (args, cb) {
- var env = {
- HOME: process.env.HOME,
- Path: process.env.PATH,
- PATH: process.env.PATH,
- "npm_config_loglevel": "silent"
- }
+test('cleanup', function (t) {
+ cleanup()
+ t.end()
+})
- if (process.platform === "win32")
- env.npm_config_cache = "%APPDATA%\\npm-cache"
+function cleanup () {
+ rimraf.sync(pkg)
+}
- return common.npm(args, {
- cwd: pkg,
- stdio: "inherit",
- env: env
- }, cb)
+function setup () {
+ cleanup()
+ mkdirp.sync(pkg)
+ fs.writeFileSync(path.join(pkg, 'binding.gyp'), gypfile)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+}
+
+function createChild (args, cb) {
+ return common.npm(
+ args.concat(['--loglevel', 'silent']),
+ { cwd: pkg },
+ cb
+ )
}
diff --git a/test/tap/ignore-scripts/binding.gyp b/test/tap/ignore-scripts/binding.gyp
deleted file mode 100644
index 9348f0f94..000000000
--- a/test/tap/ignore-scripts/binding.gyp
+++ /dev/null
@@ -1 +0,0 @@
-bad_binding_file
diff --git a/test/tap/ignore-scripts/package.json b/test/tap/ignore-scripts/package.json
deleted file mode 100644
index 261aa902d..000000000
--- a/test/tap/ignore-scripts/package.json
+++ /dev/null
@@ -1,28 +0,0 @@
-{
- "author": "Milton the Aussie",
- "name": "ignore-scripts",
- "version": "0.0.0",
- "scripts": {
- "prepublish": "exit 123",
- "publish": "exit 123",
- "postpublish": "exit 123",
- "preinstall": "exit 123",
- "postinstall": "exit 123",
- "preuninstall": "exit 123",
- "install": "exit 123",
- "uninstall": "exit 123",
- "postuninstall": "exit 123",
- "pretest": "exit 123",
- "test": "exit 123",
- "posttest": "exit 123",
- "prestop": "exit 123",
- "stop": "exit 123",
- "poststop": "exit 123",
- "prestart": "exit 123",
- "start": "exit 123",
- "poststart": "exit 123",
- "prerestart": "exit 123",
- "restart": "exit 123",
- "postrestart": "exit 123"
- }
-}
diff --git a/test/tap/ignore-shrinkwrap.js b/test/tap/ignore-shrinkwrap.js
index a8efa8191..9468162ee 100644
--- a/test/tap/ignore-shrinkwrap.js
+++ b/test/tap/ignore-shrinkwrap.js
@@ -1,75 +1,135 @@
-var common = require("../common-tap.js")
-var test = require("tap").test
-var pkg = require("path").join(__dirname,"ignore-shrinkwrap")
+var fs = require('graceful-fs')
+var path = require('path')
-var mr = require("npm-registry-mock")
+var mkdirp = require('mkdirp')
+var mr = require('npm-registry-mock')
+var rimraf = require('rimraf')
+var test = require('tap').test
-var spawn = require("child_process").spawn
-var npm = require.resolve("../../bin/npm-cli.js")
-var node = process.execPath
+var common = require('../common-tap.js')
+
+var pkg = require('path').join(__dirname, 'ignore-shrinkwrap')
+
+var EXEC_OPTS = { cwd: pkg }
var customMocks = {
- "get": {
- "/package.js": [200, {"ente" : true}],
- "/shrinkwrap.js": [200, {"ente" : true}]
+ 'get': {
+ '/package.js': [200, { ente: true }],
+ '/shrinkwrap.js': [200, { ente: true }]
+ }
+}
+
+var json = {
+ author: 'Rocko Artischocko',
+ name: 'ignore-shrinkwrap',
+ version: '0.0.0',
+ dependencies: {
+ 'npm-test-ignore-shrinkwrap-file': 'http://localhost:1337/package.js'
+ }
+}
+
+var shrinkwrap = {
+ name: 'ignore-shrinkwrap',
+ version: '0.0.0',
+ dependencies: {
+ 'npm-test-ignore-shrinkwrap-file': {
+ version: '1.2.3',
+ from: 'http://localhost:1337/shrinkwrap.js',
+ resolved: 'http://localhost:1337/shrinkwrap.js',
+ dependencies: {
+ opener: {
+ version: '1.3.0',
+ from: 'opener@1.3.0'
+ }
+ }
+ }
}
}
-test("ignore-shrinkwrap: using the option", function (t) {
- mr({port: common.port, mocks: customMocks}, function (err, s) {
- s._server.on("request", function (req) {
+test('setup', function (t) {
+ setup()
+ t.end()
+})
+
+test('npm install --no-shrinkwrap', function (t) {
+ mr({ port: common.port, mocks: customMocks }, function (err, s) {
+ t.ifError(err, 'mock registry bootstrapped without issue')
+ s._server.on('request', function (req) {
switch (req.url) {
- case "/shrinkwrap.js":
- t.fail()
+ case '/shrinkwrap.js':
+ t.fail('npm-shrinkwrap.json used instead of package.json')
break
- case "/package.js":
- t.pass("package.json used")
+ case '/package.js':
+ t.pass('package.json used')
}
})
- var child = createChild(true)
- child.on("close", function () {
- s.close()
- t.end()
- })
+
+ common.npm(
+ [
+ '--registry', common.registry,
+ '--loglevel', 'silent',
+ 'install', '--no-shrinkwrap'
+ ],
+ EXEC_OPTS,
+ function (err, code) {
+ t.ifError(err, 'npm ran without issue')
+ t.ok(code, "install isn't going to succeed")
+ s.close()
+ t.end()
+ }
+ )
})
})
-test("ignore-shrinkwrap: NOT using the option", function (t) {
- mr({port: common.port, mocks: customMocks}, function (err, s) {
- s._server.on("request", function (req) {
+test('npm install (with shrinkwrap)', function (t) {
+ mr({ port: common.port, mocks: customMocks }, function (err, s) {
+ t.ifError(err, 'mock registry bootstrapped without issue')
+ s._server.on('request', function (req) {
switch (req.url) {
- case "/shrinkwrap.js":
- t.pass("shrinkwrap used")
+ case '/shrinkwrap.js':
+ t.pass('shrinkwrap used')
break
- case "/package.js":
- t.fail()
+ case '/package.js':
+ t.fail('shrinkwrap ignored')
}
})
- var child = createChild(false)
- child.on("close", function () {
- s.close()
- t.end()
- })
+
+ common.npm(
+ [
+ '--registry', common.registry,
+ '--loglevel', 'silent',
+ 'install'
+ ],
+ EXEC_OPTS,
+ function (err, code) {
+ t.ifError(err, 'npm ran without issue')
+ t.ok(code, "install isn't going to succeed")
+ s.close()
+ t.end()
+ }
+ )
})
})
-function createChild (ignoreShrinkwrap) {
- var args
- if (ignoreShrinkwrap) {
- args = [npm, "install", "--no-shrinkwrap"]
- } else {
- args = [npm, "install"]
- }
+test('cleanup', function (t) {
+ cleanup()
+ t.end()
+})
- return spawn(node, args, {
- cwd: pkg,
- env: {
- "npm_config_registry": common.registry,
- "npm_config_cache_lock_stale": 1000,
- "npm_config_cache_lock_wait": 1000,
- HOME: process.env.HOME,
- Path: process.env.PATH,
- PATH: process.env.PATH
- }
- })
+function cleanup () {
+ rimraf.sync(pkg)
+}
+
+function setup () {
+ cleanup()
+ mkdirp.sync(pkg)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+ fs.writeFileSync(
+ path.join(pkg, 'npm-shrinkwrap.json'),
+ JSON.stringify(shrinkwrap, null, 2)
+ )
+ process.chdir(pkg)
}
diff --git a/test/tap/ignore-shrinkwrap/npm-shrinkwrap.json b/test/tap/ignore-shrinkwrap/npm-shrinkwrap.json
deleted file mode 100644
index b15538018..000000000
--- a/test/tap/ignore-shrinkwrap/npm-shrinkwrap.json
+++ /dev/null
@@ -1,17 +0,0 @@
-{
- "name": "ignore-shrinkwrap",
- "version": "0.0.0",
- "dependencies": {
- "npm-test-ignore-shrinkwrap-file": {
- "version": "1.2.3",
- "from": "http://localhost:1337/shrinkwrap.js",
- "resolved": "http://localhost:1337/shrinkwrap.js",
- "dependencies": {
- "opener": {
- "version": "1.3.0",
- "from": "opener@1.3.0"
- }
- }
- }
- }
-}
diff --git a/test/tap/ignore-shrinkwrap/package.json b/test/tap/ignore-shrinkwrap/package.json
deleted file mode 100644
index 5b9500664..000000000
--- a/test/tap/ignore-shrinkwrap/package.json
+++ /dev/null
@@ -1,8 +0,0 @@
-{
- "author": "Rocko Artischocko",
- "name": "ignore-shrinkwrap",
- "version": "0.0.0",
- "dependencies": {
- "npm-test-ignore-shrinkwrap-file": "http://localhost:1337/package.js"
- }
-}
diff --git a/test/tap/install-at-locally.js b/test/tap/install-at-locally.js
index 02874d0cd..9c5d85980 100644
--- a/test/tap/install-at-locally.js
+++ b/test/tap/install-at-locally.js
@@ -1,42 +1,69 @@
-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 pkg = path.join(__dirname, "install-at-locally")
-
-var EXEC_OPTS = { }
-
-test("setup", function (t) {
- mkdirp.sync(pkg)
- mkdirp.sync(path.resolve(pkg, "node_modules"))
- process.chdir(pkg)
+var fs = require('graceful-fs')
+var path = require('path')
+
+var mkdirp = require('mkdirp')
+var osenv = require('osenv')
+var rimraf = require('rimraf')
+var test = require('tap').test
+
+var common = require('../common-tap.js')
+
+var pkg = path.join(__dirname, 'install-at-locally')
+
+var EXEC_OPTS = { cwd: pkg }
+
+var json = {
+ name: 'install-at-locally',
+ version: '0.0.0'
+}
+
+test('setup', function (t) {
+ cleanup()
t.end()
})
-test("\"npm install ./package@1.2.3\" should install local pkg", function(t) {
- common.npm(["install", "./package@1.2.3"], EXEC_OPTS, function(err, code) {
- var p = path.resolve(pkg, "node_modules/install-at-locally/package.json")
- t.ifError(err, "install local package successful")
- t.equal(code, 0, "npm install exited with code")
- t.ok(JSON.parse(fs.readFileSync(p, "utf8")))
+test('\'npm install ./package@1.2.3\' should install local pkg', function (t) {
+ var target = './package@1.2.3'
+ setup(target)
+ common.npm(['install', target], EXEC_OPTS, function (err, code) {
+ var p = path.resolve(pkg, 'node_modules/install-at-locally/package.json')
+ t.ifError(err, 'install local package successful')
+ t.equal(code, 0, 'npm install exited with code')
+ t.ok(JSON.parse(fs.readFileSync(p, 'utf8')))
t.end()
})
})
-test("\"npm install install/at/locally@./package@1.2.3\" should install local pkg", function(t) {
- common.npm(["install", "./package@1.2.3"], EXEC_OPTS, function(err, code) {
- var p = path.resolve(pkg, "node_modules/install-at-locally/package.json")
- t.ifError(err, "install local package in explicit directory successful")
- t.equal(code, 0, "npm install exited with code")
- t.ok(JSON.parse(fs.readFileSync(p, "utf8")))
+test('\'npm install install/at/locally@./package@1.2.3\' should install local pkg', function (t) {
+ var target = 'install/at/locally@./package@1.2.3'
+ setup(target)
+ common.npm(['install', target], EXEC_OPTS, function (err, code) {
+ var p = path.resolve(pkg, 'node_modules/install-at-locally/package.json')
+ t.ifError(err, 'install local package in explicit directory successful')
+ t.equal(code, 0, 'npm install exited with code')
+ t.ok(JSON.parse(fs.readFileSync(p, 'utf8')))
t.end()
})
})
-test("cleanup", function(t) {
- process.chdir(__dirname)
- rimraf.sync(path.resolve(pkg, "node_modules"))
+test('cleanup', function (t) {
+ cleanup()
t.end()
})
+
+function cleanup () {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(pkg)
+}
+
+function setup (target) {
+ cleanup()
+ var root = path.resolve(pkg, target)
+ mkdirp.sync(root)
+ fs.writeFileSync(
+ path.join(root, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+ mkdirp.sync(path.resolve(pkg, 'node_modules'))
+ process.chdir(pkg)
+}
diff --git a/test/tap/install-at-locally/package@1.2.3/package.json b/test/tap/install-at-locally/package@1.2.3/package.json
deleted file mode 100644
index b11d00c65..000000000
--- a/test/tap/install-at-locally/package@1.2.3/package.json
+++ /dev/null
@@ -1,5 +0,0 @@
-{
- "name": "install-at-locally",
- "version": "0.0.0",
- "description": "Test for 404-parent"
-}
diff --git a/test/tap/install-cli-production.js b/test/tap/install-cli-production.js
index 00c935527..fbaf23afb 100644
--- a/test/tap/install-cli-production.js
+++ b/test/tap/install-cli-production.js
@@ -1,44 +1,88 @@
-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 pkg = path.join(__dirname, "install-cli-production")
-
-var EXEC_OPTS = {
- cwd: pkg
+var fs = require('graceful-fs')
+var path = require('path')
+var existsSync = fs.existsSync || path.existsSync
+
+var mkdirp = require('mkdirp')
+var osenv = require('osenv')
+var rimraf = require('rimraf')
+var test = require('tap').test
+
+var common = require('../common-tap.js')
+
+var pkg = path.join(__dirname, 'install-cli-production')
+
+var EXEC_OPTS = { cwd: pkg }
+
+var json = {
+ name: 'install-cli-production',
+ description: 'fixture',
+ version: '0.0.0',
+ scripts: {
+ prepublish: 'exit 123'
+ },
+ dependencies: {
+ dependency: 'file:./dependency'
+ },
+ devDependencies: {
+ 'dev-dependency': 'file:./dev-dependency'
+ }
+}
+
+var dependency = {
+ name: 'dependency',
+ description: 'fixture',
+ version: '0.0.0'
+}
+
+var devDependency = {
+ name: 'dev-dependency',
+ description: 'fixture',
+ version: '0.0.0'
}
-test("setup", function(t) {
- mkdirp.sync(pkg)
- mkdirp.sync(path.resolve(pkg, "node_modules"))
+test('setup', function (t) {
+ mkdirp.sync(path.join(pkg, 'dependency'))
+ fs.writeFileSync(
+ path.join(pkg, 'dependency', 'package.json'),
+ JSON.stringify(dependency, null, 2)
+ )
+
+ mkdirp.sync(path.join(pkg, 'devDependency'))
+ fs.writeFileSync(
+ path.join(pkg, 'devDependency', 'package.json'),
+ JSON.stringify(devDependency, null, 2)
+ )
+
+ mkdirp.sync(path.join(pkg, 'node_modules'))
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+
process.chdir(pkg)
t.end()
})
-test("\"npm install --production\" should install dependencies", function(t) {
- common.npm(["install", "--production"], EXEC_OPTS, function(err, code) {
- t.ifError(err, "install production successful")
- t.equal(code, 0, "npm install exited with code")
- var p = path.resolve(pkg, "node_modules/dependency/package.json")
- t.ok(JSON.parse(fs.readFileSync(p, "utf8")))
- t.end()
- })
-})
-
-test("\"npm install --production\" should not install dev dependencies", function(t) {
- common.npm(["install", "--production"], EXEC_OPTS, function(err, code) {
- t.ifError(err, "install production successful")
- t.equal(code, 0, "npm install exited with code")
- var p = path.resolve(pkg, "node_modules/dev-dependency/package.json")
- t.ok(!fs.existsSync(p), "")
+test('\'npm install --production\' should only install dependencies', function (t) {
+ common.npm(['install', '--production'], EXEC_OPTS, function (err, code) {
+ t.ifError(err, 'install production successful')
+ t.equal(code, 0, 'npm install did not raise error code')
+ t.ok(
+ JSON.parse(fs.readFileSync(
+ path.resolve(pkg, 'node_modules/dependency/package.json'), 'utf8')
+ ),
+ 'dependency was installed'
+ )
+ t.notOk(
+ existsSync(path.resolve(pkg, 'node_modules/dev-dependency/package.json')),
+ 'devDependency was NOT installed'
+ )
t.end()
})
})
-test("cleanup", function(t) {
- process.chdir(__dirname)
- rimraf.sync(path.resolve(pkg, "node_modules"))
+test('cleanup', function (t) {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(pkg)
t.end()
})
diff --git a/test/tap/install-cli-production/dependency/package.json b/test/tap/install-cli-production/dependency/package.json
deleted file mode 100644
index 6ee6be0c3..000000000
--- a/test/tap/install-cli-production/dependency/package.json
+++ /dev/null
@@ -1,5 +0,0 @@
-{
- "name": "dependency",
- "description": "fixture",
- "version": "0.0.0"
-}
diff --git a/test/tap/install-cli-production/dev-dependency/package.json b/test/tap/install-cli-production/dev-dependency/package.json
deleted file mode 100644
index a6a8f6976..000000000
--- a/test/tap/install-cli-production/dev-dependency/package.json
+++ /dev/null
@@ -1,5 +0,0 @@
-{
- "name": "dev-dependency",
- "description": "fixture",
- "version": "0.0.0"
-}
diff --git a/test/tap/install-cli-production/package.json b/test/tap/install-cli-production/package.json
deleted file mode 100644
index 8f2f0e2ec..000000000
--- a/test/tap/install-cli-production/package.json
+++ /dev/null
@@ -1,14 +0,0 @@
-{
- "name": "install-cli-production",
- "description": "fixture",
- "version": "0.0.0",
- "scripts": {
- "prepublish": "exit 123"
- },
- "dependencies": {
- "dependency": "file:./dependency"
- },
- "devDependencies": {
- "dev-dependency": "file:./dev-dependency"
- }
-}
diff --git a/test/tap/install-cli-unicode.js b/test/tap/install-cli-unicode.js
index 004229cf8..01a5f4a47 100644
--- a/test/tap/install-cli-unicode.js
+++ b/test/tap/install-cli-unicode.js
@@ -1,39 +1,71 @@
-var common = require("../common-tap.js")
-var test = require("tap").test
-var mr = require("npm-registry-mock")
-var path = require("path")
+var fs = require('graceful-fs')
+var path = require('path')
-var pkg = path.resolve(__dirname, "install-cli")
+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 server
+
+var pkg = path.resolve(__dirname, 'install-cli-unicode')
function hasOnlyAscii (s) {
return /^[\000-\177]*$/.test(s)
}
-var EXEC_OPTS = {
- cwd : pkg
+var EXEC_OPTS = { cwd: pkg }
+
+var json = {
+ name: 'install-cli',
+ description: 'fixture',
+ version: '0.0.1',
+ dependencies: {
+ read: '1.0.5'
+ }
}
-test("does not use unicode with --unicode false", function (t) {
- t.plan(5)
- mr({port : common.port}, function (er, s) {
- common.npm(["install", "--unicode", "false", "read"], EXEC_OPTS, function (err, code, stdout) {
- t.ifError(err, "install package read without unicode success")
- t.notOk(code, "npm install exited with code 0")
- t.ifError(err)
- t.ok(stdout, stdout.length)
- t.ok(hasOnlyAscii(stdout))
- s.close()
- })
+test('setup', function (t) {
+ rimraf.sync(pkg)
+ mkdirp.sync(pkg)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+
+ mr({ port: common.port }, function (er, s) {
+ server = s
+ t.end()
})
})
-test("cleanup", function (t) {
- mr({port : common.port}, function (er, s) {
- common.npm(["uninstall", "read"], EXEC_OPTS, function (err, code) {
- t.ifError(err, "uninstall read package success")
- t.notOk(code, "npm uninstall exited with code 0")
- s.close()
- })
- })
+test('does not use unicode with --unicode false', function (t) {
+ common.npm(
+ [
+ '--unicode', 'false',
+ '--registry', common.registry,
+ '--loglevel', 'silent',
+ 'install', 'optimist'
+ ],
+ EXEC_OPTS,
+ function (err, code, stdout) {
+ t.ifError(err, 'install package read without unicode success')
+ t.notOk(code, 'npm install exited with code 0')
+ t.ifError(err, 'npm install ran without issue')
+ t.ok(stdout, 'got some output')
+ t.ok(hasOnlyAscii(stdout), 'only ASCII in install output')
+
+ t.end()
+ }
+ )
+})
+
+test('cleanup', function (t) {
+ server.close()
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(pkg)
+
t.end()
})
diff --git a/test/tap/install-cli/README.md b/test/tap/install-cli/README.md
deleted file mode 100644
index dbdfb5aa0..000000000
--- a/test/tap/install-cli/README.md
+++ /dev/null
@@ -1 +0,0 @@
-# Tests for `npm install` CLI output.
diff --git a/test/tap/install-cli/index.js b/test/tap/install-cli/index.js
deleted file mode 100644
index 33c1891f8..000000000
--- a/test/tap/install-cli/index.js
+++ /dev/null
@@ -1 +0,0 @@
-module.exports = true
diff --git a/test/tap/install-cli/package.json b/test/tap/install-cli/package.json
deleted file mode 100644
index 3d7e41d46..000000000
--- a/test/tap/install-cli/package.json
+++ /dev/null
@@ -1,10 +0,0 @@
-{
- "name": "install-cli",
- "description": "fixture",
- "version": "0.0.1",
- "main": "index.js",
- "dependencies": {
- "read": "1.0.5"
- },
- "repository": "git://github.com/robertkowalski/bogusfixture"
-}
diff --git a/test/tap/install-from-local.js b/test/tap/install-from-local.js
index d1fbb3b90..3cac382a7 100644
--- a/test/tap/install-from-local.js
+++ b/test/tap/install-from-local.js
@@ -1,39 +1,98 @@
-var common = require("../common-tap")
-var test = require("tap").test
-var path = require("path")
-var fs = require("fs")
-var rimraf = require("rimraf")
-var pkg = path.join(__dirname, "install-from-local", "package-with-local-paths")
+var fs = require('graceful-fs')
+var path = require('path')
-var EXEC_OPTS = { }
+var mkdirp = require('mkdirp')
+var osenv = require('osenv')
+var rimraf = require('rimraf')
+var test = require('tap').test
+
+var common = require('../common-tap')
+
+var root = path.join(__dirname, 'install-from-local')
+var pkg = path.join(root, 'package-with-local-paths')
+
+var EXEC_OPTS = { cwd: pkg }
+
+var localPaths = {
+ name: 'package-with-local-paths',
+ version: '0.0.0',
+ dependencies: {
+ 'package-local-dependency': 'file:../package-local-dependency'
+ },
+ devDependencies: {
+ 'package-local-dev-dependency': 'file:../package-local-dev-dependency'
+ }
+}
+
+var localDependency = {
+ name: 'package-local-dependency',
+ version: '0.0.0',
+ description: 'Test for local installs'
+}
+
+var localDevDependency = {
+ name: 'package-local-dev-dependency',
+ version: '0.0.0',
+ description: 'Test for local installs'
+}
+
+test('setup', function (t) {
+ rimraf.sync(pkg)
+ mkdirp.sync(pkg)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(localPaths, null, 2)
+ )
+
+ mkdirp.sync(path.join(root, 'package-local-dependency'))
+ fs.writeFileSync(
+ path.join(root, 'package-local-dependency', 'package.json'),
+ JSON.stringify(localDependency, null, 2)
+ )
+
+ mkdirp.sync(path.join(root, 'package-local-dev-dependency'))
+ fs.writeFileSync(
+ path.join(root, 'package-local-dev-dependency', 'package.json'),
+ JSON.stringify(localDevDependency, null, 2)
+ )
-test("setup", function (t) {
process.chdir(pkg)
t.end()
})
-test('"npm install" should install local packages', function (t) {
- common.npm(["install", "."], EXEC_OPTS, function (err, code) {
- t.ifError(err, "error should not exist")
- t.notOk(code, "npm install exited with code 0")
- var dependencyPackageJson = path.resolve(pkg, "node_modules/package-local-dependency/package.json")
- t.ok(
- JSON.parse(fs.readFileSync(dependencyPackageJson, "utf8")),
- "package with local dependency installed"
- )
-
- var devDependencyPackageJson = path.resolve(pkg, "node_modules/package-local-dev-dependency/package.json")
- t.ok(
- JSON.parse(fs.readFileSync(devDependencyPackageJson, "utf8")),
- "package with local dev dependency installed"
- )
-
- t.end()
- })
+test('\'npm install\' should install local packages', function (t) {
+ common.npm(
+ [
+ 'install', '.'
+ ],
+ EXEC_OPTS,
+ function (err, code) {
+ t.ifError(err, 'error should not exist')
+ t.notOk(code, 'npm install exited with code 0')
+ var dependencyPackageJson = path.resolve(
+ pkg,
+ 'node_modules/package-local-dependency/package.json'
+ )
+ t.ok(
+ JSON.parse(fs.readFileSync(dependencyPackageJson, 'utf8')),
+ 'package with local dependency installed'
+ )
+
+ var devDependencyPackageJson = path.resolve(
+ pkg, 'node_modules/package-local-dev-dependency/package.json'
+ )
+ t.ok(
+ JSON.parse(fs.readFileSync(devDependencyPackageJson, 'utf8')),
+ 'package with local dev dependency installed'
+ )
+
+ t.end()
+ }
+ )
})
-test("cleanup", function (t) {
- process.chdir(__dirname)
- rimraf.sync(path.resolve(pkg, "node_modules"))
+test('cleanup', function (t) {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(root)
t.end()
})
diff --git a/test/tap/install-from-local/package-local-dependency/package.json b/test/tap/install-from-local/package-local-dependency/package.json
deleted file mode 100644
index a524d8262..000000000
--- a/test/tap/install-from-local/package-local-dependency/package.json
+++ /dev/null
@@ -1,5 +0,0 @@
-{
- "name": "package-local-dependency",
- "version": "0.0.0",
- "description": "Test for local installs"
-}
diff --git a/test/tap/install-from-local/package-local-dev-dependency/package.json b/test/tap/install-from-local/package-local-dev-dependency/package.json
deleted file mode 100644
index 23f3ad682..000000000
--- a/test/tap/install-from-local/package-local-dev-dependency/package.json
+++ /dev/null
@@ -1,5 +0,0 @@
-{
- "name": "package-local-dev-dependency",
- "version": "0.0.0",
- "description": "Test for local installs"
-}
diff --git a/test/tap/install-from-local/package-scoped-dependency/package.json b/test/tap/install-from-local/package-scoped-dependency/package.json
deleted file mode 100644
index ec3e13214..000000000
--- a/test/tap/install-from-local/package-scoped-dependency/package.json
+++ /dev/null
@@ -1,5 +0,0 @@
-{
- "name": "@scoped/package",
- "version": "0.0.0",
- "description": "Test for local installs"
-}
diff --git a/test/tap/install-from-local/package-with-local-paths/package.json b/test/tap/install-from-local/package-with-local-paths/package.json
deleted file mode 100644
index bf4a3e946..000000000
--- a/test/tap/install-from-local/package-with-local-paths/package.json
+++ /dev/null
@@ -1,10 +0,0 @@
-{
- "name": "package-with-local-paths",
- "version": "0.0.0",
- "dependencies": {
- "package-local-dependency": "file:../package-local-dependency"
- },
- "devDependencies": {
- "package-local-dev-dependency": "file:../package-local-dev-dependency"
- }
-}
diff --git a/test/tap/install-from-local/package-with-scoped-paths/package.json b/test/tap/install-from-local/package-with-scoped-paths/package.json
deleted file mode 100644
index 262aa57e0..000000000
--- a/test/tap/install-from-local/package-with-scoped-paths/package.json
+++ /dev/null
@@ -1,8 +0,0 @@
-{
- "name": "package-with-scoped-paths",
- "version": "0.0.0",
- "dependencies": {
- "package-local-dependency": "file:../package-local-dependency",
- "@scoped/package-scoped-dependency": "file:../package-scoped-dependency"
- }
-}
diff --git a/test/tap/install-save-exact.js b/test/tap/install-save-exact.js
index b2feaa1b4..14e32f0f8 100644
--- a/test/tap/install-save-exact.js
+++ b/test/tap/install-save-exact.js
@@ -1,92 +1,114 @@
-var common = require("../common-tap.js")
-var test = require("tap").test
-var npm = require("../../")
-var path = require("path")
-var fs = require("fs")
-var rimraf = require("rimraf")
-var mkdirp = require("mkdirp")
-var pkg = path.join(__dirname, "install-save-exact")
-var mr = require("npm-registry-mock")
-
-test("setup", function (t) {
- mkdirp.sync(pkg)
- mkdirp.sync(path.resolve(pkg, "node_modules"))
- process.chdir(pkg)
- t.end()
-})
+var fs = require('graceful-fs')
+var path = require('path')
+
+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 server
+
+var pkg = path.join(__dirname, 'install-save-exact')
-test("\"npm install --save --save-exact\" should install local pkg", function (t) {
- resetPackageJSON(pkg)
- mr({port : common.port}, function (er, s) {
- npm.load({
- cache: pkg + "/cache",
- loglevel: "silent",
- registry: common.registry }, function (err) {
- t.ifError(err)
- npm.config.set("save", true)
- npm.config.set("save-exact", true)
- npm.commands.install(["underscore@1.3.1"], function (err) {
- t.ifError(err)
- var p = path.resolve(pkg, "node_modules/underscore/package.json")
- t.ok(JSON.parse(fs.readFileSync(p)))
- p = path.resolve(pkg, "package.json")
- var pkgJson = JSON.parse(fs.readFileSync(p, "utf8"))
- t.deepEqual(pkgJson.dependencies, {
- "underscore": "1.3.1"
- }, "Underscore dependency should specify exactly 1.3.1")
- npm.config.set("save", undefined)
- npm.config.set("save-exact", undefined)
- s.close()
- t.end()
- })
- })
+var EXEC_OPTS = { cwd: pkg }
+
+var json = {
+ name: 'install-save-exact',
+ version: '0.0.1',
+ description: 'fixture'
+}
+
+test('setup', function (t) {
+ setup()
+ mr({ port: common.port }, function (er, s) {
+ server = s
+ t.end()
})
})
-test("\"npm install --save-dev --save-exact\" should install local pkg", function (t) {
- resetPackageJSON(pkg)
-
- mr({port : common.port}, function (er, s) {
- npm.load({
- cache: pkg + "/cache",
- loglevel: "silent",
- registry: common.registry }, function (err) {
- t.ifError(err)
- npm.config.set("save-dev", true)
- npm.config.set("save-exact", true)
- npm.commands.install(["underscore@1.3.1"], function (err) {
- t.ifError(err)
- var p = path.resolve(pkg, "node_modules/underscore/package.json")
- t.ok(JSON.parse(fs.readFileSync(p)))
- p = path.resolve(pkg, "package.json")
- var pkgJson = JSON.parse(fs.readFileSync(p, "utf8"))
- console.log(pkgJson)
- t.deepEqual(pkgJson.devDependencies, {
- "underscore": "1.3.1"
- }, "underscore devDependency should specify exactly 1.3.1")
- s.close()
- npm.config.set("save-dev", undefined)
- npm.config.set("save-exact", undefined)
- t.end()
- })
- })
- })
+test('\'npm install --save --save-exact\' should install local pkg', function (t) {
+ common.npm(
+ [
+ '--loglevel', 'silent',
+ '--registry', common.registry,
+ '--save',
+ '--save-exact',
+ 'install', 'underscore@1.3.1'
+ ],
+ EXEC_OPTS,
+ function (err, code) {
+ t.ifError(err, 'npm ran without issue')
+ t.notOk(code, 'npm install exited without raising an error code')
+
+ var p = path.resolve(pkg, 'node_modules/underscore/package.json')
+ t.ok(JSON.parse(fs.readFileSync(p)))
+
+ p = path.resolve(pkg, 'package.json')
+ var pkgJson = JSON.parse(fs.readFileSync(p, 'utf8'))
+
+ t.same(
+ pkgJson.dependencies,
+ { 'underscore': '1.3.1' },
+ 'underscore dependency should specify exactly 1.3.1'
+ )
+
+ t.end()
+ }
+ )
+})
+
+test('\'npm install --save-dev --save-exact\' should install local pkg', function (t) {
+ setup()
+
+ common.npm(
+ [
+ '--loglevel', 'silent',
+ '--registry', common.registry,
+ '--save-dev',
+ '--save-exact',
+ 'install', 'underscore@1.3.1'
+ ],
+ EXEC_OPTS,
+ function (err, code) {
+ t.ifError(err, 'npm ran without issue')
+ t.notOk(code, 'npm install exited without raising an error code')
+
+ var p = path.resolve(pkg, 'node_modules/underscore/package.json')
+ t.ok(JSON.parse(fs.readFileSync(p)))
+
+ p = path.resolve(pkg, 'package.json')
+ var pkgJson = JSON.parse(fs.readFileSync(p, 'utf8'))
+
+ t.same(
+ pkgJson.devDependencies,
+ { 'underscore': '1.3.1' },
+ 'underscore dependency should specify exactly 1.3.1'
+ )
+
+ t.end()
+ }
+ )
})
-test("cleanup", function (t) {
- process.chdir(__dirname)
- rimraf.sync(path.resolve(pkg, "node_modules"))
- rimraf.sync(path.resolve(pkg, "cache"))
- resetPackageJSON(pkg)
+test('cleanup', function (t) {
+ server.close()
+ cleanup()
t.end()
})
-function resetPackageJSON(pkg) {
- var pkgJson = JSON.parse(fs.readFileSync(pkg + "/package.json", "utf8"))
- delete pkgJson.dependencies
- delete pkgJson.devDependencies
- delete pkgJson.optionalDependencies
- var json = JSON.stringify(pkgJson, null, 2) + "\n"
- var p = path.resolve(pkg, "package.json")
- fs.writeFileSync(p, json, "ascii")
+function cleanup () {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(pkg)
+}
+
+function setup () {
+ cleanup()
+ mkdirp.sync(path.resolve(pkg, 'node_modules'))
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+ process.chdir(pkg)
}
diff --git a/test/tap/install-save-exact/README.md b/test/tap/install-save-exact/README.md
deleted file mode 100644
index aca67ff17..000000000
--- a/test/tap/install-save-exact/README.md
+++ /dev/null
@@ -1 +0,0 @@
-# just a test
diff --git a/test/tap/install-save-exact/index.js b/test/tap/install-save-exact/index.js
deleted file mode 100644
index 33c1891f8..000000000
--- a/test/tap/install-save-exact/index.js
+++ /dev/null
@@ -1 +0,0 @@
-module.exports = true
diff --git a/test/tap/install-save-exact/package.json b/test/tap/install-save-exact/package.json
deleted file mode 100644
index 84789fc22..000000000
--- a/test/tap/install-save-exact/package.json
+++ /dev/null
@@ -1,7 +0,0 @@
-{
- "name": "bla",
- "description": "fixture",
- "version": "0.0.1",
- "main": "index.js",
- "repository": "git://github.com/robertkowalski/bogusfixture"
-}
diff --git a/test/tap/install-save-local.js b/test/tap/install-save-local.js
index 2a1f83998..33a1c613f 100644
--- a/test/tap/install-save-local.js
+++ b/test/tap/install-save-local.js
@@ -1,65 +1,126 @@
-var common = require("../common-tap.js")
-var test = require("tap").test
-var path = require("path")
-var fs = require("fs")
-var rimraf = require("rimraf")
-var pkg = path.join(__dirname, "install-save-local", "package")
+var fs = require('graceful-fs')
+var path = require('path')
-var EXEC_OPTS = { }
+var mkdirp = require('mkdirp')
+var osenv = require('osenv')
+var rimraf = require('rimraf')
+var test = require('tap').test
-test("setup", function (t) {
- resetPackageJSON(pkg)
- process.chdir(pkg)
+var common = require('../common-tap.js')
+
+var root = path.join(__dirname, 'install-save-local')
+var pkg = path.join(root, 'package')
+
+var EXEC_OPTS = { cwd: pkg }
+
+var json = {
+ name: 'install-save-local',
+ version: '0.0.0'
+}
+
+var localDependency = {
+ name: 'package-local-dependency',
+ version: '0.0.0'
+}
+
+var localDevDependency = {
+ name: 'package-local-dev-dependency',
+ version: '0.0.0'
+}
+
+test('setup', function (t) {
+ setup()
t.end()
})
-test('"npm install --save ../local/path" should install local package and save to package.json', function (t) {
- resetPackageJSON(pkg)
- common.npm(["install", "--save", "../package-local-dependency"], EXEC_OPTS, function (err, code) {
- t.ifError(err)
- t.notOk(code, "npm install exited with code 0")
-
- var dependencyPackageJson = path.resolve(pkg, "node_modules/package-local-dependency/package.json")
- t.ok(JSON.parse(fs.readFileSync(dependencyPackageJson, "utf8")))
-
- var pkgJson = JSON.parse(fs.readFileSync(pkg + "/package.json", "utf8"))
- t.deepEqual(pkgJson.dependencies, {
- "package-local-dependency": "file:../package-local-dependency"
- })
- t.end()
- })
+test('\'npm install --save ../local/path\' should save to package.json', function (t) {
+ common.npm(
+ [
+ '--loglevel', 'silent',
+ '--save',
+ 'install', '../package-local-dependency'
+ ],
+ EXEC_OPTS,
+ function (err, code) {
+ t.ifError(err, 'npm install ran without issue')
+ t.notOk(code, 'npm install exited with code 0')
+
+ var dependencyPackageJson = path.join(
+ pkg, 'node_modules', 'package-local-dependency', 'package.json'
+ )
+ t.ok(JSON.parse(fs.readFileSync(dependencyPackageJson, 'utf8')))
+
+ var pkgJson = JSON.parse(fs.readFileSync(pkg + '/package.json', 'utf8'))
+ t.deepEqual(
+ pkgJson.dependencies,
+ { 'package-local-dependency': 'file:../package-local-dependency' },
+ 'local package saved correctly'
+ )
+ t.end()
+ }
+ )
})
-test('"npm install --save-dev ../local/path" should install local package and save to package.json', function (t) {
- resetPackageJSON(pkg)
- common.npm(["install", "--save-dev", "../package-local-dev-dependency"], EXEC_OPTS, function (err, code) {
- t.ifError(err)
- t.notOk(code, "npm install exited with code 0")
+test('\'npm install --save-dev ../local/path\' should save to package.json', function (t) {
+ setup()
+ common.npm(
+ [
+ '--loglevel', 'silent',
+ '--save-dev',
+ 'install', '../package-local-dev-dependency'
+ ],
+ EXEC_OPTS,
+ function (err, code) {
+ t.ifError(err, 'npm install ran without issue')
+ t.notOk(code, 'npm install exited with code 0')
- var dependencyPackageJson = path.resolve(pkg, "node_modules/package-local-dev-dependency/package.json")
- t.ok(JSON.parse(fs.readFileSync(dependencyPackageJson, "utf8")))
+ var dependencyPackageJson = path.resolve(
+ pkg, 'node_modules', 'package-local-dev-dependency', 'package.json'
+ )
+ t.ok(JSON.parse(fs.readFileSync(dependencyPackageJson, 'utf8')))
- var pkgJson = JSON.parse(fs.readFileSync(pkg + "/package.json", "utf8"))
- t.deepEqual(pkgJson.devDependencies, {
- "package-local-dev-dependency": "file:../package-local-dev-dependency"
- })
+ var pkgJson = JSON.parse(fs.readFileSync(pkg + '/package.json', 'utf8'))
+ t.deepEqual(
+ pkgJson.devDependencies,
+ { 'package-local-dev-dependency': 'file:../package-local-dev-dependency' },
+ 'local package saved correctly'
+ )
- t.end()
- })
+ t.end()
+ }
+ )
})
-
-test("cleanup", function (t) {
- resetPackageJSON(pkg)
- process.chdir(__dirname)
- rimraf.sync(path.resolve(pkg, "node_modules"))
+test('cleanup', function (t) {
+ cleanup()
t.end()
})
-function resetPackageJSON(pkg) {
- var pkgJson = JSON.parse(fs.readFileSync(pkg + "/package.json", "utf8"))
- delete pkgJson.dependencies
- delete pkgJson.devDependencies
- var json = JSON.stringify(pkgJson, null, 2) + "\n"
- fs.writeFileSync(pkg + "/package.json", json, "ascii")
+function cleanup () {
+ process.chdir(osenv.tmpdir())
+ process.chdir(__dirname)
+ rimraf.sync(root)
+}
+
+function setup () {
+ cleanup()
+ mkdirp.sync(pkg)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+
+ mkdirp.sync(path.join(root, 'package-local-dependency'))
+ fs.writeFileSync(
+ path.join(root, 'package-local-dependency', 'package.json'),
+ JSON.stringify(localDependency, null, 2)
+ )
+
+ mkdirp.sync(path.join(root, 'package-local-dev-dependency'))
+ fs.writeFileSync(
+ path.join(root, 'package-local-dev-dependency', 'package.json'),
+ JSON.stringify(localDevDependency, null, 2)
+ )
+
+ process.chdir(pkg)
}
diff --git a/test/tap/install-save-local/package-local-dependency/package.json b/test/tap/install-save-local/package-local-dependency/package.json
deleted file mode 100644
index a524d8262..000000000
--- a/test/tap/install-save-local/package-local-dependency/package.json
+++ /dev/null
@@ -1,5 +0,0 @@
-{
- "name": "package-local-dependency",
- "version": "0.0.0",
- "description": "Test for local installs"
-}
diff --git a/test/tap/install-save-local/package-local-dev-dependency/package.json b/test/tap/install-save-local/package-local-dev-dependency/package.json
deleted file mode 100644
index 23f3ad682..000000000
--- a/test/tap/install-save-local/package-local-dev-dependency/package.json
+++ /dev/null
@@ -1,5 +0,0 @@
-{
- "name": "package-local-dev-dependency",
- "version": "0.0.0",
- "description": "Test for local installs"
-}
diff --git a/test/tap/install-save-local/package/package.json b/test/tap/install-save-local/package/package.json
deleted file mode 100644
index c6a5cb99d..000000000
--- a/test/tap/install-save-local/package/package.json
+++ /dev/null
@@ -1,4 +0,0 @@
-{
- "name": "package",
- "version": "0.0.0"
-}
diff --git a/test/tap/install-save-prefix.js b/test/tap/install-save-prefix.js
index 1844a2c29..b669c5fb7 100644
--- a/test/tap/install-save-prefix.js
+++ b/test/tap/install-save-prefix.js
@@ -1,139 +1,178 @@
-var common = require("../common-tap.js")
-var test = require("tap").test
-var npm = require("../../")
-var path = require("path")
-var fs = require("fs")
-var rimraf = require("rimraf")
-var mkdirp = require("mkdirp")
-var pkg = path.join(__dirname, "install-save-prefix")
-var mr = require("npm-registry-mock")
-
-test("setup", function (t) {
- mkdirp.sync(pkg)
- mkdirp.sync(path.resolve(pkg, "node_modules"))
- process.chdir(pkg)
- t.end()
-})
+var fs = require('fs')
+var path = require('path')
+
+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 server
+
+var pkg = path.join(__dirname, 'install-save-prefix')
+
+var EXEC_OPTS = { cwd: pkg }
-test("npm install --save with default save-prefix should install local pkg versioned to allow minor updates", function (t) {
- resetPackageJSON(pkg)
- mr({port : common.port}, function (er, s) {
- npm.load({
- cache: pkg + "/cache",
- loglevel: "silent",
- "save-prefix": "^",
- registry: common.registry }, function (err) {
- t.ifError(err)
- npm.config.set("save", true)
- npm.commands.install(["underscore@latest"], function (err) {
- t.ifError(err)
- var p = path.resolve(pkg, "node_modules/underscore/package.json")
- t.ok(JSON.parse(fs.readFileSync(p)))
- var pkgJson = JSON.parse(fs.readFileSync(pkg + "/package.json", "utf8"))
- t.deepEqual(pkgJson.dependencies, {
- "underscore": "^1.5.1"
- }, "Underscore dependency should specify ^1.5.1")
- npm.config.set("save", undefined)
- s.close()
- t.end()
- })
- })
+var json = {
+ name: 'install-save-prefix',
+ version: '0.0.1'
+}
+
+test('setup', function (t) {
+ setup()
+ mr({ port: common.port }, function (er, s) {
+ t.ifError(er, 'started mock registry')
+ server = s
+ t.end()
})
})
-test("npm install --save-dev with default save-prefix should install local pkg to dev dependencies versioned to allow minor updates", function (t) {
- resetPackageJSON(pkg)
- mr({port : common.port}, function (er, s) {
- npm.load({
- cache: pkg + "/cache",
- loglevel: "silent",
- "save-prefix": "^",
- registry: common.registry }, function (err) {
- t.ifError(err)
- npm.config.set("save-dev", true)
- npm.commands.install(["underscore@1.3.1"], function (err) {
- t.ifError(err)
- var p = path.resolve(pkg, "node_modules/underscore/package.json")
- t.ok(JSON.parse(fs.readFileSync(p)))
- var pkgJson = JSON.parse(fs.readFileSync(pkg + "/package.json", "utf8"))
- t.deepEqual(pkgJson.devDependencies, {
- "underscore": "^1.3.1"
- }, "Underscore devDependency should specify ^1.3.1")
- npm.config.set("save-dev", undefined)
- s.close()
- t.end()
- })
- })
- })
+test('install --save with \'^\' save prefix should accept minor updates', function (t) {
+ common.npm(
+ [
+ '--registry', common.registry,
+ '--loglevel', 'silent',
+ '--save-prefix', '^',
+ '--save',
+ 'install', 'underscore@latest'
+ ],
+ EXEC_OPTS,
+ function (err, code) {
+ t.ifError(err, 'npm install ran without issue')
+ t.notOk(code, 'npm install exited with code 0')
+
+ var p = path.join(pkg, 'node_modules', 'underscore', 'package.json')
+ t.ok(JSON.parse(fs.readFileSync(p)))
+
+ var pkgJson = JSON.parse(fs.readFileSync(
+ path.join(pkg, 'package.json'),
+ 'utf8'
+ ))
+ t.deepEqual(
+ pkgJson.dependencies,
+ { 'underscore': '^1.5.1' },
+ 'got expected save prefix and version of 1.5.1'
+ )
+ t.end()
+ }
+ )
})
-test("npm install --save with \"~\" save-prefix should install local pkg versioned to allow patch updates", function (t) {
- resetPackageJSON(pkg)
- mr({port : common.port}, function (er, s) {
- npm.load({
- cache: pkg + "/cache",
- loglevel: "silent",
- registry: common.registry }, function (err) {
- t.ifError(err)
- npm.config.set("save", true)
- npm.config.set("save-prefix", "~")
- npm.commands.install(["underscore@1.3.1"], function (err) {
- t.ifError(err)
- var p = path.resolve(pkg, "node_modules/underscore/package.json")
- t.ok(JSON.parse(fs.readFileSync(p)))
- var pkgJson = JSON.parse(fs.readFileSync(pkg + "/package.json", "utf8"))
- t.deepEqual(pkgJson.dependencies, {
- "underscore": "~1.3.1"
- }, "Underscore dependency should specify ~1.3.1")
- npm.config.set("save", undefined)
- npm.config.set("save-prefix", undefined)
- s.close()
- t.end()
- })
- })
- })
+test('install --save-dev with \'^\' save prefix should accept minor dev updates', function (t) {
+ setup()
+ common.npm(
+ [
+ '--registry', common.registry,
+ '--loglevel', 'silent',
+ '--save-prefix', '^',
+ '--save-dev',
+ 'install', 'underscore@1.3.1'
+ ],
+ EXEC_OPTS,
+ function (err, code) {
+ t.ifError(err, 'npm install ran without issue')
+ t.notOk(code, 'npm install exited with code 0')
+
+ var p = path.join(pkg, 'node_modules', 'underscore', 'package.json')
+ t.ok(JSON.parse(fs.readFileSync(p)))
+
+ var pkgJson = JSON.parse(fs.readFileSync(
+ path.join(pkg, 'package.json'),
+ 'utf8'
+ ))
+ t.deepEqual(
+ pkgJson.devDependencies,
+ { 'underscore': '^1.3.1' },
+ 'got expected save prefix and version of 1.3.1'
+ )
+ t.end()
+ }
+ )
})
-test("npm install --save-dev with \"~\" save-prefix should install local pkg to dev dependencies versioned to allow patch updates", function (t) {
- resetPackageJSON(pkg)
- mr({port : common.port}, function (er, s) {
- npm.load({
- cache: pkg + "/cache",
- loglevel: "silent",
- registry: common.registry }, function (err) {
- t.ifError(err)
- npm.config.set("save-dev", true)
- npm.config.set("save-prefix", "~")
- npm.commands.install(["underscore@1.3.1"], function (err) {
- t.ifError(err)
- var p = path.resolve(pkg, "node_modules/underscore/package.json")
- t.ok(JSON.parse(fs.readFileSync(p)))
- var pkgJson = JSON.parse(fs.readFileSync(pkg + "/package.json", "utf8"))
- t.deepEqual(pkgJson.devDependencies, {
- "underscore": "~1.3.1"
- }, "Underscore devDependency should specify ~1.3.1")
- npm.config.set("save-dev", undefined)
- npm.config.set("save-prefix", undefined)
- s.close()
- t.end()
- })
- })
- })
+test('install --save with \'~\' save prefix should accept patch updates', function (t) {
+ setup()
+ common.npm(
+ [
+ '--registry', common.registry,
+ '--loglevel', 'silent',
+ '--save-prefix', '~',
+ '--save',
+ 'install', 'underscore@1.3.1'
+ ],
+ EXEC_OPTS,
+ function (err, code) {
+ t.ifError(err, 'npm install ran without issue')
+ t.notOk(code, 'npm install exited with code 0')
+
+ var p = path.join(pkg, 'node_modules', 'underscore', 'package.json')
+ t.ok(JSON.parse(fs.readFileSync(p)))
+
+ var pkgJson = JSON.parse(fs.readFileSync(
+ path.join(pkg, 'package.json'),
+ 'utf8'
+ ))
+ t.deepEqual(
+ pkgJson.dependencies,
+ { 'underscore': '~1.3.1' },
+ 'got expected save prefix and version of 1.3.1'
+ )
+ t.end()
+ }
+ )
})
-test("cleanup", function (t) {
- process.chdir(__dirname)
- rimraf.sync(path.resolve(pkg, "node_modules"))
- rimraf.sync(path.resolve(pkg, "cache"))
- resetPackageJSON(pkg)
+test('install --save-dev with \'~\' save prefix should accept patch updates', function (t) {
+ setup()
+ common.npm(
+ [
+ '--registry', common.registry,
+ '--loglevel', 'silent',
+ '--save-prefix', '~',
+ '--save-dev',
+ 'install', 'underscore@1.3.1'
+ ],
+ EXEC_OPTS,
+ function (err, code) {
+ t.ifError(err, 'npm install ran without issue')
+ t.notOk(code, 'npm install exited with code 0')
+
+ var p = path.join(pkg, 'node_modules', 'underscore', 'package.json')
+ t.ok(JSON.parse(fs.readFileSync(p)))
+
+ var pkgJson = JSON.parse(fs.readFileSync(
+ path.join(pkg, 'package.json'),
+ 'utf8'
+ ))
+ t.deepEqual(
+ pkgJson.devDependencies,
+ { 'underscore': '~1.3.1' },
+ 'got expected save prefix and version of 1.3.1'
+ )
+ t.end()
+ }
+ )
+})
+
+test('cleanup', function (t) {
+ server.close()
+ cleanup()
t.end()
})
-function resetPackageJSON(pkg) {
- var pkgJson = JSON.parse(fs.readFileSync(pkg + "/package.json", "utf8"))
- delete pkgJson.dependencies
- delete pkgJson.devDependencies
- delete pkgJson.optionalDependencies
- var json = JSON.stringify(pkgJson, null, 2) + "\n"
- fs.writeFileSync(pkg + "/package.json", json, "ascii")
+function cleanup () {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(pkg)
+}
+
+function setup () {
+ cleanup()
+ mkdirp.sync(path.resolve(pkg, 'node_modules'))
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+
+ process.chdir(pkg)
}
diff --git a/test/tap/install-save-prefix/README.md b/test/tap/install-save-prefix/README.md
deleted file mode 100644
index aca67ff17..000000000
--- a/test/tap/install-save-prefix/README.md
+++ /dev/null
@@ -1 +0,0 @@
-# just a test
diff --git a/test/tap/install-save-prefix/index.js b/test/tap/install-save-prefix/index.js
deleted file mode 100644
index 33c1891f8..000000000
--- a/test/tap/install-save-prefix/index.js
+++ /dev/null
@@ -1 +0,0 @@
-module.exports = true
diff --git a/test/tap/install-save-prefix/package.json b/test/tap/install-save-prefix/package.json
deleted file mode 100644
index 84789fc22..000000000
--- a/test/tap/install-save-prefix/package.json
+++ /dev/null
@@ -1,7 +0,0 @@
-{
- "name": "bla",
- "description": "fixture",
- "version": "0.0.1",
- "main": "index.js",
- "repository": "git://github.com/robertkowalski/bogusfixture"
-}
diff --git a/test/tap/install-scoped-already-installed.js b/test/tap/install-scoped-already-installed.js
index a355a4a50..1446897d4 100644
--- a/test/tap/install-scoped-already-installed.js
+++ b/test/tap/install-scoped-already-installed.js
@@ -1,79 +1,130 @@
-var common = require("../common-tap")
-var existsSync = require("fs").existsSync
-var join = require("path").join
+var fs = require('graceful-fs')
+var path = require('path')
+var existsSync = fs.existsSync || path.existsSync
-var test = require("tap").test
-var rimraf = require("rimraf")
-var mkdirp = require("mkdirp")
+var mkdirp = require('mkdirp')
+var osenv = require('osenv')
+var rimraf = require('rimraf')
+var test = require('tap').test
-var pkg = join(__dirname, "install-from-local", "package-with-scoped-paths")
-var modules = join(pkg, "node_modules")
+var common = require('../common-tap')
-var EXEC_OPTS = {
- cwd : pkg
+var root = path.join(__dirname, 'install-scoped-already-installed')
+var pkg = path.join(root, 'package-with-scoped-paths')
+var modules = path.join(pkg, 'node_modules')
+
+var EXEC_OPTS = { cwd: pkg }
+
+var scopedPaths = {
+ name: 'package-with-scoped-paths',
+ version: '0.0.0',
+ dependencies: {
+ 'package-local-dependency': 'file:../package-local-dependency',
+ '@scoped/package-scoped-dependency': 'file:../package-scoped-dependency'
+ }
+}
+
+var localDependency = {
+ name: 'package-local-dependency',
+ version: '0.0.0',
+ description: 'Test for local installs'
}
-test("setup", function (t) {
- rimraf.sync(modules)
- rimraf.sync(join(pkg, "cache"))
+var scopedDependency = {
+ name: '@scoped/package',
+ version: '0.0.0',
+ description: 'Test for local installs'
+}
+
+test('setup', function (t) {
+ rimraf.sync(root)
+ mkdirp.sync(pkg)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(scopedPaths, null, 2)
+ )
+
+ mkdirp.sync(path.join(root, 'package-local-dependency'))
+ fs.writeFileSync(
+ path.join(root, 'package-local-dependency', 'package.json'),
+ JSON.stringify(localDependency, null, 2)
+ )
+
+ mkdirp.sync(path.join(root, 'package-scoped-dependency'))
+ fs.writeFileSync(
+ path.join(root, 'package-scoped-dependency', 'package.json'),
+ JSON.stringify(scopedDependency, null, 2)
+ )
+
process.chdir(pkg)
- mkdirp.sync(modules)
t.end()
})
-test("installing already installed local scoped package", function (t) {
- common.npm(["install", "--loglevel", "silent"], EXEC_OPTS, function (err, code, stdout) {
- var installed = parseNpmInstallOutput(stdout)
- t.ifError(err, "error should not exist")
- t.notOk(code, "npm install exited with code 0")
- t.ifError(err, "install ran to completion without error")
- t.ok(
- existsSync(join(modules, "@scoped", "package", "package.json")),
- "package installed"
- )
- t.ok(
- contains(installed, "node_modules/@scoped/package"),
- "installed @scoped/package"
- )
- t.ok(
- contains(installed, "node_modules/package-local-dependency"),
- "installed package-local-dependency"
- )
-
- common.npm(["install", "--loglevel", "silent"], EXEC_OPTS, function (err, code, stdout) {
- installed = parseNpmInstallOutput(stdout)
- t.ifError(err, "error should not exist")
- t.notOk(code, "npm install exited with code 0")
-
- t.ifError(err, "install ran to completion without error")
+test('installing already installed local scoped package', function (t) {
+ common.npm(
+ [
+ '--loglevel', 'silent',
+ 'install'
+ ],
+ EXEC_OPTS,
+ function (err, code, stdout) {
+ var installed = parseNpmInstallOutput(stdout)
+ t.ifError(err, 'install ran to completion without error')
+ t.notOk(code, 'npm install exited with code 0')
t.ok(
- existsSync(join(modules, "@scoped", "package", "package.json")),
- "package installed"
+ existsSync(path.join(modules, '@scoped', 'package', 'package.json')),
+ 'package installed'
)
-
- t.notOk(
- contains(installed, "node_modules/@scoped/package"),
- "did not reinstall @scoped/package"
+ t.ok(
+ contains(installed, 'node_modules/@scoped/package'),
+ 'installed @scoped/package'
)
- t.notOk(
- contains(installed, "node_modules/package-local-dependency"),
- "did not reinstall package-local-dependency"
+ t.ok(
+ contains(installed, 'node_modules/package-local-dependency'),
+ 'installed package-local-dependency'
)
- t.end()
- })
- })
+
+ common.npm(
+ [
+ '--loglevel', 'silent',
+ 'install'
+ ],
+ EXEC_OPTS,
+ function (err, code, stdout) {
+ t.ifError(err, 'install ran to completion without error')
+ t.notOk(code, 'npm install raised no error code')
+
+ installed = parseNpmInstallOutput(stdout)
+
+ t.ok(
+ existsSync(path.join(modules, '@scoped', 'package', 'package.json')),
+ 'package installed'
+ )
+
+ t.notOk(
+ contains(installed, 'node_modules/@scoped/package'),
+ 'did not reinstall @scoped/package'
+ )
+ t.notOk(
+ contains(installed, 'node_modules/package-local-dependency'),
+ 'did not reinstall package-local-dependency'
+ )
+ t.end()
+ }
+ )
+ }
+ )
})
-test("cleanup", function (t) {
- process.chdir(__dirname)
- rimraf.sync(join(modules))
- rimraf.sync(join(pkg, "cache"))
+test('cleanup', function (t) {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(root)
t.end()
})
-function contains(list, element) {
- for (var i=0; i < list.length; ++i) {
+function contains (list, element) {
+ for (var i = 0; i < list.length; ++i) {
if (list[i] === element) {
return true
}
@@ -81,6 +132,6 @@ function contains(list, element) {
return false
}
-function parseNpmInstallOutput(stdout) {
+function parseNpmInstallOutput (stdout) {
return stdout.trim().split(/\n\n|\s+/)
}
diff --git a/test/tap/install-scoped-link.js b/test/tap/install-scoped-link.js
index b1e6ca0b2..029acb381 100644
--- a/test/tap/install-scoped-link.js
+++ b/test/tap/install-scoped-link.js
@@ -1,51 +1,84 @@
-var common = require("../common-tap.js")
-var existsSync = require("fs").existsSync
-var join = require("path").join
-var exec = require("child_process").exec
+var exec = require('child_process').exec
+var fs = require('graceful-fs')
+var path = require('path')
+var existsSync = fs.existsSync || path.existsSync
-var test = require("tap").test
-var rimraf = require("rimraf")
-var mkdirp = require("mkdirp")
+var mkdirp = require('mkdirp')
+var osenv = require('osenv')
+var rimraf = require('rimraf')
+var test = require('tap').test
-var pkg = join(__dirname, "install-scoped")
-var work = join(__dirname, "install-scoped-TEST")
-var modules = join(work, "node_modules")
+var common = require('../common-tap.js')
-var EXEC_OPTS = {}
+var pkg = path.join(__dirname, 'install-scoped-link')
+var work = path.join(__dirname, 'install-scoped-link-TEST')
+var modules = path.join(work, 'node_modules')
+
+var EXEC_OPTS = { cwd: work }
+
+var world = 'console.log("hello blrbld")\n'
+
+var json = {
+ name: '@scoped/package',
+ version: '0.0.0',
+ bin: {
+ hello: './world.js'
+ }
+}
+
+test('setup', function (t) {
+ cleanup()
+ mkdirp.sync(pkg)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+ fs.writeFileSync(path.join(pkg, 'world.js'), world)
-test("setup", function (t) {
mkdirp.sync(modules)
process.chdir(work)
t.end()
})
-test("installing package with links", function (t) {
- common.npm(["install", pkg], EXEC_OPTS, function (err, code) {
- t.ifError(err, "install ran to completion without error")
- t.notOk(code, "npm install exited with code 0")
+test('installing package with links', function (t) {
+ common.npm(
+ [
+ '--loglevel', 'silent',
+ 'install', pkg
+ ],
+ EXEC_OPTS,
+ function (err, code) {
+ t.ifError(err, 'install ran to completion without error')
+ t.notOk(code, 'npm install exited with code 0')
- t.ok(
- existsSync(join(modules, "@scoped", "package", "package.json")),
- "package installed"
- )
- t.ok(existsSync(join(modules, ".bin")), "binary link directory exists")
+ t.ok(
+ existsSync(path.join(modules, '@scoped', 'package', 'package.json')),
+ 'package installed'
+ )
+ t.ok(existsSync(path.join(modules, '.bin')), 'binary link directory exists')
- var hello = join(modules, ".bin", "hello")
- t.ok(existsSync(hello), "binary link exists")
+ var hello = path.join(modules, '.bin', 'hello')
+ t.ok(existsSync(hello), 'binary link exists')
- exec("node " + hello, function (err, stdout, stderr) {
- t.ifError(err, "command ran fine")
- t.notOk(stderr, "got no error output back")
- t.equal(stdout, "hello blrbld\n", "output was as expected")
+ exec('node ' + hello, function (err, stdout, stderr) {
+ t.ifError(err, 'command ran fine')
+ t.notOk(stderr, 'got no error output back')
+ t.equal(stdout, 'hello blrbld\n', 'output was as expected')
- t.end()
- })
- })
+ t.end()
+ })
+ }
+ )
})
-test("cleanup", function (t) {
- process.chdir(__dirname)
- rimraf.sync(work)
+test('cleanup', function (t) {
+ cleanup()
t.end()
})
+
+function cleanup () {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(work)
+ rimraf.sync(pkg)
+}
diff --git a/test/tap/install-scoped/package.json b/test/tap/install-scoped/package.json
deleted file mode 100644
index 32700cf6a..000000000
--- a/test/tap/install-scoped/package.json
+++ /dev/null
@@ -1,7 +0,0 @@
-{
- "name": "@scoped/package",
- "version": "0.0.0",
- "bin": {
- "hello": "./world.js"
- }
-}
diff --git a/test/tap/install-scoped/world.js b/test/tap/install-scoped/world.js
deleted file mode 100644
index f6333ba5b..000000000
--- a/test/tap/install-scoped/world.js
+++ /dev/null
@@ -1 +0,0 @@
-console.log("hello blrbld")
diff --git a/test/tap/lifecycle-path.js b/test/tap/lifecycle-path.js
index dc05a15dc..fae6fcc83 100644
--- a/test/tap/lifecycle-path.js
+++ b/test/tap/lifecycle-path.js
@@ -1,61 +1,87 @@
-var test = require("tap").test
-var common = require("../common-tap.js")
-var path = require("path")
-var rimraf = require("rimraf")
-var pkg = path.resolve(__dirname, "lifecycle-path")
-var fs = require("fs")
-var link = path.resolve(pkg, "node-bin")
+var fs = require('fs')
+var path = require('path')
+
+var mkdirp = require('mkdirp')
+var osenv = require('osenv')
+var rimraf = require('rimraf')
+var test = require('tap').test
+
+var common = require('../common-tap.js')
+
+var pkg = path.resolve(__dirname, 'lifecycle-path')
+var link = path.resolve(pkg, 'node-bin')
var PATH
-if (process.platform === "win32") {
+if (process.platform === 'win32') {
// On Windows the 'comspec' environment variable is used,
// so cmd.exe does not need to be on the path.
- PATH = "C:\\foo\\bar"
+ PATH = 'C:\\foo\\bar'
} else {
// On non-Windows, without the path to the shell, nothing usually works.
- PATH = "/bin:/usr/bin"
+ PATH = '/bin:/usr/bin'
+}
+
+var printPath = 'console.log(process.env.PATH)\n'
+
+var json = {
+ name: 'glorb',
+ version: '1.2.3',
+ scripts: {
+ path: './node-bin/node print-path.js'
+ }
}
-test("setup", function (t) {
- rimraf.sync(link)
- fs.symlinkSync(path.dirname(process.execPath), link, "dir")
+test('setup', function (t) {
+ cleanup()
+ mkdirp.sync(pkg)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+ fs.writeFileSync(path.join(pkg, 'print-path.js'), printPath)
+ fs.symlinkSync(path.dirname(process.execPath), link, 'dir')
t.end()
})
-test("make sure the path is correct", function (t) {
- common.npm(["run-script", "path"], {
+test('make sure the path is correct', function (t) {
+ common.npm(['run-script', 'path'], {
cwd: pkg,
env: {
PATH: PATH,
- stdio: [ 0, "pipe", 2 ]
+ stdio: [ 0, 'pipe', 2 ]
}
}, function (er, code, stdout) {
if (er) throw er
- t.equal(code, 0, "exit code")
+ t.equal(code, 0, 'exit code')
// remove the banner, we just care about the last line
stdout = stdout.trim().split(/\r|\n/).pop()
- var pathSplit = process.platform === "win32" ? ";" : ":"
- var root = path.resolve(__dirname, "../..")
+ var pathSplit = process.platform === 'win32' ? ';' : ':'
+ var root = path.resolve(__dirname, '../..')
var actual = stdout.split(pathSplit).map(function (p) {
if (p.indexOf(root) === 0) {
- p = "{{ROOT}}" + p.substr(root.length)
+ p = '{{ROOT}}' + p.substr(root.length)
}
- return p.replace(/\\/g, "/")
+ return p.replace(/\\/g, '/')
})
// get the ones we tacked on, then the system-specific requirements
var expect = [
- "{{ROOT}}/bin/node-gyp-bin",
- "{{ROOT}}/test/tap/lifecycle-path/node_modules/.bin"
+ '{{ROOT}}/bin/node-gyp-bin',
+ '{{ROOT}}/test/tap/lifecycle-path/node_modules/.bin'
].concat(PATH.split(pathSplit).map(function (p) {
- return p.replace(/\\/g, "/")
+ return p.replace(/\\/g, '/')
}))
t.same(actual, expect)
t.end()
})
})
-test("clean", function (t) {
- rimraf.sync(link)
+test('cleanup', function (t) {
+ cleanup()
t.end()
})
+
+function cleanup () {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(pkg)
+}
diff --git a/test/tap/lifecycle-path/package.json b/test/tap/lifecycle-path/package.json
deleted file mode 100644
index 42e792e46..000000000
--- a/test/tap/lifecycle-path/package.json
+++ /dev/null
@@ -1 +0,0 @@
-{"name":"glorb","version":"1.2.3","scripts":{"path":"./node-bin/node print-path.js"}}
diff --git a/test/tap/lifecycle-path/print-path.js b/test/tap/lifecycle-path/print-path.js
deleted file mode 100644
index c7ad00b3d..000000000
--- a/test/tap/lifecycle-path/print-path.js
+++ /dev/null
@@ -1 +0,0 @@
-console.log(process.env.PATH)
diff --git a/test/tap/lifecycle-signal.js b/test/tap/lifecycle-signal.js
index ee56e9afc..e28caf72f 100644
--- a/test/tap/lifecycle-signal.js
+++ b/test/tap/lifecycle-signal.js
@@ -1,20 +1,57 @@
-var test = require("tap").test
-var npm = require.resolve("../../bin/npm-cli.js")
+var fs = require('graceful-fs')
+var path = require('path')
+var spawn = require('child_process').spawn
+
+var mkdirp = require('mkdirp')
+var osenv = require('osenv')
+var rimraf = require('rimraf')
+var test = require('tap').test
+
var node = process.execPath
-var spawn = require("child_process").spawn
-var path = require("path")
-var pkg = path.resolve(__dirname, "lifecycle-signal")
+var npm = require.resolve('../../bin/npm-cli.js')
+
+var pkg = path.resolve(__dirname, 'lifecycle-signal')
+
+var json = {
+ name: 'lifecycle-signal',
+ version: '1.2.5',
+ scripts: {
+ preinstall: 'node -e "process.kill(process.pid,\'SIGSEGV\')"'
+ }
+}
+
+test('setup', function (t) {
+ cleanup()
+ mkdirp.sync(pkg)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
-test("lifecycle signal abort", function (t) {
+ process.chdir(pkg)
+ t.end()
+})
+
+test('lifecycle signal abort', function (t) {
// windows does not use lifecycle signals, abort
- if (process.platform === "win32" || process.env.TRAVIS) return t.end()
+ if (process.platform === 'win32' || process.env.TRAVIS) return t.end()
- var child = spawn(node, [npm, "install"], {
+ var child = spawn(node, [npm, 'install'], {
cwd: pkg
})
- child.on("close", function (code, signal) {
+ child.on('close', function (code, signal) {
t.equal(code, null)
- t.equal(signal, "SIGSEGV")
+ t.equal(signal, 'SIGSEGV')
t.end()
})
})
+
+test('cleanup', function (t) {
+ cleanup()
+ t.end()
+})
+
+function cleanup () {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(pkg)
+}
diff --git a/test/tap/lifecycle-signal/package.json b/test/tap/lifecycle-signal/package.json
deleted file mode 100644
index 6b7f2f1c5..000000000
--- a/test/tap/lifecycle-signal/package.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{ "name":"lifecycle-signal",
- "version":"1.2.5",
- "scripts": {"preinstall":"node -e 'process.kill(process.pid,\"SIGSEGV\")'"}}
diff --git a/test/tap/ls-depth-cli.js b/test/tap/ls-depth-cli.js
index b449804cd..77689cbc5 100644
--- a/test/tap/ls-depth-cli.js
+++ b/test/tap/ls-depth-cli.js
@@ -1,75 +1,124 @@
-var common = require("../common-tap")
- , test = require("tap").test
- , path = require("path")
- , rimraf = require("rimraf")
- , osenv = require("osenv")
- , mkdirp = require("mkdirp")
- , pkg = path.resolve(__dirname, "ls-depth")
- , mr = require("npm-registry-mock")
- , opts = {cwd: pkg}
+var fs = require('graceful-fs')
+var path = require('path')
+var mkdirp = require('mkdirp')
+var mr = require('npm-registry-mock')
+var osenv = require('osenv')
+var rimraf = require('rimraf')
+var test = require('tap').test
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg + "/cache")
- rimraf.sync(pkg + "/tmp")
- rimraf.sync(pkg + "/node_modules")
+var common = require('../common-tap')
+
+var pkg = path.resolve(__dirname, 'ls-depth-cli')
+
+var EXEC_OPTS = { cwd: pkg }
+
+var json = {
+ name: 'ls-depth-cli',
+ version: '0.0.0',
+ dependencies: {
+ 'test-package-with-one-dep': '0.0.0'
+ }
}
-test("setup", function (t) {
+test('setup', function (t) {
cleanup()
- mkdirp.sync(pkg + "/cache")
- mkdirp.sync(pkg + "/tmp")
- mr({port : common.port}, function (er, s) {
- var cmd = ["install", "--registry=" + common.registry]
- common.npm(cmd, opts, function (er, c) {
- if (er) throw er
- t.equal(c, 0)
- s.close()
- t.end()
- })
+ mkdirp.sync(pkg)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+ mr({ port: common.port }, function (er, s) {
+ common.npm(
+ [
+ '--registry', common.registry,
+ 'install'
+ ],
+ EXEC_OPTS,
+ function (er, c) {
+ t.ifError(er, 'setup installation ran without issue')
+ t.equal(c, 0)
+ s.close()
+ t.end()
+ }
+ )
})
})
-test("npm ls --depth=0", function (t) {
- common.npm(["ls", "--depth=0"], opts, function (er, c, out) {
- if (er) throw er
- t.equal(c, 0)
- t.has(out, /test-package-with-one-dep@0\.0\.0/
- , "output contains test-package-with-one-dep@0.0.0")
- t.doesNotHave(out, /test-package@0\.0\.0/
- , "output not contains test-package@0.0.0")
- t.end()
- })
+test('npm ls --depth=0', function (t) {
+ common.npm(
+ ['ls', '--depth=0'],
+ EXEC_OPTS,
+ function (er, c, out) {
+ t.ifError(er, 'npm ls ran without issue')
+ t.equal(c, 0, 'ls ran without raising error code')
+ t.has(
+ out,
+ /test-package-with-one-dep@0\.0\.0/,
+ 'output contains test-package-with-one-dep@0.0.0'
+ )
+ t.doesNotHave(
+ out,
+ /test-package@0\.0\.0/,
+ 'output not contains test-package@0.0.0'
+ )
+ t.end()
+ }
+ )
})
-test("npm ls --depth=1", function (t) {
- common.npm(["ls", "--depth=1"], opts, function (er, c, out) {
- if (er) throw er
- t.equal(c, 0)
- t.has(out, /test-package-with-one-dep@0\.0\.0/
- , "output contains test-package-with-one-dep@0.0.0")
- t.has(out, /test-package@0\.0\.0/
- , "output contains test-package@0.0.0")
- t.end()
- })
+test('npm ls --depth=1', function (t) {
+ common.npm(
+ ['ls', '--depth=1'],
+ EXEC_OPTS,
+ function (er, c, out) {
+ t.ifError(er, 'npm ls ran without issue')
+ t.equal(c, 0, 'ls ran without raising error code')
+ t.has(
+ out,
+ /test-package-with-one-dep@0\.0\.0/,
+ 'output contains test-package-with-one-dep@0.0.0'
+ )
+ t.has(
+ out,
+ /test-package@0\.0\.0/,
+ 'output contains test-package@0.0.0'
+ )
+ t.end()
+ }
+ )
})
-test("npm ls --depth=Infinity", function (t) {
+test('npm ls --depth=Infinity', function (t) {
// travis has a preconfigured depth=0, in general we can not depend
// on the default value in all environments, so explictly set it here
- common.npm(["ls", "--depth=Infinity"], opts, function (er, c, out) {
- if (er) throw er
- t.equal(c, 0)
- t.has(out, /test-package-with-one-dep@0\.0\.0/
- , "output contains test-package-with-one-dep@0.0.0")
- t.has(out, /test-package@0\.0\.0/
- , "output contains test-package@0.0.0")
- t.end()
- })
+ common.npm(
+ ['ls', '--depth=Infinity'],
+ EXEC_OPTS,
+ function (er, c, out) {
+ t.ifError(er, 'npm ls ran without issue')
+ t.equal(c, 0, 'ls ran without raising error code')
+ t.has(
+ out,
+ /test-package-with-one-dep@0\.0\.0/,
+ 'output contains test-package-with-one-dep@0.0.0'
+ )
+ t.has(
+ out,
+ /test-package@0\.0\.0/,
+ 'output contains test-package@0.0.0'
+ )
+ t.end()
+ }
+ )
})
-test("cleanup", function (t) {
+test('cleanup', function (t) {
cleanup()
t.end()
})
+
+function cleanup () {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(pkg)
+}
diff --git a/test/tap/ls-depth-unmet.js b/test/tap/ls-depth-unmet.js
index ddd9f3baf..6511cdb33 100644
--- a/test/tap/ls-depth-unmet.js
+++ b/test/tap/ls-depth-unmet.js
@@ -1,96 +1,172 @@
-var common = require("../common-tap")
- , test = require("tap").test
- , path = require("path")
- , rimraf = require("rimraf")
- , osenv = require("osenv")
- , mkdirp = require("mkdirp")
- , pkg = path.resolve(__dirname, "ls-depth-unmet")
- , mr = require("npm-registry-mock")
- , opts = {cwd: pkg}
- , cache = path.resolve(pkg, "cache")
- , tmp = path.resolve(pkg, "tmp")
- , nodeModules = path.resolve(pkg, "node_modules")
+var fs = require('graceful-fs')
+var path = require('path')
+var mkdirp = require('mkdirp')
+var mr = require('npm-registry-mock')
+var osenv = require('osenv')
+var rimraf = require('rimraf')
+var test = require('tap').test
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(cache)
- rimraf.sync(tmp)
- rimraf.sync(nodeModules)
+var common = require('../common-tap')
+
+var pkg = path.resolve(__dirname, 'ls-depth-unmet')
+
+var EXEC_OPTS = { cwd: pkg }
+
+var json = {
+ name: 'ls-depth-umnet',
+ author: 'Evan You',
+ version: '0.0.0',
+ dependencies: {
+ 'test-package-with-one-dep': '0.0.0',
+ underscore: '1.5.1',
+ optimist: '0.6.0'
+ }
}
-test("setup", function (t) {
+test('setup', function (t) {
cleanup()
- mkdirp.sync(cache)
- mkdirp.sync(tmp)
- mr({port : common.port}, function (er, s) {
- var cmd = ["install", "underscore@1.3.1", "mkdirp", "test-package-with-one-dep", "--registry=" + common.registry]
- common.npm(cmd, opts, function (er, c) {
- if (er) throw er
- t.equal(c, 0)
- s.close()
- t.end()
- })
+ mkdirp.sync(pkg)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+ mr({ port: common.port }, function (er, s) {
+ common.npm(
+ [
+ '--registry', common.registry,
+ 'install', 'underscore@1.3.1', 'mkdirp', 'test-package-with-one-dep'
+ ],
+ EXEC_OPTS,
+ function (er, c) {
+ t.ifError(er, 'setup installation ran without issue')
+ t.equal(c, 0)
+ s.close()
+ t.end()
+ }
+ )
})
})
-test("npm ls --depth=0", function (t) {
- common.npm(["ls", "--depth=0"], opts, function (er, c, out) {
- if (er) throw er
- t.equal(c, 1)
- t.has(out, /UNMET DEPENDENCY optimist@0\.6\.0/
- , "output contains optimist@0.6.0 and labeled as unmet dependency")
- t.has(out, /mkdirp@0\.3\.5 extraneous/
- , "output contains mkdirp@0.3.5 and labeled as extraneous")
- t.has(out, /underscore@1\.3\.1 invalid/
- , "output contains underscore@1.3.1 and labeled as invalid")
- t.has(out, /test-package-with-one-dep@0\.0\.0\n/
- , "output contains test-package-with-one-dep@0.0.0 and has no labels")
- t.doesNotHave(out, /test-package@0\.0\.0/
- , "output does not contain test-package@0.0.0 which is at depth=1")
- t.end()
- })
+test('npm ls --depth=0', function (t) {
+ common.npm(
+ ['ls', '--depth=0'],
+ EXEC_OPTS,
+ function (er, c, out) {
+ t.ifError(er, 'setup installation ran without issue')
+ t.equal(c, 1, 'ls barfed')
+ t.has(
+ out,
+ /UNMET DEPENDENCY optimist@0\.6\.0/,
+ 'output contains optimist@0.6.0 and labeled as unmet dependency'
+ )
+ t.has(
+ out,
+ /mkdirp@0\.3\.5 extraneous/,
+ 'output contains mkdirp@0.3.5 and labeled as extraneous'
+ )
+ t.has(
+ out,
+ /underscore@1\.3\.1 invalid/,
+ 'output contains underscore@1.3.1 and labeled as invalid'
+ )
+ t.has(
+ out,
+ /test-package-with-one-dep@0\.0\.0\n/,
+ 'output contains test-package-with-one-dep@0.0.0 and has no labels'
+ )
+ t.doesNotHave(
+ out,
+ /test-package@0\.0\.0/,
+ 'output does not contain test-package@0.0.0 which is at depth=1'
+ )
+ t.end()
+ }
+ )
})
-test("npm ls --depth=1", function (t) {
- common.npm(["ls", "--depth=1"], opts, function (er, c, out) {
- if (er) throw er
- t.equal(c, 1)
- t.has(out, /UNMET DEPENDENCY optimist@0\.6\.0/
- , "output contains optimist@0.6.0 and labeled as unmet dependency")
- t.has(out, /mkdirp@0\.3\.5 extraneous/
- , "output contains mkdirp@0.3.5 and labeled as extraneous")
- t.has(out, /underscore@1\.3\.1 invalid/
- , "output contains underscore@1.3.1 and labeled as invalid")
- t.has(out, /test-package-with-one-dep@0\.0\.0\n/
- , "output contains test-package-with-one-dep@0.0.0 and has no labels")
- t.has(out, /test-package@0\.0\.0/
- , "output contains test-package@0.0.0 which is at depth=1")
- t.end()
- })
+test('npm ls --depth=1', function (t) {
+ common.npm(
+ ['ls', '--depth=1'],
+ EXEC_OPTS,
+ function (er, c, out) {
+ t.ifError(er, 'setup installation ran without issue')
+ t.equal(c, 1, 'ls barfed')
+ t.has(
+ out,
+ /UNMET DEPENDENCY optimist@0\.6\.0/,
+ 'output contains optimist@0.6.0 and labeled as unmet dependency'
+ )
+ t.has(
+ out,
+ /mkdirp@0\.3\.5 extraneous/,
+ 'output contains mkdirp@0.3.5 and labeled as extraneous'
+ )
+ t.has(
+ out,
+ /underscore@1\.3\.1 invalid/,
+ 'output contains underscore@1.3.1 and labeled as invalid'
+ )
+ t.has(
+ out,
+ /test-package-with-one-dep@0\.0\.0\n/,
+ 'output contains test-package-with-one-dep@0.0.0 and has no labels'
+ )
+ t.has(
+ out,
+ /test-package@0\.0\.0/,
+ 'output contains test-package@0.0.0 which is at depth=1'
+ )
+ t.end()
+ }
+ )
})
-test("npm ls --depth=Infinity", function (t) {
+test('npm ls --depth=Infinity', function (t) {
// travis has a preconfigured depth=0, in general we can not depend
// on the default value in all environments, so explictly set it here
- common.npm(["ls", "--depth=Infinity"], opts, function (er, c, out) {
- if (er) throw er
- t.equal(c, 1)
- t.has(out, /UNMET DEPENDENCY optimist@0\.6\.0/
- , "output contains optimist@0.6.0 and labeled as unmet dependency")
- t.has(out, /mkdirp@0\.3\.5 extraneous/
- , "output contains mkdirp@0.3.5 and labeled as extraneous")
- t.has(out, /underscore@1\.3\.1 invalid/
- , "output contains underscore@1.3.1 and labeled as invalid")
- t.has(out, /test-package-with-one-dep@0\.0\.0\n/
- , "output contains test-package-with-one-dep@0.0.0 and has no labels")
- t.has(out, /test-package@0\.0\.0/
- , "output contains test-package@0.0.0 which is at depth=1")
- t.end()
- })
+ common.npm(
+ ['ls', '--depth=Infinity'],
+ EXEC_OPTS,
+ function (er, c, out) {
+ t.ifError(er, 'setup installation ran without issue')
+ t.equal(c, 1, 'ls barfed')
+ t.has(
+ out,
+ /UNMET DEPENDENCY optimist@0\.6\.0/,
+ 'output contains optimist@0.6.0 and labeled as unmet dependency'
+ )
+ t.has(
+ out,
+ /mkdirp@0\.3\.5 extraneous/,
+ 'output contains mkdirp@0.3.5 and labeled as extraneous'
+ )
+ t.has(
+ out,
+ /underscore@1\.3\.1 invalid/,
+ 'output contains underscore@1.3.1 and labeled as invalid'
+ )
+ t.has(
+ out,
+ /test-package-with-one-dep@0\.0\.0\n/,
+ 'output contains test-package-with-one-dep@0.0.0 and has no labels'
+ )
+ t.has(
+ out,
+ /test-package@0\.0\.0/,
+ 'output contains test-package@0.0.0 which is at depth=1'
+ )
+ t.end()
+ }
+ )
})
-test("cleanup", function (t) {
+test('cleanup', function (t) {
cleanup()
t.end()
})
+
+function cleanup () {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(pkg)
+}
diff --git a/test/tap/ls-depth-unmet/package.json b/test/tap/ls-depth-unmet/package.json
deleted file mode 100644
index 391fa8d5b..000000000
--- a/test/tap/ls-depth-unmet/package.json
+++ /dev/null
@@ -1,10 +0,0 @@
-{
- "name": "ls-depth-umnet",
- "author": "Evan You",
- "version": "0.0.0",
- "dependencies": {
- "test-package-with-one-dep": "0.0.0",
- "underscore": "1.5.1",
- "optimist": "0.6.0"
- }
-} \ No newline at end of file
diff --git a/test/tap/ls-depth/package.json b/test/tap/ls-depth/package.json
deleted file mode 100644
index 06f8e48a9..000000000
--- a/test/tap/ls-depth/package.json
+++ /dev/null
@@ -1,8 +0,0 @@
-{
- "author": "Rocko Artischocko",
- "name": "ls-depth",
- "version": "0.0.0",
- "dependencies": {
- "test-package-with-one-dep": "0.0.0"
- }
-}
diff --git a/test/tap/ls-env.js b/test/tap/ls-env.js
index 5ff0618f4..30039b5b3 100644
--- a/test/tap/ls-env.js
+++ b/test/tap/ls-env.js
@@ -1,31 +1,40 @@
-var common = require('../common-tap')
-var test = require('tap').test
+var fs = require('graceful-fs')
var path = require('path')
-var rimraf = require('rimraf')
-var osenv = require('osenv')
+
var mkdirp = require('mkdirp')
-var pkg = path.resolve(__dirname, 'ls-depth')
var mr = require('npm-registry-mock')
-var opts = {cwd: pkg}
+var osenv = require('osenv')
+var rimraf = require('rimraf')
+var test = require('tap').test
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg + '/cache')
- rimraf.sync(pkg + '/tmp')
- rimraf.sync(pkg + '/node_modules')
+var common = require('../common-tap')
+
+var pkg = path.resolve(__dirname, 'ls-depth')
+
+var EXEC_OPTS = { cwd: pkg }
+
+var json = {
+ name: 'ls-env',
+ version: '0.0.0',
+ dependencies: {
+ 'test-package-with-one-dep': '0.0.0'
+ }
}
test('setup', function (t) {
cleanup()
- mkdirp.sync(pkg + '/cache')
- mkdirp.sync(pkg + '/tmp')
+ mkdirp.sync(pkg)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
mr({port: common.port}, function (er, s) {
common.npm(
[
- 'install',
- '--registry', common.registry
+ '--registry', common.registry,
+ 'install'
],
- opts,
+ EXEC_OPTS,
function (er, c) {
t.ifError(er, 'install ran without issue')
t.equal(c, 0)
@@ -37,7 +46,7 @@ test('setup', function (t) {
})
test('npm ls --dev', function (t) {
- common.npm(['ls', '--dev'], opts, function (er, code, stdout) {
+ common.npm(['ls', '--dev'], EXEC_OPTS, function (er, code, stdout) {
t.ifError(er, 'ls --dev ran without issue')
t.equal(code, 0)
t.has(stdout, /(empty)/, 'output contains (empty)')
@@ -46,7 +55,7 @@ test('npm ls --dev', function (t) {
})
test('npm ls --production', function (t) {
- common.npm(['ls', '--production'], opts, function (er, code, stdout) {
+ common.npm(['ls', '--production'], EXEC_OPTS, function (er, code, stdout) {
t.ifError(er, 'ls --production ran without issue')
t.notOk(code, 'npm exited ok')
t.has(
@@ -59,7 +68,7 @@ test('npm ls --production', function (t) {
})
test('npm ls --prod', function (t) {
- common.npm(['ls', '--prod'], opts, function (er, code, stdout) {
+ common.npm(['ls', '--prod'], EXEC_OPTS, function (er, code, stdout) {
t.ifError(er, 'ls --prod ran without issue')
t.notOk(code, 'npm exited ok')
t.has(
@@ -75,3 +84,8 @@ test('cleanup', function (t) {
cleanup()
t.end()
})
+
+function cleanup () {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(pkg)
+}
diff --git a/test/tap/optional-metadep-rollback-collision.js b/test/tap/optional-metadep-rollback-collision.js
index f8645840b..929c4fc0f 100644
--- a/test/tap/optional-metadep-rollback-collision.js
+++ b/test/tap/optional-metadep-rollback-collision.js
@@ -1,56 +1,237 @@
-var test = require("tap").test
-var rimraf = require("rimraf")
-var common = require("../common-tap.js")
-var path = require("path")
-var fs = require("fs")
-
-var pkg = path.resolve(__dirname, "optional-metadep-rollback-collision")
-var nm = path.resolve(pkg, "node_modules")
-var cache = path.resolve(pkg, "cache")
-var pidfile = path.resolve(pkg, "child.pid")
-
-test("setup", function (t) {
+var fs = require('graceful-fs')
+var path = require('path')
+
+var mkdirp = require('mkdirp')
+var osenv = require('osenv')
+var rimraf = require('rimraf')
+var test = require('tap').test
+
+var common = require('../common-tap.js')
+
+var pkg = path.resolve(__dirname, 'optional-metadep-rollback-collision')
+var deps = path.resolve(pkg, 'deps')
+var nm = path.resolve(pkg, 'node_modules')
+var cache = path.resolve(pkg, 'cache')
+var pidfile = path.resolve(pkg, 'child.pid')
+
+var json = {
+ name: 'optional-metadep-rollback-collision',
+ version: '1.0.0',
+ description: 'let\'s just see about that race condition',
+ optionalDependencies: {
+ opdep: 'file:./deps/opdep'
+ }
+}
+
+var d1 = {
+ name: 'd1',
+ version: '1.0.0',
+ description: 'I FAIL CONSTANTLY',
+ scripts: {
+ preinstall: 'sleep 1'
+ },
+ dependencies: {
+ foo: 'http://localhost:8080/'
+ }
+}
+
+var d2 = {
+ name: 'd2',
+ version: '1.0.0',
+ description: 'how do you *really* know you exist?',
+ scripts: {
+ postinstall: 'node blart.js'
+ },
+ dependencies: {
+ 'graceful-fs': '^3.0.2',
+ mkdirp: '^0.5.0',
+ rimraf: '^2.2.8'
+ }
+}
+
+var opdep = {
+ name: 'opdep',
+ version: '1.0.0',
+ description: 'To explode, of course!',
+ main: 'index.js',
+ scripts: {
+ preinstall: 'node bad-server.js'
+ },
+ dependencies: {
+ d1: 'file:../d1',
+ d2: 'file:../d2'
+ }
+}
+
+test('setup', function (t) {
cleanup()
+
+ mkdirp.sync(pkg)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+
+ mkdirp.sync(path.join(deps, 'd1'))
+ fs.writeFileSync(
+ path.join(deps, 'd1', 'package.json'),
+ JSON.stringify(d1, null, 2)
+ )
+
+ mkdirp.sync(path.join(deps, 'd2'))
+ fs.writeFileSync(
+ path.join(deps, 'd2', 'package.json'),
+ JSON.stringify(d2, null, 2)
+ )
+ fs.writeFileSync(path.join(deps, 'd2', 'blart.js'), blart)
+
+ mkdirp.sync(path.join(deps, 'opdep'))
+ fs.writeFileSync(
+ path.join(deps, 'opdep', 'package.json'),
+ JSON.stringify(opdep, null, 2)
+ )
+ fs.writeFileSync(path.join(deps, 'opdep', 'bad-server.js'), badServer)
+
t.end()
})
-test("go go test racer", function (t) {
- common.npm(["install", "--prefix=" + pkg, "--fetch-retries=0", "--cache=" + cache], {
- cwd: pkg,
- env: {
- PATH: process.env.PATH,
- Path: process.env.Path,
- "npm_config_loglevel": "silent"
+test('go go test racer', function (t) {
+ common.npm(
+ [
+ '--prefix', pkg,
+ '--fetch-retries', '0',
+ '--loglevel', 'silent',
+ '--cache', cache,
+ 'install'
+ ],
+ {
+ cwd: pkg,
+ env: {
+ PATH: process.env.PATH,
+ Path: process.env.Path
+ },
+ stdio: [0, 'pipe', 2]
},
- stdio: [ 0, "pipe", 2 ]
- }, function (er, code, sout) {
- if (er) throw er
- t.notOk(code, "npm install exited with code 0")
- t.equal(sout, "ok\nok\n")
- t.notOk(/not ok/.test(sout), "should not contain the string 'not ok'")
- t.end()
- })
+ function (er, code, stdout, stderr) {
+ t.ifError(er, 'install ran to completion without error')
+ t.notOk(code, 'npm install exited with code 0')
+
+ t.equal(stdout, 'ok\nok\n')
+ t.notOk(/not ok/.test(stdout), 'should not contain the string \'not ok\'')
+ t.end()
+ }
+ )
})
-test("verify results", function (t) {
+test('verify results', function (t) {
t.throws(function () {
fs.statSync(nm)
})
t.end()
})
-test("cleanup", function (t) {
+test('cleanup', function (t) {
cleanup()
t.end()
})
function cleanup () {
+ process.chdir(osenv.tmpdir())
try {
var pid = +fs.readFileSync(pidfile)
- process.kill(pid, "SIGKILL")
+ process.kill(pid, 'SIGKILL')
} catch (er) {}
- rimraf.sync(cache)
- rimraf.sync(nm)
- rimraf.sync(pidfile)
+ rimraf.sync(pkg)
}
+
+var badServer = function () {/*
+var createServer = require('http').createServer
+var spawn = require('child_process').spawn
+var fs = require('fs')
+var path = require('path')
+var pidfile = path.resolve(__dirname, '..', '..', 'child.pid')
+
+if (process.argv[2]) {
+ console.log('ok')
+ createServer(function (req, res) {
+ setTimeout(function () {
+ res.writeHead(404)
+ res.end()
+ }, 1000)
+ this.close()
+ }).listen(8080)
+} else {
+ var child = spawn(
+ process.execPath,
+ [__filename, 'whatever'],
+ {
+ stdio: [0, 1, 2],
+ detached: true
+ }
+ )
+ child.unref()
+
+ // kill any prior children, if existing.
+ try {
+ var pid = +fs.readFileSync(pidfile)
+ process.kill(pid, 'SIGKILL')
+ } catch (er) {}
+
+ fs.writeFileSync(pidfile, child.pid + '\n')
+}
+*/}.toString().split('\n').slice(1, -1).join('\n')
+
+var blart = function () {/*
+var rando = require('crypto').randomBytes
+var resolve = require('path').resolve
+
+var mkdirp = require('mkdirp')
+var rimraf = require('rimraf')
+var writeFile = require('graceful-fs').writeFile
+
+var BASEDIR = resolve(__dirname, 'arena')
+
+var keepItGoingLouder = {}
+var writers = 0
+var errors = 0
+
+function gensym () { return rando(16).toString('hex') }
+
+function writeAlmostForever (filename) {
+ if (!keepItGoingLouder[filename]) {
+ writers--
+ if (writers < 1) return done()
+ } else {
+ writeFile(filename, keepItGoingLouder[filename], function (err) {
+ if (err) errors++
+
+ writeAlmostForever(filename)
+ })
+ }
+}
+
+function done () {
+ rimraf(BASEDIR, function () {
+ if (errors > 0) console.log('not ok - %d errors', errors)
+ else console.log('ok')
+ })
+}
+
+mkdirp(BASEDIR, function go () {
+ for (var i = 0; i < 16; i++) {
+ var filename = resolve(BASEDIR, gensym() + '.txt')
+
+ keepItGoingLouder[filename] = ''
+ for (var j = 0; j < 512; j++) keepItGoingLouder[filename] += filename
+
+ writers++
+ writeAlmostForever(filename)
+ }
+
+ setTimeout(function viktor () {
+ // kill all the writers
+ keepItGoingLouder = {}
+ }, 3 * 1000)
+})
+*/}.toString().split('\n').slice(1, -1).join('\n')
diff --git a/test/tap/optional-metadep-rollback-collision/deps/d1/package.json b/test/tap/optional-metadep-rollback-collision/deps/d1/package.json
deleted file mode 100644
index 26cd1dea3..000000000
--- a/test/tap/optional-metadep-rollback-collision/deps/d1/package.json
+++ /dev/null
@@ -1,13 +0,0 @@
-{
- "name": "d1",
- "version": "1.0.0",
- "description": "I FAIL CONSTANTLY",
- "scripts": {
- "preinstall": "sleep 1"
- },
- "dependencies": {
- "foo": "http://localhost:8080/"
- },
- "author": "Forrest L Norvell <ogd@aoaioxxysz.net>",
- "license": "ISC"
-}
diff --git a/test/tap/optional-metadep-rollback-collision/deps/d2/blart.js b/test/tap/optional-metadep-rollback-collision/deps/d2/blart.js
deleted file mode 100644
index c69b8a5d0..000000000
--- a/test/tap/optional-metadep-rollback-collision/deps/d2/blart.js
+++ /dev/null
@@ -1,52 +0,0 @@
-var rando = require("crypto").randomBytes
-var resolve = require("path").resolve
-
-var mkdirp = require("mkdirp")
-var rimraf = require("rimraf")
-var writeFile = require("graceful-fs").writeFile
-
-var BASEDIR = resolve(__dirname, "arena")
-
-var keepItGoingLouder = {}
-var writers = 0
-var errors = 0
-
-function gensym() { return rando(16).toString("hex") }
-
-function writeAlmostForever(filename) {
- if (!keepItGoingLouder[filename]) {
- writers--
- if (writers < 1) return done()
- }
- else {
- writeFile(filename, keepItGoingLouder[filename], function (err) {
- if (err) errors++
-
- writeAlmostForever(filename)
- })
- }
-}
-
-function done() {
- rimraf(BASEDIR, function () {
- if (errors > 0) console.log("not ok - %d errors", errors)
- else console.log("ok")
- })
-}
-
-mkdirp(BASEDIR, function go() {
- for (var i = 0; i < 16; i++) {
- var filename = resolve(BASEDIR, gensym() + ".txt")
-
- keepItGoingLouder[filename] = ""
- for (var j = 0; j < 512; j++) keepItGoingLouder[filename] += filename
-
- writers++
- writeAlmostForever(filename)
- }
-
- setTimeout(function viktor() {
- // kill all the writers
- keepItGoingLouder = {}
- }, 3 * 1000)
-})
diff --git a/test/tap/optional-metadep-rollback-collision/deps/d2/package.json b/test/tap/optional-metadep-rollback-collision/deps/d2/package.json
deleted file mode 100644
index 08eeba4f7..000000000
--- a/test/tap/optional-metadep-rollback-collision/deps/d2/package.json
+++ /dev/null
@@ -1,15 +0,0 @@
-{
- "name": "d2",
- "version": "1.0.0",
- "description": "how do you *really* know you exist?",
- "scripts": {
- "postinstall": "node blart.js"
- },
- "dependencies": {
- "graceful-fs": "^3.0.2",
- "mkdirp": "^0.5.0",
- "rimraf": "^2.2.8"
- },
- "author": "Forrest L Norvell <ogd@aoaioxxysz.net>",
- "license": "ISC"
-}
diff --git a/test/tap/optional-metadep-rollback-collision/deps/opdep/bad-server.js b/test/tap/optional-metadep-rollback-collision/deps/opdep/bad-server.js
deleted file mode 100644
index 4818884c4..000000000
--- a/test/tap/optional-metadep-rollback-collision/deps/opdep/bad-server.js
+++ /dev/null
@@ -1,35 +0,0 @@
-var createServer = require("http").createServer
-var spawn = require("child_process").spawn
-var fs = require("fs")
-var path = require("path")
-var pidfile = path.resolve(__dirname, "..", "..", "child.pid")
-
-if (process.argv[2]) {
- console.log("ok")
- createServer(function (req, res) {
- setTimeout(function () {
- res.writeHead(404)
- res.end()
- }, 1000)
- this.close()
- }).listen(8080)
-}
-else {
- var child = spawn(
- process.execPath,
- [__filename, "whatever"],
- {
- stdio: [0, 1, 2],
- detached: true
- }
- )
- child.unref()
-
- // kill any prior children, if existing.
- try {
- var pid = +fs.readFileSync(pidfile)
- process.kill(pid, "SIGKILL")
- } catch (er) {}
-
- fs.writeFileSync(pidfile, child.pid + "\n")
-}
diff --git a/test/tap/optional-metadep-rollback-collision/deps/opdep/package.json b/test/tap/optional-metadep-rollback-collision/deps/opdep/package.json
deleted file mode 100644
index 3289c123e..000000000
--- a/test/tap/optional-metadep-rollback-collision/deps/opdep/package.json
+++ /dev/null
@@ -1,15 +0,0 @@
-{
- "name": "opdep",
- "version": "1.0.0",
- "description": "To explode, of course!",
- "main": "index.js",
- "scripts": {
- "preinstall": "node bad-server.js"
- },
- "dependencies": {
- "d1": "file:../d1",
- "d2": "file:../d2"
- },
- "author": "Forrest L Norvell <ogd@aoaioxxysz.net>",
- "license": "ISC"
-}
diff --git a/test/tap/optional-metadep-rollback-collision/package.json b/test/tap/optional-metadep-rollback-collision/package.json
deleted file mode 100644
index 0d812a6e0..000000000
--- a/test/tap/optional-metadep-rollback-collision/package.json
+++ /dev/null
@@ -1,10 +0,0 @@
-{
- "name": "optional-metadep-rollback-collision",
- "version": "1.0.0",
- "description": "let's just see about that race condition",
- "optionalDependencies": {
- "opdep": "file:./deps/opdep"
- },
- "author": "Forrest L Norvell <ogd@aoaioxxysz.net>",
- "license": "ISC"
-}
diff --git a/test/tap/outdated-color.js b/test/tap/outdated-color.js
index 1a04980a3..b35070c45 100644
--- a/test/tap/outdated-color.js
+++ b/test/tap/outdated-color.js
@@ -1,44 +1,63 @@
-var common = require("../common-tap.js")
-var test = require("tap").test
-var mkdirp = require("mkdirp")
-var rimraf = require("rimraf")
-var mr = require("npm-registry-mock")
-var path = require("path")
-
-var pkg = path.resolve(__dirname, "outdated")
-var cache = path.resolve(pkg, "cache")
-mkdirp.sync(cache)
-
-var EXEC_OPTS = {
- cwd: pkg
-}
+var fs = require('graceful-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 common = require('../common-tap.js')
+
+var pkg = path.resolve(__dirname, 'outdated-color')
-function hasControlCodes(str) {
+var EXEC_OPTS = { cwd: pkg }
+
+function hasControlCodes (str) {
return str.length !== ansiTrim(str).length
}
function ansiTrim (str) {
- var r = new RegExp("\x1b(?:\\[(?:\\d+[ABCDEFGJKSTm]|\\d+;\\d+[Hfm]|" +
- "\\d+;\\d+;\\d+m|6n|s|u|\\?25[lh])|\\w)", "g")
- return str.replace(r, "")
+ var r = new RegExp('\x1b(?:\\[(?:\\d+[ABCDEFGJKSTm]|\\d+;\\d+[Hfm]|' +
+ '\\d+;\\d+;\\d+m|6n|s|u|\\?25[lh])|\\w)', 'g')
+ return str.replace(r, '')
+}
+
+var json = {
+ name: 'outdated-color',
+ description: 'fixture',
+ version: '0.0.1',
+ dependencies: {
+ underscore: '1.3.1'
+ }
}
+test('setup', function (t) {
+ cleanup()
+ mkdirp.sync(pkg)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+
+ process.chdir(pkg)
+ t.end()
+})
+
// note hard to automate tests for color = true
// as npm kills the color config when it detects
-// it"s not running in a tty
-test("does not use ansi styling", function (t) {
+// it's not running in a tty
+test('does not use ansi styling', function (t) {
t.plan(4)
- mr({port : common.port}, function (er, s) { // create mock registry.
+ mr({ port: common.port }, function (er, s) { // create mock registry.
common.npm(
[
- "outdated",
- "--registry", common.registry,
- "underscore"
+ '--registry', common.registry,
+ 'outdated', 'underscore'
],
EXEC_OPTS,
function (err, code, stdout) {
t.ifError(err)
- t.notOk(code, "npm outdated exited with code 0")
+ t.notOk(code, 'npm outdated exited with code 0')
t.ok(stdout, stdout.length)
t.ok(!hasControlCodes(stdout))
s.close()
@@ -46,7 +65,11 @@ test("does not use ansi styling", function (t) {
})
})
-test("cleanup", function (t) {
- rimraf.sync(cache)
+test('cleanup', function (t) {
+ cleanup()
t.end()
})
+
+function cleanup () {
+ rimraf.sync(pkg)
+}
diff --git a/test/tap/outdated-depth.js b/test/tap/outdated-depth.js
index 4e1aca0e7..2f0612791 100644
--- a/test/tap/outdated-depth.js
+++ b/test/tap/outdated-depth.js
@@ -1,38 +1,56 @@
-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")
- , cache = path.resolve(pkg, "cache")
- , nodeModules = path.resolve(pkg, "node_modules")
+var fs = require('graceful-fs')
+var path = require('path')
-function cleanup () {
- rimraf.sync(nodeModules)
- rimraf.sync(cache)
+var mkdirp = require('mkdirp')
+var mr = require('npm-registry-mock')
+var osenv = require('osenv')
+var rimraf = require('rimraf')
+var test = require('tap').test
+
+var npm = require('../../')
+var common = require('../common-tap')
+
+var pkg = path.resolve(__dirname, 'outdated-depth')
+
+var json = {
+ name: 'outdated-depth',
+ version: '1.2.3',
+ dependencies: {
+ underscore: '1.3.1',
+ 'npm-test-peer-deps': '0.0.0'
+ }
}
-test("outdated depth zero", function (t) {
+test('setup', function (t) {
+ cleanup()
+ mkdirp.sync(pkg)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+ process.chdir(pkg)
+
+ t.end()
+})
+
+test('outdated depth zero', function (t) {
var expected = [
pkg,
- "underscore",
- "1.3.1",
- "1.3.1",
- "1.5.1",
- "1.3.1"
+ 'underscore',
+ '1.3.1',
+ '1.3.1',
+ '1.5.1',
+ '1.3.1'
]
- process.chdir(pkg)
-
- mr({port : common.port}, function (er, s) {
- npm.load({
- cache: cache
- , loglevel: "silent"
- , registry: common.registry
- }
- , function () {
- npm.install(".", function (er) {
+ mr({ port: common.port }, function (er, s) {
+ npm.load(
+ {
+ loglevel: 'silent',
+ registry: common.registry
+ },
+ function () {
+ npm.install('.', function (er) {
if (er) throw new Error(er)
npm.outdated(function (err, d) {
if (err) throw new Error(err)
@@ -46,7 +64,12 @@ test("outdated depth zero", function (t) {
})
})
-test("cleanup", function (t) {
+test('cleanup', function (t) {
cleanup()
t.end()
})
+
+function cleanup () {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(pkg)
+}
diff --git a/test/tap/outdated-depth/README.md b/test/tap/outdated-depth/README.md
deleted file mode 100644
index aca67ff17..000000000
--- a/test/tap/outdated-depth/README.md
+++ /dev/null
@@ -1 +0,0 @@
-# just a test
diff --git a/test/tap/outdated-depth/index.js b/test/tap/outdated-depth/index.js
deleted file mode 100644
index 33c1891f8..000000000
--- a/test/tap/outdated-depth/index.js
+++ /dev/null
@@ -1 +0,0 @@
-module.exports = true
diff --git a/test/tap/outdated-depth/package.json b/test/tap/outdated-depth/package.json
deleted file mode 100644
index aed35fe03..000000000
--- a/test/tap/outdated-depth/package.json
+++ /dev/null
@@ -1,11 +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"
-}
diff --git a/test/tap/outdated-include-devdependencies.js b/test/tap/outdated-include-devdependencies.js
index 9425d5b8a..7ab008843 100644
--- a/test/tap/outdated-include-devdependencies.js
+++ b/test/tap/outdated-include-devdependencies.js
@@ -1,22 +1,43 @@
-var common = require("../common-tap.js")
-var test = require("tap").test
-var npm = require("../../")
-var mkdirp = require("mkdirp")
-var rimraf = require("rimraf")
-var mr = require("npm-registry-mock")
-var path = require("path")
+var fs = require('graceful-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 npm = require('../../')
+var common = require('../common-tap.js')
// config
-var pkg = path.resolve(__dirname, "outdated-include-devdependencies")
-var cache = path.resolve(pkg, "cache")
-mkdirp.sync(cache)
+var pkg = path.resolve(__dirname, 'outdated-include-devdependencies')
+var cache = path.resolve(pkg, 'cache')
-test("includes devDependencies in outdated", function (t) {
+var json = {
+ author: 'Rocko Artischocko',
+ name: 'ignore-shrinkwrap',
+ version: '0.0.0',
+ devDependencies: {
+ underscore: '>=1.3.1'
+ }
+}
+
+test('setup', function (t) {
+ cleanup()
+ mkdirp.sync(cache)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+ t.end()
+})
+
+test('includes devDependencies in outdated', function (t) {
process.chdir(pkg)
- mr({port : common.port}, function (er, s) {
- npm.load({cache: cache, registry: common.registry}, function () {
+ mr({ port: common.port }, function (er, s) {
+ npm.load({ cache: cache, registry: common.registry }, function () {
npm.outdated(function (er, d) {
- t.equal("1.5.1", d[0][3])
+ t.equal('1.5.1', d[0][3])
s.close()
t.end()
})
@@ -24,7 +45,11 @@ test("includes devDependencies in outdated", function (t) {
})
})
-test("cleanup", function (t) {
- rimraf.sync(cache)
+test('cleanup', function (t) {
+ cleanup()
t.end()
})
+
+function cleanup () {
+ rimraf.sync(pkg)
+}
diff --git a/test/tap/outdated-include-devdependencies/package.json b/test/tap/outdated-include-devdependencies/package.json
deleted file mode 100644
index 70998419b..000000000
--- a/test/tap/outdated-include-devdependencies/package.json
+++ /dev/null
@@ -1,8 +0,0 @@
-{
- "author": "Rocko Artischocko",
- "name": "ignore-shrinkwrap",
- "version": "0.0.0",
- "devDependencies": {
- "underscore": ">=1.3.1"
- }
-} \ No newline at end of file
diff --git a/test/tap/outdated-json.js b/test/tap/outdated-json.js
index e02675afe..2dd6867e3 100644
--- a/test/tap/outdated-json.js
+++ b/test/tap/outdated-json.js
@@ -1,67 +1,99 @@
-var common = require("../common-tap.js")
- , test = require("tap").test
- , rimraf = require("rimraf")
- , npm = require("../../")
- , mr = require("npm-registry-mock")
- , path = require("path")
- , osenv = require("osenv")
- , spawn = require("child_process").spawn
- , node = process.execPath
- , npmc = require.resolve("../../")
- , pkg = path.resolve(__dirname, "outdated-new-versions")
- , args = [ npmc
- , "outdated"
- , "--json"
- , "--silent"
- , "--registry=" + common.registry
- , "--cache=" + pkg + "/cache"
- ]
+var fs = require('graceful-fs')
+var path = require('path')
-var expected = { underscore:
- { current: "1.3.3"
- , wanted: "1.3.3"
- , latest: "1.5.1"
- , location: "node_modules" + path.sep + "underscore"
- }
- , request:
- { current: "0.9.5"
- , wanted: "0.9.5"
- , latest: "2.27.0"
- , location: "node_modules" + path.sep + "request"
- }
- }
+var mkdirp = require('mkdirp')
+var mr = require('npm-registry-mock')
+var osenv = require('osenv')
+var rimraf = require('rimraf')
+var test = require('tap').test
-test("it should log json data", function (t) {
+var common = require('../common-tap.js')
+var server
+
+var pkg = path.resolve(__dirname, 'outdated-json')
+
+var EXEC_OPTS = { cwd: pkg }
+
+var json = {
+ name: 'outdated-json',
+ author: 'Rockbert',
+ version: '0.0.0',
+ dependencies: {
+ underscore: '~1.3.1'
+ },
+ devDependencies: {
+ request: '~0.9.0'
+ }
+}
+
+var expected = {
+ underscore: {
+ current: '1.3.3',
+ wanted: '1.3.3',
+ latest: '1.5.1',
+ location: 'node_modules' + path.sep + 'underscore'
+ },
+ request: {
+ current: '0.9.5',
+ wanted: '0.9.5',
+ latest: '2.27.0',
+ location: 'node_modules' + path.sep + 'request'
+ }
+}
+
+test('setup', function (t) {
cleanup()
+ mkdirp.sync(pkg)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
process.chdir(pkg)
+ mr({ port: common.port }, function (er, s) {
+ t.ifError(er, 'mock registry should never fail to start')
+ server = s
+ common.npm(
+ [
+ '--registry', common.registry,
+ '--silent',
+ 'install'
+ ],
+ EXEC_OPTS,
+ function (err, code) {
+ t.ifError(err, 'npm install ran without issue')
+ t.notOk(code, 'npm install ran without raising error code')
- mr({port : common.port}, function (er, s) {
- npm.load({
- cache: pkg + "/cache",
- loglevel: "silent",
- registry: common.registry }
- , function () {
- npm.install(".", function (err) {
- t.ifError(err, "error should not exist")
- var child = spawn(node, args)
- , out = ""
- child.stdout
- .on("data", function (buf) {
- out += buf.toString()
- })
- .pipe(process.stdout)
- child.on("exit", function () {
- out = JSON.parse(out)
- t.deepEqual(out, expected)
- s.close()
- t.end()
- })
- })
- })
+ t.end()
+ }
+ )
})
})
-test("cleanup", function (t) {
+test('it should log json data', function (t) {
+ common.npm(
+ [
+ '--registry', common.registry,
+ '--silent',
+ '--json',
+ 'outdated'
+ ],
+ EXEC_OPTS,
+ function (err, code, stdout) {
+ t.ifError(err, 'npm outdated ran without issue')
+ t.notOk(code, 'npm outdated ran without raising error code')
+ var out
+ t.doesNotThrow(function () {
+ out = JSON.parse(stdout)
+ }, 'output correctly parsed as JSON')
+ t.deepEqual(out, expected)
+
+ t.end()
+ }
+ )
+})
+
+test('cleanup', function (t) {
+ server.close()
cleanup()
t.end()
})
@@ -69,6 +101,5 @@ test("cleanup", function (t) {
function cleanup () {
// windows fix for locked files
process.chdir(osenv.tmpdir())
- rimraf.sync(pkg + "/node_modules")
- rimraf.sync(pkg + "/cache")
+ rimraf.sync(pkg)
}
diff --git a/test/tap/outdated-long.js b/test/tap/outdated-long.js
index db011ab65..87e1f23b2 100644
--- a/test/tap/outdated-long.js
+++ b/test/tap/outdated-long.js
@@ -1,70 +1,101 @@
-var path = require("path")
+var fs = require('graceful-fs')
+var path = require('path')
-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 npm = require("../../")
+var common = require('../common-tap.js')
+var npm = require('../../')
// config
-var pkg = path.resolve(__dirname, "outdated")
-var cache = path.resolve(pkg, "cache")
-var nodeModules = path.resolve(pkg, "node_modules")
+var pkg = path.resolve(__dirname, 'outdated-long')
+var cache = path.resolve(pkg, 'cache')
-test("it should not throw", function (t) {
+var json = {
+ name: 'outdated-long',
+ description: 'fixture',
+ version: '0.0.1',
+ dependencies: {
+ underscore: '1.3.1'
+ }
+}
+
+test('setup', function (t) {
cleanup()
+ mkdirp.sync(cache)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+
process.chdir(pkg)
+ t.end()
+})
+test('it should not throw', function (t) {
var originalLog = console.log
+
var output = []
- var expOut = [ path.resolve(__dirname, "outdated/node_modules/underscore"),
- path.resolve(__dirname, "outdated/node_modules/underscore")
- + ":underscore@1.3.1"
- + ":underscore@1.3.1"
- + ":underscore@1.5.1"
- + ":dependencies" ]
- var expData = [ [ path.resolve(__dirname, "outdated"),
- "underscore",
- "1.3.1",
- "1.3.1",
- "1.5.1",
- "1.3.1",
- "dependencies" ] ]
+ var expOut = [
+ path.resolve(pkg, 'node_modules', 'underscore'),
+ path.resolve(pkg, 'node_modules', 'underscore') +
+ ':underscore@1.3.1' +
+ ':underscore@1.3.1' +
+ ':underscore@1.5.1' +
+ ':dependencies'
+ ]
+
+ var expData = [
+ [
+ pkg,
+ 'underscore',
+ '1.3.1',
+ '1.3.1',
+ '1.5.1',
+ '1.3.1',
+ 'dependencies'
+ ]
+ ]
console.log = function () {
output.push.apply(output, arguments)
}
- mr({port : common.port}, function (er, s) {
- npm.load({
- cache : "cache",
- loglevel : "silent",
- parseable : true,
- registry : common.registry
- },
- function () {
- npm.install(".", function (err) {
- t.ifError(err, "install success")
- npm.config.set("long", true)
- npm.outdated(function (er, d) {
- t.ifError(er, "outdated success")
- console.log = originalLog
- t.same(output, expOut)
- t.same(d, expData)
- s.close()
- t.end()
+ mr({ port: common.port }, function (er, s) {
+ npm.load(
+ {
+ cache: 'cache',
+ loglevel: 'silent',
+ parseable: true,
+ registry: common.registry
+ },
+ function () {
+ npm.install('.', function (err) {
+ t.ifError(err, 'install success')
+ npm.config.set('long', true)
+ npm.outdated(function (er, d) {
+ t.ifError(er, 'outdated success')
+
+ console.log = originalLog
+
+ t.same(output, expOut)
+ t.same(d, expData)
+
+ s.close()
+ t.end()
+ })
})
- })
- })
+ }
+ )
})
})
-test("cleanup", function (t) {
+test('cleanup', function (t) {
cleanup()
t.end()
})
function cleanup () {
- rimraf.sync(nodeModules)
- rimraf.sync(cache)
+ rimraf.sync(pkg)
}
diff --git a/test/tap/outdated-new-versions.js b/test/tap/outdated-new-versions.js
index 0608824dc..c6fbd426d 100644
--- a/test/tap/outdated-new-versions.js
+++ b/test/tap/outdated-new-versions.js
@@ -1,29 +1,49 @@
-var common = require("../common-tap.js")
-var test = require("tap").test
-var npm = require("../../")
-var mkdirp = require("mkdirp")
-var rimraf = require("rimraf")
-var path = require("path")
+var fs = require('graceful-fs')
+var path = require('path')
-var mr = require("npm-registry-mock")
+var mkdirp = require('mkdirp')
+var mr = require('npm-registry-mock')
+var rimraf = require('rimraf')
+var test = require('tap').test
-var pkg = path.resolve(__dirname, "outdated-new-versions")
-var cache = path.resolve(pkg, "cache")
-mkdirp.sync(cache)
+var common = require('../common-tap.js')
+var npm = require('../../')
+var pkg = path.resolve(__dirname, 'outdated-new-versions')
+var cache = path.resolve(pkg, 'cache')
-test("dicovers new versions in outdated", function (t) {
+var json = {
+ name: 'new-versions-with-outdated',
+ author: 'Rockbert',
+ version: '0.0.0',
+ dependencies: {
+ underscore: '~1.3.1'
+ },
+ devDependencies: {
+ request: '~0.9.0'
+ }
+}
+
+test('setup', function (t) {
+ cleanup()
+ mkdirp.sync(cache)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+ t.end()
+})
+
+test('dicovers new versions in outdated', function (t) {
process.chdir(pkg)
t.plan(2)
- mr({port : common.port}, function (er, s) {
- npm.load({cache: cache, registry: common.registry}, function () {
+ mr({ port: common.port }, function (er, s) {
+ npm.load({ cache: cache, registry: common.registry }, function () {
npm.outdated(function (er, d) {
for (var i = 0; i < d.length; i++) {
- if (d[i][1] === "underscore")
- t.equal("1.5.1", d[i][4])
- if (d[i][1] === "request")
- t.equal("2.27.0", d[i][4])
+ if (d[i][1] === 'underscore') t.equal('1.5.1', d[i][4])
+ if (d[i][1] === 'request') t.equal('2.27.0', d[i][4])
}
s.close()
t.end()
@@ -32,7 +52,11 @@ test("dicovers new versions in outdated", function (t) {
})
})
-test("cleanup", function (t) {
- rimraf.sync(cache)
+test('cleanup', function (t) {
+ cleanup()
t.end()
})
+
+function cleanup () {
+ rimraf.sync(pkg)
+}
diff --git a/test/tap/outdated-new-versions/package.json b/test/tap/outdated-new-versions/package.json
deleted file mode 100644
index 2bfcdc5ab..000000000
--- a/test/tap/outdated-new-versions/package.json
+++ /dev/null
@@ -1,11 +0,0 @@
-{
- "name": "new-versions-with-outdated",
- "author": "Rockbert",
- "version": "0.0.0",
- "dependencies": {
- "underscore": "~1.3.1"
- },
- "devDependencies": {
- "request": "~0.9.0"
- }
-}
diff --git a/test/tap/outdated.js b/test/tap/outdated.js
index 8e7ebe568..8bda330bd 100644
--- a/test/tap/outdated.js
+++ b/test/tap/outdated.js
@@ -1,64 +1,98 @@
-var common = require("../common-tap.js")
-var test = require("tap").test
-var rimraf = require("rimraf")
-var npm = require("../../")
-var path = require("path")
+var fs = require('graceful-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 npm = require('../../')
+var common = require('../common-tap.js')
-var mr = require("npm-registry-mock")
// config
-var pkg = path.resolve(__dirname, "outdated")
-var cache = path.resolve(pkg, "cache")
-var nodeModules = path.resolve(pkg, "node_modules")
+var pkg = path.resolve(__dirname, 'outdated')
+var cache = path.resolve(pkg, 'cache')
-test("it should not throw", function (t) {
+var json = {
+ name: 'outdated',
+ description: 'fixture',
+ version: '0.0.1',
+ dependencies: {
+ underscore: '1.3.1'
+ }
+}
+
+test('setup', function (t) {
cleanup()
+ mkdirp.sync(cache)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+
process.chdir(pkg)
+ t.end()
+})
+test('it should not throw', function (t) {
var originalLog = console.log
+
var output = []
- var expOut = [ path.resolve(__dirname, "outdated/node_modules/underscore")
- , path.resolve(__dirname, "outdated/node_modules/underscore")
- + ":underscore@1.3.1"
- + ":underscore@1.3.1"
- + ":underscore@1.5.1" ]
- var expData = [ [ path.resolve(__dirname, "outdated")
- , "underscore"
- , "1.3.1"
- , "1.3.1"
- , "1.5.1"
- , "1.3.1" ] ]
+ var expOut = [
+ path.resolve(pkg, 'node_modules', 'underscore'),
+ path.resolve(pkg, 'node_modules', 'underscore') +
+ ':underscore@1.3.1' +
+ ':underscore@1.3.1' +
+ ':underscore@1.5.1'
+ ]
+
+ var expData = [
+ [
+ pkg,
+ 'underscore',
+ '1.3.1',
+ '1.3.1',
+ '1.5.1',
+ '1.3.1'
+ ]
+ ]
console.log = function () {
output.push.apply(output, arguments)
}
- mr({port : common.port}, function (er, s) {
- npm.load({
- cache: "cache",
- loglevel: "silent",
- parseable: true,
- registry: common.registry }
- , function () {
- npm.install(".", function (err) {
- t.ifError(err, "install success")
- npm.outdated(function (er, d) {
- t.ifError(er, "outdated success")
- console.log = originalLog
- t.same(output, expOut)
- t.same(d, expData)
- s.close()
- t.end()
+ mr({ port: common.port }, function (er, s) {
+ npm.load(
+ {
+ cache: 'cache',
+ loglevel: 'silent',
+ parseable: true,
+ registry: common.registry
+ },
+ function () {
+ npm.install('.', function (err) {
+ t.ifError(err, 'install success')
+ npm.outdated(function (er, d) {
+ t.ifError(er, 'outdated success')
+
+ console.log = originalLog
+
+ t.same(output, expOut)
+ t.same(d, expData)
+
+ s.close()
+ t.end()
+ })
})
- })
- })
+ }
+ )
})
})
-test("cleanup", function (t) {
+test('cleanup', function (t) {
cleanup()
t.end()
})
function cleanup () {
- rimraf.sync(nodeModules)
- rimraf.sync(cache)
+ rimraf.sync(pkg)
}
diff --git a/test/tap/outdated/README.md b/test/tap/outdated/README.md
deleted file mode 100644
index aca67ff17..000000000
--- a/test/tap/outdated/README.md
+++ /dev/null
@@ -1 +0,0 @@
-# just a test
diff --git a/test/tap/outdated/index.js b/test/tap/outdated/index.js
deleted file mode 100644
index 33c1891f8..000000000
--- a/test/tap/outdated/index.js
+++ /dev/null
@@ -1 +0,0 @@
-module.exports = true
diff --git a/test/tap/outdated/package.json b/test/tap/outdated/package.json
deleted file mode 100644
index 821a94b88..000000000
--- a/test/tap/outdated/package.json
+++ /dev/null
@@ -1,10 +0,0 @@
-{
- "name": "bla",
- "description": "fixture",
- "version": "0.0.1",
- "main": "index.js",
- "dependencies": {
- "underscore": "1.3.1"
- },
- "repository": "git://github.com/robertkowalski/bogusfixture"
-}
diff --git a/test/tap/package-with-peer-dep/package.json b/test/tap/package-with-peer-dep/package.json
deleted file mode 100644
index 99cc75bb8..000000000
--- a/test/tap/package-with-peer-dep/package.json
+++ /dev/null
@@ -1,7 +0,0 @@
-{
- "name": "package-with-peer-dep",
- "version": "0.0.0",
- "peerDependencies": {
- "opener": "*"
- }
-}
diff --git a/test/tap/peer-deps-invalid.js b/test/tap/peer-deps-invalid.js
index eb2ce8bb6..7d630f866 100644
--- a/test/tap/peer-deps-invalid.js
+++ b/test/tap/peer-deps-invalid.js
@@ -1,45 +1,102 @@
-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, "peer-deps-invalid")
-var cache = path.resolve(pkg, "cache")
-var nodeModules = path.resolve(pkg, "node_modules")
-
-test("installing dependencies that have conflicting peerDependencies", function (t) {
- rimraf.sync(nodeModules)
- rimraf.sync(cache)
+var fs = require('graceful-fs')
+var path = require('path')
+
+var mkdirp = require('mkdirp')
+var mr = require('npm-registry-mock')
+var osenv = require('osenv')
+var rimraf = require('rimraf')
+var test = require('tap').test
+
+var npm = require('../../')
+var common = require('../common-tap')
+
+var pkg = path.resolve(__dirname, 'peer-deps-invalid')
+var cache = path.resolve(pkg, 'cache')
+
+var json = {
+ author: 'Domenic Denicola <domenic@domenicdenicola.com> (http://domenicdenicola.com/)',
+ name: 'peer-deps-invalid',
+ version: '0.0.0',
+ dependencies: {
+ 'npm-test-peer-deps-file': 'http://localhost:1337/ok.js',
+ 'npm-test-peer-deps-file-invalid': 'http://localhost:1337/invalid.js'
+ }
+}
+
+test('setup', function (t) {
+ cleanup()
+ mkdirp.sync(cache)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+ fs.writeFileSync(path.join(pkg, 'file-ok.js'), fileOK)
+ fs.writeFileSync(path.join(pkg, 'file-fail.js'), fileFail)
+
process.chdir(pkg)
+ t.end()
+})
+test('installing dependencies that have conflicting peerDependencies', function (t) {
var customMocks = {
- "get": {
- "/ok.js": [200, path.join(pkg, "file-ok.js")],
- "/invalid.js": [200, path.join(pkg, "file-fail.js")]
+ 'get': {
+ '/ok.js': [200, path.join(pkg, 'file-ok.js')],
+ '/invalid.js': [200, path.join(pkg, 'file-fail.js')]
}
}
- mr({port: common.port, mocks: customMocks}, function (err, s) { // create mock registry.
- t.ifError(err, "mock registry started")
- npm.load({
- cache: cache,
- registry: common.registry
- }, function () {
- npm.commands.install([], function (err) {
- if (!err) {
- t.fail("No error!")
- } else {
- t.equal(err.code, "EPEERINVALID")
- }
- t.end()
- s.close() // shutdown mock registry.
- })
- })
+ mr({port: common.port, mocks: customMocks}, function (err, s) {
+ t.ifError(err, 'mock registry started')
+ npm.load(
+ {
+ cache: cache,
+ registry: common.registry
+ },
+ function () {
+ npm.commands.install([], function (err) {
+ if (!err) {
+ t.fail('No error!')
+ } else {
+ t.equal(err.code, 'EPEERINVALID')
+ }
+ s.close()
+ t.end()
+ })
+ }
+ )
})
})
-test("cleanup", function (t) {
- rimraf.sync(nodeModules)
- rimraf.sync(cache)
+test('cleanup', function (t) {
+ cleanup()
t.end()
})
+
+function cleanup () {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(pkg)
+}
+
+var fileFail = function () {
+/**package
+* { "name": "npm-test-peer-deps-file-invalid"
+* , "main": "index.js"
+* , "version": "1.2.3"
+* , "description":"This one should conflict with the other one"
+* , "peerDependencies": { "underscore": "1.3.3" }
+* }
+**/
+ module.exports = 'I\'m just a lonely index, naked as the day I was born.'
+}.toString().split('\n').slice(1, -1).join('\n')
+
+var fileOK = function () {
+/**package
+* { "name": "npm-test-peer-deps-file"
+* , "main": "index.js"
+* , "version": "1.2.3"
+* , "description":"No package.json in sight!"
+* , "peerDependencies": { "underscore": "1.3.1" }
+* , "dependencies": { "mkdirp": "0.3.5" }
+* }
+**/
+ module.exports = 'I\'m just a lonely index, naked as the day I was born.'
+}.toString().split('\n').slice(1, -1).join('\n')
diff --git a/test/tap/peer-deps-invalid/file-fail.js b/test/tap/peer-deps-invalid/file-fail.js
deleted file mode 100644
index 5a78d0f84..000000000
--- a/test/tap/peer-deps-invalid/file-fail.js
+++ /dev/null
@@ -1,10 +0,0 @@
-/**package
-* { "name": "npm-test-peer-deps-file-invalid"
-* , "main": "index.js"
-* , "version": "1.2.3"
-* , "description":"This one should conflict with the other one"
-* , "peerDependencies": { "underscore": "1.3.3" }
-* }
-**/
-
-module.exports = "I\'m just a lonely index, naked as the day I was born."
diff --git a/test/tap/peer-deps-invalid/file-ok.js b/test/tap/peer-deps-invalid/file-ok.js
deleted file mode 100644
index 957e20e41..000000000
--- a/test/tap/peer-deps-invalid/file-ok.js
+++ /dev/null
@@ -1,11 +0,0 @@
-/**package
-* { "name": "npm-test-peer-deps-file"
-* , "main": "index.js"
-* , "version": "1.2.3"
-* , "description":"No package.json in sight!"
-* , "peerDependencies": { "underscore": "1.3.1" }
-* , "dependencies": { "mkdirp": "0.3.5" }
-* }
-**/
-
-module.exports = "I\'m just a lonely index, naked as the day I was born."
diff --git a/test/tap/peer-deps-invalid/package.json b/test/tap/peer-deps-invalid/package.json
deleted file mode 100644
index c5fa7cb03..000000000
--- a/test/tap/peer-deps-invalid/package.json
+++ /dev/null
@@ -1,9 +0,0 @@
-{
- "author": "Domenic Denicola <domenic@domenicdenicola.com> (http://domenicdenicola.com/)",
- "name": "peer-deps-invalid",
- "version": "0.0.0",
- "dependencies": {
- "npm-test-peer-deps-file": "http://localhost:1337/ok.js",
- "npm-test-peer-deps-file-invalid": "http://localhost:1337/invalid.js"
- }
-}
diff --git a/test/tap/peer-deps-without-package-json.js b/test/tap/peer-deps-without-package-json.js
index 9c8daf84f..16a3a114f 100644
--- a/test/tap/peer-deps-without-package-json.js
+++ b/test/tap/peer-deps-without-package-json.js
@@ -1,43 +1,52 @@
-var common = require("../common-tap")
-var fs = require("fs")
-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, "peer-deps-without-package-json")
-var cache = path.resolve(pkg, "cache")
-var nodeModules = path.resolve(pkg, "node_modules")
-
-test("installing a peerDependencies-using package without a package.json present (GH-3049)", function (t) {
-
- rimraf.sync(nodeModules)
- rimraf.sync(cache)
-
- fs.mkdirSync(nodeModules)
+var fs = require('fs')
+var path = require('path')
+
+var mkdirp = require('mkdirp')
+var mr = require('npm-registry-mock')
+var osenv = require('osenv')
+var rimraf = require('rimraf')
+var test = require('tap').test
+
+var npm = require('../../')
+var common = require('../common-tap.js')
+
+var pkg = path.resolve(__dirname, 'peer-deps-without-package-json')
+var cache = path.resolve(pkg, 'cache')
+var nodeModules = path.resolve(pkg, 'node_modules')
+
+test('setup', function (t) {
+ t.comment('test for https://github.com/npm/npm/issues/3049')
+ cleanup()
+ mkdirp.sync(cache)
+ mkdirp.sync(nodeModules)
+ fs.writeFileSync(path.join(pkg, 'file-js.js'), fileJS)
process.chdir(pkg)
+ t.end()
+})
+
+test('installing a peerDeps-using package without package.json', function (t) {
var customMocks = {
- "get": {
- "/ok.js": [200, path.join(pkg, "file-js.js")]
+ 'get': {
+ '/ok.js': [200, path.join(pkg, 'file-js.js')]
}
}
mr({port: common.port, mocks: customMocks}, function (err, s) {
- t.ifError(err, "mock registry booted")
+ t.ifError(err, 'mock registry booted')
npm.load({
registry: common.registry,
cache: cache
}, function () {
- npm.install(common.registry + "/ok.js", function (err) {
- t.ifError(err, "installed ok.js")
+ npm.install(common.registry + '/ok.js', function (err) {
+ t.ifError(err, 'installed ok.js')
t.ok(
- fs.existsSync(path.join(nodeModules, "/npm-test-peer-deps-file")),
- "passive peer dep installed"
+ fs.existsSync(path.join(nodeModules, 'npm-test-peer-deps-file')),
+ 'passive peer dep installed'
)
t.ok(
- fs.existsSync(path.join(nodeModules, "/underscore")),
- "underscore installed"
+ fs.existsSync(path.join(nodeModules, 'underscore')),
+ 'underscore installed'
)
t.end()
@@ -47,8 +56,26 @@ test("installing a peerDependencies-using package without a package.json present
})
})
-test("cleanup", function (t) {
- rimraf.sync(nodeModules)
- rimraf.sync(cache)
+test('cleanup', function (t) {
+ cleanup()
t.end()
})
+
+function cleanup () {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(pkg)
+}
+
+var fileJS = function () {
+/**package
+* { "name": "npm-test-peer-deps-file"
+* , "main": "index.js"
+* , "version": "1.2.3"
+* , "description":"No package.json in sight!"
+* , "peerDependencies": { "underscore": "1.3.1" }
+* , "dependencies": { "mkdirp": "0.3.5" }
+* }
+**/
+
+ module.exports = 'I\'m just a lonely index, naked as the day I was born.'
+}.toString().split('\n').slice(1, -1).join('\n')
diff --git a/test/tap/peer-deps-without-package-json/.gitkeep b/test/tap/peer-deps-without-package-json/.gitkeep
deleted file mode 100644
index e69de29bb..000000000
--- a/test/tap/peer-deps-without-package-json/.gitkeep
+++ /dev/null
diff --git a/test/tap/peer-deps-without-package-json/file-js.js b/test/tap/peer-deps-without-package-json/file-js.js
deleted file mode 100644
index 957e20e41..000000000
--- a/test/tap/peer-deps-without-package-json/file-js.js
+++ /dev/null
@@ -1,11 +0,0 @@
-/**package
-* { "name": "npm-test-peer-deps-file"
-* , "main": "index.js"
-* , "version": "1.2.3"
-* , "description":"No package.json in sight!"
-* , "peerDependencies": { "underscore": "1.3.1" }
-* , "dependencies": { "mkdirp": "0.3.5" }
-* }
-**/
-
-module.exports = "I\'m just a lonely index, naked as the day I was born."
diff --git a/test/tap/prune.js b/test/tap/prune.js
index f46f6c7eb..23c8548df 100644
--- a/test/tap/prune.js
+++ b/test/tap/prune.js
@@ -1,116 +1,131 @@
-var test = require("tap").test
-var common = require("../common-tap")
-var fs = require("fs")
-var rimraf = require("rimraf")
-var mr = require("npm-registry-mock")
-var env = process.env
-var path = require("path")
+var fs = require('fs')
+var path = require('path')
-var pkg = path.resolve(__dirname, "prune")
-var cache = path.resolve(pkg, "cache")
-var nodeModules = path.resolve(pkg, "node_modules")
-
-var EXEC_OPTS = { cwd: pkg, env: env }
-EXEC_OPTS.env.npm_config_depth = "Infinity"
+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')
var server
-test("reg mock", function (t) {
- mr({port : common.port}, function (er, s) {
- server = s
- t.pass("registry mock started")
- t.end()
- })
-})
+var pkg = path.resolve(__dirname, 'prune')
+var cache = path.resolve(pkg, 'cache')
-function cleanup () {
- rimraf.sync(cache)
- rimraf.sync(nodeModules)
+var json = {
+ name: 'prune',
+ description: 'fixture',
+ version: '0.0.1',
+ main: 'index.js',
+ dependencies: {
+ underscore: '1.3.1'
+ },
+ devDependencies: {
+ mkdirp: '*'
+ }
+}
+
+var EXEC_OPTS = {
+ cwd: pkg,
+ npm_config_depth: 'Infinity'
}
-test("setup", function (t) {
+test('setup', function (t) {
cleanup()
- t.pass("setup")
- t.end()
+ mkdirp.sync(cache)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+ mr({ port: common.port }, function (er, s) {
+ server = s
+ t.end()
+ })
})
-test("npm install", function (t) {
+test('npm install', function (t) {
common.npm([
- "install",
- "--cache", cache,
- "--registry", common.registry,
- "--loglevel", "silent",
- "--production", "false"
+ 'install',
+ '--cache', cache,
+ '--registry', common.registry,
+ '--loglevel', 'silent',
+ '--production', 'false'
], EXEC_OPTS, function (err, code, stdout, stderr) {
- t.ifErr(err, "install finished successfully")
- t.notOk(code, "exit ok")
- t.notOk(stderr, "Should not get data on stderr: " + stderr)
+ t.ifErr(err, 'install finished successfully')
+ t.notOk(code, 'exit ok')
+ t.notOk(stderr, 'Should not get data on stderr: ' + stderr)
t.end()
})
})
-test("npm install test-package", function (t) {
+test('npm install test-package', function (t) {
common.npm([
- "install", "test-package",
- "--cache", cache,
- "--registry", common.registry,
- "--loglevel", "silent",
- "--production", "false"
+ 'install', 'test-package',
+ '--cache', cache,
+ '--registry', common.registry,
+ '--loglevel', 'silent',
+ '--production', 'false'
], EXEC_OPTS, function (err, code, stdout, stderr) {
- t.ifErr(err, "install finished successfully")
- t.notOk(code, "exit ok")
- t.notOk(stderr, "Should not get data on stderr: " + stderr)
+ t.ifErr(err, 'install finished successfully')
+ t.notOk(code, 'exit ok')
+ t.notOk(stderr, 'Should not get data on stderr: ' + stderr)
t.end()
})
})
-test("verify installs", function (t) {
- var dirs = fs.readdirSync(pkg + "/node_modules").sort()
- t.same(dirs, [ "test-package", "mkdirp", "underscore" ].sort())
+test('verify installs', function (t) {
+ var dirs = fs.readdirSync(pkg + '/node_modules').sort()
+ t.same(dirs, [ 'test-package', 'mkdirp', 'underscore' ].sort())
t.end()
})
-test("npm prune", function (t) {
+test('npm prune', function (t) {
common.npm([
- "prune",
- "--loglevel", "silent",
- "--production", "false"
+ 'prune',
+ '--loglevel', 'silent',
+ '--production', 'false'
], EXEC_OPTS, function (err, code, stdout, stderr) {
- t.ifErr(err, "prune finished successfully")
- t.notOk(code, "exit ok")
- t.notOk(stderr, "Should not get data on stderr: " + stderr)
+ t.ifErr(err, 'prune finished successfully')
+ t.notOk(code, 'exit ok')
+ t.notOk(stderr, 'Should not get data on stderr: ' + stderr)
t.end()
})
})
-test("verify installs", function (t) {
- var dirs = fs.readdirSync(pkg + "/node_modules").sort()
- t.same(dirs, [ "mkdirp", "underscore" ])
+test('verify installs', function (t) {
+ var dirs = fs.readdirSync(pkg + '/node_modules').sort()
+ t.same(dirs, [ 'mkdirp', 'underscore' ])
t.end()
})
-test("npm prune", function (t) {
+test('npm prune', function (t) {
common.npm([
- "prune",
- "--loglevel", "silent",
- "--production"
+ 'prune',
+ '--loglevel', 'silent',
+ '--production'
], EXEC_OPTS, function (err, code, stderr) {
- t.ifErr(err, "prune finished successfully")
- t.notOk(code, "exit ok")
- t.equal(stderr, "unbuild mkdirp@0.3.5\n")
+ t.ifErr(err, 'prune finished successfully')
+ t.notOk(code, 'exit ok')
+ t.equal(stderr, 'unbuild mkdirp@0.3.5\n')
t.end()
})
})
-test("verify installs", function (t) {
- var dirs = fs.readdirSync(pkg + "/node_modules").sort()
- t.same(dirs, [ "underscore" ])
+test('verify installs', function (t) {
+ var dirs = fs.readdirSync(pkg + '/node_modules').sort()
+ t.same(dirs, [ 'underscore' ])
t.end()
})
-test("cleanup", function (t) {
+test('cleanup', function (t) {
server.close()
cleanup()
- t.pass("cleaned up")
+ t.pass('cleaned up')
t.end()
})
+
+function cleanup () {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(pkg)
+}
diff --git a/test/tap/prune/package.json b/test/tap/prune/package.json
deleted file mode 100644
index 641ab6580..000000000
--- a/test/tap/prune/package.json
+++ /dev/null
@@ -1,13 +0,0 @@
-{
- "name": "bla",
- "description": "fixture",
- "version": "0.0.1",
- "main": "index.js",
- "dependencies": {
- "underscore": "1.3.1"
- },
- "devDependencies": {
- "mkdirp": "*"
- },
- "repository": "git://github.com/robertkowalski/bogusfixture"
-}
diff --git a/test/tap/scripts-whitespace-windows.js b/test/tap/scripts-whitespace-windows.js
index 44170af5b..b4d1f3a34 100644
--- a/test/tap/scripts-whitespace-windows.js
+++ b/test/tap/scripts-whitespace-windows.js
@@ -1,54 +1,99 @@
-var test = require("tap").test
-var common = require("../common-tap")
-var path = require("path")
-var pkg = path.resolve(__dirname, "scripts-whitespace-windows")
-var tmp = path.resolve(pkg, "tmp")
-var cache = path.resolve(pkg, "cache")
-var modules = path.resolve(pkg, "node_modules")
-var dep = path.resolve(pkg, "dep")
-
-var mkdirp = require("mkdirp")
-var rimraf = require("rimraf")
-
-test("setup", function (t) {
+var fs = require('graceful-fs')
+var path = require('path')
+
+var mkdirp = require('mkdirp')
+var osenv = require('osenv')
+var rimraf = require('rimraf')
+var test = require('tap').test
+
+var common = require('../common-tap')
+
+var pkg = path.resolve(__dirname, 'scripts-whitespace-windows')
+var tmp = path.resolve(pkg, 'tmp')
+var cache = path.resolve(pkg, 'cache')
+var dep = path.resolve(pkg, 'dep')
+
+var EXEC_OPTS = { cwd: pkg }
+
+var json = {
+ name: 'scripts-whitespace-windows',
+ version: '1.0.0',
+ description: 'a test',
+ repository: 'git://github.com/robertkowalski/bogus',
+ scripts: {
+ foo: 'foo --title \"Analysis of\" --recurse -d report src'
+ },
+ dependencies: {
+ 'scripts-whitespace-windows-dep': '0.0.1'
+ }
+}
+
+var dependency = {
+ name: 'scripts-whitespace-windows-dep',
+ version: '0.0.1',
+ bin: [ 'bin/foo' ]
+}
+
+test('setup', function (t) {
cleanup()
- mkdirp.sync(cache)
mkdirp.sync(tmp)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+ fs.writeFileSync(
+ path.join(pkg, 'README.md'),
+ "### THAT'S RIGHT\n"
+ )
- common.npm(["i", dep], {
+ mkdirp.sync(path.join(dep, 'bin'))
+ fs.writeFileSync(
+ path.join(dep, 'package.json'),
+ JSON.stringify(dependency, null, 2)
+ )
+ fs.writeFileSync(path.join(dep, 'bin', 'foo'), foo)
+
+ common.npm(['i', dep], {
cwd: pkg,
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'
}
}, function (err, code, stdout, stderr) {
- t.ifErr(err, "npm i " + dep + " finished without error")
- t.equal(code, 0, "npm i " + dep + " exited ok")
- t.notOk(stderr, "no output stderr")
+ t.ifErr(err, 'npm i ' + dep + ' finished without error')
+ t.equal(code, 0, 'npm i ' + dep + ' exited ok')
+ console.log('stderr', stderr)
+ t.notOk(stderr, 'no output stderr')
t.end()
})
})
-test("test", function (t) {
- common.npm(["run", "foo"], { cwd: pkg }, function (err, code, stdout, stderr) {
- t.ifErr(err, "npm run finished without error")
- t.equal(code, 0, "npm run exited ok")
- t.notOk(stderr, "no output stderr: ", stderr)
+test('test', function (t) {
+ common.npm(['run', 'foo'], EXEC_OPTS, function (err, code, stdout, stderr) {
+ t.ifErr(err, 'npm run finished without error')
+ t.equal(code, 0, 'npm run exited ok')
+ t.notOk(stderr, 'no output stderr: ', stderr)
stdout = stdout.trim()
t.ok(/npm-test-fine/.test(stdout))
t.end()
})
})
-test("cleanup", function (t) {
+test('cleanup', function (t) {
cleanup()
t.end()
})
-function cleanup() {
- rimraf.sync(cache)
- rimraf.sync(tmp)
- rimraf.sync(modules)
+function cleanup () {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(pkg)
}
+
+var foo = function () {/*
+#!/usr/bin/env node
+
+if (process.argv.length === 8)
+ console.log('npm-test-fine')
+*/}.toString().split('\n').slice(1, -1).join('\n')
diff --git a/test/tap/scripts-whitespace-windows/README.md b/test/tap/scripts-whitespace-windows/README.md
deleted file mode 100644
index 76f177f19..000000000
--- a/test/tap/scripts-whitespace-windows/README.md
+++ /dev/null
@@ -1 +0,0 @@
-# Hi
diff --git a/test/tap/scripts-whitespace-windows/dep/README.md b/test/tap/scripts-whitespace-windows/dep/README.md
deleted file mode 100644
index 0d9d64f27..000000000
--- a/test/tap/scripts-whitespace-windows/dep/README.md
+++ /dev/null
@@ -1 +0,0 @@
-# Hi!
diff --git a/test/tap/scripts-whitespace-windows/dep/bin/foo b/test/tap/scripts-whitespace-windows/dep/bin/foo
deleted file mode 100644
index d6708417d..000000000
--- a/test/tap/scripts-whitespace-windows/dep/bin/foo
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/usr/bin/env node
-
-if (process.argv.length === 8)
- console.log('npm-test-fine')
diff --git a/test/tap/scripts-whitespace-windows/dep/package.json b/test/tap/scripts-whitespace-windows/dep/package.json
deleted file mode 100644
index 4ff982913..000000000
--- a/test/tap/scripts-whitespace-windows/dep/package.json
+++ /dev/null
@@ -1,6 +0,0 @@
-{
- "name": "scripts-whitespace-windows-dep",
- "version": "0.0.1",
- "bin": [ "bin/foo" ],
- "repository": "git://github.com/robertkowalski/bogusfixture"
-}
diff --git a/test/tap/scripts-whitespace-windows/package.json b/test/tap/scripts-whitespace-windows/package.json
deleted file mode 100644
index 06e1a572b..000000000
--- a/test/tap/scripts-whitespace-windows/package.json
+++ /dev/null
@@ -1,11 +0,0 @@
-{
- "name": "scripts-whitespace-windows",
- "scripts": {
- "foo": "foo --title \"Analysis of\" --recurse -d report src"
- },
- "description": "a test",
- "repository": "git://github.com/robertkowalski/bogus",
- "dependencies": {
- "scripts-whitespace-windows-dep": "0.0.1"
- }
-}
diff --git a/test/tap/search.js b/test/tap/search.js
index fc3bd86e0..0412e1755 100644
--- a/test/tap/search.js
+++ b/test/tap/search.js
@@ -1,265 +1,276 @@
-var common = require("../common-tap.js")
-var test = require("tap").test
-var rimraf = require("rimraf")
-var mr = require("npm-registry-mock")
-var fs = require("fs")
-var path = require("path")
-var pkg = path.resolve(__dirname, "search")
-var cache = path.resolve(pkg, "cache")
-var registryCache = path.resolve(cache, "localhost_1337", "-", "all")
-var cacheJsonFile = path.resolve(registryCache, ".cache.json")
-var mkdirp = require("mkdirp")
+var fs = require('graceful-fs')
+var path = require('path')
+
+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 pkg = path.resolve(__dirname, 'search')
+var cache = path.resolve(pkg, 'cache')
+var registryCache = path.resolve(cache, 'localhost_1337', '-', 'all')
+var cacheJsonFile = path.resolve(registryCache, '.cache.json')
var timeMock = {
epoch: 1411727900,
- future: 1411727900+100,
- all: 1411727900+25,
+ future: 1411727900 + 100,
+ all: 1411727900 + 25,
since: 0 // filled by since server callback
}
var EXEC_OPTS = {}
-function cleanupCache() {
- rimraf.sync(cache)
-}
-function cleanup () { cleanupCache() }
-
-function setupCache() {
- mkdirp.sync(cache)
- mkdirp.sync(registryCache)
- var res = fs.writeFileSync(cacheJsonFile, stringifyUpdated(timeMock.epoch))
- if (res) throw new Error("Creating cache file failed")
-}
-
var mocks = {
/* Since request, always response with an _update time > the time requested */
- sinceFuture: function(server) {
- server.filteringPathRegEx(/startkey=[^&]*/g, function(s) {
+ sinceFuture: function (server) {
+ server.filteringPathRegEx(/startkey=[^&]*/g, function (s) {
var _allMock = JSON.parse(JSON.stringify(allMock))
- timeMock.since = _allMock._updated = s.replace("startkey=", "")
- server.get("/-/all/since?stale=update_after&" + s)
+ timeMock.since = _allMock._updated = s.replace('startkey=', '')
+ server.get('/-/all/since?stale=update_after&' + s)
.reply(200, _allMock)
return s
})
},
- allFutureUpdatedOnly: function(server) {
- server.get("/-/all")
+ allFutureUpdatedOnly: function (server) {
+ server.get('/-/all')
.reply(200, stringifyUpdated(timeMock.future))
},
- all: function(server) {
- server.get("/-/all")
+ all: function (server) {
+ server.get('/-/all')
.reply(200, allMock)
}
}
-
-test("No previous cache, init cache triggered by first search", function(t) {
- cleanupCache()
+test('No previous cache, init cache triggered by first search', function (t) {
+ cleanup()
mr({ port: common.port, plugin: mocks.allFutureUpdatedOnly }, function (err, s) {
+ t.ifError(err, 'mock registry started')
common.npm([
- "search", "do not do extra search work on my behalf",
- "--registry", common.registry,
- "--cache", cache,
- "--loglevel", "silent",
- "--color", "always"
+ 'search', 'do not do extra search work on my behalf',
+ '--registry', common.registry,
+ '--cache', cache,
+ '--loglevel', 'silent',
+ '--color', 'always'
],
EXEC_OPTS,
- function(err, code) {
+ function (err, code) {
s.close()
- t.equal(code, 0, "search finished successfully")
- t.ifErr(err, "search finished successfully")
+ t.equal(code, 0, 'search finished successfully')
+ t.ifErr(err, 'search finished successfully')
+
+ t.ok(
+ fs.existsSync(cacheJsonFile),
+ cacheJsonFile + ' expected to have been created'
+ )
- t.ok(fs.existsSync(cacheJsonFile),
- cacheJsonFile + " expected to have been created")
- var cacheData = JSON.parse(fs.readFileSync(cacheJsonFile, "utf8"))
+ var cacheData = JSON.parse(fs.readFileSync(cacheJsonFile, 'utf8'))
t.equal(cacheData._updated, String(timeMock.future))
t.end()
})
})
})
-test("previous cache, _updated set, should trigger since request", function(t) {
- cleanupCache()
+test('previous cache, _updated set, should trigger since request', function (t) {
setupCache()
- function m(server) {
- [ mocks.all, mocks.sinceFuture ].forEach(function(m) {
+ function m (server) {
+ [ mocks.all, mocks.sinceFuture ].forEach(function (m) {
m(server)
})
}
mr({ port: common.port, plugin: m }, function (err, s) {
+ t.ifError(err, 'mock registry started')
common.npm([
- "search", "do not do extra search work on my behalf",
- "--registry", common.registry,
- "--cache", cache,
- "--loglevel", "silly",
- "--color", "always"
+ 'search', 'do not do extra search work on my behalf',
+ '--registry', common.registry,
+ '--cache', cache,
+ '--loglevel', 'silly',
+ '--color', 'always'
],
EXEC_OPTS,
- function(err, code) {
+ function (err, code) {
s.close()
- t.equal(code, 0, "search finished successfully")
- t.ifErr(err, "search finished successfully")
+ t.equal(code, 0, 'search finished successfully')
+ t.ifErr(err, 'search finished successfully')
- var cacheData = JSON.parse(fs.readFileSync(cacheJsonFile, "utf8"))
- t.equal(cacheData._updated,
+ var cacheData = JSON.parse(fs.readFileSync(cacheJsonFile, 'utf8'))
+ t.equal(
+ cacheData._updated,
timeMock.since,
- "cache update time gotten from since response")
- cleanupCache()
+ 'cache update time gotten from since response'
+ )
t.end()
})
})
})
-
var searches = [
{
- term: "f36b6a6123da50959741e2ce4d634f96ec668c56",
- description: "non-regex",
+ term: 'f36b6a6123da50959741e2ce4d634f96ec668c56',
+ description: 'non-regex',
location: 241
},
{
- term: "/f36b6a6123da50959741e2ce4d634f96ec668c56/",
- description: "regex",
+ term: '/f36b6a6123da50959741e2ce4d634f96ec668c56/',
+ description: 'regex',
location: 241
}
]
-searches.forEach(function(search) {
- test(search.description + " search in color", function(t) {
- cleanupCache()
+searches.forEach(function (search) {
+ test(search.description + ' search in color', function (t) {
+ cleanup()
mr({ port: common.port, plugin: mocks.all }, function (er, s) {
common.npm([
- "search", search.term,
- "--registry", common.registry,
- "--cache", cache,
- "--loglevel", "silent",
- "--color", "always"
+ 'search', search.term,
+ '--registry', common.registry,
+ '--cache', cache,
+ '--loglevel', 'silent',
+ '--color', 'always'
],
EXEC_OPTS,
- function(err, code, stdout) {
+ function (err, code, stdout) {
s.close()
- t.equal(code, 0, "search finished successfully")
- t.ifErr(err, "search finished successfully")
+ t.equal(code, 0, 'search finished successfully')
+ t.ifErr(err, 'search finished successfully')
// \033 == \u001B
- var markStart = "\u001B\\[[0-9][0-9]m"
- var markEnd = "\u001B\\[0m"
+ var markStart = '\u001B\\[[0-9][0-9]m'
+ var markEnd = '\u001B\\[0m'
- var re = new RegExp(markStart + ".*?" + markEnd)
+ var re = new RegExp(markStart + '.*?' + markEnd)
var cnt = stdout.search(re)
- t.equal(cnt, search.location,
- search.description + " search for " + search.term)
+ t.equal(
+ cnt,
+ search.location,
+ search.description + ' search for ' + search.term
+ )
t.end()
})
})
})
})
-test("cleanup", function (t) {
+test('cleanup', function (t) {
cleanup()
t.end()
})
-function stringifyUpdated(time) {
- return JSON.stringify({ _updated : String(time) })
+function cleanup () {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(pkg)
+}
+
+function setupCache () {
+ cleanup()
+ mkdirp.sync(cache)
+ mkdirp.sync(registryCache)
+ var res = fs.writeFileSync(cacheJsonFile, stringifyUpdated(timeMock.epoch))
+ if (res) throw new Error('Creating cache file failed')
+}
+
+function stringifyUpdated (time) {
+ return JSON.stringify({ _updated: String(time) })
}
var allMock = {
- "_updated": timeMock.all,
- "generator-frontcow": {
- "name": "generator-frontcow",
- "description": "f36b6a6123da50959741e2ce4d634f96ec668c56 This is a fake description to ensure we do not accidentally search the real npm registry or use some kind of cache",
- "dist-tags": {
- "latest": "0.1.19"
+ '_updated': timeMock.all,
+ 'generator-frontcow': {
+ 'name': 'generator-frontcow',
+ 'description': 'f36b6a6123da50959741e2ce4d634f96ec668c56 This is a fake description to ensure we do not accidentally search the real npm registry or use some kind of cache',
+ 'dist-tags': {
+ 'latest': '0.1.19'
},
- "maintainers": [
+ 'maintainers': [
{
- "name": "bcabanes",
- "email": "contact@benjamincabanes.com"
+ 'name': 'bcabanes',
+ 'email': 'contact@benjamincabanes.com'
}
],
- "homepage": "https://github.com/bcabanes/generator-frontcow",
- "keywords": [
- "sass",
- "frontend",
- "yeoman-generator",
- "atomic",
- "design",
- "sass",
- "foundation",
- "foundation5",
- "atomic design",
- "bourbon",
- "polyfill",
- "font awesome"
+ 'homepage': 'https://github.com/bcabanes/generator-frontcow',
+ 'keywords': [
+ 'sass',
+ 'frontend',
+ 'yeoman-generator',
+ 'atomic',
+ 'design',
+ 'sass',
+ 'foundation',
+ 'foundation5',
+ 'atomic design',
+ 'bourbon',
+ 'polyfill',
+ 'font awesome'
],
- "repository": {
- "type": "git",
- "url": "https://github.com/bcabanes/generator-frontcow"
+ 'repository': {
+ 'type': 'git',
+ 'url': 'https://github.com/bcabanes/generator-frontcow'
},
- "author": {
- "name": "ben",
- "email": "contact@benjamincabanes.com",
- "url": "https://github.com/bcabanes"
+ 'author': {
+ 'name': 'ben',
+ 'email': 'contact@benjamincabanes.com',
+ 'url': 'https://github.com/bcabanes'
},
- "bugs": {
- "url": "https://github.com/bcabanes/generator-frontcow/issues"
+ 'bugs': {
+ 'url': 'https://github.com/bcabanes/generator-frontcow/issues'
},
- "license": "MIT",
- "readmeFilename": "README.md",
- "time": {
- "modified": "2014-10-03T02:26:18.406Z"
+ 'license': 'MIT',
+ 'readmeFilename': 'README.md',
+ 'time': {
+ 'modified': '2014-10-03T02:26:18.406Z'
},
- "versions": {
- "0.1.19": "latest"
+ 'versions': {
+ '0.1.19': 'latest'
}
},
- "marko": {
- "name": "marko",
- "description": "Marko is an extensible, streaming, asynchronous, high performance, HTML-based templating language that can be used in Node.js or in the browser.",
- "dist-tags": {
- "latest": "1.2.16"
+ 'marko': {
+ 'name': 'marko',
+ 'description': 'Marko is an extensible, streaming, asynchronous, high performance, HTML-based templating language that can be used in Node.js or in the browser.',
+ 'dist-tags': {
+ 'latest': '1.2.16'
},
- "maintainers": [
+ 'maintainers': [
{
- "name": "pnidem",
- "email": "pnidem@gmail.com"
+ 'name': 'pnidem',
+ 'email': 'pnidem@gmail.com'
},
{
- "name": "philidem",
- "email": "phillip.idem@gmail.com"
+ 'name': 'philidem',
+ 'email': 'phillip.idem@gmail.com'
}
],
- "homepage": "https://github.com/raptorjs/marko",
- "keywords": [
- "templating",
- "template",
- "async",
- "streaming"
+ 'homepage': 'https://github.com/raptorjs/marko',
+ 'keywords': [
+ 'templating',
+ 'template',
+ 'async',
+ 'streaming'
],
- "repository": {
- "type": "git",
- "url": "https://github.com/raptorjs/marko.git"
+ 'repository': {
+ 'type': 'git',
+ 'url': 'https://github.com/raptorjs/marko.git'
},
- "author": {
- "name": "Patrick Steele-Idem",
- "email": "pnidem@gmail.com"
+ 'author': {
+ 'name': 'Patrick Steele-Idem',
+ 'email': 'pnidem@gmail.com'
},
- "bugs": {
- "url": "https://github.com/raptorjs/marko/issues"
+ 'bugs': {
+ 'url': 'https://github.com/raptorjs/marko/issues'
},
- "license": "Apache License v2.0",
- "readmeFilename": "README.md",
- "users": {
- "pnidem": true
+ 'license': 'Apache License v2.0',
+ 'readmeFilename': 'README.md',
+ 'users': {
+ 'pnidem': true
},
- "time": {
- "modified": "2014-10-03T02:27:31.775Z"
+ 'time': {
+ 'modified': '2014-10-03T02:27:31.775Z'
},
- "versions": {
- "1.2.16": "latest"
+ 'versions': {
+ '1.2.16': 'latest'
}
}
}
diff --git a/test/tap/shrinkwrap-empty-deps.js b/test/tap/shrinkwrap-empty-deps.js
index 80ab82098..32cbd5eb4 100644
--- a/test/tap/shrinkwrap-empty-deps.js
+++ b/test/tap/shrinkwrap-empty-deps.js
@@ -1,48 +1,78 @@
-var test = require("tap").test
- , npm = require("../../")
- , mr = require("npm-registry-mock")
- , common = require("../common-tap.js")
- , path = require("path")
- , fs = require("fs")
- , osenv = require("osenv")
- , rimraf = require("rimraf")
- , pkg = path.resolve(__dirname, "shrinkwrap-empty-deps")
- , cache = path.resolve(pkg, "cache")
-
-test("returns a list of removed items", function (t) {
- var desiredResultsPath = path.resolve(pkg, "npm-shrinkwrap.json")
+var fs = require('fs')
+var path = require('path')
+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 pkg = path.resolve(__dirname, 'shrinkwrap-empty-deps')
+
+var EXEC_OPTS = { cwd: pkg }
+
+var json = {
+ author: 'Rockbert',
+ name: 'shrinkwrap-empty-deps',
+ version: '0.0.0',
+ dependencies: {},
+ devDependencies: {}
+}
+
+test('setup', function (t) {
cleanup()
+ mkdirp.sync(pkg)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+
+ process.chdir(pkg)
+ t.end()
+})
+
+test('returns a list of removed items', function (t) {
+ mr({ port: common.port }, function (er, s) {
+ common.npm(
+ [
+ '--registry', common.registry,
+ '--loglevel', 'silent',
+ 'shrinkwrap'
+ ],
+ EXEC_OPTS,
+ function (err, code, stdout, stderr) {
+ t.ifError(err, 'shrinkwrap ran without issue')
+ t.notOk(code, 'shrinkwrap ran without raising error code')
+
+ fs.readFile(path.resolve(pkg, 'npm-shrinkwrap.json'), function (err, desired) {
+ t.ifError(err, 'read npm-shrinkwrap.json without issue')
+ t.same(
+ {
+ 'name': 'shrinkwrap-empty-deps',
+ 'version': '0.0.0',
+ 'dependencies': {}
+ },
+ JSON.parse(desired),
+ 'shrinkwrap handled empty deps without exploding'
+ )
- mr({port : common.port}, function (er, s) {
- setup(function () {
- npm.shrinkwrap([], function (err) {
- if (err) return t.fail(err)
- fs.readFile(desiredResultsPath, function (err, desired) {
- if (err) return t.fail(err)
- t.deepEqual({
- "name": "npm-test-shrinkwrap-empty-deps",
- "version": "0.0.0",
- "dependencies": {}
- }, JSON.parse(desired))
- cleanup()
s.close()
t.end()
})
- })
- })
+ }
+ )
})
})
-function setup (cb) {
+test('cleanup', function (t) {
cleanup()
- process.chdir(pkg)
- npm.load({cache: cache, registry: common.registry}, function () {
- cb()
- })
-}
+
+ t.end()
+})
function cleanup () {
process.chdir(osenv.tmpdir())
- rimraf.sync(path.resolve(pkg, "npm-shrinkwrap.json"))
+ rimraf.sync(pkg)
}
diff --git a/test/tap/shrinkwrap-empty-deps/package.json b/test/tap/shrinkwrap-empty-deps/package.json
deleted file mode 100644
index 9a51088c7..000000000
--- a/test/tap/shrinkwrap-empty-deps/package.json
+++ /dev/null
@@ -1,7 +0,0 @@
-{
- "author": "Rockbert",
- "name": "npm-test-shrinkwrap-empty-deps",
- "version": "0.0.0",
- "dependencies": {},
- "devDependencies": {}
-}
diff --git a/test/tap/startstop.js b/test/tap/startstop.js
index 334551ed2..b17a303c8 100644
--- a/test/tap/startstop.js
+++ b/test/tap/startstop.js
@@ -1,18 +1,30 @@
-var common = require("../common-tap")
- , test = require("tap").test
- , path = require("path")
- , rimraf = require("rimraf")
- , mkdirp = require("mkdirp")
- , pkg = path.resolve(__dirname, "startstop")
- , cache = path.resolve(pkg, "cache")
- , tmp = path.resolve(pkg, "tmp")
- , opts = { cwd: pkg }
+var fs = require('graceful-fs')
+var path = require('path')
+
+var mkdirp = require('mkdirp')
+var osenv = require('osenv')
+var rimraf = require('rimraf')
+var test = require('tap').test
+
+var common = require('../common-tap')
+
+var pkg = path.resolve(__dirname, 'startstop')
+
+var EXEC_OPTS = { cwd: pkg }
+
+var json = {
+ name: 'startstop',
+ version: '1.2.3',
+ scripts: {
+ start: 'node -e \"console.log(\'start\')\"',
+ stop: 'node -e \"console.log(\'stop\')\"'
+ }
+}
function testOutput (t, command, er, code, stdout, stderr) {
- t.notOk(code, "npm " + command + " exited with code 0")
+ t.notOk(code, 'npm ' + command + ' exited with code 0')
- if (stderr)
- throw new Error("npm " + command + " stderr: " + stderr.toString())
+ if (stderr) throw new Error('npm ' + command + ' stderr: ' + stderr.toString())
stdout = stdout.trim().split(/\n|\r/)
stdout = stdout[stdout.length - 1]
@@ -20,41 +32,43 @@ function testOutput (t, command, er, code, stdout, stderr) {
t.end()
}
-function cleanup () {
- rimraf.sync(cache)
- rimraf.sync(tmp)
-}
-
-test("setup", function (t) {
+test('setup', function (t) {
cleanup()
- mkdirp.sync(cache)
- mkdirp.sync(tmp)
+ mkdirp.sync(pkg)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
t.end()
})
-test("npm start", function (t) {
- common.npm(["start"], opts, testOutput.bind(null, t, "start"))
+test('npm start', function (t) {
+ common.npm(['start'], EXEC_OPTS, testOutput.bind(null, t, 'start'))
})
-test("npm stop", function (t) {
- common.npm(["stop"], opts, testOutput.bind(null, t, "stop"))
+test('npm stop', function (t) {
+ common.npm(['stop'], EXEC_OPTS, testOutput.bind(null, t, 'stop'))
})
-test("npm restart", function (t) {
- common.npm(["restart"], opts, function (er, c, stdout) {
- if (er)
- throw er
+test('npm restart', function (t) {
+ common.npm(['restart'], EXEC_OPTS, function (er, c, stdout) {
+ if (er) throw er
- var output = stdout.split("\n").filter(function (val) {
+ var output = stdout.split('\n').filter(function (val) {
return val.match(/^s/)
})
- t.same(output.sort(), ["start", "stop"].sort())
+ t.same(output.sort(), ['start', 'stop'].sort())
t.end()
})
})
-test("cleanup", function (t) {
+test('cleanup', function (t) {
cleanup()
t.end()
})
+
+function cleanup () {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(pkg)
+}
diff --git a/test/tap/startstop/package.json b/test/tap/startstop/package.json
deleted file mode 100644
index 08a6547eb..000000000
--- a/test/tap/startstop/package.json
+++ /dev/null
@@ -1,7 +0,0 @@
-{"name":"startstop"
-,"version":"1.2.3"
-,"scripts":{
- "start":"node -e \"console.log('start')\"",
- "stop":"node -e \"console.log('stop')\""
- }
-}
diff --git a/test/tap/uninstall-package.js b/test/tap/uninstall-package.js
index f62aa24df..6e86df531 100644
--- a/test/tap/uninstall-package.js
+++ b/test/tap/uninstall-package.js
@@ -1,42 +1,79 @@
-var test = require("tap").test
- , npm = require("../../")
- , rimraf = require("rimraf")
- , mr = require("npm-registry-mock")
- , common = require("../common-tap.js")
- , path = require("path")
- , pkg = path.join(__dirname, "uninstall-package")
-
-test("returns a list of removed items", function (t) {
- t.plan(1)
- mr({port : common.port}, function (er, s) {
- setup(function () {
- npm.install(".", function (err) {
- if (err) return t.fail(err)
- npm.uninstall("underscore", "request", "lala", function (err, d) {
- if (err) return t.fail(err)
- t.same(d.sort(), ["underscore", "request"].sort())
- s.close()
- t.end()
- })
- })
- })
- })
-})
+var fs = require('graceful-fs')
+var path = require('path')
+
+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 pkg = path.join(__dirname, 'uninstall-package')
-test("cleanup", function (t) {
+var EXEC_OPTS = { cwd: pkg }
+
+var json = {
+ name: 'uninstall-package',
+ version: '0.0.0',
+ dependencies: {
+ underscore: '~1.3.1',
+ request: '~0.9.0'
+ }
+}
+
+test('setup', function (t) {
cleanup()
+ mkdirp.sync(pkg)
+ process.chdir(pkg)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+
t.end()
})
-function setup (cb) {
- cleanup()
- process.chdir(pkg)
- npm.load({cache: pkg + "/cache", registry: common.registry}, function () {
- cb()
+test('returns a list of removed items', function (t) {
+ mr({ port: common.port }, function (er, s) {
+ common.npm(
+ [
+ '--registry', common.registry,
+ '--loglevel', 'silent',
+ 'install', '.'
+ ],
+ EXEC_OPTS,
+ function (err, code, stdout, stderr) {
+ t.ifError(err, 'install ran without issue')
+ t.notOk(code, 'install ran without raising error code')
+ common.npm(
+ [
+ '--registry', common.registry,
+ '--loglevel', 'silent',
+ 'uninstall', 'underscore', 'request', 'lala'
+ ],
+ EXEC_OPTS,
+ function (err, code, stdout, stderr) {
+ t.ifError(err, 'uninstall ran without issue')
+ t.notOk(code, 'uninstall ran without raising error code')
+ t.has(stdout, /unbuild underscore@1.3.3/, 'underscore uninstalled')
+ t.has(stdout, /unbuild request@0.9.5/, 'request uninstalled')
+
+ s.close()
+ t.end()
+ }
+ )
+ }
+ )
})
-}
+})
+
+test('cleanup', function (t) {
+ cleanup()
+ t.end()
+})
function cleanup () {
- rimraf.sync(pkg + "/node_modules")
- rimraf.sync(pkg + "/cache")
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(pkg)
}
diff --git a/test/tap/uninstall-package/package.json b/test/tap/uninstall-package/package.json
deleted file mode 100644
index 49ce42a89..000000000
--- a/test/tap/uninstall-package/package.json
+++ /dev/null
@@ -1,11 +0,0 @@
-{
- "name": "beep",
- "version": "0.0.0",
- "author": "Rockbert",
- "description": "i am a fixture",
- "main": "index.js",
- "dependencies": {
- "underscore": "~1.3.1",
- "request": "~0.9.0"
- }
-}
diff --git a/test/tap/update-save.js b/test/tap/update-save.js
index d246fa8a4..f01fa0f54 100644
--- a/test/tap/update-save.js
+++ b/test/tap/update-save.js
@@ -1,161 +1,219 @@
-var common = require("../common-tap.js")
-var test = require("tap").test
-var npm = require("../../")
-var mkdirp = require("mkdirp")
-var rimraf = require("rimraf")
-var fs = require("fs")
-var path = require("path")
-var mr = require("npm-registry-mock")
-
-var PKG_DIR = path.resolve(__dirname, "update-save")
-var PKG = path.resolve(PKG_DIR, "package.json")
-var CACHE_DIR = path.resolve(PKG_DIR, "cache")
-var MODULES_DIR = path.resolve(PKG_DIR, "node_modules")
+var fs = require('graceful-fs')
+var path = require('path')
+
+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 server
+
+var pkg = path.resolve(__dirname, 'update-save')
+var cache = path.resolve(pkg, 'cache')
var EXEC_OPTS = {
- cwd: PKG_DIR,
- stdio: "ignore",
+ cwd: pkg,
+ stdio: 'ignore',
env: {
- "npm_config_registry": common.registry,
- "npm_config_loglevel": "verbose",
- "npm_config_save_prefix": "^"
+ npm_config_registry: common.registry,
+ npm_config_loglevel: 'verbose',
+ npm_config_save_prefix: '^'
}
}
-var DEFAULT_PKG = {
- "name": "update-save-example",
- "version": "1.2.3",
- "dependencies": {
- "mkdirp": "~0.3.0"
+var json = {
+ name: 'update-save-example',
+ version: '1.2.3',
+ dependencies: {
+ mkdirp: '~0.3.0'
},
- "devDependencies": {
- "underscore": "~1.3.1"
+ devDependencies: {
+ underscore: '~1.3.1'
}
}
-var s // mock server reference
+function clone (a) {
+ return extend({}, a)
+}
+
+function extend (a, b) {
+ for (var key in b) { a[key] = b[key] }
+ return a
+}
-test("setup", function (t) {
- resetPackage()
+test('setup', function (t) {
+ setup()
- mr({port : common.port}, function (er, server) {
- npm.load({cache: CACHE_DIR, registry: common.registry}, function (err) {
- t.ifError(err)
- s = server
- t.end()
- })
+ mr({ port: common.port }, function (er, s) {
+ t.ifError(er)
+ server = s
+ t.end()
})
})
-test("update regular dependencies only", function (t) {
- resetPackage()
+test('update regular dependencies only', function (t) {
+ setup()
- common.npm(["update", "--save"], EXEC_OPTS, function (err, code) {
+ common.npm(['update', '--save'], EXEC_OPTS, function (err, code) {
t.ifError(err)
- t.notOk(code, "npm update exited with code 0")
+ t.notOk(code, 'npm update exited with code 0')
+
+ var pkgdata = JSON.parse(fs.readFileSync(path.join(pkg, 'package.json'), 'utf8'))
+ t.deepEqual(
+ pkgdata.dependencies,
+ { mkdirp: '^0.3.5' },
+ 'only dependencies updated'
+ )
+ t.deepEqual(
+ pkgdata.devDependencies,
+ json.devDependencies,
+ 'dev dependencies should be untouched'
+ )
+ t.deepEqual(
+ pkgdata.optionalDependencies,
+ json.optionalDependencies,
+ 'optional dependencies should be untouched'
+ )
- var pkgdata = JSON.parse(fs.readFileSync(PKG, "utf8"))
- t.deepEqual(pkgdata.dependencies, {mkdirp: "^0.3.5"}, "only dependencies updated")
- t.deepEqual(pkgdata.devDependencies, DEFAULT_PKG.devDependencies, "dev dependencies should be untouched")
- t.deepEqual(pkgdata.optionalDependencies, DEFAULT_PKG.optionalDependencies, "optional dependencies should be untouched")
t.end()
})
})
-test("update devDependencies only", function (t) {
- resetPackage()
+test('update devDependencies only', function (t) {
+ setup()
- common.npm(["update", "--save-dev"], EXEC_OPTS, function (err, code) {
+ common.npm(['update', '--save-dev'], EXEC_OPTS, function (err, code) {
t.ifError(err)
- t.notOk(code, "npm update exited with code 0")
+ t.notOk(code, 'npm update exited with code 0')
+
+ var pkgdata = JSON.parse(fs.readFileSync(path.join(pkg, 'package.json'), 'utf8'))
+ t.deepEqual(
+ pkgdata.dependencies,
+ json.dependencies,
+ 'dependencies should be untouched'
+ )
+ t.deepEqual(
+ pkgdata.devDependencies,
+ { underscore: '^1.3.3' },
+ 'dev dependencies should be updated'
+ )
+ t.deepEqual(
+ pkgdata.optionalDependencies,
+ json.optionalDependencies,
+ 'optional dependencies should be untouched'
+ )
- var pkgdata = JSON.parse(fs.readFileSync(PKG, "utf8"))
- t.deepEqual(pkgdata.dependencies, DEFAULT_PKG.dependencies, "dependencies should be untouched")
- t.deepEqual(pkgdata.devDependencies, {underscore: "^1.3.3"}, "dev dependencies should be updated")
- t.deepEqual(pkgdata.optionalDependencies, DEFAULT_PKG.optionalDependencies, "optional dependencies should be untouched")
t.end()
})
})
-test("update optionalDependencies only", function (t) {
- resetPackage({
- "optionalDependencies": {
- "underscore": "~1.3.1"
- }
- })
+test('update optionalDependencies only', function (t) {
+ setup({ optionalDependencies: { underscore: '~1.3.1' } })
- common.npm(["update", "--save-optional"], EXEC_OPTS, function (err, code) {
+ common.npm(['update', '--save-optional'], EXEC_OPTS, function (err, code) {
t.ifError(err)
- t.notOk(code, "npm update exited with code 0")
+ t.notOk(code, 'npm update exited with code 0')
+
+ var pkgdata = JSON.parse(fs.readFileSync(path.join(pkg, 'package.json'), 'utf8'))
+ t.deepEqual(
+ pkgdata.dependencies,
+ json.dependencies,
+ 'dependencies should be untouched'
+ )
+ t.deepEqual(
+ pkgdata.devDependencies,
+ json.devDependencies,
+ 'dev dependencies should be untouched'
+ )
+ t.deepEqual(
+ pkgdata.optionalDependencies,
+ { underscore: '^1.3.3' },
+ 'optional dependencies should be updated'
+ )
- var pkgdata = JSON.parse(fs.readFileSync(PKG, "utf8"))
- t.deepEqual(pkgdata.dependencies, DEFAULT_PKG.dependencies, "dependencies should be untouched")
- t.deepEqual(pkgdata.devDependencies, DEFAULT_PKG.devDependencies, "dev dependencies should be untouched")
- t.deepEqual(pkgdata.optionalDependencies, {underscore: "^1.3.3"}, "optional dependencies should be updated")
t.end()
})
})
-test("optionalDependencies are merged into dependencies during --save", function (t) {
- var pkg = resetPackage({
- "optionalDependencies": {
- "underscore": "~1.3.1"
- }
- })
+test('optionalDependencies are merged into dependencies during --save', function (t) {
+ var cloned = setup({ optionalDependencies: { underscore: '~1.3.1' } })
- common.npm(["update", "--save"], EXEC_OPTS, function (err, code) {
+ common.npm(['update', '--save'], EXEC_OPTS, function (err, code) {
t.ifError(err)
- t.notOk(code, "npm update exited with code 0")
+ t.notOk(code, 'npm update exited with code 0')
+
+ var pkgdata = JSON.parse(fs.readFileSync(path.join(pkg, 'package.json'), 'utf8'))
+ t.deepEqual(
+ pkgdata.dependencies,
+ { mkdirp: '^0.3.5' },
+ 'dependencies should not include optional dependencies'
+ )
+ t.deepEqual(
+ pkgdata.devDependencies,
+ cloned.devDependencies,
+ 'dev dependencies should be untouched'
+ )
+ t.deepEqual(
+ pkgdata.optionalDependencies,
+ cloned.optionalDependencies,
+ 'optional dependencies should be untouched'
+ )
- var pkgdata = JSON.parse(fs.readFileSync(PKG, "utf8"))
- t.deepEqual(pkgdata.dependencies, {mkdirp: "^0.3.5"}, "dependencies should not include optional dependencies")
- t.deepEqual(pkgdata.devDependencies, pkg.devDependencies, "dev dependencies should be untouched")
- t.deepEqual(pkgdata.optionalDependencies, pkg.optionalDependencies, "optional dependencies should be untouched")
t.end()
})
})
-test("semver prefix is replaced with configured save-prefix", function (t) {
- resetPackage()
+test('semver prefix is replaced with configured save-prefix', function (t) {
+ setup()
- common.npm(["update", "--save", "--save-prefix", "~"], EXEC_OPTS, function (err, code) {
+ common.npm(['update', '--save', '--save-prefix', '~'], EXEC_OPTS, function (err, code) {
t.ifError(err)
- t.notOk(code, "npm update exited with code 0")
-
- var pkgdata = JSON.parse(fs.readFileSync(PKG, "utf8"))
- t.deepEqual(pkgdata.dependencies, {
- mkdirp: "~0.3.5"
- }, "dependencies should be updated")
- t.deepEqual(pkgdata.devDependencies, DEFAULT_PKG.devDependencies, "dev dependencies should be untouched")
- t.deepEqual(pkgdata.optionalDependencies, DEFAULT_PKG.optionalDependencies, "optional dependencies should be updated")
+ t.notOk(code, 'npm update exited with code 0')
+
+ var pkgdata = JSON.parse(fs.readFileSync(path.join(pkg, 'package.json'), 'utf8'))
+ t.deepEqual(
+ pkgdata.dependencies,
+ { mkdirp: '~0.3.5' },
+ 'dependencies should be updated'
+ )
+ t.deepEqual(
+ pkgdata.devDependencies,
+ json.devDependencies,
+ 'dev dependencies should be untouched'
+ )
+ t.deepEqual(
+ pkgdata.optionalDependencies,
+ json.optionalDependencies,
+ 'optional dependencies should be updated'
+ )
+
t.end()
})
})
-function resetPackage(extendWith) {
- rimraf.sync(CACHE_DIR)
- rimraf.sync(MODULES_DIR)
- mkdirp.sync(CACHE_DIR)
- var pkg = clone(DEFAULT_PKG)
- extend(pkg, extendWith)
- for (var key in extend) { pkg[key] = extend[key]}
- fs.writeFileSync(PKG, JSON.stringify(pkg, null, 2), "ascii")
- return pkg
-}
-
-test("cleanup", function (t) {
- s.close()
- resetPackage() // restore package.json
- rimraf.sync(CACHE_DIR)
- rimraf.sync(MODULES_DIR)
+test('cleanup', function (t) {
+ server.close()
+ cleanup()
t.end()
})
-function clone(a) {
- return extend({}, a)
+function cleanup () {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(pkg)
}
-function extend(a, b) {
- for (var key in b) { a[key] = b[key]}
- return a
+function setup (extendWith) {
+ cleanup()
+ mkdirp.sync(cache)
+ process.chdir(pkg)
+
+ var template = clone(json)
+ extend(template, extendWith)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(template, null, 2)
+ )
+ return template
}
diff --git a/test/tap/update-save/README.md b/test/tap/update-save/README.md
deleted file mode 100644
index aca67ff17..000000000
--- a/test/tap/update-save/README.md
+++ /dev/null
@@ -1 +0,0 @@
-# just a test
diff --git a/test/tap/update-save/index.js b/test/tap/update-save/index.js
deleted file mode 100644
index 33c1891f8..000000000
--- a/test/tap/update-save/index.js
+++ /dev/null
@@ -1 +0,0 @@
-module.exports = true
diff --git a/test/tap/update-save/package.json b/test/tap/update-save/package.json
deleted file mode 100644
index cb41e88cf..000000000
--- a/test/tap/update-save/package.json
+++ /dev/null
@@ -1,10 +0,0 @@
-{
- "name": "update-save-example",
- "version": "1.2.3",
- "dependencies": {
- "mkdirp": "~0.3.0"
- },
- "devDependencies": {
- "underscore": "~1.3.1"
- }
-} \ No newline at end of file
diff --git a/test/tap/url-dependencies.js b/test/tap/url-dependencies.js
index a24e70e90..bc54da711 100644
--- a/test/tap/url-dependencies.js
+++ b/test/tap/url-dependencies.js
@@ -1,74 +1,113 @@
-var test = require("tap").test
-var rimraf = require("rimraf")
-var path = require("path")
-var osenv = require("osenv")
-var mr = require("npm-registry-mock")
-var pkg = path.resolve(__dirname, "url-dependencies")
-var common = require("../common-tap")
+var fs = require('graceful-fs')
+var path = require('path')
+
+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')
+var server
+
+var pkg = path.resolve(__dirname, 'url-dependencies')
+
+var json = {
+ author: 'Steve Mason',
+ name: 'url-dependencies',
+ version: '0.0.0',
+ dependencies: {
+ underscore: common.registry + '/underscore/-/underscore-1.3.1.tgz'
+ }
+}
var mockRoutes = {
- "get": {
- "/underscore/-/underscore-1.3.1.tgz": [200]
+ 'get': {
+ '/underscore/-/underscore-1.3.1.tgz': [200]
}
}
-test("url-dependencies: download first time", function (t) {
- cleanup()
+test('setup', function (t) {
+ mr({ port: common.port, mocks: mockRoutes }, function (er, s) {
+ server = s
+ t.end()
+ })
+})
- performInstall(t, function (output){
- if (!tarballWasFetched(output)){
- t.fail("Tarball was not fetched")
+test('url-dependencies: download first time', function (t) {
+ setup()
+
+ performInstall(t, function (output) {
+ if (!tarballWasFetched(output)) {
+ t.fail('Tarball was not fetched')
} else {
- t.pass("Tarball was fetched")
+ t.pass('Tarball was fetched')
}
t.end()
})
})
-test("url-dependencies: do not download subsequent times", function (t) {
- cleanup()
+test('url-dependencies: do not download subsequent times', function (t) {
+ setup()
performInstall(t, function () {
performInstall(t, function (output) {
- if (tarballWasFetched(output)){
- t.fail("Tarball was fetched second time around")
+ if (tarballWasFetched(output)) {
+ t.fail('Tarball was fetched second time around')
} else {
- t.pass("Tarball was not fetched")
+ t.pass('Tarball was not fetched')
}
t.end()
})
})
})
-function tarballWasFetched(output){
- return output.indexOf("http fetch GET " + common.registry + "/underscore/-/underscore-1.3.1.tgz") > -1
+test('cleanup', function (t) {
+ server.close()
+ cleanup()
+ t.end()
+})
+
+function cleanup () {
+ // windows fix for locked files
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(path.resolve(pkg))
+}
+
+function setup () {
+ cleanup()
+ mkdirp.sync(pkg)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+}
+
+function tarballWasFetched (output) {
+ return output.indexOf(
+ 'http fetch GET ' +
+ common.registry +
+ '/underscore/-/underscore-1.3.1.tgz'
+ ) > -1
}
function performInstall (t, cb) {
- mr({port: common.port, mocks: mockRoutes}, function (er, s) {
- var opts = {
- cwd : pkg,
- env: {
- "npm_config_registry": common.registry,
- "npm_config_cache_lock_stale": 1000,
- "npm_config_cache_lock_wait": 1000,
- "npm_config_loglevel": "http",
- HOME: process.env.HOME,
- Path: process.env.PATH,
- PATH: process.env.PATH
- }
+ var opts = {
+ cwd: pkg,
+ env: {
+ npm_config_registry: common.registry,
+ npm_config_cache_lock_stale: 1000,
+ npm_config_cache_lock_wait: 1000,
+ npm_config_loglevel: 'http',
+ HOME: process.env.HOME,
+ Path: process.env.PATH,
+ PATH: process.env.PATH
}
- common.npm(["install"], opts, function (err, code, stdout, stderr) {
- t.ifError(err, "install success")
- t.notOk(code, "npm install exited with code 0")
- s.close()
- cb(stderr)
- })
- })
-}
+ }
+ common.npm(['install'], opts, function (err, code, stdout, stderr) {
+ t.ifError(err, 'install success')
+ t.notOk(code, 'npm install exited with code 0')
-function cleanup() {
- // windows fix for locked files
- process.chdir(osenv.tmpdir())
- rimraf.sync(path.resolve(pkg, "node_modules"))
+ cb(stderr)
+ })
}
diff --git a/test/tap/url-dependencies/package.json b/test/tap/url-dependencies/package.json
deleted file mode 100644
index 96ae3e247..000000000
--- a/test/tap/url-dependencies/package.json
+++ /dev/null
@@ -1,8 +0,0 @@
-{
- "author": "Steve Mason",
- "name": "url-dependencies",
- "version": "0.0.0",
- "dependencies": {
- "underscore": "http://localhost:1337/underscore/-/underscore-1.3.1.tgz"
- }
-}