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