diff options
author | Forrest L Norvell <forrest@npmjs.com> | 2015-04-03 05:43:08 +0300 |
---|---|---|
committer | Forrest L Norvell <forrest@npmjs.com> | 2015-04-03 05:43:08 +0300 |
commit | c3744baf2e4a140ada61c71fb4725804cec0f7e8 (patch) | |
tree | 52d36a4ca2186c49c89064f6bf029b60cc080ebd /test | |
parent | da015eee45f6daf384598151d06a9b57ffce136e (diff) |
install: better logging, no more readJSON caching
A bunch of the tests are now getting more complete from / resolved
information because the contents of rewritten package.json files on disk
are no longer masked by `read-package-json` memoizing fs reads of
package.json files. Part of fixing #7074.
Diffstat (limited to 'test')
-rw-r--r-- | test/tap/dev-dep-duplicate/desired-ls-results.json | 9 | ||||
-rw-r--r-- | test/tap/dev-dep-duplicate/package.json | 11 | ||||
-rw-r--r-- | test/tap/install-with-dev-dep-duplicate.js | 82 | ||||
-rw-r--r-- | test/tap/peer-deps-toplevel.js | 102 | ||||
-rw-r--r-- | test/tap/peer-deps-toplevel/desired-ls-results.json | 20 | ||||
-rw-r--r-- | test/tap/peer-deps-toplevel/package.json | 11 | ||||
-rw-r--r-- | test/tap/peer-deps.js | 88 | ||||
-rw-r--r-- | test/tap/peer-deps/desired-ls-results.json | 17 | ||||
-rw-r--r-- | test/tap/peer-deps/package.json | 8 | ||||
-rw-r--r-- | test/tap/shrinkwrap-dev-dependency.js | 27 | ||||
-rw-r--r-- | test/tap/shrinkwrap-prod-dependency.js | 8 | ||||
-rw-r--r-- | test/tap/shrinkwrap-shared-dev-dependency.js | 82 | ||||
-rw-r--r-- | test/tap/shrinkwrap-shared-dev-dependency/desired-shrinkwrap-results.json | 12 | ||||
-rw-r--r-- | test/tap/shrinkwrap-shared-dev-dependency/package.json | 11 |
14 files changed, 265 insertions, 223 deletions
diff --git a/test/tap/dev-dep-duplicate/desired-ls-results.json b/test/tap/dev-dep-duplicate/desired-ls-results.json deleted file mode 100644 index 355039a09..000000000 --- a/test/tap/dev-dep-duplicate/desired-ls-results.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "dev-dep-duplicate", - "version": "0.0.0", - "dependencies": { - "underscore": { - "version": "1.5.1" - } - } -} diff --git a/test/tap/dev-dep-duplicate/package.json b/test/tap/dev-dep-duplicate/package.json deleted file mode 100644 index 87061b9d5..000000000 --- a/test/tap/dev-dep-duplicate/package.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "author": "Anders Janmyr", - "name": "dev-dep-duplicate", - "version": "0.0.0", - "dependencies": { - "underscore": "1.5.1" - }, - "devDependencies": { - "underscore": "1.3.1" - } -} diff --git a/test/tap/install-with-dev-dep-duplicate.js b/test/tap/install-with-dev-dep-duplicate.js index 9df8123ed..19ad0c2bf 100644 --- a/test/tap/install-with-dev-dep-duplicate.js +++ b/test/tap/install-with-dev-dep-duplicate.js @@ -1,57 +1,85 @@ -var npm = npm = require("../../") -var test = require("tap").test -var path = require("path") -var fs = require("fs") -var osenv = require("osenv") -var rimraf = require("rimraf") -var mr = require("npm-registry-mock") -var common = require("../common-tap.js") - -var pkg = path.resolve(__dirname, "dev-dep-duplicate") -var desiredResultsPath = path.resolve(pkg, "desired-ls-results.json") - -test("prefers version from dependencies over devDependencies", function (t) { +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 npm = npm = require('../../') + +var pkg = path.resolve(__dirname, 'dev-dep-duplicate') + +var json = { + author: 'Anders Janmyr', + name: 'dev-dep-duplicate', + version: '0.0.0', + dependencies: { + underscore: '1.5.1' + }, + devDependencies: { + underscore: '1.3.1' + } +} + +var expected = { + name: 'dev-dep-duplicate', + version: '0.0.0', + dependencies: { + underscore: { + version: '1.5.1', + from: 'underscore@1.5.1', + resolved: common.registry + '/underscore/-/underscore-1.5.1.tgz' + } + } +} + +test('prefers version from dependencies over devDependencies', function (t) { t.plan(1) - mr({port : common.port}, function (er, s) { + mr({ port: common.port }, function (er, s) { setup(function (err) { if (err) return t.fail(err) - npm.install(".", function (err) { + npm.install('.', function (err) { if (err) return t.fail(err) npm.commands.ls([], true, function (err, _, results) { if (err) return t.fail(err) - fs.readFile(desiredResultsPath, function (err, desired) { - if (err) return t.fail(err) - - t.deepEqual(results, JSON.parse(desired)) - s.close() - t.end() - }) + t.deepEqual(results, expected) + s.close() + t.end() }) }) }) }) }) -test("cleanup", function (t) { +test('cleanup', function (t) { cleanup() t.end() }) - function setup (cb) { cleanup() + mkdirp.sync(pkg) + fs.writeFileSync( + path.join(pkg, 'package.json'), + JSON.stringify(json, null, 2) + ) process.chdir(pkg) - var opts = { cache: path.resolve(pkg, "cache"), registry: common.registry} + var opts = { + cache: path.resolve(pkg, 'cache'), + registry: common.registry + } npm.load(opts, cb) } function cleanup () { process.chdir(osenv.tmpdir()) - rimraf.sync(path.resolve(pkg, "node_modules")) - rimraf.sync(path.resolve(pkg, "cache")) + rimraf.sync(pkg) } diff --git a/test/tap/peer-deps-toplevel.js b/test/tap/peer-deps-toplevel.js index 1cb71bc19..5b5e29b06 100644 --- a/test/tap/peer-deps-toplevel.js +++ b/test/tap/peer-deps-toplevel.js @@ -1,55 +1,97 @@ -var npm = npm = require("../../") -var test = require("tap").test -var path = require("path") -var fs = require("fs") -var osenv = require("osenv") -var rimraf = require("rimraf") -var mr = require("npm-registry-mock") -var common = require("../common-tap.js") - -var pkg = path.resolve(__dirname, "peer-deps-toplevel") -var desiredResultsPath = path.resolve(pkg, "desired-ls-results.json") - -test("installs the peer dependency directory structure", function (t) { - mr({port : common.port}, function (er, s) { +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 npm = npm = require('../../') + +var pkg = path.resolve(__dirname, 'peer-deps-toplevel') + +var expected = { + name: 'npm-test-peer-deps-toplevel', + version: '0.0.0', + dependencies: { + 'npm-test-peer-deps': { + version: '0.0.0', + from: 'npm-test-peer-deps@*', + resolved: common.registry + '/npm-test-peer-deps/-/npm-test-peer-deps-0.0.0.tgz', + dependencies: { + underscore: { + version: '1.3.1', + from: 'underscore@1.3.1', + resolved: common.registry + '/underscore/-/underscore-1.3.1.tgz' + } + } + }, + mkdirp: { + version: '0.3.5', + from: 'mkdirp@*', + resolved: common.registry + '/mkdirp/-/mkdirp-0.3.5.tgz' + }, + request: { + version: '0.9.5', + from: 'request@>=0.9.0 <0.10.0', + resolved: common.registry + '/request/-/request-0.9.5.tgz' + } + } +} + +var json = { + author: 'Domenic Denicola', + name: 'npm-test-peer-deps-toplevel', + version: '0.0.0', + dependencies: { + 'npm-test-peer-deps': '*' + }, + peerDependencies: { + mkdirp: '*' + } +} + +test('installs the peer dependency directory structure', function (t) { + mr({ port: common.port }, function (er, s) { setup(function (err) { - t.ifError(err, "setup ran successfully") + t.ifError(err, 'setup ran successfully') - npm.install(".", function (err) { - t.ifError(err, "packages were installed") + npm.install('.', function (err) { + t.ifError(err, 'packages were installed') npm.commands.ls([], true, function (err, _, results) { - t.ifError(err, "listed tree without problems") + t.ifError(err, 'listed tree without problems') - fs.readFile(desiredResultsPath, function (err, desired) { - t.ifError(err, "read desired results") - - t.deepEqual(results, JSON.parse(desired), "got expected output from ls") - s.close() - t.end() - }) + t.deepEqual(results, expected, 'got expected output from ls') + s.close() + t.end() }) }) }) }) }) -test("cleanup", function (t) { +test('cleanup', function (t) { cleanup() t.end() }) - function setup (cb) { cleanup() + mkdirp.sync(pkg) + fs.writeFileSync( + path.join(pkg, 'package.json'), + JSON.stringify(json, null, 2) + ) process.chdir(pkg) - var opts = { cache: path.resolve(pkg, "cache"), registry: common.registry} + var opts = { cache: path.resolve(pkg, 'cache'), registry: common.registry} npm.load(opts, cb) } function cleanup () { process.chdir(osenv.tmpdir()) - rimraf.sync(path.resolve(pkg, "node_modules")) - rimraf.sync(path.resolve(pkg, "cache")) + rimraf.sync(pkg) } diff --git a/test/tap/peer-deps-toplevel/desired-ls-results.json b/test/tap/peer-deps-toplevel/desired-ls-results.json deleted file mode 100644 index 28eff4c6d..000000000 --- a/test/tap/peer-deps-toplevel/desired-ls-results.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "name": "npm-test-peer-deps-toplevel", - "version": "0.0.0", - "dependencies": { - "npm-test-peer-deps": { - "version": "0.0.0", - "dependencies": { - "underscore": { - "version": "1.3.1" - } - } - }, - "mkdirp": { - "version": "0.3.5" - }, - "request": { - "version": "0.9.5" - } - } -} diff --git a/test/tap/peer-deps-toplevel/package.json b/test/tap/peer-deps-toplevel/package.json deleted file mode 100644 index ab77daeec..000000000 --- a/test/tap/peer-deps-toplevel/package.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "author": "Domenic Denicola", - "name": "npm-test-peer-deps-toplevel", - "version": "0.0.0", - "dependencies": { - "npm-test-peer-deps": "*" - }, - "peerDependencies": { - "mkdirp": "*" - } -} diff --git a/test/tap/peer-deps.js b/test/tap/peer-deps.js index 8fa28a54f..48023d7ac 100644 --- a/test/tap/peer-deps.js +++ b/test/tap/peer-deps.js @@ -1,55 +1,89 @@ -var npm = npm = require("../../") -var test = require("tap").test -var path = require("path") -var fs = require("fs") -var osenv = require("osenv") -var rimraf = require("rimraf") -var mr = require("npm-registry-mock") -var common = require("../common-tap.js") - -var pkg = path.resolve(__dirname, "peer-deps") -var desiredResultsPath = path.resolve(pkg, "desired-ls-results.json") - -test("installs the peer dependency directory structure", function (t) { - mr({port : common.port}, function (er, s) { +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 npm = npm = require('../../') + +var pkg = path.resolve(__dirname, 'peer-deps') + +var expected = { + name: 'npm-test-peer-deps-installer', + version: '0.0.0', + dependencies: { + 'npm-test-peer-deps': { + version: '0.0.0', + from: 'npm-test-peer-deps@*', + resolved: common.registry + '/npm-test-peer-deps/-/npm-test-peer-deps-0.0.0.tgz', + dependencies: { + underscore: { + version: '1.3.1', + from: 'underscore@1.3.1', + resolved: common.registry + '/underscore/-/underscore-1.3.1.tgz' + } + } + }, + request: { + version: '0.9.5', + from: 'request@>=0.9.0 <0.10.0', + resolved: common.registry + '/request/-/request-0.9.5.tgz' + } + } +} + +var json = { + author: 'Domenic Denicola', + name: 'npm-test-peer-deps-installer', + version: '0.0.0', + dependencies: { + 'npm-test-peer-deps': '*' + } +} + +test('installs the peer dependency directory structure', function (t) { + mr({ port: common.port }, function (er, s) { setup(function (err) { if (err) return t.fail(err) - npm.install(".", function (err) { + npm.install('.', function (err) { if (err) return t.fail(err) npm.commands.ls([], true, function (err, _, results) { if (err) return t.fail(err) - fs.readFile(desiredResultsPath, function (err, desired) { - if (err) return t.fail(err) - - t.deepEqual(results, JSON.parse(desired)) - s.close() - t.end() - }) + t.deepEqual(results, expected) + s.close() + t.end() }) }) }) }) }) -test("cleanup", function (t) { +test('cleanup', function (t) { cleanup() t.end() }) - function setup (cb) { cleanup() + mkdirp.sync(pkg) + fs.writeFileSync( + path.join(pkg, 'package.json'), + JSON.stringify(json, null, 2) + ) process.chdir(pkg) - var opts = { cache: path.resolve(pkg, "cache"), registry: common.registry} + var opts = { cache: path.resolve(pkg, 'cache'), registry: common.registry} npm.load(opts, cb) } function cleanup () { process.chdir(osenv.tmpdir()) - rimraf.sync(path.resolve(pkg, "node_modules")) - rimraf.sync(path.resolve(pkg, "cache")) + rimraf.sync(pkg) } diff --git a/test/tap/peer-deps/desired-ls-results.json b/test/tap/peer-deps/desired-ls-results.json deleted file mode 100644 index 9c1033af0..000000000 --- a/test/tap/peer-deps/desired-ls-results.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "name": "npm-test-peer-deps-installer", - "version": "0.0.0", - "dependencies": { - "npm-test-peer-deps": { - "version": "0.0.0", - "dependencies": { - "underscore": { - "version": "1.3.1" - } - } - }, - "request": { - "version": "0.9.5" - } - } -} diff --git a/test/tap/peer-deps/package.json b/test/tap/peer-deps/package.json deleted file mode 100644 index e78a1a7e1..000000000 --- a/test/tap/peer-deps/package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "author": "Domenic Denicola", - "name": "npm-test-peer-deps-installer", - "version": "0.0.0", - "dependencies": { - "npm-test-peer-deps": "*" - } -} diff --git a/test/tap/shrinkwrap-dev-dependency.js b/test/tap/shrinkwrap-dev-dependency.js index 49421107c..a124c2b7f 100644 --- a/test/tap/shrinkwrap-dev-dependency.js +++ b/test/tap/shrinkwrap-dev-dependency.js @@ -7,16 +7,16 @@ var osenv = require('osenv') var rimraf = require('rimraf') var test = require('tap').test +var common = require('../common-tap.js') var npm = npm = require('../../') -var common = require('../common-tap.js') var pkg = path.resolve(__dirname, 'shrinkwrap-dev-dependency') test("shrinkwrap doesn't strip out the dependency", function (t) { t.plan(1) mr({port: common.port}, function (er, s) { - setup({}, function (err) { + setup(function (err) { if (err) return t.fail(err) npm.install('.', function (err) { @@ -44,10 +44,14 @@ var desired = { version: '0.0.0', dependencies: { request: { - version: '0.9.0' + version: '0.9.0', + from: 'request@0.9.0', + resolved: common.registry + '/request/-/request-0.9.0.tgz' }, underscore: { - version: '1.3.1' + version: '1.3.1', + from: 'underscore@1.3.1', + resolved: common.registry + '/underscore/-/underscore-1.3.1.tgz' } } } @@ -65,22 +69,19 @@ var json = { } } -function setup (opts, cb) { +function setup (cb) { cleanup() mkdirp.sync(pkg) fs.writeFileSync(path.join(pkg, 'package.json'), JSON.stringify(json, null, 2)) process.chdir(pkg) - var allOpts = { + var opts = { cache: path.resolve(pkg, 'cache'), - registry: common.registry + registry: common.registry, + // important to make sure devDependencies don't get stripped + dev: true } - - for (var key in opts) { - allOpts[key] = opts[key] - } - - npm.load(allOpts, cb) + npm.load(opts, cb) } function cleanup () { diff --git a/test/tap/shrinkwrap-prod-dependency.js b/test/tap/shrinkwrap-prod-dependency.js index 1dc665091..5bc834376 100644 --- a/test/tap/shrinkwrap-prod-dependency.js +++ b/test/tap/shrinkwrap-prod-dependency.js @@ -45,10 +45,14 @@ var desired = { version: '0.0.0', dependencies: { request: { - version: '0.9.0' + version: '0.9.0', + from: 'request@0.9.0', + resolved: common.registry + '/request/-/request-0.9.0.tgz' }, underscore: { - version: '1.5.1' + version: '1.5.1', + from: 'underscore@1.5.1', + resolved: common.registry + '/underscore/-/underscore-1.5.1.tgz' } } } diff --git a/test/tap/shrinkwrap-shared-dev-dependency.js b/test/tap/shrinkwrap-shared-dev-dependency.js index 8a0126072..a6cddae33 100644 --- a/test/tap/shrinkwrap-shared-dev-dependency.js +++ b/test/tap/shrinkwrap-shared-dev-dependency.js @@ -1,58 +1,90 @@ -var npm = npm = require("../../") -var test = require("tap").test -var path = require("path") -var fs = require("fs") -var osenv = require("osenv") -var rimraf = require("rimraf") -var mr = require("npm-registry-mock") -var common = require("../common-tap.js") - -var pkg = path.resolve(__dirname, "shrinkwrap-shared-dev-dependency") -var desiredResultsPath = path.resolve(pkg, "desired-shrinkwrap-results.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 npm = npm = require('../../') + +var pkg = path.resolve(__dirname, 'shrinkwrap-shared-dev-dependency') test("shrinkwrap doesn't strip out the shared dependency", function (t) { t.plan(1) - mr({port : common.port}, function (er, s) { + mr({ port: common.port }, function (er, s) { setup(function (err) { if (err) return t.fail(err) - npm.install(".", function (err) { + npm.install('.', function (err) { if (err) return t.fail(err) npm.commands.shrinkwrap([], true, function (err, results) { if (err) return t.fail(err) - fs.readFile(desiredResultsPath, function (err, desired) { - if (err) return t.fail(err) - - t.deepEqual(results, JSON.parse(desired)) - s.close() - t.end() - }) + t.deepEqual(results, desired) + s.close() + t.end() }) }) }) }) }) -test("cleanup", function (t) { +test('cleanup', function (t) { cleanup() t.end() }) +var desired = { + name: 'npm-test-shrinkwrap-shared-dev-dependency', + version: '0.0.0', + dependencies: { + 'test-package-with-one-dep': { + version: '0.0.0', + from: 'test-package-with-one-dep@0.0.0', + resolved: common.registry + + '/test-package-with-one-dep/-/test-package-with-one-dep-0.0.0.tgz' + }, + 'test-package': { + version: '0.0.0', + from: 'test-package@0.0.0', + resolved: common.registry + '/test-package/-/test-package-0.0.0.tgz' + } + } +} + +var json = { + author: 'Domenic Denicola', + name: 'npm-test-shrinkwrap-shared-dev-dependency', + version: '0.0.0', + dependencies: { + 'test-package-with-one-dep': '0.0.0' + }, + devDependencies: { + 'test-package': '0.0.0' + } +} function setup (cb) { cleanup() + mkdirp.sync(pkg) + fs.writeFileSync(path.join(pkg, 'package.json'), JSON.stringify(json, null, 2)) process.chdir(pkg) - var opts = { cache: path.resolve(pkg, "cache"), registry: common.registry } + var opts = { + cache: path.resolve(pkg, 'cache'), + registry: common.registry, + // important to make sure devDependencies don't get stripped + dev: true + } npm.load(opts, cb) } function cleanup () { process.chdir(osenv.tmpdir()) - rimraf.sync(path.resolve(pkg, "node_modules")) - rimraf.sync(path.resolve(pkg, "cache")) - rimraf.sync(path.resolve(pkg, "npm-shrinkwrap.json")) + rimraf.sync(pkg) } diff --git a/test/tap/shrinkwrap-shared-dev-dependency/desired-shrinkwrap-results.json b/test/tap/shrinkwrap-shared-dev-dependency/desired-shrinkwrap-results.json deleted file mode 100644 index 230b68761..000000000 --- a/test/tap/shrinkwrap-shared-dev-dependency/desired-shrinkwrap-results.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "name": "npm-test-shrinkwrap-shared-dev-dependency", - "version": "0.0.0", - "dependencies": { - "test-package-with-one-dep": { - "version": "0.0.0" - }, - "test-package": { - "version": "0.0.0" - } - } -} diff --git a/test/tap/shrinkwrap-shared-dev-dependency/package.json b/test/tap/shrinkwrap-shared-dev-dependency/package.json deleted file mode 100644 index 41260accf..000000000 --- a/test/tap/shrinkwrap-shared-dev-dependency/package.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "author": "Domenic Denicola", - "name": "npm-test-shrinkwrap-shared-dev-dependency", - "version": "0.0.0", - "dependencies": { - "test-package-with-one-dep": "0.0.0" - }, - "devDependencies": { - "test-package": "0.0.0" - } -} |