@jest/core
Advanced tools
Comparing version 28.0.0-alpha.8 to 28.0.0-alpha.9
@@ -78,4 +78,12 @@ 'use strict'; | ||
var _TestWatcher = _interopRequireDefault(require('../TestWatcher')); | ||
function _jestWatcher() { | ||
const data = require('jest-watcher'); | ||
_jestWatcher = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _collectHandles = require('../collectHandles'); | ||
@@ -403,3 +411,3 @@ | ||
startRun, | ||
testWatcher: new _TestWatcher.default({ | ||
testWatcher: new (_jestWatcher().TestWatcher)({ | ||
isWatchMode: false | ||
@@ -406,0 +414,0 @@ }) |
@@ -8,12 +8,14 @@ /** | ||
import {AggregatedResult} from '@jest/test-result'; | ||
import {BaseReporter} from '@jest/reporters'; | ||
import type {ChangedFiles} from 'jest-changed-files'; | ||
import type {Config} from '@jest/types'; | ||
import type {Context} from 'jest-runtime'; | ||
import emittery = require('emittery'); | ||
import {Reporter} from '@jest/reporters'; | ||
import {ReporterContext} from '@jest/reporters'; | ||
import {Test} from '@jest/test-result'; | ||
import type {TestContext} from '@jest/test-result'; | ||
import type {TestRunnerContext} from 'jest-runner'; | ||
import type {TestWatcher} from 'jest-watcher'; | ||
export declare function createTestScheduler( | ||
globalConfig: Config.GlobalConfig, | ||
options: TestSchedulerOptions, | ||
context: TestSchedulerContext, | ||
@@ -33,2 +35,8 @@ ): Promise<TestScheduler>; | ||
declare type ReporterConstructor = new ( | ||
globalConfig: Config.GlobalConfig, | ||
reporterConfig: Record<string, unknown>, | ||
reporterContext: ReporterContext, | ||
) => BaseReporter; | ||
export declare function runCLI( | ||
@@ -54,3 +62,3 @@ argv: Config.Argv, | ||
private _testPathCases; | ||
constructor(context: Context); | ||
constructor(context: TestContext); | ||
private _getOrBuildDependencyResolver; | ||
@@ -86,6 +94,2 @@ private _filterTestPathsWithStats; | ||
declare type State = { | ||
interrupted: boolean; | ||
}; | ||
declare type Stats = { | ||
@@ -100,13 +104,8 @@ roots: number; | ||
declare class TestScheduler { | ||
private readonly _context; | ||
private readonly _dispatcher; | ||
private readonly _globalConfig; | ||
private readonly _options; | ||
private readonly _context; | ||
constructor( | ||
globalConfig: Config.GlobalConfig, | ||
options: TestSchedulerOptions, | ||
context: TestSchedulerContext, | ||
); | ||
constructor(globalConfig: Config.GlobalConfig, context: TestSchedulerContext); | ||
addReporter(reporter: Reporter): void; | ||
removeReporter(ReporterClass: Function): void; | ||
removeReporter(reporterConstructor: ReporterConstructor): void; | ||
scheduleTests( | ||
@@ -117,36 +116,9 @@ tests: Array<Test>, | ||
private _partitionTests; | ||
private _shouldAddDefaultReporters; | ||
_setupReporters(): Promise<void>; | ||
private _setupDefaultReporters; | ||
private _addCustomReporters; | ||
/** | ||
* Get properties of a reporter in an object | ||
* to make dealing with them less painful. | ||
*/ | ||
private _getReporterProps; | ||
private _addCustomReporter; | ||
private _bailIfNeeded; | ||
} | ||
declare type TestSchedulerContext = { | ||
firstRun: boolean; | ||
previousSuccess: boolean; | ||
changedFiles?: Set<string>; | ||
sourcesRelatedToTestsInChangedFiles?: Set<string>; | ||
}; | ||
declare type TestSchedulerContext = ReporterContext & TestRunnerContext; | ||
declare type TestSchedulerOptions = { | ||
startRun: (globalConfig: Config.GlobalConfig) => void; | ||
}; | ||
export declare class TestWatcher extends emittery<{ | ||
change: State; | ||
}> { | ||
state: State; | ||
private _isWatchMode; | ||
constructor({isWatchMode}: {isWatchMode: boolean}); | ||
setState(state: State): Promise<void>; | ||
isInterrupted(): boolean; | ||
isWatchMode(): boolean; | ||
} | ||
export {}; |
@@ -12,8 +12,2 @@ 'use strict'; | ||
}); | ||
Object.defineProperty(exports, 'TestWatcher', { | ||
enumerable: true, | ||
get: function () { | ||
return _TestWatcher.default; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'createTestScheduler', { | ||
@@ -42,4 +36,2 @@ enumerable: true, | ||
var _TestWatcher = _interopRequireDefault(require('./TestWatcher')); | ||
var _cli = require('./cli'); | ||
@@ -46,0 +38,0 @@ |
@@ -14,4 +14,2 @@ 'use strict'; | ||
*/ | ||
/* eslint-disable local/ban-types-eventually */ | ||
class ReporterDispatcher { | ||
@@ -28,5 +26,5 @@ _reporters; | ||
unregister(ReporterClass) { | ||
unregister(reporterConstructor) { | ||
this._reporters = this._reporters.filter( | ||
reporter => !(reporter instanceof ReporterClass) | ||
reporter => !(reporter instanceof reporterConstructor) | ||
); | ||
@@ -72,6 +70,6 @@ } | ||
async onRunComplete(contexts, results) { | ||
async onRunComplete(testContexts, results) { | ||
for (const reporter of this._reporters) { | ||
if (reporter.onRunComplete) { | ||
await reporter.onRunComplete(contexts, results); | ||
await reporter.onRunComplete(testContexts, results); | ||
} | ||
@@ -78,0 +76,0 @@ } |
@@ -403,5 +403,5 @@ 'use strict'; | ||
{ | ||
startRun | ||
}, | ||
testSchedulerContext | ||
startRun, | ||
...testSchedulerContext | ||
} | ||
); | ||
@@ -408,0 +408,0 @@ const results = await scheduler.scheduleTests(allTests, testWatcher); |
@@ -18,2 +18,12 @@ 'use strict'; | ||
function _ciInfo() { | ||
const data = require('ci-info'); | ||
_ciInfo = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _exit() { | ||
@@ -105,6 +115,4 @@ const data = _interopRequireDefault(require('exit')); | ||
*/ | ||
/* eslint-disable local/ban-types-eventually */ | ||
async function createTestScheduler(globalConfig, options, context) { | ||
const scheduler = new TestScheduler(globalConfig, options, context); | ||
async function createTestScheduler(globalConfig, context) { | ||
const scheduler = new TestScheduler(globalConfig, context); | ||
await scheduler._setupReporters(); | ||
@@ -115,12 +123,10 @@ return scheduler; | ||
class TestScheduler { | ||
_context; | ||
_dispatcher; | ||
_globalConfig; | ||
_options; | ||
_context; | ||
constructor(globalConfig, options, context) { | ||
constructor(globalConfig, context) { | ||
this._context = context; | ||
this._dispatcher = new _ReporterDispatcher.default(); | ||
this._globalConfig = globalConfig; | ||
this._options = options; | ||
this._context = context; | ||
} | ||
@@ -132,4 +138,4 @@ | ||
removeReporter(ReporterClass) { | ||
this._dispatcher.unregister(ReporterClass); | ||
removeReporter(reporterConstructor) { | ||
this._dispatcher.unregister(reporterConstructor); | ||
} | ||
@@ -143,5 +149,5 @@ | ||
const timings = []; | ||
const contexts = new Set(); | ||
const testContexts = new Set(); | ||
tests.forEach(test => { | ||
contexts.add(test.context); | ||
testContexts.add(test.context); | ||
@@ -197,3 +203,3 @@ if (test.duration) { | ||
); | ||
return this._bailIfNeeded(contexts, aggregatedResults, watcher); | ||
return this._bailIfNeeded(testContexts, aggregatedResults, watcher); | ||
}; | ||
@@ -226,3 +232,3 @@ | ||
const contextsWithSnapshotResolvers = await Promise.all( | ||
Array.from(contexts).map(async context => [ | ||
Array.from(testContexts).map(async context => [ | ||
context, | ||
@@ -261,8 +267,6 @@ await (0, _jestSnapshot().buildSnapshotResolver)(context.config) | ||
await Promise.all( | ||
Array.from(contexts).map(async context => { | ||
Array.from(testContexts).map(async context => { | ||
const {config} = context; | ||
if (!testRunners[config.runner]) { | ||
var _this$_context, _this$_context2; | ||
const transformer = await (0, _transform().createScriptTransformer)( | ||
@@ -275,12 +279,5 @@ config | ||
const runner = new Runner(this._globalConfig, { | ||
changedFiles: | ||
(_this$_context = this._context) === null || | ||
_this$_context === void 0 | ||
? void 0 | ||
: _this$_context.changedFiles, | ||
changedFiles: this._context.changedFiles, | ||
sourcesRelatedToTestsInChangedFiles: | ||
(_this$_context2 = this._context) === null || | ||
_this$_context2 === void 0 | ||
? void 0 | ||
: _this$_context2.sourcesRelatedToTestsInChangedFiles | ||
this._context.sourcesRelatedToTestsInChangedFiles | ||
}); | ||
@@ -305,8 +302,4 @@ testRunners[config.runner] = runner; | ||
}; | ||
/** | ||
* Test runners with event emitters are still not supported | ||
* for third party test runners. | ||
*/ | ||
if (testRunner.__PRIVATE_UNSTABLE_API_supportsEventEmitters__) { | ||
if (testRunner.supportsEventEmitters) { | ||
const unsubscribes = [ | ||
@@ -334,10 +327,3 @@ testRunner.on('test-file-start', ([test]) => | ||
]; | ||
await testRunner.runTests( | ||
tests, | ||
watcher, | ||
undefined, | ||
undefined, | ||
undefined, | ||
testRunnerOptions | ||
); | ||
await testRunner.runTests(tests, watcher, testRunnerOptions); | ||
unsubscribes.forEach(sub => sub()); | ||
@@ -364,3 +350,3 @@ } else { | ||
aggregatedResults.wasInterrupted = watcher.isInterrupted(); | ||
await this._dispatcher.onRunComplete(contexts, aggregatedResults); | ||
await this._dispatcher.onRunComplete(testContexts, aggregatedResults); | ||
const anyTestFailures = !( | ||
@@ -403,37 +389,32 @@ aggregatedResults.numFailedTests === 0 && | ||
_shouldAddDefaultReporters(reporters) { | ||
return ( | ||
!reporters || | ||
!!reporters.find( | ||
reporter => this._getReporterProps(reporter).path === 'default' | ||
) | ||
); | ||
} | ||
async _setupReporters() { | ||
const {collectCoverage, notify, reporters} = this._globalConfig; | ||
const {collectCoverage: coverage, notify, verbose} = this._globalConfig; | ||
const reporters = this._globalConfig.reporters || [['default', {}]]; | ||
let summary = false; | ||
const isDefault = this._shouldAddDefaultReporters(reporters); | ||
for (const [reporter, options] of reporters) { | ||
switch (reporter) { | ||
case 'default': | ||
summary = true; | ||
verbose | ||
? this.addReporter( | ||
new (_reporters().VerboseReporter)(this._globalConfig) | ||
) | ||
: this.addReporter( | ||
new (_reporters().DefaultReporter)(this._globalConfig) | ||
); | ||
break; | ||
if (isDefault) { | ||
this._setupDefaultReporters(collectCoverage); | ||
} | ||
case 'github-actions': | ||
_ciInfo().GITHUB_ACTIONS && | ||
this.addReporter(new (_reporters().GitHubActionsReporter)()); | ||
break; | ||
if (!isDefault && collectCoverage) { | ||
var _this$_context3, _this$_context4; | ||
case 'summary': | ||
summary = true; | ||
break; | ||
this.addReporter( | ||
new (_reporters().CoverageReporter)(this._globalConfig, { | ||
changedFiles: | ||
(_this$_context3 = this._context) === null || | ||
_this$_context3 === void 0 | ||
? void 0 | ||
: _this$_context3.changedFiles, | ||
sourcesRelatedToTestsInChangedFiles: | ||
(_this$_context4 = this._context) === null || | ||
_this$_context4 === void 0 | ||
? void 0 | ||
: _this$_context4.sourcesRelatedToTestsInChangedFiles | ||
}) | ||
); | ||
default: | ||
await this._addCustomReporter(reporter, options); | ||
} | ||
} | ||
@@ -443,87 +424,32 @@ | ||
this.addReporter( | ||
new (_reporters().NotifyReporter)( | ||
this._globalConfig, | ||
this._options.startRun, | ||
this._context | ||
) | ||
new (_reporters().NotifyReporter)(this._globalConfig, this._context) | ||
); | ||
} | ||
if (reporters && Array.isArray(reporters)) { | ||
await this._addCustomReporters(reporters); | ||
} | ||
} | ||
_setupDefaultReporters(collectCoverage) { | ||
this.addReporter( | ||
this._globalConfig.verbose | ||
? new (_reporters().VerboseReporter)(this._globalConfig) | ||
: new (_reporters().DefaultReporter)(this._globalConfig) | ||
); | ||
if (collectCoverage) { | ||
var _this$_context5, _this$_context6; | ||
if (coverage) { | ||
this.addReporter( | ||
new (_reporters().CoverageReporter)(this._globalConfig, { | ||
changedFiles: | ||
(_this$_context5 = this._context) === null || | ||
_this$_context5 === void 0 | ||
? void 0 | ||
: _this$_context5.changedFiles, | ||
sourcesRelatedToTestsInChangedFiles: | ||
(_this$_context6 = this._context) === null || | ||
_this$_context6 === void 0 | ||
? void 0 | ||
: _this$_context6.sourcesRelatedToTestsInChangedFiles | ||
}) | ||
new (_reporters().CoverageReporter)(this._globalConfig, this._context) | ||
); | ||
} | ||
this.addReporter(new (_reporters().SummaryReporter)(this._globalConfig)); | ||
} | ||
async _addCustomReporters(reporters) { | ||
for (const reporter of reporters) { | ||
const {options, path} = this._getReporterProps(reporter); | ||
if (path === 'default') continue; | ||
try { | ||
const Reporter = await (0, _jestUtil().requireOrImportModule)( | ||
path, | ||
true | ||
); | ||
this.addReporter(new Reporter(this._globalConfig, options)); | ||
} catch (error) { | ||
error.message = `An error occurred while adding the reporter at path "${_chalk().default.bold( | ||
path | ||
)}".${error.message}`; | ||
throw error; | ||
} | ||
if (summary) { | ||
this.addReporter(new (_reporters().SummaryReporter)(this._globalConfig)); | ||
} | ||
} | ||
/** | ||
* Get properties of a reporter in an object | ||
* to make dealing with them less painful. | ||
*/ | ||
_getReporterProps(reporter) { | ||
if (typeof reporter === 'string') { | ||
return { | ||
options: this._options, | ||
path: reporter | ||
}; | ||
} else if (Array.isArray(reporter)) { | ||
const [path, options] = reporter; | ||
return { | ||
options, | ||
path | ||
}; | ||
async _addCustomReporter(reporter, options) { | ||
try { | ||
const Reporter = await (0, _jestUtil().requireOrImportModule)(reporter); | ||
this.addReporter( | ||
new Reporter(this._globalConfig, options, this._context) | ||
); | ||
} catch (error) { | ||
error.message = `An error occurred while adding the reporter at path "${_chalk().default.bold( | ||
reporter | ||
)}".\n${error instanceof Error ? error.message : ''}`; | ||
throw error; | ||
} | ||
throw new Error('Reporter should be either a string or an array'); | ||
} | ||
async _bailIfNeeded(contexts, aggregatedResults, watcher) { | ||
async _bailIfNeeded(testContexts, aggregatedResults, watcher) { | ||
if ( | ||
@@ -541,3 +467,3 @@ this._globalConfig.bail !== 0 && | ||
try { | ||
await this._dispatcher.onRunComplete(contexts, aggregatedResults); | ||
await this._dispatcher.onRunComplete(testContexts, aggregatedResults); | ||
} finally { | ||
@@ -544,0 +470,0 @@ const exitCode = this._globalConfig.testFailureExitCode; |
@@ -102,4 +102,2 @@ 'use strict'; | ||
var _TestWatcher = _interopRequireDefault(require('./TestWatcher')); | ||
var _getChangedFilesPromise = _interopRequireDefault( | ||
@@ -439,3 +437,3 @@ require('./getChangedFilesPromise') | ||
testWatcher = new _TestWatcher.default({ | ||
testWatcher = new (_jestWatcher().TestWatcher)({ | ||
isWatchMode: true | ||
@@ -465,3 +463,3 @@ }); | ||
testWatcher = new _TestWatcher.default({ | ||
testWatcher = new (_jestWatcher().TestWatcher)({ | ||
isWatchMode: true | ||
@@ -468,0 +466,0 @@ }); // Do not show any Watch Usage related stuff when running in a |
{ | ||
"name": "@jest/core", | ||
"description": "Delightful JavaScript Testing.", | ||
"version": "28.0.0-alpha.8", | ||
"version": "28.0.0-alpha.9", | ||
"main": "./build/index.js", | ||
@@ -15,28 +15,28 @@ "types": "./build/index.d.ts", | ||
"dependencies": { | ||
"@jest/console": "^28.0.0-alpha.8", | ||
"@jest/reporters": "^28.0.0-alpha.8", | ||
"@jest/test-result": "^28.0.0-alpha.8", | ||
"@jest/transform": "^28.0.0-alpha.8", | ||
"@jest/types": "^28.0.0-alpha.8", | ||
"@jest/console": "^28.0.0-alpha.9", | ||
"@jest/reporters": "^28.0.0-alpha.9", | ||
"@jest/test-result": "^28.0.0-alpha.9", | ||
"@jest/transform": "^28.0.0-alpha.9", | ||
"@jest/types": "^28.0.0-alpha.9", | ||
"@types/node": "*", | ||
"ansi-escapes": "^4.2.1", | ||
"chalk": "^4.0.0", | ||
"emittery": "^0.8.1", | ||
"ci-info": "^3.2.0", | ||
"exit": "^0.1.2", | ||
"graceful-fs": "^4.2.9", | ||
"jest-changed-files": "^28.0.0-alpha.3", | ||
"jest-config": "^28.0.0-alpha.8", | ||
"jest-haste-map": "^28.0.0-alpha.8", | ||
"jest-message-util": "^28.0.0-alpha.8", | ||
"jest-config": "^28.0.0-alpha.9", | ||
"jest-haste-map": "^28.0.0-alpha.9", | ||
"jest-message-util": "^28.0.0-alpha.9", | ||
"jest-regex-util": "^28.0.0-alpha.6", | ||
"jest-resolve": "^28.0.0-alpha.8", | ||
"jest-resolve-dependencies": "^28.0.0-alpha.8", | ||
"jest-runner": "^28.0.0-alpha.8", | ||
"jest-runtime": "^28.0.0-alpha.8", | ||
"jest-snapshot": "^28.0.0-alpha.8", | ||
"jest-util": "^28.0.0-alpha.8", | ||
"jest-validate": "^28.0.0-alpha.8", | ||
"jest-watcher": "^28.0.0-alpha.8", | ||
"jest-resolve": "^28.0.0-alpha.9", | ||
"jest-resolve-dependencies": "^28.0.0-alpha.9", | ||
"jest-runner": "^28.0.0-alpha.9", | ||
"jest-runtime": "^28.0.0-alpha.9", | ||
"jest-snapshot": "^28.0.0-alpha.9", | ||
"jest-util": "^28.0.0-alpha.9", | ||
"jest-validate": "^28.0.0-alpha.9", | ||
"jest-watcher": "^28.0.0-alpha.9", | ||
"micromatch": "^4.0.4", | ||
"pretty-format": "^28.0.0-alpha.8", | ||
"pretty-format": "^28.0.0-alpha.9", | ||
"rimraf": "^3.0.0", | ||
@@ -47,6 +47,6 @@ "slash": "^3.0.0", | ||
"devDependencies": { | ||
"@jest/test-sequencer": "^28.0.0-alpha.8", | ||
"@jest/test-utils": "^28.0.0-alpha.8", | ||
"@jest/test-sequencer": "^28.0.0-alpha.9", | ||
"@jest/test-utils": "^28.0.0-alpha.9", | ||
"@types/exit": "^0.1.30", | ||
"@types/graceful-fs": "^4.1.2", | ||
"@types/graceful-fs": "^4.1.3", | ||
"@types/micromatch": "^4.0.1", | ||
@@ -68,3 +68,3 @@ "@types/rimraf": "^3.0.0" | ||
"type": "git", | ||
"url": "https://github.com/facebook/jest", | ||
"url": "https://github.com/facebook/jest.git", | ||
"directory": "packages/jest-core" | ||
@@ -106,3 +106,3 @@ }, | ||
}, | ||
"gitHead": "d915e7df92b220dbe6e124585ba6459838a6c41c" | ||
"gitHead": "7c63f5981eb20d4b89a4c04f3675e0050d8d7887" | ||
} |
142702
46
4667
+ Addedci-info@^3.2.0
- Removedemittery@^0.8.1
- Removedemittery@0.8.1(transitive)
Updated@jest/types@^28.0.0-alpha.9
Updatedjest-config@^28.0.0-alpha.9
Updatedjest-resolve@^28.0.0-alpha.9
Updatedjest-runner@^28.0.0-alpha.9
Updatedjest-runtime@^28.0.0-alpha.9
Updatedjest-util@^28.0.0-alpha.9
Updatedjest-watcher@^28.0.0-alpha.9