test-create-config-gypi.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. 'use strict'
  2. const path = require('path')
  3. const { test } = require('tap')
  4. const gyp = require('../lib/node-gyp')
  5. const createConfigGypi = require('../lib/create-config-gypi')
  6. const { parseConfigGypi, getCurrentConfigGypi } = createConfigGypi.test
  7. test('config.gypi with no options', async function (t) {
  8. t.plan(2)
  9. const prog = gyp()
  10. prog.parseArgv([])
  11. const config = await getCurrentConfigGypi({ gyp: prog, vsInfo: {} })
  12. t.equal(config.target_defaults.default_configuration, 'Release')
  13. t.equal(config.variables.target_arch, process.arch)
  14. })
  15. test('config.gypi with --debug', async function (t) {
  16. t.plan(1)
  17. const prog = gyp()
  18. prog.parseArgv(['_', '_', '--debug'])
  19. const config = await getCurrentConfigGypi({ gyp: prog, vsInfo: {} })
  20. t.equal(config.target_defaults.default_configuration, 'Debug')
  21. })
  22. test('config.gypi with custom options', async function (t) {
  23. t.plan(1)
  24. const prog = gyp()
  25. prog.parseArgv(['_', '_', '--shared-libxml2'])
  26. const config = await getCurrentConfigGypi({ gyp: prog, vsInfo: {} })
  27. t.equal(config.variables.shared_libxml2, true)
  28. })
  29. test('config.gypi with nodedir', async function (t) {
  30. t.plan(1)
  31. const nodeDir = path.join(__dirname, 'fixtures', 'nodedir')
  32. const prog = gyp()
  33. prog.parseArgv(['_', '_', `--nodedir=${nodeDir}`])
  34. const config = await getCurrentConfigGypi({ gyp: prog, nodeDir, vsInfo: {} })
  35. t.equal(config.variables.build_with_electron, true)
  36. })
  37. test('config.gypi with --force-process-config', async function (t) {
  38. t.plan(1)
  39. const nodeDir = path.join(__dirname, 'fixtures', 'nodedir')
  40. const prog = gyp()
  41. prog.parseArgv(['_', '_', '--force-process-config', `--nodedir=${nodeDir}`])
  42. const config = await getCurrentConfigGypi({ gyp: prog, nodeDir, vsInfo: {} })
  43. t.equal(config.variables.build_with_electron, undefined)
  44. })
  45. test('config.gypi parsing', function (t) {
  46. t.plan(1)
  47. const str = "# Some comments\n{'variables': {'multiline': 'A'\n'B'}}"
  48. const config = parseConfigGypi(str)
  49. t.deepEqual(config, { variables: { multiline: 'AB' } })
  50. })