Skip to content

Commit 2407f68

Browse files
committed
add tests
1 parent 891e7fa commit 2407f68

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

test/test-options.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,38 @@ describe('options', function () {
88
it('options in environment', () => {
99
// `npm test` dumps a ton of npm_config_* variables in the environment.
1010
Object.keys(process.env)
11-
.filter((key) => /^npm_config_/.test(key))
11+
.filter((key) => /^npm_config_/.test(key) || /^npm_package_config_node_gyp_/.test(key))
1212
.forEach((key) => { delete process.env[key] })
1313

1414
// in some platforms, certain keys are stubborn and cannot be removed
1515
const keys = Object.keys(process.env)
16-
.filter((key) => /^npm_config_/.test(key))
16+
.filter((key) => /^npm_config_/.test(key) || /^npm_package_config_node_gyp_/.test(key))
1717
.map((key) => key.substring('npm_config_'.length))
18-
.concat('argv', 'x')
18+
.concat('argv', 'x', 'y', 'foo')
19+
20+
// Environment variables with the following prefixes should be added to opts.
21+
// - `npm_config_` for npm versions before v11.
22+
// - `npm_package_config_node_gyp_` for npm versions 11 and later.
1923

2024
// Zero-length keys should get filtered out.
2125
process.env.npm_config_ = '42'
26+
process.env.npm_package_config_node_gyp_ = '42'
2227
// Other keys should get added.
2328
process.env.npm_config_x = '42'
29+
process.env.npm_config_y = '41'
30+
process.env.npm_package_config_node_gyp_foo = '42'
31+
// Package config should take precedence over npm_config_ keys.
32+
process.env.npm_package_config_node_gyp_y = '42'
2433
// Except loglevel.
2534
process.env.npm_config_loglevel = 'debug'
2635

2736
const g = gyp()
2837
g.parseArgv(['rebuild']) // Also sets opts.argv.
2938

3039
assert.deepStrictEqual(Object.keys(g.opts).sort(), keys.sort())
40+
assert.strictEqual(g.opts['x'], '42')
41+
assert.strictEqual(g.opts['y'], '42')
42+
assert.strictEqual(g.opts['foo'], '42')
3143
})
3244

3345
it('options with spaces in environment', () => {

0 commit comments

Comments
 (0)