electron/script/node-spec-runner.js

88 lines
2.2 KiB
JavaScript
Raw Normal View History

2019-07-23 18:40:06 +00:00
const cp = require('child_process')
const fs = require('fs')
const path = require('path')
const args = require('minimist')(process.argv.slice(2), {
boolean: ['default'],
string: ['jUnitDir']
})
2019-07-23 18:40:06 +00:00
const BASE = path.resolve(__dirname, '../..')
const DISABLED_TESTS = require('./node-disabled-tests.json')
2019-07-23 18:40:06 +00:00
const NODE_DIR = path.resolve(BASE, 'third_party', 'electron_node')
const NPX_CMD = process.platform === 'win32' ? 'npx.cmd' : 'npx'
const JUNIT_DIR = args.jUnitDir ? path.resolve(args.jUnitDir) : null
const TAP_FILE_NAME = 'test.tap'
2019-07-23 18:40:06 +00:00
const utils = require('./lib/utils')
const { YARN_VERSION } = require('./yarn')
if (!process.mainModule) {
throw new Error('Must call the node spec runner directly')
}
const defaultOptions = [
'tools/test.py',
'-p',
'tap',
'--logfile',
TAP_FILE_NAME,
'--mode=debug',
'default',
`--skip-tests=${DISABLED_TESTS.join(',')}`,
'--shell',
utils.getAbsoluteElectronExec(),
'-J'
]
const getCustomOptions = () => {
let customOptions = ['tools/test.py']
// Add all custom arguments.
const extra = process.argv.slice(2)
if (extra) {
customOptions = customOptions.concat(extra)
}
// We need this unilaterally or Node.js will try
// to run from out/Release/node.
customOptions = customOptions.concat([
'--shell',
utils.getAbsoluteElectronExec()
])
return customOptions
}
2019-07-23 18:40:06 +00:00
async function main () {
const options = args.default ? defaultOptions : getCustomOptions()
2019-07-23 18:40:06 +00:00
const testChild = cp.spawn('python', options, {
2019-07-23 18:40:06 +00:00
env: {
...process.env,
ELECTRON_RUN_AS_NODE: 'true',
ELECTRON_EAGER_ASAR_HOOK_FOR_TESTING: 'true'
2019-07-23 18:40:06 +00:00
},
cwd: NODE_DIR,
stdio: 'inherit'
})
testChild.on('exit', (testCode) => {
if (JUNIT_DIR) {
fs.mkdirSync(JUNIT_DIR)
const converterStream = require('tap-xunit')()
fs.createReadStream(
path.resolve(NODE_DIR, TAP_FILE_NAME)
).pipe(converterStream).pipe(
fs.createWriteStream(path.resolve(JUNIT_DIR, 'nodejs.xml'))
).on('close', () => {
process.exit(testCode)
})
}
2019-07-23 18:40:06 +00:00
})
}
main().catch((err) => {
console.error('An unhandled error occurred in the node spec runner', err)
process.exit(1)
})