test-options.js 923 B

12345678910111213141516171819202122232425262728293031
  1. 'use strict'
  2. const test = require('tap').test
  3. const gyp = require('../lib/node-gyp')
  4. test('options in environment', (t) => {
  5. t.plan(1)
  6. // `npm test` dumps a ton of npm_config_* variables in the environment.
  7. Object.keys(process.env)
  8. .filter((key) => /^npm_config_/.test(key))
  9. .forEach((key) => { delete process.env[key] })
  10. // in some platforms, certain keys are stubborn and cannot be removed
  11. const keys = Object.keys(process.env)
  12. .filter((key) => /^npm_config_/.test(key))
  13. .map((key) => key.substring('npm_config_'.length))
  14. .concat('argv', 'x')
  15. // Zero-length keys should get filtered out.
  16. process.env.npm_config_ = '42'
  17. // Other keys should get added.
  18. process.env.npm_config_x = '42'
  19. // Except loglevel.
  20. process.env.npm_config_loglevel = 'debug'
  21. const g = gyp()
  22. g.parseArgv(['rebuild']) // Also sets opts.argv.
  23. t.deepEqual(Object.keys(g.opts).sort(), keys.sort())
  24. })