diff options
author | isaacs <i@izs.me> | 2020-12-11 22:00:42 +0300 |
---|---|---|
committer | isaacs <i@izs.me> | 2020-12-11 22:36:36 +0300 |
commit | 31544914294948085a84097af7f0f5de2a2e8f7e (patch) | |
tree | d217eb7030c3110ce4a195c55033a7292623f5e6 /test | |
parent | e340cf64ba31ef329a9049b60c32ffd0342cfb7d (diff) |
Set NODE_ENV=production if 'dev' is on the omit listisaacs/set-node-env-production
Fix: #2021
PR-URL: https://github.com/npm/cli/pull/2331
Credit: @isaacs
Close: #2331
Reviewed-by: @ruyadorno @darcyclarke
Diffstat (limited to 'test')
-rw-r--r-- | test/lib/utils/flat-options.js | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/test/lib/utils/flat-options.js b/test/lib/utils/flat-options.js index 3cbf06a48..ee7620fa7 100644 --- a/test/lib/utils/flat-options.js +++ b/test/lib/utils/flat-options.js @@ -1,6 +1,7 @@ const t = require('tap') process.env.NODE = '/path/to/some/node' +process.env.NODE_ENV = 'development' const logs = [] const log = require('npmlog') @@ -195,43 +196,56 @@ t.test('tag emits warning', t => { t.test('omit/include options', t => { t.test('omit explicitly', t => { + const { NODE_ENV } = process.env const npm = new Mocknpm({ omit: ['dev', 'optional', 'peer'], }) t.strictSame(flatOptions(npm).omit, ['dev', 'optional', 'peer']) + t.equal(process.env.NODE_ENV, 'production') + process.env.NODE_ENV = NODE_ENV t.end() }) t.test('omit and include some', t => { + const { NODE_ENV } = process.env const npm = new Mocknpm({ omit: ['dev', 'optional', 'peer'], include: ['peer'], }) t.strictSame(flatOptions(npm).omit, ['dev', 'optional']) + t.equal(process.env.NODE_ENV, 'production') + process.env.NODE_ENV = NODE_ENV t.end() }) t.test('dev flag', t => { + const { NODE_ENV } = process.env const npm = new Mocknpm({ omit: ['dev', 'optional', 'peer'], include: [], dev: true, }) t.strictSame(flatOptions(npm).omit, ['optional', 'peer']) + t.equal(process.env.NODE_ENV, NODE_ENV) + process.env.NODE_ENV = NODE_ENV t.end() }) t.test('production flag', t => { + const { NODE_ENV } = process.env const npm = new Mocknpm({ omit: [], include: [], production: true, }) t.strictSame(flatOptions(npm).omit, ['dev']) + t.equal(process.env.NODE_ENV, 'production') + process.env.NODE_ENV = NODE_ENV t.end() }) t.test('only', t => { + const { NODE_ENV } = process.env const cases = ['prod', 'production'] t.plan(cases.length) cases.forEach(c => t.test(c, t => { @@ -241,26 +255,34 @@ t.test('omit/include options', t => { only: c, }) t.strictSame(flatOptions(npm).omit, ['dev']) + t.equal(process.env.NODE_ENV, 'production') + process.env.NODE_ENV = NODE_ENV t.end() })) }) t.test('also dev', t => { + const { NODE_ENV } = process.env const npm = new Mocknpm({ omit: ['dev', 'optional', 'peer'], also: 'dev', }) t.strictSame(flatOptions(npm).omit, ['optional', 'peer']) + t.equal(process.env.NODE_ENV, NODE_ENV) + process.env.NODE_ENV = NODE_ENV t.end() }) t.test('no-optional', t => { + const { NODE_ENV } = process.env const npm = new Mocknpm({ optional: false, omit: null, include: null, }) t.strictSame(flatOptions(npm).omit, ['optional']) + t.equal(process.env.NODE_ENV, NODE_ENV) + process.env.NODE_ENV = NODE_ENV t.end() }) |