UNPKG

@stryker-mutator/tap-runner

Version:

A plugin to use the TAP (test anything protocol) test runner in Stryker, the JavaScript mutation testing framework

55 lines (54 loc) 2.44 kB
import os from 'os'; import { glob } from 'glob'; import { TapParser } from './tap-parser-factory.js'; export function findTestyLookingFiles(globPatterns) { return glob(globPatterns, { ignore: ['**/node_modules/**'], posix: true }); } function parseTap(tapProcess, forceBail) { return new Promise((resolve) => { const failedTests = []; const config = { bail: forceBail }; const parser = TapParser.Parser(config, (result) => { resolve({ result, failedTests }); }); parser.on('bailout', () => { // Bailout within a test file is not supported on windows, because when the process is killed the exit handler which saves the file with the result does not run. if (os.platform() !== 'win32') { tapProcess.kill(); } }); parser.on('fail', (reason) => { failedTests.push(reason); }); tapProcess.stdout.pipe(parser); }); } export async function captureTapResult(tapProcess, disableBail) { const exitAsPromised = new Promise((resolve) => tapProcess.on('exit', resolve)); const stderrOutput = []; tapProcess.stderr.on('data', (chunk) => { stderrOutput.push(chunk); }); const [exitCodeResult, tapResult] = await Promise.all([exitAsPromised, parseTap(tapProcess, disableBail)]); if (exitCodeResult !== 0 && !tapResult.failedTests.length) { // The tap process errored, but we don't have any failed tests. This is probably a syntax error in the test file. throw new Error(`Tap process exited with code ${exitCodeResult}. To reproduce it yourself, use the following command: cd "${process.cwd()}" ${tapProcess.spawnargs.map((arg, index) => (index === 0 ? arg : `"${arg}"`)).join(' ')} Stderr output: ${stderrOutput.join('')}`); } return tapResult; } export function buildArguments(args, hookFile, testFile) { const hookFilePlaceholder = '{{hookFile}}'; const testFilePlaceholder = '{{testFile}}'; if (!args.some((arg) => arg.includes(hookFilePlaceholder))) { args = ['-r', hookFilePlaceholder, ...args]; } if (!args.some((arg) => arg.includes(testFilePlaceholder))) { args = [...args, testFilePlaceholder]; } return args.map((arg) => arg.replaceAll(testFilePlaceholder, testFile).replaceAll(hookFilePlaceholder, hookFile)); } //# sourceMappingURL=tap-helper.js.map