create-jest-runner
Advanced tools
Comparing version 0.12.2 to 0.12.3
@@ -0,4 +1,5 @@ | ||
/// <reference types="node" /> | ||
import type { Config, OnTestFailure, OnTestStart, OnTestSuccess, Test, TestRunnerOptions, TestWatcher } from 'jest-runner'; | ||
import type { CreateRunnerOptions } from './types'; | ||
export default function createRunner<ExtraOptions extends Record<string, unknown>>(runPath: string, { getExtraOptions }?: CreateRunnerOptions<ExtraOptions>): { | ||
export default function createRunner<ExtraOptions extends Record<string, unknown>>(runPath: string | URL, { getExtraOptions }?: CreateRunnerOptions<ExtraOptions>): { | ||
new (globalConfig: Config.GlobalConfig): { | ||
@@ -5,0 +6,0 @@ "__#2@#globalConfig": Config.GlobalConfig; |
@@ -7,18 +7,14 @@ "use strict"; | ||
exports.default = createRunner; | ||
var _jestWorker = require("jest-worker"); | ||
var _pLimit = _interopRequireDefault(require("p-limit")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function determineSlowTestResult(test, result) { | ||
// See: https://github.com/facebook/jest/blob/acd7c83c8365140f4ecf44a456ff7366ffa31fa2/packages/jest-runner/src/runTest.ts#L287 | ||
if (result.perfStats.runtime / 1000 > test.context.config.slowTestThreshold) { | ||
return { ...result, | ||
perfStats: { ...result.perfStats, | ||
return { | ||
...result, | ||
perfStats: { | ||
...result.perfStats, | ||
slow: true | ||
@@ -28,6 +24,4 @@ } | ||
} | ||
return result; | ||
} | ||
class CancelRun extends Error { | ||
@@ -38,5 +32,3 @@ constructor(message) { | ||
} | ||
} | ||
function createRunner(runPath, { | ||
@@ -47,13 +39,10 @@ getExtraOptions | ||
#globalConfig; | ||
constructor(globalConfig) { | ||
this.#globalConfig = globalConfig; | ||
} | ||
runTests(tests, watcher, onStart, onResult, onFailure, options) { | ||
return options.serial ? this._createInBandTestRun(tests, watcher, onStart, onResult, onFailure, options) : this._createParallelTestRun(tests, watcher, onStart, onResult, onFailure, options); | ||
} | ||
async _createInBandTestRun(tests, watcher, onStart, onResult, onFailure, options) { | ||
const runner = (await Promise.resolve(`${runPath}`).then(s => _interopRequireWildcard(require(s)))).default; | ||
const runner = (await (specifier => new Promise(r => r(`${specifier}`)).then(s => _interopRequireWildcard(require(s))))(runPath.toString())).default; | ||
const mutex = (0, _pLimit.default)(1); | ||
@@ -64,3 +53,2 @@ return tests.reduce((promise, test) => mutex(() => promise.then(() => { | ||
} | ||
return onStart(test).then(() => { | ||
@@ -75,7 +63,2 @@ const baseOptions = { | ||
}; | ||
if (typeof runner.default === 'function') { | ||
return runner.default(baseOptions); | ||
} | ||
return runner(baseOptions); | ||
@@ -85,3 +68,2 @@ }); | ||
} | ||
_createParallelTestRun(tests, watcher, onStart, onResult, onFailure, options) { | ||
@@ -96,3 +78,2 @@ const worker = new _jestWorker.Worker(runPath, { | ||
const mutex = (0, _pLimit.default)(this.#globalConfig.maxWorkers); | ||
const runTestInWorker = test => mutex(() => { | ||
@@ -102,3 +83,2 @@ if (watcher.isInterrupted()) { | ||
} | ||
return onStart(test).then(() => { | ||
@@ -116,3 +96,2 @@ const runTestOptions = { | ||
}); | ||
const onInterrupt = new Promise((_, reject) => { | ||
@@ -126,11 +105,8 @@ watcher.on('change', state => { | ||
const runAllTests = Promise.all(tests.map(test => runTestInWorker(test).then(result => determineSlowTestResult(test, result)).then(testResult => onResult(test, testResult)).catch(error => onFailure(test, error)))); | ||
const cleanup = () => { | ||
worker.end(); | ||
}; | ||
return Promise.race([runAllTests, onInterrupt]).then(cleanup, cleanup); | ||
} | ||
}; | ||
} |
@@ -7,7 +7,4 @@ "use strict"; | ||
exports.default = fail; | ||
var _toTestResult = _interopRequireDefault(require("./toTestResult")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function fail({ | ||
@@ -14,0 +11,0 @@ start, |
@@ -36,13 +36,7 @@ "use strict"; | ||
}); | ||
var _createJestRunner = _interopRequireDefault(require("./createJestRunner")); | ||
var _fail = _interopRequireDefault(require("./fail")); | ||
var _pass = _interopRequireDefault(require("./pass")); | ||
var _skip = _interopRequireDefault(require("./skip")); | ||
var _todo = _interopRequireDefault(require("./todo")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } |
@@ -7,7 +7,4 @@ "use strict"; | ||
exports.default = pass; | ||
var _toTestResult = _interopRequireDefault(require("./toTestResult")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function pass({ | ||
@@ -14,0 +11,0 @@ start, |
@@ -7,7 +7,4 @@ "use strict"; | ||
exports.default = skip; | ||
var _toTestResult = _interopRequireDefault(require("./toTestResult")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function skip({ | ||
@@ -14,0 +11,0 @@ start, |
@@ -7,7 +7,4 @@ "use strict"; | ||
exports.default = todo; | ||
var _toTestResult = _interopRequireDefault(require("./toTestResult")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function todo({ | ||
@@ -14,0 +11,0 @@ start, |
@@ -7,3 +7,2 @@ "use strict"; | ||
exports.default = toTestResult; | ||
function getPerfStats({ | ||
@@ -14,4 +13,4 @@ stats | ||
const end = new Date(stats.end).getTime(); | ||
const runtime = end - start; // Note: this flag is set in 'lib/createJestRunner.ts' | ||
const runtime = end - start; | ||
// Note: this flag is set in 'lib/createJestRunner.ts' | ||
const slow = false; | ||
@@ -25,3 +24,2 @@ return { | ||
} | ||
function getSnapshot() { | ||
@@ -38,3 +36,2 @@ return { | ||
} | ||
function getTestResults({ | ||
@@ -59,3 +56,2 @@ errorMessage, | ||
} | ||
function toTestResult(options) { | ||
@@ -62,0 +58,0 @@ const { |
@@ -6,3 +6,3 @@ import type { TestContext, TestResult } from '@jest/test-result'; | ||
} | ||
export declare type RunTestOptions<ExtraOptions extends Record<string, unknown> = Record<string, unknown>> = { | ||
export type RunTestOptions<ExtraOptions extends Record<string, unknown> = Record<string, unknown>> = { | ||
config: Config.ProjectConfig; | ||
@@ -15,3 +15,3 @@ extraOptions: ExtraOptions; | ||
}; | ||
export declare type RunTest<ExtraOptions extends Record<string, unknown> = Record<string, unknown>> = (options: RunTestOptions<ExtraOptions>) => TestResult | Promise<TestResult>; | ||
export type RunTest<ExtraOptions extends Record<string, unknown> = Record<string, unknown>> = (options: RunTestOptions<ExtraOptions>) => TestResult | Promise<TestResult>; | ||
export interface TestDetail { | ||
@@ -18,0 +18,0 @@ title: string; |
{ | ||
"name": "create-jest-runner", | ||
"version": "0.12.2", | ||
"version": "0.12.3", | ||
"main": "build/index.js", | ||
@@ -42,3 +42,3 @@ "types": "build/index.d.ts", | ||
"chalk": "^4.1.0", | ||
"jest-worker": "^29.0.0", | ||
"jest-worker": "^29.5.0", | ||
"p-limit": "^3.1.0" | ||
@@ -91,3 +91,3 @@ }, | ||
}, | ||
"packageManager": "yarn@3.2.3" | ||
"packageManager": "yarn@3.4.1" | ||
} |
@@ -32,3 +32,3 @@ # create-jest-runner | ||
- `pathToRunFile`: path to your run file. | ||
- `pathToRunFile`: path to your run file. This must be an absolute path or a `file://` URL. | ||
- `config`: Optional argument for configuring the runner. | ||
@@ -35,0 +35,0 @@ - `getExtraOptions`: `() => object` used for passing extra options to the runner. It needs to be a serializable object because it will be send to a different Node process. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
522
24965
Updatedjest-worker@^29.5.0