diff --git a/script/spec-runner.js b/script/spec-runner.js index 7ca6828af387..64d9ef798788 100755 --- a/script/spec-runner.js +++ b/script/spec-runner.js @@ -7,6 +7,10 @@ const { hashElement } = require('folder-hash') const path = require('path') const unknownFlags = [] +require('colors') +const pass = '\u2713'.green +const fail = '\u2717'.red + const args = require('minimist')(process.argv, { string: ['runners'], unknown: arg => unknownFlags.push(arg) @@ -28,14 +32,23 @@ const BASE = path.resolve(__dirname, '../..') const NPM_CMD = process.platform === 'win32' ? 'npm.cmd' : 'npm' 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') let runnersToRun = null if (args.runners) { 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) } else { - console.log('Will trigger all spec runners') + console.log(`Triggering both ${[...runners.keys()].join(' and ')} runners`) } async function main () { @@ -79,14 +92,10 @@ function saveSpecHash ([newSpecHash, newSpecInstallHash]) { async function runElectronTests () { 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 for (const [runnerId, { description, run }] of runners) { - if (runnersToRun && !runnersToRun.includes(runnerId)) { + if (runnersToRun && runnersToRun.includes(runnerId)) { console.info('\nSkipping:', description) continue } @@ -106,7 +115,8 @@ async function runElectronTests () { console.error('\n\nRunner Failed:', err[0]) 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) { 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 () { @@ -142,8 +154,10 @@ async function runMainProcessElectronTests () { }) if (status !== 0) { 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 () { @@ -158,7 +172,8 @@ async function installSpecModules () { stdio: 'inherit' }) 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) } }