@stryker-mutator/mocha-runner
Version:
A plugin to use the mocha test runner in Stryker, the JavaScript mutation testing framework
33 lines • 1.37 kB
JavaScript
import path from 'path';
import { createRequire } from 'module';
import Mocha from 'mocha';
const require = createRequire(import.meta.url);
const mochaRoot = path.dirname(require.resolve('mocha/package.json'));
// https://github.com/mochajs/mocha/blob/master/lib/cli/run-helpers.js#L132
const runHelpers = require(`${mochaRoot}/lib/cli/run-helpers`);
let collectFiles;
/*
* If read, object containing parsed arguments
* @since 6.0.0'
* @see https://mochajs.org/api/module-lib_cli_options.html#.loadOptions
*/
const loadOptions = require(`${mochaRoot}/lib/cli/options`).loadOptions;
const handleRequires = runHelpers.handleRequires;
const loadRootHooks = runHelpers.loadRootHooks; // loadRootHooks is available since mocha v7.2 and removed again in 8.0
collectFiles = runHelpers.handleFiles;
if (!collectFiles) {
// Might be moved: https://github.com/mochajs/mocha/commit/15b96afccaf508312445770e3af1c145d90b28c6#diff-39b692a81eb0c9f3614247af744ab4a8
collectFiles = require(`${mochaRoot}/lib/cli/collect-files`);
}
/**
* Wraps Mocha class and require for testability
*/
export class LibWrapper {
static Mocha = Mocha;
static require = require;
static loadOptions = loadOptions;
static collectFiles = collectFiles;
static handleRequires = handleRequires;
static loadRootHooks = loadRootHooks;
}
//# sourceMappingURL=lib-wrapper.js.map