diff options
author | Daijiro Wachi <daijiro.wachi@gmail.com> | 2015-10-03 17:23:07 +0300 |
---|---|---|
committer | Rebecca Turner <me@re-becca.org> | 2015-10-09 02:24:37 +0300 |
commit | 3c44763b40f3e93978c10f6d2e6c60dd2feca51d (patch) | |
tree | ad6bad912935aee3792f481c0e7227c31a3273e4 /test | |
parent | 7e6e0079a164968c61867b2ae62e2ee84f9a1961 (diff) |
install: Update --only option to install only the argument env regardless of the NODE_ENV.
The following is the condition of setting the value of the development / production option.
npm install
+ dev: true
+ prod: true
--only=dev
+ dev: true
+ prod: false
--only=prod || NODE_ENV=production
+ dev: false
+ prod: true
PR-URL: https://github.com/npm/npm/pull/9835
Fixes: #9463
Diffstat (limited to 'test')
-rw-r--r-- | test/tap/install-cli-only-development.js | 73 |
1 files changed, 52 insertions, 21 deletions
diff --git a/test/tap/install-cli-only-development.js b/test/tap/install-cli-only-development.js index 21c30378e..6a5995e7e 100644 --- a/test/tap/install-cli-only-development.js +++ b/test/tap/install-cli-only-development.js @@ -38,25 +38,8 @@ var devDependency = { } 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, 'dev-dependency')) - fs.writeFileSync( - path.join(pkg, 'dev-dependency', '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) + setup() + t.pass('setup ran') t.end() }) @@ -78,8 +61,56 @@ test('\'npm install --only=development\' should only install devDependencies', f }) }) +test('\'npm install --only=development\' should only install devDependencies regardless of npm.config.get(\'production\')', function (t) { + + cleanup() + setup() + + common.npm(['install', '--only=development', '--production'], EXEC_OPTS, function (err, code) { + t.ifError(err, 'install development successful') + t.equal(code, 0, 'npm install did not raise error code') + t.ok( + JSON.parse(fs.readFileSync( + path.resolve(pkg, 'node_modules/dev-dependency/package.json'), 'utf8') + ), + 'devDependency was installed' + ) + t.notOk( + existsSync(path.resolve(pkg, 'node_modules/dependency/package.json')), + 'dependency was NOT installed' + ) + t.end() + }) +}) + test('cleanup', function (t) { - process.chdir(osenv.tmpdir()) - rimraf.sync(pkg) + cleanup() + t.pass('cleaned up') t.end() }) + +function setup () { + mkdirp.sync(path.join(pkg, 'dependency')) + fs.writeFileSync( + path.join(pkg, 'dependency', 'package.json'), + JSON.stringify(dependency, null, 2) + ) + + mkdirp.sync(path.join(pkg, 'dev-dependency')) + fs.writeFileSync( + path.join(pkg, 'dev-dependency', '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) +} + +function cleanup () { + process.chdir(osenv.tmpdir()) + rimraf.sync(pkg) +} |