build: add test runner parameter checks (#19994)

This commit is contained in:
Shelley Vohr 2019-08-28 15:19:52 -07:00 committed by GitHub
parent af138dab55
commit 04debd5890
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -7,6 +7,10 @@ const { hashElement } = require('folder-hash')
const path = require('path') const path = require('path')
const unknownFlags = [] const unknownFlags = []
require('colors')
const pass = '\u2713'.green
const fail = '\u2717'.red
const args = require('minimist')(process.argv, { const args = require('minimist')(process.argv, {
string: ['runners'], string: ['runners'],
unknown: arg => unknownFlags.push(arg) unknown: arg => unknownFlags.push(arg)
@ -28,14 +32,23 @@ const BASE = path.resolve(__dirname, '../..')
const NPM_CMD = process.platform === 'win32' ? 'npm.cmd' : 'npm' const NPM_CMD = process.platform === 'win32' ? 'npm.cmd' : 'npm'
const NPX_CMD = process.platform === 'win32' ? 'npx.cmd' : 'npx' const NPX_CMD = process.platform === 'win32' ? 'npx.cmd' : 'npx'
const runners = new Map([
['main', { description: 'Main process specs', run: runMainProcessElectronTests }],
['remote', { description: 'Remote based specs', run: runRemoteBasedElectronTests }]
])
const specHashPath = path.resolve(__dirname, '../spec/.hash') const specHashPath = path.resolve(__dirname, '../spec/.hash')
let runnersToRun = null let runnersToRun = null
if (args.runners) { if (args.runners) {
runnersToRun = args.runners.split(',') runnersToRun = args.runners.split(',')
if (!runnersToRun.every(r => [...runners.keys()].includes(r))) {
console.log(`${fail} ${runnersToRun} must be a subset of [${[...runners.keys()].join(' | ')}]`)
process.exit(1)
}
console.log('Only running:', runnersToRun) console.log('Only running:', runnersToRun)
} else { } else {
console.log('Will trigger all spec runners') console.log(`Triggering both ${[...runners.keys()].join(' and ')} runners`)
} }
async function main () { async function main () {
@ -79,14 +92,10 @@ function saveSpecHash ([newSpecHash, newSpecInstallHash]) {
async function runElectronTests () { async function runElectronTests () {
const errors = [] const errors = []
const runners = new Map([
['main', { description: 'Main process specs', run: runMainProcessElectronTests }],
['remote', { description: 'Remote based specs', run: runRemoteBasedElectronTests }]
])
const testResultsDir = process.env.ELECTRON_TEST_RESULTS_DIR const testResultsDir = process.env.ELECTRON_TEST_RESULTS_DIR
for (const [runnerId, { description, run }] of runners) { for (const [runnerId, { description, run }] of runners) {
if (runnersToRun && !runnersToRun.includes(runnerId)) { if (runnersToRun && runnersToRun.includes(runnerId)) {
console.info('\nSkipping:', description) console.info('\nSkipping:', description)
continue continue
} }
@ -106,7 +115,8 @@ async function runElectronTests () {
console.error('\n\nRunner Failed:', err[0]) console.error('\n\nRunner Failed:', err[0])
console.error(err[1]) console.error(err[1])
} }
throw new Error('Electron test runners have failed') console.log(`${fail} Electron test runners have failed`)
process.exit(1)
} }
} }
@ -124,8 +134,10 @@ async function runRemoteBasedElectronTests () {
}) })
if (status !== 0) { if (status !== 0) {
const textStatus = process.platform === 'win32' ? `0x${status.toString(16)}` : status.toString() const textStatus = process.platform === 'win32' ? `0x${status.toString(16)}` : status.toString()
throw new Error(`Electron tests failed with code ${textStatus}.`) console.log(`${fail} Electron tests failed with code ${textStatus}.`)
process.exit(1)
} }
console.log(`${pass} Electron remote process tests passed.`)
} }
async function runMainProcessElectronTests () { async function runMainProcessElectronTests () {
@ -142,8 +154,10 @@ async function runMainProcessElectronTests () {
}) })
if (status !== 0) { if (status !== 0) {
const textStatus = process.platform === 'win32' ? `0x${status.toString(16)}` : status.toString() const textStatus = process.platform === 'win32' ? `0x${status.toString(16)}` : status.toString()
throw new Error(`Electron tests failed with code ${textStatus}.`) console.log(`${fail} Electron tests failed with code ${textStatus}.`)
process.exit(1)
} }
console.log(`${pass} Electron main process tests passed.`)
} }
async function installSpecModules () { async function installSpecModules () {
@ -158,7 +172,8 @@ async function installSpecModules () {
stdio: 'inherit' stdio: 'inherit'
}) })
if (status !== 0 && !process.env.IGNORE_YARN_INSTALL_ERROR) { if (status !== 0 && !process.env.IGNORE_YARN_INSTALL_ERROR) {
throw new Error('Failed to yarn install in the spec folder') console.log(`${fail} Failed to yarn install in the spec folder`)
process.exit(1)
} }
} }