feat: initial commit
This commit is contained in:
21
node_modules/@jest/reporters/LICENSE
generated
vendored
Normal file
21
node_modules/@jest/reporters/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
BIN
node_modules/@jest/reporters/assets/jest_logo.png
generated
vendored
Normal file
BIN
node_modules/@jest/reporters/assets/jest_logo.png
generated
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.0 KiB |
48
node_modules/@jest/reporters/build/BaseReporter.js
generated
vendored
Normal file
48
node_modules/@jest/reporters/build/BaseReporter.js
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
function _jestUtil() {
|
||||
const data = require('jest-util');
|
||||
_jestUtil = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
const {remove: preRunMessageRemove} = _jestUtil().preRunMessage;
|
||||
class BaseReporter {
|
||||
_error;
|
||||
log(message) {
|
||||
process.stderr.write(`${message}\n`);
|
||||
}
|
||||
onRunStart(_results, _options) {
|
||||
preRunMessageRemove(process.stderr);
|
||||
}
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-empty-function */
|
||||
onTestCaseResult(_test, _testCaseResult) {}
|
||||
onTestResult(_test, _testResult, _results) {}
|
||||
onTestStart(_test) {}
|
||||
onRunComplete(_testContexts, _aggregatedResults) {}
|
||||
/* eslint-enable */
|
||||
|
||||
_setError(error) {
|
||||
this._error = error;
|
||||
}
|
||||
|
||||
// Return an error that occurred during reporting. This error will
|
||||
// define whether the test run was successful or failed.
|
||||
getLastError() {
|
||||
return this._error;
|
||||
}
|
||||
}
|
||||
exports.default = BaseReporter;
|
||||
561
node_modules/@jest/reporters/build/CoverageReporter.js
generated
vendored
Normal file
561
node_modules/@jest/reporters/build/CoverageReporter.js
generated
vendored
Normal file
@@ -0,0 +1,561 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
function path() {
|
||||
const data = _interopRequireWildcard(require('path'));
|
||||
path = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _v8Coverage() {
|
||||
const data = require('@bcoe/v8-coverage');
|
||||
_v8Coverage = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _chalk() {
|
||||
const data = _interopRequireDefault(require('chalk'));
|
||||
_chalk = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _glob() {
|
||||
const data = _interopRequireDefault(require('glob'));
|
||||
_glob = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function fs() {
|
||||
const data = _interopRequireWildcard(require('graceful-fs'));
|
||||
fs = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _istanbulLibCoverage() {
|
||||
const data = _interopRequireDefault(require('istanbul-lib-coverage'));
|
||||
_istanbulLibCoverage = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _istanbulLibReport() {
|
||||
const data = _interopRequireDefault(require('istanbul-lib-report'));
|
||||
_istanbulLibReport = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _istanbulLibSourceMaps() {
|
||||
const data = _interopRequireDefault(require('istanbul-lib-source-maps'));
|
||||
_istanbulLibSourceMaps = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _istanbulReports() {
|
||||
const data = _interopRequireDefault(require('istanbul-reports'));
|
||||
_istanbulReports = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _v8ToIstanbul() {
|
||||
const data = _interopRequireDefault(require('v8-to-istanbul'));
|
||||
_v8ToIstanbul = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _jestUtil() {
|
||||
const data = require('jest-util');
|
||||
_jestUtil = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _jestWorker() {
|
||||
const data = require('jest-worker');
|
||||
_jestWorker = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
var _BaseReporter = _interopRequireDefault(require('./BaseReporter'));
|
||||
var _getWatermarks = _interopRequireDefault(require('./getWatermarks'));
|
||||
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;
|
||||
}
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
const FAIL_COLOR = _chalk().default.bold.red;
|
||||
const RUNNING_TEST_COLOR = _chalk().default.bold.dim;
|
||||
class CoverageReporter extends _BaseReporter.default {
|
||||
_context;
|
||||
_coverageMap;
|
||||
_globalConfig;
|
||||
_sourceMapStore;
|
||||
_v8CoverageResults;
|
||||
static filename = __filename;
|
||||
constructor(globalConfig, context) {
|
||||
super();
|
||||
this._context = context;
|
||||
this._coverageMap = _istanbulLibCoverage().default.createCoverageMap({});
|
||||
this._globalConfig = globalConfig;
|
||||
this._sourceMapStore =
|
||||
_istanbulLibSourceMaps().default.createSourceMapStore();
|
||||
this._v8CoverageResults = [];
|
||||
}
|
||||
onTestResult(_test, testResult) {
|
||||
if (testResult.v8Coverage) {
|
||||
this._v8CoverageResults.push(testResult.v8Coverage);
|
||||
return;
|
||||
}
|
||||
if (testResult.coverage) {
|
||||
this._coverageMap.merge(testResult.coverage);
|
||||
}
|
||||
}
|
||||
async onRunComplete(testContexts, aggregatedResults) {
|
||||
await this._addUntestedFiles(testContexts);
|
||||
const {map, reportContext} = await this._getCoverageResult();
|
||||
try {
|
||||
const coverageReporters = this._globalConfig.coverageReporters || [];
|
||||
if (!this._globalConfig.useStderr && coverageReporters.length < 1) {
|
||||
coverageReporters.push('text-summary');
|
||||
}
|
||||
coverageReporters.forEach(reporter => {
|
||||
let additionalOptions = {};
|
||||
if (Array.isArray(reporter)) {
|
||||
[reporter, additionalOptions] = reporter;
|
||||
}
|
||||
_istanbulReports()
|
||||
.default.create(reporter, {
|
||||
maxCols: process.stdout.columns || Infinity,
|
||||
...additionalOptions
|
||||
})
|
||||
.execute(reportContext);
|
||||
});
|
||||
aggregatedResults.coverageMap = map;
|
||||
} catch (e) {
|
||||
console.error(
|
||||
_chalk().default.red(`
|
||||
Failed to write coverage reports:
|
||||
ERROR: ${e.toString()}
|
||||
STACK: ${e.stack}
|
||||
`)
|
||||
);
|
||||
}
|
||||
this._checkThreshold(map);
|
||||
}
|
||||
async _addUntestedFiles(testContexts) {
|
||||
const files = [];
|
||||
testContexts.forEach(context => {
|
||||
const config = context.config;
|
||||
if (
|
||||
this._globalConfig.collectCoverageFrom &&
|
||||
this._globalConfig.collectCoverageFrom.length
|
||||
) {
|
||||
context.hasteFS
|
||||
.matchFilesWithGlob(
|
||||
this._globalConfig.collectCoverageFrom,
|
||||
config.rootDir
|
||||
)
|
||||
.forEach(filePath =>
|
||||
files.push({
|
||||
config,
|
||||
path: filePath
|
||||
})
|
||||
);
|
||||
}
|
||||
});
|
||||
if (!files.length) {
|
||||
return;
|
||||
}
|
||||
if (_jestUtil().isInteractive) {
|
||||
process.stderr.write(
|
||||
RUNNING_TEST_COLOR('Running coverage on untested files...')
|
||||
);
|
||||
}
|
||||
let worker;
|
||||
if (this._globalConfig.maxWorkers <= 1) {
|
||||
worker = require('./CoverageWorker');
|
||||
} else {
|
||||
worker = new (_jestWorker().Worker)(require.resolve('./CoverageWorker'), {
|
||||
enableWorkerThreads: this._globalConfig.workerThreads,
|
||||
exposedMethods: ['worker'],
|
||||
forkOptions: {
|
||||
serialization: 'json'
|
||||
},
|
||||
maxRetries: 2,
|
||||
numWorkers: this._globalConfig.maxWorkers
|
||||
});
|
||||
}
|
||||
const instrumentation = files.map(async fileObj => {
|
||||
const filename = fileObj.path;
|
||||
const config = fileObj.config;
|
||||
const hasCoverageData = this._v8CoverageResults.some(v8Res =>
|
||||
v8Res.some(innerRes => innerRes.result.url === filename)
|
||||
);
|
||||
if (
|
||||
!hasCoverageData &&
|
||||
!this._coverageMap.data[filename] &&
|
||||
'worker' in worker
|
||||
) {
|
||||
try {
|
||||
const result = await worker.worker({
|
||||
config,
|
||||
context: {
|
||||
changedFiles:
|
||||
this._context.changedFiles &&
|
||||
Array.from(this._context.changedFiles),
|
||||
sourcesRelatedToTestsInChangedFiles:
|
||||
this._context.sourcesRelatedToTestsInChangedFiles &&
|
||||
Array.from(this._context.sourcesRelatedToTestsInChangedFiles)
|
||||
},
|
||||
globalConfig: this._globalConfig,
|
||||
path: filename
|
||||
});
|
||||
if (result) {
|
||||
if (result.kind === 'V8Coverage') {
|
||||
this._v8CoverageResults.push([
|
||||
{
|
||||
codeTransformResult: undefined,
|
||||
result: result.result
|
||||
}
|
||||
]);
|
||||
} else {
|
||||
this._coverageMap.addFileCoverage(result.coverage);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(
|
||||
_chalk().default.red(
|
||||
[
|
||||
`Failed to collect coverage from ${filename}`,
|
||||
`ERROR: ${error.message}`,
|
||||
`STACK: ${error.stack}`
|
||||
].join('\n')
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
try {
|
||||
await Promise.all(instrumentation);
|
||||
} catch {
|
||||
// Do nothing; errors were reported earlier to the console.
|
||||
}
|
||||
if (_jestUtil().isInteractive) {
|
||||
(0, _jestUtil().clearLine)(process.stderr);
|
||||
}
|
||||
if (worker && 'end' in worker && typeof worker.end === 'function') {
|
||||
await worker.end();
|
||||
}
|
||||
}
|
||||
_checkThreshold(map) {
|
||||
const {coverageThreshold} = this._globalConfig;
|
||||
if (coverageThreshold) {
|
||||
function check(name, thresholds, actuals) {
|
||||
return ['statements', 'branches', 'lines', 'functions'].reduce(
|
||||
(errors, key) => {
|
||||
const actual = actuals[key].pct;
|
||||
const actualUncovered = actuals[key].total - actuals[key].covered;
|
||||
const threshold = thresholds[key];
|
||||
if (threshold !== undefined) {
|
||||
if (threshold < 0) {
|
||||
if (threshold * -1 < actualUncovered) {
|
||||
errors.push(
|
||||
`Jest: Uncovered count for ${key} (${actualUncovered}) ` +
|
||||
`exceeds ${name} threshold (${-1 * threshold})`
|
||||
);
|
||||
}
|
||||
} else if (actual < threshold) {
|
||||
errors.push(
|
||||
`Jest: "${name}" coverage threshold for ${key} (${threshold}%) not met: ${actual}%`
|
||||
);
|
||||
}
|
||||
}
|
||||
return errors;
|
||||
},
|
||||
[]
|
||||
);
|
||||
}
|
||||
const THRESHOLD_GROUP_TYPES = {
|
||||
GLOB: 'glob',
|
||||
GLOBAL: 'global',
|
||||
PATH: 'path'
|
||||
};
|
||||
const coveredFiles = map.files();
|
||||
const thresholdGroups = Object.keys(coverageThreshold);
|
||||
const groupTypeByThresholdGroup = {};
|
||||
const filesByGlob = {};
|
||||
const coveredFilesSortedIntoThresholdGroup = coveredFiles.reduce(
|
||||
(files, file) => {
|
||||
const pathOrGlobMatches = thresholdGroups.reduce(
|
||||
(agg, thresholdGroup) => {
|
||||
// Preserve trailing slash, but not required if root dir
|
||||
// See https://github.com/jestjs/jest/issues/12703
|
||||
const resolvedThresholdGroup = path().resolve(thresholdGroup);
|
||||
const suffix =
|
||||
(thresholdGroup.endsWith(path().sep) ||
|
||||
(process.platform === 'win32' &&
|
||||
thresholdGroup.endsWith('/'))) &&
|
||||
!resolvedThresholdGroup.endsWith(path().sep)
|
||||
? path().sep
|
||||
: '';
|
||||
const absoluteThresholdGroup = `${resolvedThresholdGroup}${suffix}`;
|
||||
|
||||
// The threshold group might be a path:
|
||||
|
||||
if (file.indexOf(absoluteThresholdGroup) === 0) {
|
||||
groupTypeByThresholdGroup[thresholdGroup] =
|
||||
THRESHOLD_GROUP_TYPES.PATH;
|
||||
return agg.concat([[file, thresholdGroup]]);
|
||||
}
|
||||
|
||||
// If the threshold group is not a path it might be a glob:
|
||||
|
||||
// Note: glob.sync is slow. By memoizing the files matching each glob
|
||||
// (rather than recalculating it for each covered file) we save a tonne
|
||||
// of execution time.
|
||||
if (filesByGlob[absoluteThresholdGroup] === undefined) {
|
||||
filesByGlob[absoluteThresholdGroup] = _glob()
|
||||
.default.sync(absoluteThresholdGroup)
|
||||
.map(filePath => path().resolve(filePath));
|
||||
}
|
||||
if (filesByGlob[absoluteThresholdGroup].indexOf(file) > -1) {
|
||||
groupTypeByThresholdGroup[thresholdGroup] =
|
||||
THRESHOLD_GROUP_TYPES.GLOB;
|
||||
return agg.concat([[file, thresholdGroup]]);
|
||||
}
|
||||
return agg;
|
||||
},
|
||||
[]
|
||||
);
|
||||
if (pathOrGlobMatches.length > 0) {
|
||||
return files.concat(pathOrGlobMatches);
|
||||
}
|
||||
|
||||
// Neither a glob or a path? Toss it in global if there's a global threshold:
|
||||
if (thresholdGroups.indexOf(THRESHOLD_GROUP_TYPES.GLOBAL) > -1) {
|
||||
groupTypeByThresholdGroup[THRESHOLD_GROUP_TYPES.GLOBAL] =
|
||||
THRESHOLD_GROUP_TYPES.GLOBAL;
|
||||
return files.concat([[file, THRESHOLD_GROUP_TYPES.GLOBAL]]);
|
||||
}
|
||||
|
||||
// A covered file that doesn't have a threshold:
|
||||
return files.concat([[file, undefined]]);
|
||||
},
|
||||
[]
|
||||
);
|
||||
const getFilesInThresholdGroup = thresholdGroup =>
|
||||
coveredFilesSortedIntoThresholdGroup
|
||||
.filter(fileAndGroup => fileAndGroup[1] === thresholdGroup)
|
||||
.map(fileAndGroup => fileAndGroup[0]);
|
||||
function combineCoverage(filePaths) {
|
||||
return filePaths
|
||||
.map(filePath => map.fileCoverageFor(filePath))
|
||||
.reduce((combinedCoverage, nextFileCoverage) => {
|
||||
if (combinedCoverage === undefined || combinedCoverage === null) {
|
||||
return nextFileCoverage.toSummary();
|
||||
}
|
||||
return combinedCoverage.merge(nextFileCoverage.toSummary());
|
||||
}, undefined);
|
||||
}
|
||||
let errors = [];
|
||||
thresholdGroups.forEach(thresholdGroup => {
|
||||
switch (groupTypeByThresholdGroup[thresholdGroup]) {
|
||||
case THRESHOLD_GROUP_TYPES.GLOBAL: {
|
||||
const coverage = combineCoverage(
|
||||
getFilesInThresholdGroup(THRESHOLD_GROUP_TYPES.GLOBAL)
|
||||
);
|
||||
if (coverage) {
|
||||
errors = errors.concat(
|
||||
check(
|
||||
thresholdGroup,
|
||||
coverageThreshold[thresholdGroup],
|
||||
coverage
|
||||
)
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case THRESHOLD_GROUP_TYPES.PATH: {
|
||||
const coverage = combineCoverage(
|
||||
getFilesInThresholdGroup(thresholdGroup)
|
||||
);
|
||||
if (coverage) {
|
||||
errors = errors.concat(
|
||||
check(
|
||||
thresholdGroup,
|
||||
coverageThreshold[thresholdGroup],
|
||||
coverage
|
||||
)
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case THRESHOLD_GROUP_TYPES.GLOB:
|
||||
getFilesInThresholdGroup(thresholdGroup).forEach(
|
||||
fileMatchingGlob => {
|
||||
errors = errors.concat(
|
||||
check(
|
||||
fileMatchingGlob,
|
||||
coverageThreshold[thresholdGroup],
|
||||
map.fileCoverageFor(fileMatchingGlob).toSummary()
|
||||
)
|
||||
);
|
||||
}
|
||||
);
|
||||
break;
|
||||
default:
|
||||
// If the file specified by path is not found, error is returned.
|
||||
if (thresholdGroup !== THRESHOLD_GROUP_TYPES.GLOBAL) {
|
||||
errors = errors.concat(
|
||||
`Jest: Coverage data for ${thresholdGroup} was not found.`
|
||||
);
|
||||
}
|
||||
// Sometimes all files in the coverage data are matched by
|
||||
// PATH and GLOB threshold groups in which case, don't error when
|
||||
// the global threshold group doesn't match any files.
|
||||
}
|
||||
});
|
||||
|
||||
errors = errors.filter(
|
||||
err => err !== undefined && err !== null && err.length > 0
|
||||
);
|
||||
if (errors.length > 0) {
|
||||
this.log(`${FAIL_COLOR(errors.join('\n'))}`);
|
||||
this._setError(new Error(errors.join('\n')));
|
||||
}
|
||||
}
|
||||
}
|
||||
async _getCoverageResult() {
|
||||
if (this._globalConfig.coverageProvider === 'v8') {
|
||||
const mergedCoverages = (0, _v8Coverage().mergeProcessCovs)(
|
||||
this._v8CoverageResults.map(cov => ({
|
||||
result: cov.map(r => r.result)
|
||||
}))
|
||||
);
|
||||
const fileTransforms = new Map();
|
||||
this._v8CoverageResults.forEach(res =>
|
||||
res.forEach(r => {
|
||||
if (r.codeTransformResult && !fileTransforms.has(r.result.url)) {
|
||||
fileTransforms.set(r.result.url, r.codeTransformResult);
|
||||
}
|
||||
})
|
||||
);
|
||||
const transformedCoverage = await Promise.all(
|
||||
mergedCoverages.result.map(async res => {
|
||||
const fileTransform = fileTransforms.get(res.url);
|
||||
let sourcemapContent = undefined;
|
||||
if (
|
||||
fileTransform?.sourceMapPath &&
|
||||
fs().existsSync(fileTransform.sourceMapPath)
|
||||
) {
|
||||
sourcemapContent = JSON.parse(
|
||||
fs().readFileSync(fileTransform.sourceMapPath, 'utf8')
|
||||
);
|
||||
}
|
||||
const converter = (0, _v8ToIstanbul().default)(
|
||||
res.url,
|
||||
fileTransform?.wrapperLength ?? 0,
|
||||
fileTransform && sourcemapContent
|
||||
? {
|
||||
originalSource: fileTransform.originalCode,
|
||||
source: fileTransform.code,
|
||||
sourceMap: {
|
||||
sourcemap: {
|
||||
file: res.url,
|
||||
...sourcemapContent
|
||||
}
|
||||
}
|
||||
}
|
||||
: {
|
||||
source: fs().readFileSync(res.url, 'utf8')
|
||||
}
|
||||
);
|
||||
await converter.load();
|
||||
converter.applyCoverage(res.functions);
|
||||
const istanbulData = converter.toIstanbul();
|
||||
return istanbulData;
|
||||
})
|
||||
);
|
||||
const map = _istanbulLibCoverage().default.createCoverageMap({});
|
||||
transformedCoverage.forEach(res => map.merge(res));
|
||||
const reportContext = _istanbulLibReport().default.createContext({
|
||||
coverageMap: map,
|
||||
dir: this._globalConfig.coverageDirectory,
|
||||
watermarks: (0, _getWatermarks.default)(this._globalConfig)
|
||||
});
|
||||
return {
|
||||
map,
|
||||
reportContext
|
||||
};
|
||||
}
|
||||
const map = await this._sourceMapStore.transformCoverage(this._coverageMap);
|
||||
const reportContext = _istanbulLibReport().default.createContext({
|
||||
coverageMap: map,
|
||||
dir: this._globalConfig.coverageDirectory,
|
||||
sourceFinder: this._sourceMapStore.sourceFinder,
|
||||
watermarks: (0, _getWatermarks.default)(this._globalConfig)
|
||||
});
|
||||
return {
|
||||
map,
|
||||
reportContext
|
||||
};
|
||||
}
|
||||
}
|
||||
exports.default = CoverageReporter;
|
||||
89
node_modules/@jest/reporters/build/CoverageWorker.js
generated
vendored
Normal file
89
node_modules/@jest/reporters/build/CoverageWorker.js
generated
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true
|
||||
});
|
||||
exports.worker = worker;
|
||||
function _exit() {
|
||||
const data = _interopRequireDefault(require('exit'));
|
||||
_exit = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function fs() {
|
||||
const data = _interopRequireWildcard(require('graceful-fs'));
|
||||
fs = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
var _generateEmptyCoverage = _interopRequireDefault(
|
||||
require('./generateEmptyCoverage')
|
||||
);
|
||||
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 _interopRequireDefault(obj) {
|
||||
return obj && obj.__esModule ? obj : {default: obj};
|
||||
}
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
// Make sure uncaught errors are logged before we exit.
|
||||
process.on('uncaughtException', err => {
|
||||
console.error(err.stack);
|
||||
(0, _exit().default)(1);
|
||||
});
|
||||
function worker({config, globalConfig, path, context}) {
|
||||
return (0, _generateEmptyCoverage.default)(
|
||||
fs().readFileSync(path, 'utf8'),
|
||||
path,
|
||||
globalConfig,
|
||||
config,
|
||||
context.changedFiles && new Set(context.changedFiles),
|
||||
context.sourcesRelatedToTestsInChangedFiles &&
|
||||
new Set(context.sourcesRelatedToTestsInChangedFiles)
|
||||
);
|
||||
}
|
||||
229
node_modules/@jest/reporters/build/DefaultReporter.js
generated
vendored
Normal file
229
node_modules/@jest/reporters/build/DefaultReporter.js
generated
vendored
Normal file
@@ -0,0 +1,229 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
function _chalk() {
|
||||
const data = _interopRequireDefault(require('chalk'));
|
||||
_chalk = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _console() {
|
||||
const data = require('@jest/console');
|
||||
_console = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _jestMessageUtil() {
|
||||
const data = require('jest-message-util');
|
||||
_jestMessageUtil = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _jestUtil() {
|
||||
const data = require('jest-util');
|
||||
_jestUtil = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
var _BaseReporter = _interopRequireDefault(require('./BaseReporter'));
|
||||
var _Status = _interopRequireDefault(require('./Status'));
|
||||
var _getResultHeader = _interopRequireDefault(require('./getResultHeader'));
|
||||
var _getSnapshotStatus = _interopRequireDefault(require('./getSnapshotStatus'));
|
||||
function _interopRequireDefault(obj) {
|
||||
return obj && obj.__esModule ? obj : {default: obj};
|
||||
}
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
const TITLE_BULLET = _chalk().default.bold('\u25cf ');
|
||||
class DefaultReporter extends _BaseReporter.default {
|
||||
_clear; // ANSI clear sequence for the last printed status
|
||||
_err;
|
||||
_globalConfig;
|
||||
_out;
|
||||
_status;
|
||||
_bufferedOutput;
|
||||
static filename = __filename;
|
||||
constructor(globalConfig) {
|
||||
super();
|
||||
this._globalConfig = globalConfig;
|
||||
this._clear = '';
|
||||
this._out = process.stdout.write.bind(process.stdout);
|
||||
this._err = process.stderr.write.bind(process.stderr);
|
||||
this._status = new _Status.default(globalConfig);
|
||||
this._bufferedOutput = new Set();
|
||||
this.__wrapStdio(process.stdout);
|
||||
this.__wrapStdio(process.stderr);
|
||||
this._status.onChange(() => {
|
||||
this.__clearStatus();
|
||||
this.__printStatus();
|
||||
});
|
||||
}
|
||||
__wrapStdio(stream) {
|
||||
const write = stream.write.bind(stream);
|
||||
let buffer = [];
|
||||
let timeout = null;
|
||||
const flushBufferedOutput = () => {
|
||||
const string = buffer.join('');
|
||||
buffer = [];
|
||||
|
||||
// This is to avoid conflicts between random output and status text
|
||||
this.__clearStatus();
|
||||
if (string) {
|
||||
write(string);
|
||||
}
|
||||
this.__printStatus();
|
||||
this._bufferedOutput.delete(flushBufferedOutput);
|
||||
};
|
||||
this._bufferedOutput.add(flushBufferedOutput);
|
||||
const debouncedFlush = () => {
|
||||
// If the process blows up no errors would be printed.
|
||||
// There should be a smart way to buffer stderr, but for now
|
||||
// we just won't buffer it.
|
||||
if (stream === process.stderr) {
|
||||
flushBufferedOutput();
|
||||
} else {
|
||||
if (!timeout) {
|
||||
timeout = setTimeout(() => {
|
||||
flushBufferedOutput();
|
||||
timeout = null;
|
||||
}, 100);
|
||||
}
|
||||
}
|
||||
};
|
||||
stream.write = chunk => {
|
||||
buffer.push(chunk);
|
||||
debouncedFlush();
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
// Don't wait for the debounced call and flush all output immediately.
|
||||
forceFlushBufferedOutput() {
|
||||
for (const flushBufferedOutput of this._bufferedOutput) {
|
||||
flushBufferedOutput();
|
||||
}
|
||||
}
|
||||
__clearStatus() {
|
||||
if (_jestUtil().isInteractive) {
|
||||
if (this._globalConfig.useStderr) {
|
||||
this._err(this._clear);
|
||||
} else {
|
||||
this._out(this._clear);
|
||||
}
|
||||
}
|
||||
}
|
||||
__printStatus() {
|
||||
const {content, clear} = this._status.get();
|
||||
this._clear = clear;
|
||||
if (_jestUtil().isInteractive) {
|
||||
if (this._globalConfig.useStderr) {
|
||||
this._err(content);
|
||||
} else {
|
||||
this._out(content);
|
||||
}
|
||||
}
|
||||
}
|
||||
onRunStart(aggregatedResults, options) {
|
||||
this._status.runStarted(aggregatedResults, options);
|
||||
}
|
||||
onTestStart(test) {
|
||||
this._status.testStarted(test.path, test.context.config);
|
||||
}
|
||||
onTestCaseResult(test, testCaseResult) {
|
||||
this._status.addTestCaseResult(test, testCaseResult);
|
||||
}
|
||||
onRunComplete() {
|
||||
this.forceFlushBufferedOutput();
|
||||
this._status.runFinished();
|
||||
process.stdout.write = this._out;
|
||||
process.stderr.write = this._err;
|
||||
(0, _jestUtil().clearLine)(process.stderr);
|
||||
}
|
||||
onTestResult(test, testResult, aggregatedResults) {
|
||||
this.testFinished(test.context.config, testResult, aggregatedResults);
|
||||
if (!testResult.skipped) {
|
||||
this.printTestFileHeader(
|
||||
testResult.testFilePath,
|
||||
test.context.config,
|
||||
testResult
|
||||
);
|
||||
this.printTestFileFailureMessage(
|
||||
testResult.testFilePath,
|
||||
test.context.config,
|
||||
testResult
|
||||
);
|
||||
}
|
||||
this.forceFlushBufferedOutput();
|
||||
}
|
||||
testFinished(config, testResult, aggregatedResults) {
|
||||
this._status.testFinished(config, testResult, aggregatedResults);
|
||||
}
|
||||
printTestFileHeader(testPath, config, result) {
|
||||
// log retry errors if any exist
|
||||
result.testResults.forEach(testResult => {
|
||||
const testRetryReasons = testResult.retryReasons;
|
||||
if (testRetryReasons && testRetryReasons.length > 0) {
|
||||
this.log(
|
||||
`${_chalk().default.reset.inverse.bold.yellow(
|
||||
' LOGGING RETRY ERRORS '
|
||||
)} ${_chalk().default.bold(testResult.fullName)}`
|
||||
);
|
||||
testRetryReasons.forEach((retryReasons, index) => {
|
||||
let {message, stack} = (0,
|
||||
_jestMessageUtil().separateMessageFromStack)(retryReasons);
|
||||
stack = this._globalConfig.noStackTrace
|
||||
? ''
|
||||
: _chalk().default.dim(
|
||||
(0, _jestMessageUtil().formatStackTrace)(
|
||||
stack,
|
||||
config,
|
||||
this._globalConfig,
|
||||
testPath
|
||||
)
|
||||
);
|
||||
message = (0, _jestMessageUtil().indentAllLines)(message);
|
||||
this.log(
|
||||
`${_chalk().default.reset.inverse.bold.blueBright(
|
||||
` RETRY ${index + 1} `
|
||||
)}\n`
|
||||
);
|
||||
this.log(`${message}\n${stack}\n`);
|
||||
});
|
||||
}
|
||||
});
|
||||
this.log((0, _getResultHeader.default)(result, this._globalConfig, config));
|
||||
if (result.console) {
|
||||
this.log(
|
||||
` ${TITLE_BULLET}Console\n\n${(0, _console().getConsoleOutput)(
|
||||
result.console,
|
||||
config,
|
||||
this._globalConfig
|
||||
)}`
|
||||
);
|
||||
}
|
||||
}
|
||||
printTestFileFailureMessage(_testPath, _config, result) {
|
||||
if (result.failureMessage) {
|
||||
this.log(result.failureMessage);
|
||||
}
|
||||
const didUpdate = this._globalConfig.updateSnapshot === 'all';
|
||||
const snapshotStatuses = (0, _getSnapshotStatus.default)(
|
||||
result.snapshot,
|
||||
didUpdate
|
||||
);
|
||||
snapshotStatuses.forEach(this.log);
|
||||
}
|
||||
}
|
||||
exports.default = DefaultReporter;
|
||||
381
node_modules/@jest/reporters/build/GitHubActionsReporter.js
generated
vendored
Normal file
381
node_modules/@jest/reporters/build/GitHubActionsReporter.js
generated
vendored
Normal file
@@ -0,0 +1,381 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
function _chalk() {
|
||||
const data = _interopRequireDefault(require('chalk'));
|
||||
_chalk = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _stripAnsi() {
|
||||
const data = _interopRequireDefault(require('strip-ansi'));
|
||||
_stripAnsi = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _jestMessageUtil() {
|
||||
const data = require('jest-message-util');
|
||||
_jestMessageUtil = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _jestUtil() {
|
||||
const data = require('jest-util');
|
||||
_jestUtil = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
var _BaseReporter = _interopRequireDefault(require('./BaseReporter'));
|
||||
function _interopRequireDefault(obj) {
|
||||
return obj && obj.__esModule ? obj : {default: obj};
|
||||
}
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
const titleSeparator = ' \u203A ';
|
||||
const ICONS = _jestUtil().specialChars.ICONS;
|
||||
class GitHubActionsReporter extends _BaseReporter.default {
|
||||
static filename = __filename;
|
||||
options;
|
||||
constructor(
|
||||
_globalConfig,
|
||||
reporterOptions = {
|
||||
silent: true
|
||||
}
|
||||
) {
|
||||
super();
|
||||
this.options = {
|
||||
silent:
|
||||
typeof reporterOptions.silent === 'boolean'
|
||||
? reporterOptions.silent
|
||||
: true
|
||||
};
|
||||
}
|
||||
onTestResult(test, testResult, aggregatedResults) {
|
||||
this.generateAnnotations(test, testResult);
|
||||
if (!this.options.silent) {
|
||||
this.printFullResult(test.context, testResult);
|
||||
}
|
||||
if (this.isLastTestSuite(aggregatedResults)) {
|
||||
this.printFailedTestLogs(test, aggregatedResults);
|
||||
}
|
||||
}
|
||||
generateAnnotations({context}, {testResults}) {
|
||||
testResults.forEach(result => {
|
||||
const title = [...result.ancestorTitles, result.title].join(
|
||||
titleSeparator
|
||||
);
|
||||
result.retryReasons?.forEach((retryReason, index) => {
|
||||
this.#createAnnotation({
|
||||
...this.#getMessageDetails(retryReason, context.config),
|
||||
title: `RETRY ${index + 1}: ${title}`,
|
||||
type: 'warning'
|
||||
});
|
||||
});
|
||||
result.failureMessages.forEach(failureMessage => {
|
||||
this.#createAnnotation({
|
||||
...this.#getMessageDetails(failureMessage, context.config),
|
||||
title,
|
||||
type: 'error'
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
#getMessageDetails(failureMessage, config) {
|
||||
const {message, stack} = (0, _jestMessageUtil().separateMessageFromStack)(
|
||||
failureMessage
|
||||
);
|
||||
const stackLines = (0, _jestMessageUtil().getStackTraceLines)(stack);
|
||||
const topFrame = (0, _jestMessageUtil().getTopFrame)(stackLines);
|
||||
const normalizedStackLines = stackLines.map(line =>
|
||||
(0, _jestMessageUtil().formatPath)(line, config)
|
||||
);
|
||||
const messageText = [message, ...normalizedStackLines].join('\n');
|
||||
return {
|
||||
file: topFrame?.file,
|
||||
line: topFrame?.line,
|
||||
message: messageText
|
||||
};
|
||||
}
|
||||
#createAnnotation({file, line, message, title, type}) {
|
||||
message = (0, _stripAnsi().default)(
|
||||
// copied from: https://github.com/actions/toolkit/blob/main/packages/core/src/command.ts
|
||||
message.replace(/%/g, '%25').replace(/\r/g, '%0D').replace(/\n/g, '%0A')
|
||||
);
|
||||
this.log(
|
||||
`\n::${type} file=${file},line=${line},title=${title}::${message}`
|
||||
);
|
||||
}
|
||||
isLastTestSuite(results) {
|
||||
const passedTestSuites = results.numPassedTestSuites;
|
||||
const failedTestSuites = results.numFailedTestSuites;
|
||||
const totalTestSuites = results.numTotalTestSuites;
|
||||
const computedTotal = passedTestSuites + failedTestSuites;
|
||||
if (computedTotal < totalTestSuites) {
|
||||
return false;
|
||||
} else if (computedTotal === totalTestSuites) {
|
||||
return true;
|
||||
} else {
|
||||
throw new Error(
|
||||
`Sum(${computedTotal}) of passed (${passedTestSuites}) and failed (${failedTestSuites}) test suites is greater than the total number of test suites (${totalTestSuites}). Please report the bug at https://github.com/jestjs/jest/issues`
|
||||
);
|
||||
}
|
||||
}
|
||||
printFullResult(context, results) {
|
||||
const rootDir = context.config.rootDir;
|
||||
let testDir = results.testFilePath.replace(rootDir, '');
|
||||
testDir = testDir.slice(1, testDir.length);
|
||||
const resultTree = this.getResultTree(
|
||||
results.testResults,
|
||||
testDir,
|
||||
results.perfStats
|
||||
);
|
||||
this.printResultTree(resultTree);
|
||||
}
|
||||
arrayEqual(a1, a2) {
|
||||
if (a1.length !== a2.length) {
|
||||
return false;
|
||||
}
|
||||
for (let index = 0; index < a1.length; index++) {
|
||||
const element = a1[index];
|
||||
if (element !== a2[index]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
arrayChild(a1, a2) {
|
||||
if (a1.length - a2.length !== 1) {
|
||||
return false;
|
||||
}
|
||||
for (let index = 0; index < a2.length; index++) {
|
||||
const element = a2[index];
|
||||
if (element !== a1[index]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
getResultTree(suiteResult, testPath, suitePerf) {
|
||||
const root = {
|
||||
children: [],
|
||||
name: testPath,
|
||||
passed: true,
|
||||
performanceInfo: suitePerf
|
||||
};
|
||||
const branches = [];
|
||||
suiteResult.forEach(element => {
|
||||
if (element.ancestorTitles.length === 0) {
|
||||
if (element.status === 'failed') {
|
||||
root.passed = false;
|
||||
}
|
||||
const duration = element.duration || 1;
|
||||
root.children.push({
|
||||
children: [],
|
||||
duration,
|
||||
name: element.title,
|
||||
status: element.status
|
||||
});
|
||||
} else {
|
||||
let alreadyInserted = false;
|
||||
for (let index = 0; index < branches.length; index++) {
|
||||
if (
|
||||
this.arrayEqual(branches[index], element.ancestorTitles.slice(0, 1))
|
||||
) {
|
||||
alreadyInserted = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!alreadyInserted) {
|
||||
branches.push(element.ancestorTitles.slice(0, 1));
|
||||
}
|
||||
}
|
||||
});
|
||||
branches.forEach(element => {
|
||||
const newChild = this.getResultChildren(suiteResult, element);
|
||||
if (!newChild.passed) {
|
||||
root.passed = false;
|
||||
}
|
||||
root.children.push(newChild);
|
||||
});
|
||||
return root;
|
||||
}
|
||||
getResultChildren(suiteResult, ancestors) {
|
||||
const node = {
|
||||
children: [],
|
||||
name: ancestors[ancestors.length - 1],
|
||||
passed: true
|
||||
};
|
||||
const branches = [];
|
||||
suiteResult.forEach(element => {
|
||||
let duration = element.duration;
|
||||
if (!duration || isNaN(duration)) {
|
||||
duration = 1;
|
||||
}
|
||||
if (this.arrayEqual(element.ancestorTitles, ancestors)) {
|
||||
if (element.status === 'failed') {
|
||||
node.passed = false;
|
||||
}
|
||||
node.children.push({
|
||||
children: [],
|
||||
duration,
|
||||
name: element.title,
|
||||
status: element.status
|
||||
});
|
||||
} else if (
|
||||
this.arrayChild(
|
||||
element.ancestorTitles.slice(0, ancestors.length + 1),
|
||||
ancestors
|
||||
)
|
||||
) {
|
||||
let alreadyInserted = false;
|
||||
for (let index = 0; index < branches.length; index++) {
|
||||
if (
|
||||
this.arrayEqual(
|
||||
branches[index],
|
||||
element.ancestorTitles.slice(0, ancestors.length + 1)
|
||||
)
|
||||
) {
|
||||
alreadyInserted = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!alreadyInserted) {
|
||||
branches.push(element.ancestorTitles.slice(0, ancestors.length + 1));
|
||||
}
|
||||
}
|
||||
});
|
||||
branches.forEach(element => {
|
||||
const newChild = this.getResultChildren(suiteResult, element);
|
||||
if (!newChild.passed) {
|
||||
node.passed = false;
|
||||
}
|
||||
node.children.push(newChild);
|
||||
});
|
||||
return node;
|
||||
}
|
||||
printResultTree(resultTree) {
|
||||
let perfMs;
|
||||
if (resultTree.performanceInfo.slow) {
|
||||
perfMs = ` (${_chalk().default.red.inverse(
|
||||
`${resultTree.performanceInfo.runtime} ms`
|
||||
)})`;
|
||||
} else {
|
||||
perfMs = ` (${resultTree.performanceInfo.runtime} ms)`;
|
||||
}
|
||||
if (resultTree.passed) {
|
||||
this.startGroup(
|
||||
`${_chalk().default.bold.green.inverse('PASS')} ${
|
||||
resultTree.name
|
||||
}${perfMs}`
|
||||
);
|
||||
resultTree.children.forEach(child => {
|
||||
this.recursivePrintResultTree(child, true, 1);
|
||||
});
|
||||
this.endGroup();
|
||||
} else {
|
||||
this.log(
|
||||
` ${_chalk().default.bold.red.inverse('FAIL')} ${
|
||||
resultTree.name
|
||||
}${perfMs}`
|
||||
);
|
||||
resultTree.children.forEach(child => {
|
||||
this.recursivePrintResultTree(child, false, 1);
|
||||
});
|
||||
}
|
||||
}
|
||||
recursivePrintResultTree(resultTree, alreadyGrouped, depth) {
|
||||
if (resultTree.children.length === 0) {
|
||||
if (!('duration' in resultTree)) {
|
||||
throw new Error('Expected a leaf. Got a node.');
|
||||
}
|
||||
let numberSpaces = depth;
|
||||
if (!alreadyGrouped) {
|
||||
numberSpaces++;
|
||||
}
|
||||
const spaces = ' '.repeat(numberSpaces);
|
||||
let resultSymbol;
|
||||
switch (resultTree.status) {
|
||||
case 'passed':
|
||||
resultSymbol = _chalk().default.green(ICONS.success);
|
||||
break;
|
||||
case 'failed':
|
||||
resultSymbol = _chalk().default.red(ICONS.failed);
|
||||
break;
|
||||
case 'todo':
|
||||
resultSymbol = _chalk().default.magenta(ICONS.todo);
|
||||
break;
|
||||
case 'pending':
|
||||
case 'skipped':
|
||||
resultSymbol = _chalk().default.yellow(ICONS.pending);
|
||||
break;
|
||||
}
|
||||
this.log(
|
||||
`${spaces + resultSymbol} ${resultTree.name} (${
|
||||
resultTree.duration
|
||||
} ms)`
|
||||
);
|
||||
} else {
|
||||
if (!('passed' in resultTree)) {
|
||||
throw new Error('Expected a node. Got a leaf');
|
||||
}
|
||||
if (resultTree.passed) {
|
||||
if (alreadyGrouped) {
|
||||
this.log(' '.repeat(depth) + resultTree.name);
|
||||
resultTree.children.forEach(child => {
|
||||
this.recursivePrintResultTree(child, true, depth + 1);
|
||||
});
|
||||
} else {
|
||||
this.startGroup(' '.repeat(depth) + resultTree.name);
|
||||
resultTree.children.forEach(child => {
|
||||
this.recursivePrintResultTree(child, true, depth + 1);
|
||||
});
|
||||
this.endGroup();
|
||||
}
|
||||
} else {
|
||||
this.log(' '.repeat(depth + 1) + resultTree.name);
|
||||
resultTree.children.forEach(child => {
|
||||
this.recursivePrintResultTree(child, false, depth + 1);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
printFailedTestLogs(context, testResults) {
|
||||
const rootDir = context.context.config.rootDir;
|
||||
const results = testResults.testResults;
|
||||
let written = false;
|
||||
results.forEach(result => {
|
||||
let testDir = result.testFilePath;
|
||||
testDir = testDir.replace(rootDir, '');
|
||||
testDir = testDir.slice(1, testDir.length);
|
||||
if (result.failureMessage) {
|
||||
if (!written) {
|
||||
this.log('');
|
||||
written = true;
|
||||
}
|
||||
this.startGroup(`Errors thrown in ${testDir}`);
|
||||
this.log(result.failureMessage);
|
||||
this.endGroup();
|
||||
}
|
||||
});
|
||||
return written;
|
||||
}
|
||||
startGroup(title) {
|
||||
this.log(`::group::${title}`);
|
||||
}
|
||||
endGroup() {
|
||||
this.log('::endgroup::');
|
||||
}
|
||||
}
|
||||
exports.default = GitHubActionsReporter;
|
||||
218
node_modules/@jest/reporters/build/NotifyReporter.js
generated
vendored
Normal file
218
node_modules/@jest/reporters/build/NotifyReporter.js
generated
vendored
Normal file
@@ -0,0 +1,218 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
function path() {
|
||||
const data = _interopRequireWildcard(require('path'));
|
||||
path = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function util() {
|
||||
const data = _interopRequireWildcard(require('util'));
|
||||
util = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _exit() {
|
||||
const data = _interopRequireDefault(require('exit'));
|
||||
_exit = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _jestUtil() {
|
||||
const data = require('jest-util');
|
||||
_jestUtil = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
var _BaseReporter = _interopRequireDefault(require('./BaseReporter'));
|
||||
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;
|
||||
}
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
const isDarwin = process.platform === 'darwin';
|
||||
const icon = path().resolve(__dirname, '../assets/jest_logo.png');
|
||||
class NotifyReporter extends _BaseReporter.default {
|
||||
_notifier = loadNotifier();
|
||||
_globalConfig;
|
||||
_context;
|
||||
static filename = __filename;
|
||||
constructor(globalConfig, context) {
|
||||
super();
|
||||
this._globalConfig = globalConfig;
|
||||
this._context = context;
|
||||
}
|
||||
onRunComplete(testContexts, result) {
|
||||
const success =
|
||||
result.numFailedTests === 0 && result.numRuntimeErrorTestSuites === 0;
|
||||
const firstContext = testContexts.values().next();
|
||||
const hasteFS =
|
||||
firstContext && firstContext.value && firstContext.value.hasteFS;
|
||||
let packageName;
|
||||
if (hasteFS != null) {
|
||||
// assuming root package.json is the first one
|
||||
const [filePath] = hasteFS.matchFiles('package.json');
|
||||
packageName =
|
||||
filePath != null
|
||||
? hasteFS.getModuleName(filePath)
|
||||
: this._globalConfig.rootDir;
|
||||
} else {
|
||||
packageName = this._globalConfig.rootDir;
|
||||
}
|
||||
packageName = packageName != null ? `${packageName} - ` : '';
|
||||
const notifyMode = this._globalConfig.notifyMode;
|
||||
const statusChanged =
|
||||
this._context.previousSuccess !== success || this._context.firstRun;
|
||||
const testsHaveRun = result.numTotalTests !== 0;
|
||||
if (
|
||||
testsHaveRun &&
|
||||
success &&
|
||||
(notifyMode === 'always' ||
|
||||
notifyMode === 'success' ||
|
||||
notifyMode === 'success-change' ||
|
||||
(notifyMode === 'change' && statusChanged) ||
|
||||
(notifyMode === 'failure-change' && statusChanged))
|
||||
) {
|
||||
const title = util().format('%s%d%% Passed', packageName, 100);
|
||||
const message = `${isDarwin ? '\u2705 ' : ''}${(0, _jestUtil().pluralize)(
|
||||
'test',
|
||||
result.numPassedTests
|
||||
)} passed`;
|
||||
this._notifier.notify({
|
||||
hint: 'int:transient:1',
|
||||
icon,
|
||||
message,
|
||||
timeout: false,
|
||||
title
|
||||
});
|
||||
} else if (
|
||||
testsHaveRun &&
|
||||
!success &&
|
||||
(notifyMode === 'always' ||
|
||||
notifyMode === 'failure' ||
|
||||
notifyMode === 'failure-change' ||
|
||||
(notifyMode === 'change' && statusChanged) ||
|
||||
(notifyMode === 'success-change' && statusChanged))
|
||||
) {
|
||||
const failed = result.numFailedTests / result.numTotalTests;
|
||||
const title = util().format(
|
||||
'%s%d%% Failed',
|
||||
packageName,
|
||||
Math.ceil(Number.isNaN(failed) ? 0 : failed * 100)
|
||||
);
|
||||
const message = util().format(
|
||||
`${isDarwin ? '\u26D4\uFE0F ' : ''}%d of %d tests failed`,
|
||||
result.numFailedTests,
|
||||
result.numTotalTests
|
||||
);
|
||||
const watchMode = this._globalConfig.watch || this._globalConfig.watchAll;
|
||||
const restartAnswer = 'Run again';
|
||||
const quitAnswer = 'Exit tests';
|
||||
if (!watchMode) {
|
||||
this._notifier.notify({
|
||||
hint: 'int:transient:1',
|
||||
icon,
|
||||
message,
|
||||
timeout: false,
|
||||
title
|
||||
});
|
||||
} else {
|
||||
this._notifier.notify(
|
||||
{
|
||||
// @ts-expect-error - not all options are supported by all systems (specifically `actions` and `hint`)
|
||||
actions: [restartAnswer, quitAnswer],
|
||||
closeLabel: 'Close',
|
||||
hint: 'int:transient:1',
|
||||
icon,
|
||||
message,
|
||||
timeout: false,
|
||||
title
|
||||
},
|
||||
(err, _, metadata) => {
|
||||
if (err || !metadata) {
|
||||
return;
|
||||
}
|
||||
if (metadata.activationValue === quitAnswer) {
|
||||
(0, _exit().default)(0);
|
||||
return;
|
||||
}
|
||||
if (
|
||||
metadata.activationValue === restartAnswer &&
|
||||
this._context.startRun
|
||||
) {
|
||||
this._context.startRun(this._globalConfig);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
this._context.previousSuccess = success;
|
||||
this._context.firstRun = false;
|
||||
}
|
||||
}
|
||||
exports.default = NotifyReporter;
|
||||
function loadNotifier() {
|
||||
try {
|
||||
return require('node-notifier');
|
||||
} catch (err) {
|
||||
if (err.code !== 'MODULE_NOT_FOUND') {
|
||||
throw err;
|
||||
}
|
||||
throw Error(
|
||||
'notify reporter requires optional peer dependency "node-notifier" but it was not found'
|
||||
);
|
||||
}
|
||||
}
|
||||
214
node_modules/@jest/reporters/build/Status.js
generated
vendored
Normal file
214
node_modules/@jest/reporters/build/Status.js
generated
vendored
Normal file
@@ -0,0 +1,214 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
function _chalk() {
|
||||
const data = _interopRequireDefault(require('chalk'));
|
||||
_chalk = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _stringLength() {
|
||||
const data = _interopRequireDefault(require('string-length'));
|
||||
_stringLength = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
var _getSummary = _interopRequireDefault(require('./getSummary'));
|
||||
var _printDisplayName = _interopRequireDefault(require('./printDisplayName'));
|
||||
var _trimAndFormatPath = _interopRequireDefault(require('./trimAndFormatPath'));
|
||||
var _wrapAnsiString = _interopRequireDefault(require('./wrapAnsiString'));
|
||||
function _interopRequireDefault(obj) {
|
||||
return obj && obj.__esModule ? obj : {default: obj};
|
||||
}
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
const RUNNING_TEXT = ' RUNS ';
|
||||
const RUNNING = `${_chalk().default.reset.inverse.yellow.bold(RUNNING_TEXT)} `;
|
||||
|
||||
/**
|
||||
* This class is a perf optimization for sorting the list of currently
|
||||
* running tests. It tries to keep tests in the same positions without
|
||||
* shifting the whole list.
|
||||
*/
|
||||
class CurrentTestList {
|
||||
_array;
|
||||
constructor() {
|
||||
this._array = [];
|
||||
}
|
||||
add(testPath, config) {
|
||||
const index = this._array.indexOf(null);
|
||||
const record = {
|
||||
config,
|
||||
testPath
|
||||
};
|
||||
if (index !== -1) {
|
||||
this._array[index] = record;
|
||||
} else {
|
||||
this._array.push(record);
|
||||
}
|
||||
}
|
||||
delete(testPath) {
|
||||
const record = this._array.find(
|
||||
record => record !== null && record.testPath === testPath
|
||||
);
|
||||
this._array[this._array.indexOf(record || null)] = null;
|
||||
}
|
||||
get() {
|
||||
return this._array;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* A class that generates the CLI status of currently running tests
|
||||
* and also provides an ANSI escape sequence to remove status lines
|
||||
* from the terminal.
|
||||
*/
|
||||
class Status {
|
||||
_cache;
|
||||
_callback;
|
||||
_currentTests;
|
||||
_currentTestCases;
|
||||
_done;
|
||||
_emitScheduled;
|
||||
_estimatedTime;
|
||||
_interval;
|
||||
_aggregatedResults;
|
||||
_showStatus;
|
||||
constructor(_globalConfig) {
|
||||
this._globalConfig = _globalConfig;
|
||||
this._cache = null;
|
||||
this._currentTests = new CurrentTestList();
|
||||
this._currentTestCases = [];
|
||||
this._done = false;
|
||||
this._emitScheduled = false;
|
||||
this._estimatedTime = 0;
|
||||
this._showStatus = false;
|
||||
}
|
||||
onChange(callback) {
|
||||
this._callback = callback;
|
||||
}
|
||||
runStarted(aggregatedResults, options) {
|
||||
this._estimatedTime = (options && options.estimatedTime) || 0;
|
||||
this._showStatus = options && options.showStatus;
|
||||
this._interval = setInterval(() => this._tick(), 1000);
|
||||
this._aggregatedResults = aggregatedResults;
|
||||
this._debouncedEmit();
|
||||
}
|
||||
runFinished() {
|
||||
this._done = true;
|
||||
if (this._interval) clearInterval(this._interval);
|
||||
this._emit();
|
||||
}
|
||||
addTestCaseResult(test, testCaseResult) {
|
||||
this._currentTestCases.push({
|
||||
test,
|
||||
testCaseResult
|
||||
});
|
||||
if (!this._showStatus) {
|
||||
this._emit();
|
||||
} else {
|
||||
this._debouncedEmit();
|
||||
}
|
||||
}
|
||||
testStarted(testPath, config) {
|
||||
this._currentTests.add(testPath, config);
|
||||
if (!this._showStatus) {
|
||||
this._emit();
|
||||
} else {
|
||||
this._debouncedEmit();
|
||||
}
|
||||
}
|
||||
testFinished(_config, testResult, aggregatedResults) {
|
||||
const {testFilePath} = testResult;
|
||||
this._aggregatedResults = aggregatedResults;
|
||||
this._currentTests.delete(testFilePath);
|
||||
this._currentTestCases = this._currentTestCases.filter(({test}) => {
|
||||
if (_config !== test.context.config) {
|
||||
return true;
|
||||
}
|
||||
return test.path !== testFilePath;
|
||||
});
|
||||
this._debouncedEmit();
|
||||
}
|
||||
get() {
|
||||
if (this._cache) {
|
||||
return this._cache;
|
||||
}
|
||||
if (this._done) {
|
||||
return {
|
||||
clear: '',
|
||||
content: ''
|
||||
};
|
||||
}
|
||||
const width = process.stdout.columns;
|
||||
let content = '\n';
|
||||
this._currentTests.get().forEach(record => {
|
||||
if (record) {
|
||||
const {config, testPath} = record;
|
||||
const projectDisplayName = config.displayName
|
||||
? `${(0, _printDisplayName.default)(config)} `
|
||||
: '';
|
||||
const prefix = RUNNING + projectDisplayName;
|
||||
content += `${(0, _wrapAnsiString.default)(
|
||||
prefix +
|
||||
(0, _trimAndFormatPath.default)(
|
||||
(0, _stringLength().default)(prefix),
|
||||
config,
|
||||
testPath,
|
||||
width
|
||||
),
|
||||
width
|
||||
)}\n`;
|
||||
}
|
||||
});
|
||||
if (this._showStatus && this._aggregatedResults) {
|
||||
content += `\n${(0, _getSummary.default)(this._aggregatedResults, {
|
||||
currentTestCases: this._currentTestCases,
|
||||
estimatedTime: this._estimatedTime,
|
||||
roundTime: true,
|
||||
seed: this._globalConfig.seed,
|
||||
showSeed: this._globalConfig.showSeed,
|
||||
width
|
||||
})}`;
|
||||
}
|
||||
let height = 0;
|
||||
for (let i = 0; i < content.length; i++) {
|
||||
if (content[i] === '\n') {
|
||||
height++;
|
||||
}
|
||||
}
|
||||
const clear = '\r\x1B[K\r\x1B[1A'.repeat(height);
|
||||
return (this._cache = {
|
||||
clear,
|
||||
content
|
||||
});
|
||||
}
|
||||
_emit() {
|
||||
this._cache = null;
|
||||
if (this._callback) this._callback();
|
||||
}
|
||||
_debouncedEmit() {
|
||||
if (!this._emitScheduled) {
|
||||
// Perf optimization to avoid two separate renders When
|
||||
// one test finishes and another test starts executing.
|
||||
this._emitScheduled = true;
|
||||
setTimeout(() => {
|
||||
this._emit();
|
||||
this._emitScheduled = false;
|
||||
}, 100);
|
||||
}
|
||||
}
|
||||
_tick() {
|
||||
this._debouncedEmit();
|
||||
}
|
||||
}
|
||||
exports.default = Status;
|
||||
239
node_modules/@jest/reporters/build/SummaryReporter.js
generated
vendored
Normal file
239
node_modules/@jest/reporters/build/SummaryReporter.js
generated
vendored
Normal file
@@ -0,0 +1,239 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
function _chalk() {
|
||||
const data = _interopRequireDefault(require('chalk'));
|
||||
_chalk = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _jestUtil() {
|
||||
const data = require('jest-util');
|
||||
_jestUtil = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
var _BaseReporter = _interopRequireDefault(require('./BaseReporter'));
|
||||
var _getResultHeader = _interopRequireDefault(require('./getResultHeader'));
|
||||
var _getSnapshotSummary = _interopRequireDefault(
|
||||
require('./getSnapshotSummary')
|
||||
);
|
||||
var _getSummary = _interopRequireDefault(require('./getSummary'));
|
||||
function _interopRequireDefault(obj) {
|
||||
return obj && obj.__esModule ? obj : {default: obj};
|
||||
}
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
const NPM_EVENTS = new Set([
|
||||
'prepublish',
|
||||
'publish',
|
||||
'postpublish',
|
||||
'preinstall',
|
||||
'install',
|
||||
'postinstall',
|
||||
'preuninstall',
|
||||
'uninstall',
|
||||
'postuninstall',
|
||||
'preversion',
|
||||
'version',
|
||||
'postversion',
|
||||
'pretest',
|
||||
'test',
|
||||
'posttest',
|
||||
'prestop',
|
||||
'stop',
|
||||
'poststop',
|
||||
'prestart',
|
||||
'start',
|
||||
'poststart',
|
||||
'prerestart',
|
||||
'restart',
|
||||
'postrestart'
|
||||
]);
|
||||
const {npm_config_user_agent, npm_lifecycle_event, npm_lifecycle_script} =
|
||||
process.env;
|
||||
class SummaryReporter extends _BaseReporter.default {
|
||||
_estimatedTime;
|
||||
_globalConfig;
|
||||
_summaryThreshold;
|
||||
static filename = __filename;
|
||||
constructor(globalConfig, options) {
|
||||
super();
|
||||
this._globalConfig = globalConfig;
|
||||
this._estimatedTime = 0;
|
||||
this._validateOptions(options);
|
||||
this._summaryThreshold = options?.summaryThreshold ?? 20;
|
||||
}
|
||||
_validateOptions(options) {
|
||||
if (
|
||||
options?.summaryThreshold &&
|
||||
typeof options.summaryThreshold !== 'number'
|
||||
) {
|
||||
throw new TypeError('The option summaryThreshold should be a number');
|
||||
}
|
||||
}
|
||||
|
||||
// If we write more than one character at a time it is possible that
|
||||
// Node.js exits in the middle of printing the result. This was first observed
|
||||
// in Node.js 0.10 and still persists in Node.js 6.7+.
|
||||
// Let's print the test failure summary character by character which is safer
|
||||
// when hundreds of tests are failing.
|
||||
_write(string) {
|
||||
for (let i = 0; i < string.length; i++) {
|
||||
process.stderr.write(string.charAt(i));
|
||||
}
|
||||
}
|
||||
onRunStart(aggregatedResults, options) {
|
||||
super.onRunStart(aggregatedResults, options);
|
||||
this._estimatedTime = options.estimatedTime;
|
||||
}
|
||||
onRunComplete(testContexts, aggregatedResults) {
|
||||
const {numTotalTestSuites, testResults, wasInterrupted} = aggregatedResults;
|
||||
if (numTotalTestSuites) {
|
||||
const lastResult = testResults[testResults.length - 1];
|
||||
// Print a newline if the last test did not fail to line up newlines
|
||||
// similar to when an error would have been thrown in the test.
|
||||
if (
|
||||
!this._globalConfig.verbose &&
|
||||
lastResult &&
|
||||
!lastResult.numFailingTests &&
|
||||
!lastResult.testExecError
|
||||
) {
|
||||
this.log('');
|
||||
}
|
||||
this._printSummary(aggregatedResults, this._globalConfig);
|
||||
this._printSnapshotSummary(
|
||||
aggregatedResults.snapshot,
|
||||
this._globalConfig
|
||||
);
|
||||
let message = (0, _getSummary.default)(aggregatedResults, {
|
||||
estimatedTime: this._estimatedTime,
|
||||
seed: this._globalConfig.seed,
|
||||
showSeed: this._globalConfig.showSeed
|
||||
});
|
||||
if (!this._globalConfig.silent) {
|
||||
message += `\n${
|
||||
wasInterrupted
|
||||
? _chalk().default.bold.red('Test run was interrupted.')
|
||||
: this._getTestSummary(testContexts, this._globalConfig)
|
||||
}`;
|
||||
}
|
||||
this.log(message);
|
||||
}
|
||||
}
|
||||
_printSnapshotSummary(snapshots, globalConfig) {
|
||||
if (
|
||||
snapshots.added ||
|
||||
snapshots.filesRemoved ||
|
||||
snapshots.unchecked ||
|
||||
snapshots.unmatched ||
|
||||
snapshots.updated
|
||||
) {
|
||||
let updateCommand;
|
||||
const event = npm_lifecycle_event || '';
|
||||
const prefix = NPM_EVENTS.has(event) ? '' : 'run ';
|
||||
const isYarn =
|
||||
typeof npm_config_user_agent === 'string' &&
|
||||
npm_config_user_agent.includes('yarn');
|
||||
const client = isYarn ? 'yarn' : 'npm';
|
||||
const scriptUsesJest =
|
||||
typeof npm_lifecycle_script === 'string' &&
|
||||
npm_lifecycle_script.includes('jest');
|
||||
if (globalConfig.watch || globalConfig.watchAll) {
|
||||
updateCommand = 'press `u`';
|
||||
} else if (event && scriptUsesJest) {
|
||||
updateCommand = `run \`${`${client} ${prefix}${event}${
|
||||
isYarn ? '' : ' --'
|
||||
}`} -u\``;
|
||||
} else {
|
||||
updateCommand = 're-run jest with `-u`';
|
||||
}
|
||||
const snapshotSummary = (0, _getSnapshotSummary.default)(
|
||||
snapshots,
|
||||
globalConfig,
|
||||
updateCommand
|
||||
);
|
||||
snapshotSummary.forEach(this.log);
|
||||
this.log(''); // print empty line
|
||||
}
|
||||
}
|
||||
|
||||
_printSummary(aggregatedResults, globalConfig) {
|
||||
// If there were any failing tests and there was a large number of tests
|
||||
// executed, re-print the failing results at the end of execution output.
|
||||
const failedTests = aggregatedResults.numFailedTests;
|
||||
const runtimeErrors = aggregatedResults.numRuntimeErrorTestSuites;
|
||||
if (
|
||||
failedTests + runtimeErrors > 0 &&
|
||||
aggregatedResults.numTotalTestSuites > this._summaryThreshold
|
||||
) {
|
||||
this.log(_chalk().default.bold('Summary of all failing tests'));
|
||||
aggregatedResults.testResults.forEach(testResult => {
|
||||
const {failureMessage} = testResult;
|
||||
if (failureMessage) {
|
||||
this._write(
|
||||
`${(0, _getResultHeader.default)(
|
||||
testResult,
|
||||
globalConfig
|
||||
)}\n${failureMessage}\n`
|
||||
);
|
||||
}
|
||||
});
|
||||
this.log(''); // print empty line
|
||||
}
|
||||
}
|
||||
|
||||
_getTestSummary(testContexts, globalConfig) {
|
||||
const getMatchingTestsInfo = () => {
|
||||
const prefix = globalConfig.findRelatedTests
|
||||
? ' related to files matching '
|
||||
: ' matching ';
|
||||
return (
|
||||
_chalk().default.dim(prefix) +
|
||||
(0, _jestUtil().testPathPatternToRegExp)(
|
||||
globalConfig.testPathPattern
|
||||
).toString()
|
||||
);
|
||||
};
|
||||
let testInfo = '';
|
||||
if (globalConfig.runTestsByPath) {
|
||||
testInfo = _chalk().default.dim(' within paths');
|
||||
} else if (globalConfig.onlyChanged) {
|
||||
testInfo = _chalk().default.dim(' related to changed files');
|
||||
} else if (globalConfig.testPathPattern) {
|
||||
testInfo = getMatchingTestsInfo();
|
||||
}
|
||||
let nameInfo = '';
|
||||
if (globalConfig.runTestsByPath) {
|
||||
nameInfo = ` ${globalConfig.nonFlagArgs.map(p => `"${p}"`).join(', ')}`;
|
||||
} else if (globalConfig.testNamePattern) {
|
||||
nameInfo = `${_chalk().default.dim(' with tests matching ')}"${
|
||||
globalConfig.testNamePattern
|
||||
}"`;
|
||||
}
|
||||
const contextInfo =
|
||||
testContexts.size > 1
|
||||
? _chalk().default.dim(' in ') +
|
||||
testContexts.size +
|
||||
_chalk().default.dim(' projects')
|
||||
: '';
|
||||
return (
|
||||
_chalk().default.dim('Ran all test suites') +
|
||||
testInfo +
|
||||
nameInfo +
|
||||
contextInfo +
|
||||
_chalk().default.dim('.')
|
||||
);
|
||||
}
|
||||
}
|
||||
exports.default = SummaryReporter;
|
||||
175
node_modules/@jest/reporters/build/VerboseReporter.js
generated
vendored
Normal file
175
node_modules/@jest/reporters/build/VerboseReporter.js
generated
vendored
Normal file
@@ -0,0 +1,175 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
function _chalk() {
|
||||
const data = _interopRequireDefault(require('chalk'));
|
||||
_chalk = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _jestUtil() {
|
||||
const data = require('jest-util');
|
||||
_jestUtil = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
var _DefaultReporter = _interopRequireDefault(require('./DefaultReporter'));
|
||||
function _interopRequireDefault(obj) {
|
||||
return obj && obj.__esModule ? obj : {default: obj};
|
||||
}
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
const {ICONS} = _jestUtil().specialChars;
|
||||
class VerboseReporter extends _DefaultReporter.default {
|
||||
_globalConfig;
|
||||
static filename = __filename;
|
||||
constructor(globalConfig) {
|
||||
super(globalConfig);
|
||||
this._globalConfig = globalConfig;
|
||||
}
|
||||
|
||||
// Verbose mode is for debugging. Buffering of output is undesirable.
|
||||
// See https://github.com/jestjs/jest/issues/8208
|
||||
__wrapStdio(stream) {
|
||||
const write = stream.write.bind(stream);
|
||||
stream.write = chunk => {
|
||||
this.__clearStatus();
|
||||
write(chunk);
|
||||
this.__printStatus();
|
||||
return true;
|
||||
};
|
||||
}
|
||||
static filterTestResults(testResults) {
|
||||
return testResults.filter(({status}) => status !== 'pending');
|
||||
}
|
||||
static groupTestsBySuites(testResults) {
|
||||
const root = {
|
||||
suites: [],
|
||||
tests: [],
|
||||
title: ''
|
||||
};
|
||||
testResults.forEach(testResult => {
|
||||
let targetSuite = root;
|
||||
|
||||
// Find the target suite for this test,
|
||||
// creating nested suites as necessary.
|
||||
for (const title of testResult.ancestorTitles) {
|
||||
let matchingSuite = targetSuite.suites.find(s => s.title === title);
|
||||
if (!matchingSuite) {
|
||||
matchingSuite = {
|
||||
suites: [],
|
||||
tests: [],
|
||||
title
|
||||
};
|
||||
targetSuite.suites.push(matchingSuite);
|
||||
}
|
||||
targetSuite = matchingSuite;
|
||||
}
|
||||
targetSuite.tests.push(testResult);
|
||||
});
|
||||
return root;
|
||||
}
|
||||
onTestResult(test, result, aggregatedResults) {
|
||||
super.testFinished(test.context.config, result, aggregatedResults);
|
||||
if (!result.skipped) {
|
||||
this.printTestFileHeader(
|
||||
result.testFilePath,
|
||||
test.context.config,
|
||||
result
|
||||
);
|
||||
if (!result.testExecError && !result.skipped) {
|
||||
this._logTestResults(result.testResults);
|
||||
}
|
||||
this.printTestFileFailureMessage(
|
||||
result.testFilePath,
|
||||
test.context.config,
|
||||
result
|
||||
);
|
||||
}
|
||||
super.forceFlushBufferedOutput();
|
||||
}
|
||||
_logTestResults(testResults) {
|
||||
this._logSuite(VerboseReporter.groupTestsBySuites(testResults), 0);
|
||||
this._logLine();
|
||||
}
|
||||
_logSuite(suite, indentLevel) {
|
||||
if (suite.title) {
|
||||
this._logLine(suite.title, indentLevel);
|
||||
}
|
||||
this._logTests(suite.tests, indentLevel + 1);
|
||||
suite.suites.forEach(suite => this._logSuite(suite, indentLevel + 1));
|
||||
}
|
||||
_getIcon(status) {
|
||||
if (status === 'failed') {
|
||||
return _chalk().default.red(ICONS.failed);
|
||||
} else if (status === 'pending') {
|
||||
return _chalk().default.yellow(ICONS.pending);
|
||||
} else if (status === 'todo') {
|
||||
return _chalk().default.magenta(ICONS.todo);
|
||||
} else {
|
||||
return _chalk().default.green(ICONS.success);
|
||||
}
|
||||
}
|
||||
_logTest(test, indentLevel) {
|
||||
const status = this._getIcon(test.status);
|
||||
const time = test.duration
|
||||
? ` (${(0, _jestUtil().formatTime)(Math.round(test.duration))})`
|
||||
: '';
|
||||
this._logLine(
|
||||
`${status} ${_chalk().default.dim(test.title + time)}`,
|
||||
indentLevel
|
||||
);
|
||||
}
|
||||
_logTests(tests, indentLevel) {
|
||||
if (this._globalConfig.expand) {
|
||||
tests.forEach(test => this._logTest(test, indentLevel));
|
||||
} else {
|
||||
const summedTests = tests.reduce(
|
||||
(result, test) => {
|
||||
if (test.status === 'pending') {
|
||||
result.pending.push(test);
|
||||
} else if (test.status === 'todo') {
|
||||
result.todo.push(test);
|
||||
} else {
|
||||
this._logTest(test, indentLevel);
|
||||
}
|
||||
return result;
|
||||
},
|
||||
{
|
||||
pending: [],
|
||||
todo: []
|
||||
}
|
||||
);
|
||||
if (summedTests.pending.length > 0) {
|
||||
summedTests.pending.forEach(this._logTodoOrPendingTest(indentLevel));
|
||||
}
|
||||
if (summedTests.todo.length > 0) {
|
||||
summedTests.todo.forEach(this._logTodoOrPendingTest(indentLevel));
|
||||
}
|
||||
}
|
||||
}
|
||||
_logTodoOrPendingTest(indentLevel) {
|
||||
return test => {
|
||||
const printedTestStatus =
|
||||
test.status === 'pending' ? 'skipped' : test.status;
|
||||
const icon = this._getIcon(test.status);
|
||||
const text = _chalk().default.dim(`${printedTestStatus} ${test.title}`);
|
||||
this._logLine(`${icon} ${text}`, indentLevel);
|
||||
};
|
||||
}
|
||||
_logLine(str, indentLevel) {
|
||||
const indentation = ' '.repeat(indentLevel || 0);
|
||||
this.log(indentation + (str || ''));
|
||||
}
|
||||
}
|
||||
exports.default = VerboseReporter;
|
||||
84
node_modules/@jest/reporters/build/formatTestPath.js
generated
vendored
Normal file
84
node_modules/@jest/reporters/build/formatTestPath.js
generated
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true
|
||||
});
|
||||
exports.default = formatTestPath;
|
||||
function path() {
|
||||
const data = _interopRequireWildcard(require('path'));
|
||||
path = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _chalk() {
|
||||
const data = _interopRequireDefault(require('chalk'));
|
||||
_chalk = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _slash() {
|
||||
const data = _interopRequireDefault(require('slash'));
|
||||
_slash = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
var _relativePath = _interopRequireDefault(require('./relativePath'));
|
||||
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;
|
||||
}
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
function formatTestPath(config, testPath) {
|
||||
const {dirname, basename} = (0, _relativePath.default)(config, testPath);
|
||||
return (0, _slash().default)(
|
||||
_chalk().default.dim(dirname + path().sep) + _chalk().default.bold(basename)
|
||||
);
|
||||
}
|
||||
151
node_modules/@jest/reporters/build/generateEmptyCoverage.js
generated
vendored
Normal file
151
node_modules/@jest/reporters/build/generateEmptyCoverage.js
generated
vendored
Normal file
@@ -0,0 +1,151 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true
|
||||
});
|
||||
exports.default = generateEmptyCoverage;
|
||||
function fs() {
|
||||
const data = _interopRequireWildcard(require('graceful-fs'));
|
||||
fs = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _istanbulLibCoverage() {
|
||||
const data = require('istanbul-lib-coverage');
|
||||
_istanbulLibCoverage = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _istanbulLibInstrument() {
|
||||
const data = require('istanbul-lib-instrument');
|
||||
_istanbulLibInstrument = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _transform() {
|
||||
const data = require('@jest/transform');
|
||||
_transform = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
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;
|
||||
}
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
async function generateEmptyCoverage(
|
||||
source,
|
||||
filename,
|
||||
globalConfig,
|
||||
config,
|
||||
changedFiles,
|
||||
sourcesRelatedToTestsInChangedFiles
|
||||
) {
|
||||
const coverageOptions = {
|
||||
changedFiles,
|
||||
collectCoverage: globalConfig.collectCoverage,
|
||||
collectCoverageFrom: globalConfig.collectCoverageFrom,
|
||||
coverageProvider: globalConfig.coverageProvider,
|
||||
sourcesRelatedToTestsInChangedFiles
|
||||
};
|
||||
let coverageWorkerResult = null;
|
||||
if ((0, _transform().shouldInstrument)(filename, coverageOptions, config)) {
|
||||
if (coverageOptions.coverageProvider === 'v8') {
|
||||
const stat = fs().statSync(filename);
|
||||
return {
|
||||
kind: 'V8Coverage',
|
||||
result: {
|
||||
functions: [
|
||||
{
|
||||
functionName: '(empty-report)',
|
||||
isBlockCoverage: true,
|
||||
ranges: [
|
||||
{
|
||||
count: 0,
|
||||
endOffset: stat.size,
|
||||
startOffset: 0
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
scriptId: '0',
|
||||
url: filename
|
||||
}
|
||||
};
|
||||
}
|
||||
const scriptTransformer = await (0, _transform().createScriptTransformer)(
|
||||
config
|
||||
);
|
||||
|
||||
// Transform file with instrumentation to make sure initial coverage data is well mapped to original code.
|
||||
const {code} = await scriptTransformer.transformSourceAsync(
|
||||
filename,
|
||||
source,
|
||||
{
|
||||
instrument: true,
|
||||
supportsDynamicImport: true,
|
||||
supportsExportNamespaceFrom: true,
|
||||
supportsStaticESM: true,
|
||||
supportsTopLevelAwait: true
|
||||
}
|
||||
);
|
||||
// TODO: consider passing AST
|
||||
const extracted = (0, _istanbulLibInstrument().readInitialCoverage)(code);
|
||||
// Check extracted initial coverage is not null, this can happen when using /* istanbul ignore file */
|
||||
if (extracted) {
|
||||
coverageWorkerResult = {
|
||||
coverage: (0, _istanbulLibCoverage().createFileCoverage)(
|
||||
extracted.coverageData
|
||||
),
|
||||
kind: 'BabelCoverage'
|
||||
};
|
||||
}
|
||||
}
|
||||
return coverageWorkerResult;
|
||||
}
|
||||
65
node_modules/@jest/reporters/build/getResultHeader.js
generated
vendored
Normal file
65
node_modules/@jest/reporters/build/getResultHeader.js
generated
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true
|
||||
});
|
||||
exports.default = getResultHeader;
|
||||
function _chalk() {
|
||||
const data = _interopRequireDefault(require('chalk'));
|
||||
_chalk = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _jestUtil() {
|
||||
const data = require('jest-util');
|
||||
_jestUtil = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
var _formatTestPath = _interopRequireDefault(require('./formatTestPath'));
|
||||
var _printDisplayName = _interopRequireDefault(require('./printDisplayName'));
|
||||
function _interopRequireDefault(obj) {
|
||||
return obj && obj.__esModule ? obj : {default: obj};
|
||||
}
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
const LONG_TEST_COLOR = _chalk().default.reset.bold.bgRed;
|
||||
// Explicitly reset for these messages since they can get written out in the
|
||||
// middle of error logging
|
||||
const FAIL_TEXT = 'FAIL';
|
||||
const PASS_TEXT = 'PASS';
|
||||
const FAIL = _chalk().default.supportsColor
|
||||
? _chalk().default.reset.inverse.bold.red(` ${FAIL_TEXT} `)
|
||||
: FAIL_TEXT;
|
||||
const PASS = _chalk().default.supportsColor
|
||||
? _chalk().default.reset.inverse.bold.green(` ${PASS_TEXT} `)
|
||||
: PASS_TEXT;
|
||||
function getResultHeader(result, globalConfig, projectConfig) {
|
||||
const testPath = result.testFilePath;
|
||||
const status =
|
||||
result.numFailingTests > 0 || result.testExecError ? FAIL : PASS;
|
||||
const testDetail = [];
|
||||
if (result.perfStats?.slow) {
|
||||
const runTime = result.perfStats.runtime / 1000;
|
||||
testDetail.push(LONG_TEST_COLOR((0, _jestUtil().formatTime)(runTime, 0)));
|
||||
}
|
||||
if (result.memoryUsage) {
|
||||
const toMB = bytes => Math.floor(bytes / 1024 / 1024);
|
||||
testDetail.push(`${toMB(result.memoryUsage)} MB heap size`);
|
||||
}
|
||||
const projectDisplayName =
|
||||
projectConfig && projectConfig.displayName
|
||||
? `${(0, _printDisplayName.default)(projectConfig)} `
|
||||
: '';
|
||||
return `${status} ${projectDisplayName}${(0, _formatTestPath.default)(
|
||||
projectConfig ?? globalConfig,
|
||||
testPath
|
||||
)}${testDetail.length ? ` (${testDetail.join(', ')})` : ''}`;
|
||||
}
|
||||
92
node_modules/@jest/reporters/build/getSnapshotStatus.js
generated
vendored
Normal file
92
node_modules/@jest/reporters/build/getSnapshotStatus.js
generated
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true
|
||||
});
|
||||
exports.default = getSnapshotStatus;
|
||||
function _chalk() {
|
||||
const data = _interopRequireDefault(require('chalk'));
|
||||
_chalk = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _jestUtil() {
|
||||
const data = require('jest-util');
|
||||
_jestUtil = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _interopRequireDefault(obj) {
|
||||
return obj && obj.__esModule ? obj : {default: obj};
|
||||
}
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
const ARROW = ' \u203A ';
|
||||
const DOT = ' \u2022 ';
|
||||
const FAIL_COLOR = _chalk().default.bold.red;
|
||||
const SNAPSHOT_ADDED = _chalk().default.bold.green;
|
||||
const SNAPSHOT_UPDATED = _chalk().default.bold.green;
|
||||
const SNAPSHOT_OUTDATED = _chalk().default.bold.yellow;
|
||||
function getSnapshotStatus(snapshot, afterUpdate) {
|
||||
const statuses = [];
|
||||
if (snapshot.added) {
|
||||
statuses.push(
|
||||
SNAPSHOT_ADDED(
|
||||
`${
|
||||
ARROW + (0, _jestUtil().pluralize)('snapshot', snapshot.added)
|
||||
} written.`
|
||||
)
|
||||
);
|
||||
}
|
||||
if (snapshot.updated) {
|
||||
statuses.push(
|
||||
SNAPSHOT_UPDATED(
|
||||
`${
|
||||
ARROW + (0, _jestUtil().pluralize)('snapshot', snapshot.updated)
|
||||
} updated.`
|
||||
)
|
||||
);
|
||||
}
|
||||
if (snapshot.unmatched) {
|
||||
statuses.push(
|
||||
FAIL_COLOR(
|
||||
`${
|
||||
ARROW + (0, _jestUtil().pluralize)('snapshot', snapshot.unmatched)
|
||||
} failed.`
|
||||
)
|
||||
);
|
||||
}
|
||||
if (snapshot.unchecked) {
|
||||
if (afterUpdate) {
|
||||
statuses.push(
|
||||
SNAPSHOT_UPDATED(
|
||||
`${
|
||||
ARROW + (0, _jestUtil().pluralize)('snapshot', snapshot.unchecked)
|
||||
} removed.`
|
||||
)
|
||||
);
|
||||
} else {
|
||||
statuses.push(
|
||||
`${SNAPSHOT_OUTDATED(
|
||||
`${
|
||||
ARROW + (0, _jestUtil().pluralize)('snapshot', snapshot.unchecked)
|
||||
} obsolete`
|
||||
)}.`
|
||||
);
|
||||
}
|
||||
snapshot.uncheckedKeys.forEach(key => {
|
||||
statuses.push(` ${DOT}${key}`);
|
||||
});
|
||||
}
|
||||
if (snapshot.fileDeleted) {
|
||||
statuses.push(SNAPSHOT_UPDATED(`${ARROW}snapshot file removed.`));
|
||||
}
|
||||
return statuses;
|
||||
}
|
||||
169
node_modules/@jest/reporters/build/getSnapshotSummary.js
generated
vendored
Normal file
169
node_modules/@jest/reporters/build/getSnapshotSummary.js
generated
vendored
Normal file
@@ -0,0 +1,169 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true
|
||||
});
|
||||
exports.default = getSnapshotSummary;
|
||||
function _chalk() {
|
||||
const data = _interopRequireDefault(require('chalk'));
|
||||
_chalk = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _jestUtil() {
|
||||
const data = require('jest-util');
|
||||
_jestUtil = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
var _formatTestPath = _interopRequireDefault(require('./formatTestPath'));
|
||||
function _interopRequireDefault(obj) {
|
||||
return obj && obj.__esModule ? obj : {default: obj};
|
||||
}
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
const ARROW = ' \u203A ';
|
||||
const DOWN_ARROW = ' \u21B3 ';
|
||||
const DOT = ' \u2022 ';
|
||||
const FAIL_COLOR = _chalk().default.bold.red;
|
||||
const OBSOLETE_COLOR = _chalk().default.bold.yellow;
|
||||
const SNAPSHOT_ADDED = _chalk().default.bold.green;
|
||||
const SNAPSHOT_NOTE = _chalk().default.dim;
|
||||
const SNAPSHOT_REMOVED = _chalk().default.bold.green;
|
||||
const SNAPSHOT_SUMMARY = _chalk().default.bold;
|
||||
const SNAPSHOT_UPDATED = _chalk().default.bold.green;
|
||||
function getSnapshotSummary(snapshots, globalConfig, updateCommand) {
|
||||
const summary = [];
|
||||
summary.push(SNAPSHOT_SUMMARY('Snapshot Summary'));
|
||||
if (snapshots.added) {
|
||||
summary.push(
|
||||
`${SNAPSHOT_ADDED(
|
||||
`${
|
||||
ARROW + (0, _jestUtil().pluralize)('snapshot', snapshots.added)
|
||||
} written `
|
||||
)}from ${(0, _jestUtil().pluralize)('test suite', snapshots.filesAdded)}.`
|
||||
);
|
||||
}
|
||||
if (snapshots.unmatched) {
|
||||
summary.push(
|
||||
`${FAIL_COLOR(
|
||||
`${ARROW}${(0, _jestUtil().pluralize)(
|
||||
'snapshot',
|
||||
snapshots.unmatched
|
||||
)} failed`
|
||||
)} from ${(0, _jestUtil().pluralize)(
|
||||
'test suite',
|
||||
snapshots.filesUnmatched
|
||||
)}. ${SNAPSHOT_NOTE(
|
||||
`Inspect your code changes or ${updateCommand} to update them.`
|
||||
)}`
|
||||
);
|
||||
}
|
||||
if (snapshots.updated) {
|
||||
summary.push(
|
||||
`${SNAPSHOT_UPDATED(
|
||||
`${
|
||||
ARROW + (0, _jestUtil().pluralize)('snapshot', snapshots.updated)
|
||||
} updated `
|
||||
)}from ${(0, _jestUtil().pluralize)(
|
||||
'test suite',
|
||||
snapshots.filesUpdated
|
||||
)}.`
|
||||
);
|
||||
}
|
||||
if (snapshots.filesRemoved) {
|
||||
if (snapshots.didUpdate) {
|
||||
summary.push(
|
||||
`${SNAPSHOT_REMOVED(
|
||||
`${ARROW}${(0, _jestUtil().pluralize)(
|
||||
'snapshot file',
|
||||
snapshots.filesRemoved
|
||||
)} removed `
|
||||
)}from ${(0, _jestUtil().pluralize)(
|
||||
'test suite',
|
||||
snapshots.filesRemoved
|
||||
)}.`
|
||||
);
|
||||
} else {
|
||||
summary.push(
|
||||
`${OBSOLETE_COLOR(
|
||||
`${ARROW}${(0, _jestUtil().pluralize)(
|
||||
'snapshot file',
|
||||
snapshots.filesRemoved
|
||||
)} obsolete `
|
||||
)}from ${(0, _jestUtil().pluralize)(
|
||||
'test suite',
|
||||
snapshots.filesRemoved
|
||||
)}. ${SNAPSHOT_NOTE(
|
||||
`To remove ${
|
||||
snapshots.filesRemoved === 1 ? 'it' : 'them all'
|
||||
}, ${updateCommand}.`
|
||||
)}`
|
||||
);
|
||||
}
|
||||
}
|
||||
if (snapshots.filesRemovedList && snapshots.filesRemovedList.length) {
|
||||
const [head, ...tail] = snapshots.filesRemovedList;
|
||||
summary.push(
|
||||
` ${DOWN_ARROW} ${DOT}${(0, _formatTestPath.default)(
|
||||
globalConfig,
|
||||
head
|
||||
)}`
|
||||
);
|
||||
tail.forEach(key => {
|
||||
summary.push(
|
||||
` ${DOT}${(0, _formatTestPath.default)(globalConfig, key)}`
|
||||
);
|
||||
});
|
||||
}
|
||||
if (snapshots.unchecked) {
|
||||
if (snapshots.didUpdate) {
|
||||
summary.push(
|
||||
`${SNAPSHOT_REMOVED(
|
||||
`${ARROW}${(0, _jestUtil().pluralize)(
|
||||
'snapshot',
|
||||
snapshots.unchecked
|
||||
)} removed `
|
||||
)}from ${(0, _jestUtil().pluralize)(
|
||||
'test suite',
|
||||
snapshots.uncheckedKeysByFile.length
|
||||
)}.`
|
||||
);
|
||||
} else {
|
||||
summary.push(
|
||||
`${OBSOLETE_COLOR(
|
||||
`${ARROW}${(0, _jestUtil().pluralize)(
|
||||
'snapshot',
|
||||
snapshots.unchecked
|
||||
)} obsolete `
|
||||
)}from ${(0, _jestUtil().pluralize)(
|
||||
'test suite',
|
||||
snapshots.uncheckedKeysByFile.length
|
||||
)}. ${SNAPSHOT_NOTE(
|
||||
`To remove ${
|
||||
snapshots.unchecked === 1 ? 'it' : 'them all'
|
||||
}, ${updateCommand}.`
|
||||
)}`
|
||||
);
|
||||
}
|
||||
snapshots.uncheckedKeysByFile.forEach(uncheckedFile => {
|
||||
summary.push(
|
||||
` ${DOWN_ARROW}${(0, _formatTestPath.default)(
|
||||
globalConfig,
|
||||
uncheckedFile.filePath
|
||||
)}`
|
||||
);
|
||||
uncheckedFile.keys.forEach(key => {
|
||||
summary.push(` ${DOT}${key}`);
|
||||
});
|
||||
});
|
||||
}
|
||||
return summary;
|
||||
}
|
||||
206
node_modules/@jest/reporters/build/getSummary.js
generated
vendored
Normal file
206
node_modules/@jest/reporters/build/getSummary.js
generated
vendored
Normal file
@@ -0,0 +1,206 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true
|
||||
});
|
||||
exports.PROGRESS_BAR_WIDTH = void 0;
|
||||
exports.default = getSummary;
|
||||
function _chalk() {
|
||||
const data = _interopRequireDefault(require('chalk'));
|
||||
_chalk = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _jestUtil() {
|
||||
const data = require('jest-util');
|
||||
_jestUtil = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _interopRequireDefault(obj) {
|
||||
return obj && obj.__esModule ? obj : {default: obj};
|
||||
}
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
const PROGRESS_BAR_WIDTH = 40;
|
||||
exports.PROGRESS_BAR_WIDTH = PROGRESS_BAR_WIDTH;
|
||||
function getValuesCurrentTestCases(currentTestCases = []) {
|
||||
let numFailingTests = 0;
|
||||
let numPassingTests = 0;
|
||||
let numPendingTests = 0;
|
||||
let numTodoTests = 0;
|
||||
let numTotalTests = 0;
|
||||
currentTestCases.forEach(testCase => {
|
||||
switch (testCase.testCaseResult.status) {
|
||||
case 'failed': {
|
||||
numFailingTests++;
|
||||
break;
|
||||
}
|
||||
case 'passed': {
|
||||
numPassingTests++;
|
||||
break;
|
||||
}
|
||||
case 'skipped': {
|
||||
numPendingTests++;
|
||||
break;
|
||||
}
|
||||
case 'todo': {
|
||||
numTodoTests++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
numTotalTests++;
|
||||
});
|
||||
return {
|
||||
numFailingTests,
|
||||
numPassingTests,
|
||||
numPendingTests,
|
||||
numTodoTests,
|
||||
numTotalTests
|
||||
};
|
||||
}
|
||||
function renderTime(runTime, estimatedTime, width) {
|
||||
// If we are more than one second over the estimated time, highlight it.
|
||||
const renderedTime =
|
||||
estimatedTime && runTime >= estimatedTime + 1
|
||||
? _chalk().default.bold.yellow((0, _jestUtil().formatTime)(runTime, 0))
|
||||
: (0, _jestUtil().formatTime)(runTime, 0);
|
||||
let time = `${_chalk().default.bold('Time:')} ${renderedTime}`;
|
||||
if (runTime < estimatedTime) {
|
||||
time += `, estimated ${(0, _jestUtil().formatTime)(estimatedTime, 0)}`;
|
||||
}
|
||||
|
||||
// Only show a progress bar if the test run is actually going to take
|
||||
// some time.
|
||||
if (estimatedTime > 2 && runTime < estimatedTime && width) {
|
||||
const availableWidth = Math.min(PROGRESS_BAR_WIDTH, width);
|
||||
const length = Math.min(
|
||||
Math.floor((runTime / estimatedTime) * availableWidth),
|
||||
availableWidth
|
||||
);
|
||||
if (availableWidth >= 2) {
|
||||
time += `\n${_chalk().default.green('█').repeat(length)}${_chalk()
|
||||
.default.white('█')
|
||||
.repeat(availableWidth - length)}`;
|
||||
}
|
||||
}
|
||||
return time;
|
||||
}
|
||||
function getSummary(aggregatedResults, options) {
|
||||
let runTime = (Date.now() - aggregatedResults.startTime) / 1000;
|
||||
if (options && options.roundTime) {
|
||||
runTime = Math.floor(runTime);
|
||||
}
|
||||
const valuesForCurrentTestCases = getValuesCurrentTestCases(
|
||||
options?.currentTestCases
|
||||
);
|
||||
const estimatedTime = (options && options.estimatedTime) || 0;
|
||||
const snapshotResults = aggregatedResults.snapshot;
|
||||
const snapshotsAdded = snapshotResults.added;
|
||||
const snapshotsFailed = snapshotResults.unmatched;
|
||||
const snapshotsOutdated = snapshotResults.unchecked;
|
||||
const snapshotsFilesRemoved = snapshotResults.filesRemoved;
|
||||
const snapshotsDidUpdate = snapshotResults.didUpdate;
|
||||
const snapshotsPassed = snapshotResults.matched;
|
||||
const snapshotsTotal = snapshotResults.total;
|
||||
const snapshotsUpdated = snapshotResults.updated;
|
||||
const suitesFailed = aggregatedResults.numFailedTestSuites;
|
||||
const suitesPassed = aggregatedResults.numPassedTestSuites;
|
||||
const suitesPending = aggregatedResults.numPendingTestSuites;
|
||||
const suitesRun = suitesFailed + suitesPassed;
|
||||
const suitesTotal = aggregatedResults.numTotalTestSuites;
|
||||
const testsFailed = aggregatedResults.numFailedTests;
|
||||
const testsPassed = aggregatedResults.numPassedTests;
|
||||
const testsPending = aggregatedResults.numPendingTests;
|
||||
const testsTodo = aggregatedResults.numTodoTests;
|
||||
const testsTotal = aggregatedResults.numTotalTests;
|
||||
const width = (options && options.width) || 0;
|
||||
const optionalLines = [];
|
||||
if (options?.showSeed === true) {
|
||||
const {seed} = options;
|
||||
if (seed === undefined) {
|
||||
throw new Error('Attempted to display seed but seed value is undefined');
|
||||
}
|
||||
optionalLines.push(`${_chalk().default.bold('Seed: ') + seed}`);
|
||||
}
|
||||
const suites = `${
|
||||
_chalk().default.bold('Test Suites: ') +
|
||||
(suitesFailed
|
||||
? `${_chalk().default.bold.red(`${suitesFailed} failed`)}, `
|
||||
: '') +
|
||||
(suitesPending
|
||||
? `${_chalk().default.bold.yellow(`${suitesPending} skipped`)}, `
|
||||
: '') +
|
||||
(suitesPassed
|
||||
? `${_chalk().default.bold.green(`${suitesPassed} passed`)}, `
|
||||
: '') +
|
||||
(suitesRun !== suitesTotal ? `${suitesRun} of ${suitesTotal}` : suitesTotal)
|
||||
} total`;
|
||||
const updatedTestsFailed =
|
||||
testsFailed + valuesForCurrentTestCases.numFailingTests;
|
||||
const updatedTestsPending =
|
||||
testsPending + valuesForCurrentTestCases.numPendingTests;
|
||||
const updatedTestsTodo = testsTodo + valuesForCurrentTestCases.numTodoTests;
|
||||
const updatedTestsPassed =
|
||||
testsPassed + valuesForCurrentTestCases.numPassingTests;
|
||||
const updatedTestsTotal =
|
||||
testsTotal + valuesForCurrentTestCases.numTotalTests;
|
||||
const tests = `${
|
||||
_chalk().default.bold('Tests: ') +
|
||||
(updatedTestsFailed > 0
|
||||
? `${_chalk().default.bold.red(`${updatedTestsFailed} failed`)}, `
|
||||
: '') +
|
||||
(updatedTestsPending > 0
|
||||
? `${_chalk().default.bold.yellow(`${updatedTestsPending} skipped`)}, `
|
||||
: '') +
|
||||
(updatedTestsTodo > 0
|
||||
? `${_chalk().default.bold.magenta(`${updatedTestsTodo} todo`)}, `
|
||||
: '') +
|
||||
(updatedTestsPassed > 0
|
||||
? `${_chalk().default.bold.green(`${updatedTestsPassed} passed`)}, `
|
||||
: '')
|
||||
}${updatedTestsTotal} total`;
|
||||
const snapshots = `${
|
||||
_chalk().default.bold('Snapshots: ') +
|
||||
(snapshotsFailed
|
||||
? `${_chalk().default.bold.red(`${snapshotsFailed} failed`)}, `
|
||||
: '') +
|
||||
(snapshotsOutdated && !snapshotsDidUpdate
|
||||
? `${_chalk().default.bold.yellow(`${snapshotsOutdated} obsolete`)}, `
|
||||
: '') +
|
||||
(snapshotsOutdated && snapshotsDidUpdate
|
||||
? `${_chalk().default.bold.green(`${snapshotsOutdated} removed`)}, `
|
||||
: '') +
|
||||
(snapshotsFilesRemoved && !snapshotsDidUpdate
|
||||
? `${_chalk().default.bold.yellow(
|
||||
`${(0, _jestUtil().pluralize)(
|
||||
'file',
|
||||
snapshotsFilesRemoved
|
||||
)} obsolete`
|
||||
)}, `
|
||||
: '') +
|
||||
(snapshotsFilesRemoved && snapshotsDidUpdate
|
||||
? `${_chalk().default.bold.green(
|
||||
`${(0, _jestUtil().pluralize)('file', snapshotsFilesRemoved)} removed`
|
||||
)}, `
|
||||
: '') +
|
||||
(snapshotsUpdated
|
||||
? `${_chalk().default.bold.green(`${snapshotsUpdated} updated`)}, `
|
||||
: '') +
|
||||
(snapshotsAdded
|
||||
? `${_chalk().default.bold.green(`${snapshotsAdded} written`)}, `
|
||||
: '') +
|
||||
(snapshotsPassed
|
||||
? `${_chalk().default.bold.green(`${snapshotsPassed} passed`)}, `
|
||||
: '')
|
||||
}${snapshotsTotal} total`;
|
||||
const time = renderTime(runTime, estimatedTime, width);
|
||||
return [...optionalLines, suites, tests, snapshots, time].join('\n');
|
||||
}
|
||||
38
node_modules/@jest/reporters/build/getWatermarks.js
generated
vendored
Normal file
38
node_modules/@jest/reporters/build/getWatermarks.js
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true
|
||||
});
|
||||
exports.default = getWatermarks;
|
||||
function _istanbulLibReport() {
|
||||
const data = _interopRequireDefault(require('istanbul-lib-report'));
|
||||
_istanbulLibReport = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _interopRequireDefault(obj) {
|
||||
return obj && obj.__esModule ? obj : {default: obj};
|
||||
}
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
function getWatermarks(config) {
|
||||
const defaultWatermarks = _istanbulLibReport().default.getDefaultWatermarks();
|
||||
const {coverageThreshold} = config;
|
||||
if (!coverageThreshold || !coverageThreshold.global) {
|
||||
return defaultWatermarks;
|
||||
}
|
||||
const keys = ['branches', 'functions', 'lines', 'statements'];
|
||||
return keys.reduce((watermarks, key) => {
|
||||
const value = coverageThreshold.global[key];
|
||||
if (value !== undefined) {
|
||||
watermarks[key][1] = value;
|
||||
}
|
||||
return watermarks;
|
||||
}, defaultWatermarks);
|
||||
}
|
||||
325
node_modules/@jest/reporters/build/index.d.ts
generated
vendored
Normal file
325
node_modules/@jest/reporters/build/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,325 @@
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
/// <reference types="node" />
|
||||
|
||||
import {AggregatedResult} from '@jest/test-result';
|
||||
import type {AssertionResult} from '@jest/test-result';
|
||||
import type {Circus} from '@jest/types';
|
||||
import {Config} from '@jest/types';
|
||||
import {SnapshotSummary} from '@jest/test-result';
|
||||
import type {Suite} from '@jest/test-result';
|
||||
import {Test} from '@jest/test-result';
|
||||
import {TestCaseResult} from '@jest/test-result';
|
||||
import {TestContext} from '@jest/test-result';
|
||||
import {TestResult} from '@jest/test-result';
|
||||
|
||||
export {AggregatedResult};
|
||||
|
||||
export declare class BaseReporter implements Reporter {
|
||||
private _error?;
|
||||
log(message: string): void;
|
||||
onRunStart(
|
||||
_results?: AggregatedResult,
|
||||
_options?: ReporterOnStartOptions,
|
||||
): void;
|
||||
onTestCaseResult(_test: Test, _testCaseResult: TestCaseResult): void;
|
||||
onTestResult(
|
||||
_test?: Test,
|
||||
_testResult?: TestResult,
|
||||
_results?: AggregatedResult,
|
||||
): void;
|
||||
onTestStart(_test?: Test): void;
|
||||
onRunComplete(
|
||||
_testContexts?: Set<TestContext>,
|
||||
_aggregatedResults?: AggregatedResult,
|
||||
): Promise<void> | void;
|
||||
protected _setError(error: Error): void;
|
||||
getLastError(): Error | undefined;
|
||||
}
|
||||
|
||||
export {Config};
|
||||
|
||||
export declare class CoverageReporter extends BaseReporter {
|
||||
private readonly _context;
|
||||
private readonly _coverageMap;
|
||||
private readonly _globalConfig;
|
||||
private readonly _sourceMapStore;
|
||||
private readonly _v8CoverageResults;
|
||||
static readonly filename: string;
|
||||
constructor(globalConfig: Config.GlobalConfig, context: ReporterContext);
|
||||
onTestResult(_test: Test, testResult: TestResult): void;
|
||||
onRunComplete(
|
||||
testContexts: Set<TestContext>,
|
||||
aggregatedResults: AggregatedResult,
|
||||
): Promise<void>;
|
||||
private _addUntestedFiles;
|
||||
private _checkThreshold;
|
||||
private _getCoverageResult;
|
||||
}
|
||||
|
||||
export declare class DefaultReporter extends BaseReporter {
|
||||
private _clear;
|
||||
private readonly _err;
|
||||
protected _globalConfig: Config.GlobalConfig;
|
||||
private readonly _out;
|
||||
private readonly _status;
|
||||
private readonly _bufferedOutput;
|
||||
static readonly filename: string;
|
||||
constructor(globalConfig: Config.GlobalConfig);
|
||||
protected __wrapStdio(
|
||||
stream: NodeJS.WritableStream | NodeJS.WriteStream,
|
||||
): void;
|
||||
forceFlushBufferedOutput(): void;
|
||||
protected __clearStatus(): void;
|
||||
protected __printStatus(): void;
|
||||
onRunStart(
|
||||
aggregatedResults: AggregatedResult,
|
||||
options: ReporterOnStartOptions,
|
||||
): void;
|
||||
onTestStart(test: Test): void;
|
||||
onTestCaseResult(test: Test, testCaseResult: TestCaseResult): void;
|
||||
onRunComplete(): void;
|
||||
onTestResult(
|
||||
test: Test,
|
||||
testResult: TestResult,
|
||||
aggregatedResults: AggregatedResult,
|
||||
): void;
|
||||
testFinished(
|
||||
config: Config.ProjectConfig,
|
||||
testResult: TestResult,
|
||||
aggregatedResults: AggregatedResult,
|
||||
): void;
|
||||
printTestFileHeader(
|
||||
testPath: string,
|
||||
config: Config.ProjectConfig,
|
||||
result: TestResult,
|
||||
): void;
|
||||
printTestFileFailureMessage(
|
||||
_testPath: string,
|
||||
_config: Config.ProjectConfig,
|
||||
result: TestResult,
|
||||
): void;
|
||||
}
|
||||
|
||||
declare function formatTestPath(
|
||||
config: Config.GlobalConfig | Config.ProjectConfig,
|
||||
testPath: string,
|
||||
): string;
|
||||
|
||||
declare function getResultHeader(
|
||||
result: TestResult,
|
||||
globalConfig: Config.GlobalConfig,
|
||||
projectConfig?: Config.ProjectConfig,
|
||||
): string;
|
||||
|
||||
declare function getSnapshotStatus(
|
||||
snapshot: TestResult['snapshot'],
|
||||
afterUpdate: boolean,
|
||||
): Array<string>;
|
||||
|
||||
declare function getSnapshotSummary(
|
||||
snapshots: SnapshotSummary,
|
||||
globalConfig: Config.GlobalConfig,
|
||||
updateCommand: string,
|
||||
): Array<string>;
|
||||
|
||||
declare function getSummary(
|
||||
aggregatedResults: AggregatedResult,
|
||||
options?: SummaryOptions,
|
||||
): string;
|
||||
|
||||
export declare class GitHubActionsReporter extends BaseReporter {
|
||||
#private;
|
||||
static readonly filename: string;
|
||||
private readonly options;
|
||||
constructor(
|
||||
_globalConfig: Config.GlobalConfig,
|
||||
reporterOptions?: {
|
||||
silent?: boolean;
|
||||
},
|
||||
);
|
||||
onTestResult(
|
||||
test: Test,
|
||||
testResult: TestResult,
|
||||
aggregatedResults: AggregatedResult,
|
||||
): void;
|
||||
private generateAnnotations;
|
||||
private isLastTestSuite;
|
||||
private printFullResult;
|
||||
private arrayEqual;
|
||||
private arrayChild;
|
||||
private getResultTree;
|
||||
private getResultChildren;
|
||||
private printResultTree;
|
||||
private recursivePrintResultTree;
|
||||
private printFailedTestLogs;
|
||||
private startGroup;
|
||||
private endGroup;
|
||||
}
|
||||
|
||||
export declare class NotifyReporter extends BaseReporter {
|
||||
private readonly _notifier;
|
||||
private readonly _globalConfig;
|
||||
private _context;
|
||||
static readonly filename: string;
|
||||
constructor(globalConfig: Config.GlobalConfig, context: ReporterContext);
|
||||
onRunComplete(testContexts: Set<TestContext>, result: AggregatedResult): void;
|
||||
}
|
||||
|
||||
declare function printDisplayName(config: Config.ProjectConfig): string;
|
||||
|
||||
declare function relativePath(
|
||||
config: Config.GlobalConfig | Config.ProjectConfig,
|
||||
testPath: string,
|
||||
): {
|
||||
basename: string;
|
||||
dirname: string;
|
||||
};
|
||||
|
||||
export declare interface Reporter {
|
||||
readonly onTestResult?: (
|
||||
test: Test,
|
||||
testResult: TestResult,
|
||||
aggregatedResult: AggregatedResult,
|
||||
) => Promise<void> | void;
|
||||
readonly onTestFileResult?: (
|
||||
test: Test,
|
||||
testResult: TestResult,
|
||||
aggregatedResult: AggregatedResult,
|
||||
) => Promise<void> | void;
|
||||
/**
|
||||
* Called before running a spec (prior to `before` hooks)
|
||||
* Not called for `skipped` and `todo` specs
|
||||
*/
|
||||
readonly onTestCaseStart?: (
|
||||
test: Test,
|
||||
testCaseStartInfo: Circus.TestCaseStartInfo,
|
||||
) => Promise<void> | void;
|
||||
readonly onTestCaseResult?: (
|
||||
test: Test,
|
||||
testCaseResult: TestCaseResult,
|
||||
) => Promise<void> | void;
|
||||
readonly onRunStart?: (
|
||||
results: AggregatedResult,
|
||||
options: ReporterOnStartOptions,
|
||||
) => Promise<void> | void;
|
||||
readonly onTestStart?: (test: Test) => Promise<void> | void;
|
||||
readonly onTestFileStart?: (test: Test) => Promise<void> | void;
|
||||
readonly onRunComplete?: (
|
||||
testContexts: Set<TestContext>,
|
||||
results: AggregatedResult,
|
||||
) => Promise<void> | void;
|
||||
readonly getLastError?: () => Error | void;
|
||||
}
|
||||
|
||||
export declare type ReporterContext = {
|
||||
firstRun: boolean;
|
||||
previousSuccess: boolean;
|
||||
changedFiles?: Set<string>;
|
||||
sourcesRelatedToTestsInChangedFiles?: Set<string>;
|
||||
startRun?: (globalConfig: Config.GlobalConfig) => unknown;
|
||||
};
|
||||
|
||||
export declare type ReporterOnStartOptions = {
|
||||
estimatedTime: number;
|
||||
showStatus: boolean;
|
||||
};
|
||||
|
||||
export {SnapshotSummary};
|
||||
|
||||
export declare type SummaryOptions = {
|
||||
currentTestCases?: Array<{
|
||||
test: Test;
|
||||
testCaseResult: TestCaseResult;
|
||||
}>;
|
||||
estimatedTime?: number;
|
||||
roundTime?: boolean;
|
||||
width?: number;
|
||||
showSeed?: boolean;
|
||||
seed?: number;
|
||||
};
|
||||
|
||||
export declare class SummaryReporter extends BaseReporter {
|
||||
private _estimatedTime;
|
||||
private readonly _globalConfig;
|
||||
private readonly _summaryThreshold;
|
||||
static readonly filename: string;
|
||||
constructor(
|
||||
globalConfig: Config.GlobalConfig,
|
||||
options?: SummaryReporterOptions,
|
||||
);
|
||||
private _validateOptions;
|
||||
private _write;
|
||||
onRunStart(
|
||||
aggregatedResults: AggregatedResult,
|
||||
options: ReporterOnStartOptions,
|
||||
): void;
|
||||
onRunComplete(
|
||||
testContexts: Set<TestContext>,
|
||||
aggregatedResults: AggregatedResult,
|
||||
): void;
|
||||
private _printSnapshotSummary;
|
||||
private _printSummary;
|
||||
private _getTestSummary;
|
||||
}
|
||||
|
||||
export declare type SummaryReporterOptions = {
|
||||
summaryThreshold?: number;
|
||||
};
|
||||
|
||||
export {Test};
|
||||
|
||||
export {TestCaseResult};
|
||||
|
||||
export {TestContext};
|
||||
|
||||
export {TestResult};
|
||||
|
||||
declare function trimAndFormatPath(
|
||||
pad: number,
|
||||
config: Config.ProjectConfig | Config.GlobalConfig,
|
||||
testPath: string,
|
||||
columns: number,
|
||||
): string;
|
||||
|
||||
export declare const utils: {
|
||||
formatTestPath: typeof formatTestPath;
|
||||
getResultHeader: typeof getResultHeader;
|
||||
getSnapshotStatus: typeof getSnapshotStatus;
|
||||
getSnapshotSummary: typeof getSnapshotSummary;
|
||||
getSummary: typeof getSummary;
|
||||
printDisplayName: typeof printDisplayName;
|
||||
relativePath: typeof relativePath;
|
||||
trimAndFormatPath: typeof trimAndFormatPath;
|
||||
};
|
||||
|
||||
export declare class VerboseReporter extends DefaultReporter {
|
||||
protected _globalConfig: Config.GlobalConfig;
|
||||
static readonly filename: string;
|
||||
constructor(globalConfig: Config.GlobalConfig);
|
||||
protected __wrapStdio(
|
||||
stream: NodeJS.WritableStream | NodeJS.WriteStream,
|
||||
): void;
|
||||
static filterTestResults(
|
||||
testResults: Array<AssertionResult>,
|
||||
): Array<AssertionResult>;
|
||||
static groupTestsBySuites(testResults: Array<AssertionResult>): Suite;
|
||||
onTestResult(
|
||||
test: Test,
|
||||
result: TestResult,
|
||||
aggregatedResults: AggregatedResult,
|
||||
): void;
|
||||
private _logTestResults;
|
||||
private _logSuite;
|
||||
private _getIcon;
|
||||
private _logTest;
|
||||
private _logTests;
|
||||
private _logTodoOrPendingTest;
|
||||
private _logLine;
|
||||
}
|
||||
|
||||
export {};
|
||||
88
node_modules/@jest/reporters/build/index.js
generated
vendored
Normal file
88
node_modules/@jest/reporters/build/index.js
generated
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, 'BaseReporter', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _BaseReporter.default;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'CoverageReporter', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _CoverageReporter.default;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'DefaultReporter', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _DefaultReporter.default;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'GitHubActionsReporter', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _GitHubActionsReporter.default;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'NotifyReporter', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _NotifyReporter.default;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'SummaryReporter', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _SummaryReporter.default;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'VerboseReporter', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _VerboseReporter.default;
|
||||
}
|
||||
});
|
||||
exports.utils = void 0;
|
||||
var _formatTestPath = _interopRequireDefault(require('./formatTestPath'));
|
||||
var _getResultHeader = _interopRequireDefault(require('./getResultHeader'));
|
||||
var _getSnapshotStatus = _interopRequireDefault(require('./getSnapshotStatus'));
|
||||
var _getSnapshotSummary = _interopRequireDefault(
|
||||
require('./getSnapshotSummary')
|
||||
);
|
||||
var _getSummary = _interopRequireDefault(require('./getSummary'));
|
||||
var _printDisplayName = _interopRequireDefault(require('./printDisplayName'));
|
||||
var _relativePath = _interopRequireDefault(require('./relativePath'));
|
||||
var _trimAndFormatPath = _interopRequireDefault(require('./trimAndFormatPath'));
|
||||
var _BaseReporter = _interopRequireDefault(require('./BaseReporter'));
|
||||
var _CoverageReporter = _interopRequireDefault(require('./CoverageReporter'));
|
||||
var _DefaultReporter = _interopRequireDefault(require('./DefaultReporter'));
|
||||
var _GitHubActionsReporter = _interopRequireDefault(
|
||||
require('./GitHubActionsReporter')
|
||||
);
|
||||
var _NotifyReporter = _interopRequireDefault(require('./NotifyReporter'));
|
||||
var _SummaryReporter = _interopRequireDefault(require('./SummaryReporter'));
|
||||
var _VerboseReporter = _interopRequireDefault(require('./VerboseReporter'));
|
||||
function _interopRequireDefault(obj) {
|
||||
return obj && obj.__esModule ? obj : {default: obj};
|
||||
}
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
const utils = {
|
||||
formatTestPath: _formatTestPath.default,
|
||||
getResultHeader: _getResultHeader.default,
|
||||
getSnapshotStatus: _getSnapshotStatus.default,
|
||||
getSnapshotSummary: _getSnapshotSummary.default,
|
||||
getSummary: _getSummary.default,
|
||||
printDisplayName: _printDisplayName.default,
|
||||
relativePath: _relativePath.default,
|
||||
trimAndFormatPath: _trimAndFormatPath.default
|
||||
};
|
||||
exports.utils = utils;
|
||||
35
node_modules/@jest/reporters/build/printDisplayName.js
generated
vendored
Normal file
35
node_modules/@jest/reporters/build/printDisplayName.js
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true
|
||||
});
|
||||
exports.default = printDisplayName;
|
||||
function _chalk() {
|
||||
const data = _interopRequireDefault(require('chalk'));
|
||||
_chalk = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _interopRequireDefault(obj) {
|
||||
return obj && obj.__esModule ? obj : {default: obj};
|
||||
}
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
function printDisplayName(config) {
|
||||
const {displayName} = config;
|
||||
const white = _chalk().default.reset.inverse.white;
|
||||
if (!displayName) {
|
||||
return '';
|
||||
}
|
||||
const {name, color} = displayName;
|
||||
const chosenColor = _chalk().default.reset.inverse[color]
|
||||
? _chalk().default.reset.inverse[color]
|
||||
: white;
|
||||
return _chalk().default.supportsColor ? chosenColor(` ${name} `) : name;
|
||||
}
|
||||
72
node_modules/@jest/reporters/build/relativePath.js
generated
vendored
Normal file
72
node_modules/@jest/reporters/build/relativePath.js
generated
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true
|
||||
});
|
||||
exports.default = relativePath;
|
||||
function path() {
|
||||
const data = _interopRequireWildcard(require('path'));
|
||||
path = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
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;
|
||||
}
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
function relativePath(config, testPath) {
|
||||
// this function can be called with ProjectConfigs or GlobalConfigs. GlobalConfigs
|
||||
// do not have config.cwd, only config.rootDir. Try using config.cwd, fallback
|
||||
// to config.rootDir. (Also, some unit just use config.rootDir, which is ok)
|
||||
testPath = path().relative(config.cwd || config.rootDir, testPath);
|
||||
const dirname = path().dirname(testPath);
|
||||
const basename = path().basename(testPath);
|
||||
return {
|
||||
basename,
|
||||
dirname
|
||||
};
|
||||
}
|
||||
118
node_modules/@jest/reporters/build/trimAndFormatPath.js
generated
vendored
Normal file
118
node_modules/@jest/reporters/build/trimAndFormatPath.js
generated
vendored
Normal file
@@ -0,0 +1,118 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true
|
||||
});
|
||||
exports.default = trimAndFormatPath;
|
||||
function path() {
|
||||
const data = _interopRequireWildcard(require('path'));
|
||||
path = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _chalk() {
|
||||
const data = _interopRequireDefault(require('chalk'));
|
||||
_chalk = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _slash() {
|
||||
const data = _interopRequireDefault(require('slash'));
|
||||
_slash = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
var _relativePath = _interopRequireDefault(require('./relativePath'));
|
||||
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;
|
||||
}
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
function trimAndFormatPath(pad, config, testPath, columns) {
|
||||
const maxLength = columns - pad;
|
||||
const relative = (0, _relativePath.default)(config, testPath);
|
||||
const {basename} = relative;
|
||||
let {dirname} = relative;
|
||||
|
||||
// length is ok
|
||||
if ((dirname + path().sep + basename).length <= maxLength) {
|
||||
return (0, _slash().default)(
|
||||
_chalk().default.dim(dirname + path().sep) +
|
||||
_chalk().default.bold(basename)
|
||||
);
|
||||
}
|
||||
|
||||
// we can fit trimmed dirname and full basename
|
||||
const basenameLength = basename.length;
|
||||
if (basenameLength + 4 < maxLength) {
|
||||
const dirnameLength = maxLength - 4 - basenameLength;
|
||||
dirname = `...${dirname.slice(
|
||||
dirname.length - dirnameLength,
|
||||
dirname.length
|
||||
)}`;
|
||||
return (0, _slash().default)(
|
||||
_chalk().default.dim(dirname + path().sep) +
|
||||
_chalk().default.bold(basename)
|
||||
);
|
||||
}
|
||||
if (basenameLength + 4 === maxLength) {
|
||||
return (0, _slash().default)(
|
||||
_chalk().default.dim(`...${path().sep}`) + _chalk().default.bold(basename)
|
||||
);
|
||||
}
|
||||
|
||||
// can't fit dirname, but can fit trimmed basename
|
||||
return (0, _slash().default)(
|
||||
_chalk().default.bold(
|
||||
`...${basename.slice(basename.length - maxLength - 4, basename.length)}`
|
||||
)
|
||||
);
|
||||
}
|
||||
1
node_modules/@jest/reporters/build/types.js
generated
vendored
Normal file
1
node_modules/@jest/reporters/build/types.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
'use strict';
|
||||
69
node_modules/@jest/reporters/build/wrapAnsiString.js
generated
vendored
Normal file
69
node_modules/@jest/reporters/build/wrapAnsiString.js
generated
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true
|
||||
});
|
||||
exports.default = wrapAnsiString;
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
// word-wrap a string that contains ANSI escape sequences.
|
||||
// ANSI escape sequences do not add to the string length.
|
||||
function wrapAnsiString(string, terminalWidth) {
|
||||
if (terminalWidth === 0) {
|
||||
// if the terminal width is zero, don't bother word-wrapping
|
||||
return string;
|
||||
}
|
||||
const ANSI_REGEXP = /[\u001b\u009b]\[\d{1,2}m/gu;
|
||||
const tokens = [];
|
||||
let lastIndex = 0;
|
||||
let match;
|
||||
while ((match = ANSI_REGEXP.exec(string))) {
|
||||
const ansi = match[0];
|
||||
const index = match.index;
|
||||
if (index != lastIndex) {
|
||||
tokens.push(['string', string.slice(lastIndex, index)]);
|
||||
}
|
||||
tokens.push(['ansi', ansi]);
|
||||
lastIndex = index + ansi.length;
|
||||
}
|
||||
if (lastIndex != string.length - 1) {
|
||||
tokens.push(['string', string.slice(lastIndex, string.length)]);
|
||||
}
|
||||
let lastLineLength = 0;
|
||||
return tokens
|
||||
.reduce(
|
||||
(lines, [kind, token]) => {
|
||||
if (kind === 'string') {
|
||||
if (lastLineLength + token.length > terminalWidth) {
|
||||
while (token.length) {
|
||||
const chunk = token.slice(0, terminalWidth - lastLineLength);
|
||||
const remaining = token.slice(
|
||||
terminalWidth - lastLineLength,
|
||||
token.length
|
||||
);
|
||||
lines[lines.length - 1] += chunk;
|
||||
lastLineLength += chunk.length;
|
||||
token = remaining;
|
||||
if (token.length) {
|
||||
lines.push('');
|
||||
lastLineLength = 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
lines[lines.length - 1] += token;
|
||||
lastLineLength += token.length;
|
||||
}
|
||||
} else {
|
||||
lines[lines.length - 1] += token;
|
||||
}
|
||||
return lines;
|
||||
},
|
||||
['']
|
||||
)
|
||||
.join('\n');
|
||||
}
|
||||
21
node_modules/@jest/reporters/node_modules/jest-worker/LICENSE
generated
vendored
Normal file
21
node_modules/@jest/reporters/node_modules/jest-worker/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
272
node_modules/@jest/reporters/node_modules/jest-worker/README.md
generated
vendored
Normal file
272
node_modules/@jest/reporters/node_modules/jest-worker/README.md
generated
vendored
Normal file
@@ -0,0 +1,272 @@
|
||||
# jest-worker
|
||||
|
||||
Module for executing heavy tasks under forked processes in parallel, by providing a `Promise` based interface, minimum overhead, and bound workers.
|
||||
|
||||
The module works by providing an absolute path of the module to be loaded in all forked processes. All methods are exposed on the parent process as promises, so they can be `await`'ed. Child (worker) methods can either be synchronous or asynchronous.
|
||||
|
||||
The module also implements support for bound workers. Binding a worker means that, based on certain parameters, the same task will always be executed by the same worker. The way bound workers work is by using the returned string of the `computeWorkerKey` method. If the string was used before for a task, the call will be queued to the related worker that processed the task earlier; if not, it will be executed by the first available worker, then sticked to the worker that executed it; so the next time it will be processed by the same worker. If you have no preference on the worker executing the task, but you have defined a `computeWorkerKey` method because you want _some_ of the tasks to be sticked, you can return `null` from it.
|
||||
|
||||
The list of exposed methods can be explicitly provided via the `exposedMethods` option. If it is not provided, it will be obtained by requiring the child module into the main process, and analyzed via reflection. Check the "minimal example" section for a valid one.
|
||||
|
||||
## Install
|
||||
|
||||
```sh
|
||||
yarn add jest-worker
|
||||
```
|
||||
|
||||
## Example
|
||||
|
||||
This example covers the minimal usage:
|
||||
|
||||
### File `parent.js`
|
||||
|
||||
```js
|
||||
import {Worker as JestWorker} from 'jest-worker';
|
||||
|
||||
async function main() {
|
||||
const worker = new JestWorker(require.resolve('./worker'));
|
||||
const result = await worker.hello('Alice'); // "Hello, Alice"
|
||||
}
|
||||
|
||||
main();
|
||||
```
|
||||
|
||||
### File `worker.js`
|
||||
|
||||
```js
|
||||
export function hello(param) {
|
||||
return `Hello, ${param}`;
|
||||
}
|
||||
```
|
||||
|
||||
## Experimental worker
|
||||
|
||||
Node shipped with [`worker_threads`](https://nodejs.org/api/worker_threads.html), a "threading API" that uses `SharedArrayBuffers` to communicate between the main process and its child threads. This feature can significantly improve the communication time between parent and child processes in `jest-worker`.
|
||||
|
||||
To use `worker_threads` instead of default `child_process` you have to pass `enableWorkerThreads: true` when instantiating the worker.
|
||||
|
||||
## API
|
||||
|
||||
The `Worker` export is a constructor that is initialized by passing the worker path, plus an options object.
|
||||
|
||||
### `workerPath: string | URL` (required)
|
||||
|
||||
Node module name or absolute path or file URL of the file to be loaded in the child processes. You can use `require.resolve` to transform a relative path into an absolute one.
|
||||
|
||||
### `options: Object` (optional)
|
||||
|
||||
#### `computeWorkerKey: (method: string, ...args: Array<unknown>) => string | null` (optional)
|
||||
|
||||
Every time a method exposed via the API is called, `computeWorkerKey` is also called in order to bound the call to a worker. This is useful for workers that are able to cache the result or part of it. You bound calls to a worker by making `computeWorkerKey` return the same identifier for all different calls. If you do not want to bind the call to any worker, return `null`.
|
||||
|
||||
The callback you provide is called with the method name, plus all the rest of the arguments of the call. Thus, you have full control to decide what to return. Check a practical example on bound workers under the "bound worker usage" section.
|
||||
|
||||
By default, no process is bound to any worker.
|
||||
|
||||
#### `enableWorkerThreads: boolean` (optional)
|
||||
|
||||
By default, `jest-worker` will use `child_process` threads to spawn new Node.js processes. If you prefer [`worker_threads`](https://nodejs.org/api/worker_threads.html) instead, pass `enableWorkerThreads: true`.
|
||||
|
||||
#### `exposedMethods: ReadonlyArray<string>` (optional)
|
||||
|
||||
List of method names that can be called on the child processes from the parent process. You cannot expose any method named like a public `Worker` method, or starting with `_`. If you use method auto-discovery, then these methods will not be exposed, even if they exist.
|
||||
|
||||
#### `forkOptions: ForkOptions` (optional)
|
||||
|
||||
Allow customizing all options passed to `child_process.fork`. By default, some values are set (`cwd`, `env`, `execArgv` and `serialization`), but you can override them and customize the rest. For a list of valid values, check [the Node documentation](https://nodejs.org/api/child_process.html#child_process_child_process_fork_modulepath_args_options).
|
||||
|
||||
#### `idleMemoryLimit: number` (optional)
|
||||
|
||||
Specifies the memory limit for workers before they are recycled and is primarily a work-around for [this issue](https://github.com/jestjs/jest/issues/11956);
|
||||
|
||||
After the worker has executed a task the memory usage of it is checked. If it exceeds the value specified the worker is killed and restarted. If no limit is set this process does not occur. The limit can be specified in 2 ways:
|
||||
|
||||
- `<= 1` - The value is assumed to be a percentage of system memory. So 0.5 sets the memory limit of the worker to half of the total system memory
|
||||
- `\> 1` - Assumed to be a fixed byte value. Because of the previous rule if you wanted a value of 1 byte (I don't know why) you could use `1.1`.
|
||||
|
||||
#### `maxRetries: number` (optional)
|
||||
|
||||
Maximum amount of times that a dead child can be re-spawned, per call. Defaults to `3`, pass `Infinity` to allow endless retries.
|
||||
|
||||
#### `numWorkers: number` (optional)
|
||||
|
||||
Amount of workers to spawn. Defaults to the number of CPUs minus 1.
|
||||
|
||||
#### `resourceLimits: ResourceLimits` (optional)
|
||||
|
||||
The `resourceLimits` option which will be passed to `worker_threads` workers.
|
||||
|
||||
#### `silent: Boolean` (optional)
|
||||
|
||||
Set to false for `stdout` and `stderr` to be logged to console.
|
||||
|
||||
By default this is true.
|
||||
|
||||
#### `setupArgs: Array<unknown>` (optional)
|
||||
|
||||
The arguments that will be passed to the `setup` method during initialization.
|
||||
|
||||
#### `taskQueue: TaskQueue` (optional)
|
||||
|
||||
The task queue defines in which order tasks (method calls) are processed by the workers. `jest-worker` ships with a `FifoQueue` and `PriorityQueue`:
|
||||
|
||||
- `FifoQueue` (default): Processes the method calls (tasks) in the call order.
|
||||
- `PriorityQueue`: Processes the method calls by a computed priority in natural ordering (lower priorities first). Tasks with the same priority are processed in any order (FIFO not guaranteed). The constructor accepts a single argument, the function that is passed the name of the called function and the arguments and returns a numerical value for the priority: `new require('jest-worker').PriorityQueue((method, filename) => filename.length)`.
|
||||
|
||||
#### `WorkerPool: new (workerPath: string, options?: WorkerPoolOptions) => WorkerPoolInterface` (optional)
|
||||
|
||||
Provide a custom WorkerPool class to be used for spawning child processes.
|
||||
|
||||
#### `workerSchedulingPolicy: 'round-robin' | 'in-order'` (optional)
|
||||
|
||||
Specifies the policy how tasks are assigned to workers if multiple workers are _idle_:
|
||||
|
||||
- `round-robin` (default): The task will be sequentially distributed onto the workers. The first task is assigned to the worker 1, the second to the worker 2, to ensure that the work is distributed across workers.
|
||||
- `in-order`: The task will be assigned to the first free worker starting with worker 1 and only assign the work to worker 2 if the worker 1 is busy.
|
||||
|
||||
Tasks are always assigned to the first free worker as soon as tasks start to queue up. The scheduling policy does not define the task scheduling which is always first-in, first-out.
|
||||
|
||||
## JestWorker
|
||||
|
||||
### Methods
|
||||
|
||||
The returned `JestWorker` instance has all the exposed methods, plus some additional ones to interact with the workers itself:
|
||||
|
||||
#### `getStdout(): Readable`
|
||||
|
||||
Returns a `ReadableStream` where the standard output of all workers is piped. Note that the `silent` option of the child workers must be set to `true` to make it work. This is the default set by `jest-worker`, but keep it in mind when overriding options through `forkOptions`.
|
||||
|
||||
#### `getStderr(): Readable`
|
||||
|
||||
Returns a `ReadableStream` where the standard error of all workers is piped. Note that the `silent` option of the child workers must be set to `true` to make it work. This is the default set by `jest-worker`, but keep it in mind when overriding options through `forkOptions`.
|
||||
|
||||
#### `start()`
|
||||
|
||||
Starts up every worker and calls their `setup` function, if it exists. Returns a `Promise` which resolves when all workers are running and have completed their `setup`.
|
||||
|
||||
This is useful if you want to start up all your workers eagerly before they are used to call any other functions.
|
||||
|
||||
#### `end()`
|
||||
|
||||
Finishes the workers by killing all workers. No further calls can be done to the `Worker` instance.
|
||||
|
||||
Returns a `Promise` that resolves with `{ forceExited: boolean }` once all workers are dead. If `forceExited` is `true`, at least one of the workers did not exit gracefully, which likely happened because it executed a leaky task that left handles open. This should be avoided, force exiting workers is a last resort to prevent creating lots of orphans.
|
||||
|
||||
**Note:**
|
||||
|
||||
`await`ing the `end()` Promise immediately after the workers are no longer needed before proceeding to do other useful things in your program may not be a good idea. If workers have to be force exited, `jest-worker` may go through multiple stages of force exiting (e.g. SIGTERM, later SIGKILL) and give the worker overall around 1 second time to exit on its own. During this time, your program will wait, even though it may not be necessary that all workers are dead before continuing execution.
|
||||
|
||||
Consider deliberately leaving this Promise floating (unhandled resolution). After your program has done the rest of its work and is about to exit, the Node process will wait for the Promise to resolve after all workers are dead as the last event loop task. That way you parallelized computation time of your program and waiting time and you didn't delay the outputs of your program unnecessarily.
|
||||
|
||||
### Worker IDs
|
||||
|
||||
Each worker has a unique id (index that starts with `'1'`), which is available inside the worker as `process.env.JEST_WORKER_ID`.
|
||||
|
||||
## Setting up and tearing down the child process
|
||||
|
||||
The child process can define two special methods (both of them can be asynchronous):
|
||||
|
||||
- `setup()`: If defined, it's executed before the first call to any method in the child.
|
||||
- `teardown()`: If defined, it's executed when the farm ends.
|
||||
|
||||
# More examples
|
||||
|
||||
## Standard usage
|
||||
|
||||
This example covers the standard usage:
|
||||
|
||||
### File `parent.js`
|
||||
|
||||
```js
|
||||
import {Worker as JestWorker} from 'jest-worker';
|
||||
|
||||
async function main() {
|
||||
const myWorker = new JestWorker(require.resolve('./worker'), {
|
||||
exposedMethods: ['foo', 'bar', 'getWorkerId'],
|
||||
numWorkers: 4,
|
||||
});
|
||||
|
||||
console.log(await myWorker.foo('Alice')); // "Hello from foo: Alice"
|
||||
console.log(await myWorker.bar('Bob')); // "Hello from bar: Bob"
|
||||
console.log(await myWorker.getWorkerId()); // "3" -> this message has sent from the 3rd worker
|
||||
|
||||
const {forceExited} = await myWorker.end();
|
||||
if (forceExited) {
|
||||
console.error('Workers failed to exit gracefully');
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
```
|
||||
|
||||
### File `worker.js`
|
||||
|
||||
```js
|
||||
export function foo(param) {
|
||||
return `Hello from foo: ${param}`;
|
||||
}
|
||||
|
||||
export function bar(param) {
|
||||
return `Hello from bar: ${param}`;
|
||||
}
|
||||
|
||||
export function getWorkerId() {
|
||||
return process.env.JEST_WORKER_ID;
|
||||
}
|
||||
```
|
||||
|
||||
## Bound worker usage:
|
||||
|
||||
This example covers the usage with a `computeWorkerKey` method:
|
||||
|
||||
### File `parent.js`
|
||||
|
||||
```js
|
||||
import {Worker as JestWorker} from 'jest-worker';
|
||||
|
||||
async function main() {
|
||||
const myWorker = new JestWorker(require.resolve('./worker'), {
|
||||
computeWorkerKey: (method, filename) => filename,
|
||||
});
|
||||
|
||||
// Transform the given file, within the first available worker.
|
||||
console.log(await myWorker.transform('/tmp/foo.js'));
|
||||
|
||||
// Wait a bit.
|
||||
await sleep(10000);
|
||||
|
||||
// Transform the same file again. Will immediately return because the
|
||||
// transformed file is cached in the worker, and `computeWorkerKey` ensures
|
||||
// the same worker that processed the file the first time will process it now.
|
||||
console.log(await myWorker.transform('/tmp/foo.js'));
|
||||
|
||||
const {forceExited} = await myWorker.end();
|
||||
if (forceExited) {
|
||||
console.error('Workers failed to exit gracefully');
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
```
|
||||
|
||||
### File `worker.js`
|
||||
|
||||
```js
|
||||
import babel from '@babel/core';
|
||||
|
||||
const cache = Object.create(null);
|
||||
|
||||
export function transform(filename) {
|
||||
if (cache[filename]) {
|
||||
return cache[filename];
|
||||
}
|
||||
|
||||
// jest-worker can handle both immediate results and thenables. If a
|
||||
// thenable is returned, it will be await'ed until it resolves.
|
||||
return babel.transformFileAsync(filename).then(result => {
|
||||
cache[filename] = result;
|
||||
|
||||
return result;
|
||||
});
|
||||
}
|
||||
```
|
||||
152
node_modules/@jest/reporters/node_modules/jest-worker/build/Farm.js
generated
vendored
Normal file
152
node_modules/@jest/reporters/node_modules/jest-worker/build/Farm.js
generated
vendored
Normal file
@@ -0,0 +1,152 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
var _FifoQueue = _interopRequireDefault(require('./FifoQueue'));
|
||||
var _types = require('./types');
|
||||
function _interopRequireDefault(obj) {
|
||||
return obj && obj.__esModule ? obj : {default: obj};
|
||||
}
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
class Farm {
|
||||
_computeWorkerKey;
|
||||
_workerSchedulingPolicy;
|
||||
_cacheKeys = Object.create(null);
|
||||
_locks = [];
|
||||
_offset = 0;
|
||||
_taskQueue;
|
||||
constructor(_numOfWorkers, _callback, options = {}) {
|
||||
this._numOfWorkers = _numOfWorkers;
|
||||
this._callback = _callback;
|
||||
this._computeWorkerKey = options.computeWorkerKey;
|
||||
this._workerSchedulingPolicy =
|
||||
options.workerSchedulingPolicy ?? 'round-robin';
|
||||
this._taskQueue = options.taskQueue ?? new _FifoQueue.default();
|
||||
}
|
||||
doWork(method, ...args) {
|
||||
const customMessageListeners = new Set();
|
||||
const addCustomMessageListener = listener => {
|
||||
customMessageListeners.add(listener);
|
||||
return () => {
|
||||
customMessageListeners.delete(listener);
|
||||
};
|
||||
};
|
||||
const onCustomMessage = message => {
|
||||
customMessageListeners.forEach(listener => listener(message));
|
||||
};
|
||||
const promise = new Promise(
|
||||
// Bind args to this function so it won't reference to the parent scope.
|
||||
// This prevents a memory leak in v8, because otherwise the function will
|
||||
// retain args for the closure.
|
||||
((args, resolve, reject) => {
|
||||
const computeWorkerKey = this._computeWorkerKey;
|
||||
const request = [_types.CHILD_MESSAGE_CALL, false, method, args];
|
||||
let worker = null;
|
||||
let hash = null;
|
||||
if (computeWorkerKey) {
|
||||
hash = computeWorkerKey.call(this, method, ...args);
|
||||
worker = hash == null ? null : this._cacheKeys[hash];
|
||||
}
|
||||
const onStart = worker => {
|
||||
if (hash != null) {
|
||||
this._cacheKeys[hash] = worker;
|
||||
}
|
||||
};
|
||||
const onEnd = (error, result) => {
|
||||
customMessageListeners.clear();
|
||||
if (error) {
|
||||
reject(error);
|
||||
} else {
|
||||
resolve(result);
|
||||
}
|
||||
};
|
||||
const task = {
|
||||
onCustomMessage,
|
||||
onEnd,
|
||||
onStart,
|
||||
request
|
||||
};
|
||||
if (worker) {
|
||||
this._taskQueue.enqueue(task, worker.getWorkerId());
|
||||
this._process(worker.getWorkerId());
|
||||
} else {
|
||||
this._push(task);
|
||||
}
|
||||
}).bind(null, args)
|
||||
);
|
||||
promise.UNSTABLE_onCustomMessage = addCustomMessageListener;
|
||||
return promise;
|
||||
}
|
||||
_process(workerId) {
|
||||
if (this._isLocked(workerId)) {
|
||||
return this;
|
||||
}
|
||||
const task = this._taskQueue.dequeue(workerId);
|
||||
if (!task) {
|
||||
return this;
|
||||
}
|
||||
if (task.request[1]) {
|
||||
throw new Error('Queue implementation returned processed task');
|
||||
}
|
||||
|
||||
// Reference the task object outside so it won't be retained by onEnd,
|
||||
// and other properties of the task object, such as task.request can be
|
||||
// garbage collected.
|
||||
let taskOnEnd = task.onEnd;
|
||||
const onEnd = (error, result) => {
|
||||
if (taskOnEnd) {
|
||||
taskOnEnd(error, result);
|
||||
}
|
||||
taskOnEnd = null;
|
||||
this._unlock(workerId);
|
||||
this._process(workerId);
|
||||
};
|
||||
task.request[1] = true;
|
||||
this._lock(workerId);
|
||||
this._callback(
|
||||
workerId,
|
||||
task.request,
|
||||
task.onStart,
|
||||
onEnd,
|
||||
task.onCustomMessage
|
||||
);
|
||||
return this;
|
||||
}
|
||||
_push(task) {
|
||||
this._taskQueue.enqueue(task);
|
||||
const offset = this._getNextWorkerOffset();
|
||||
for (let i = 0; i < this._numOfWorkers; i++) {
|
||||
this._process((offset + i) % this._numOfWorkers);
|
||||
if (task.request[1]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
_getNextWorkerOffset() {
|
||||
switch (this._workerSchedulingPolicy) {
|
||||
case 'in-order':
|
||||
return 0;
|
||||
case 'round-robin':
|
||||
return this._offset++;
|
||||
}
|
||||
}
|
||||
_lock(workerId) {
|
||||
this._locks[workerId] = true;
|
||||
}
|
||||
_unlock(workerId) {
|
||||
this._locks[workerId] = false;
|
||||
}
|
||||
_isLocked(workerId) {
|
||||
return this._locks[workerId];
|
||||
}
|
||||
}
|
||||
exports.default = Farm;
|
||||
89
node_modules/@jest/reporters/node_modules/jest-worker/build/FifoQueue.js
generated
vendored
Normal file
89
node_modules/@jest/reporters/node_modules/jest-worker/build/FifoQueue.js
generated
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/**
|
||||
* First-in, First-out task queue that manages a dedicated pool
|
||||
* for each worker as well as a shared queue. The FIFO ordering is guaranteed
|
||||
* across the worker specific and shared queue.
|
||||
*/
|
||||
class FifoQueue {
|
||||
_workerQueues = [];
|
||||
_sharedQueue = new InternalQueue();
|
||||
enqueue(task, workerId) {
|
||||
if (workerId == null) {
|
||||
this._sharedQueue.enqueue(task);
|
||||
return;
|
||||
}
|
||||
let workerQueue = this._workerQueues[workerId];
|
||||
if (workerQueue == null) {
|
||||
workerQueue = this._workerQueues[workerId] = new InternalQueue();
|
||||
}
|
||||
const sharedTop = this._sharedQueue.peekLast();
|
||||
const item = {
|
||||
previousSharedTask: sharedTop,
|
||||
task
|
||||
};
|
||||
workerQueue.enqueue(item);
|
||||
}
|
||||
dequeue(workerId) {
|
||||
const workerTop = this._workerQueues[workerId]?.peek();
|
||||
const sharedTaskIsProcessed =
|
||||
workerTop?.previousSharedTask?.request[1] ?? true;
|
||||
|
||||
// Process the top task from the shared queue if
|
||||
// - there's no task in the worker specific queue or
|
||||
// - if the non-worker-specific task after which this worker specific task
|
||||
// has been queued wasn't processed yet
|
||||
if (workerTop != null && sharedTaskIsProcessed) {
|
||||
return this._workerQueues[workerId]?.dequeue()?.task ?? null;
|
||||
}
|
||||
return this._sharedQueue.dequeue();
|
||||
}
|
||||
}
|
||||
exports.default = FifoQueue;
|
||||
/**
|
||||
* FIFO queue for a single worker / shared queue.
|
||||
*/
|
||||
class InternalQueue {
|
||||
_head = null;
|
||||
_last = null;
|
||||
enqueue(value) {
|
||||
const item = {
|
||||
next: null,
|
||||
value
|
||||
};
|
||||
if (this._last == null) {
|
||||
this._head = item;
|
||||
} else {
|
||||
this._last.next = item;
|
||||
}
|
||||
this._last = item;
|
||||
}
|
||||
dequeue() {
|
||||
if (this._head == null) {
|
||||
return null;
|
||||
}
|
||||
const item = this._head;
|
||||
this._head = item.next;
|
||||
if (this._head == null) {
|
||||
this._last = null;
|
||||
}
|
||||
return item.value;
|
||||
}
|
||||
peek() {
|
||||
return this._head?.value ?? null;
|
||||
}
|
||||
peekLast() {
|
||||
return this._last?.value ?? null;
|
||||
}
|
||||
}
|
||||
137
node_modules/@jest/reporters/node_modules/jest-worker/build/PriorityQueue.js
generated
vendored
Normal file
137
node_modules/@jest/reporters/node_modules/jest-worker/build/PriorityQueue.js
generated
vendored
Normal file
@@ -0,0 +1,137 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Priority queue that processes tasks in natural ordering (lower priority first)
|
||||
* according to the priority computed by the function passed in the constructor.
|
||||
*
|
||||
* FIFO ordering isn't guaranteed for tasks with the same priority.
|
||||
*
|
||||
* Worker specific tasks with the same priority as a non-worker specific task
|
||||
* are always processed first.
|
||||
*/
|
||||
class PriorityQueue {
|
||||
_queue = [];
|
||||
_sharedQueue = new MinHeap();
|
||||
constructor(_computePriority) {
|
||||
this._computePriority = _computePriority;
|
||||
}
|
||||
enqueue(task, workerId) {
|
||||
if (workerId == null) {
|
||||
this._enqueue(task, this._sharedQueue);
|
||||
} else {
|
||||
const queue = this._getWorkerQueue(workerId);
|
||||
this._enqueue(task, queue);
|
||||
}
|
||||
}
|
||||
_enqueue(task, queue) {
|
||||
const item = {
|
||||
priority: this._computePriority(task.request[2], ...task.request[3]),
|
||||
task
|
||||
};
|
||||
queue.add(item);
|
||||
}
|
||||
dequeue(workerId) {
|
||||
const workerQueue = this._getWorkerQueue(workerId);
|
||||
const workerTop = workerQueue.peek();
|
||||
const sharedTop = this._sharedQueue.peek();
|
||||
|
||||
// use the task from the worker queue if there's no task in the shared queue
|
||||
// or if the priority of the worker queue is smaller or equal to the
|
||||
// priority of the top task in the shared queue. The tasks of the
|
||||
// worker specific queue are preferred because no other worker can pick this
|
||||
// specific task up.
|
||||
if (
|
||||
sharedTop == null ||
|
||||
(workerTop != null && workerTop.priority <= sharedTop.priority)
|
||||
) {
|
||||
return workerQueue.poll()?.task ?? null;
|
||||
}
|
||||
return this._sharedQueue.poll().task;
|
||||
}
|
||||
_getWorkerQueue(workerId) {
|
||||
let queue = this._queue[workerId];
|
||||
if (queue == null) {
|
||||
queue = this._queue[workerId] = new MinHeap();
|
||||
}
|
||||
return queue;
|
||||
}
|
||||
}
|
||||
exports.default = PriorityQueue;
|
||||
class MinHeap {
|
||||
_heap = [];
|
||||
peek() {
|
||||
return this._heap[0] ?? null;
|
||||
}
|
||||
add(item) {
|
||||
const nodes = this._heap;
|
||||
nodes.push(item);
|
||||
if (nodes.length === 1) {
|
||||
return;
|
||||
}
|
||||
let currentIndex = nodes.length - 1;
|
||||
|
||||
// Bubble up the added node as long as the parent is bigger
|
||||
while (currentIndex > 0) {
|
||||
const parentIndex = Math.floor((currentIndex + 1) / 2) - 1;
|
||||
const parent = nodes[parentIndex];
|
||||
if (parent.priority <= item.priority) {
|
||||
break;
|
||||
}
|
||||
nodes[currentIndex] = parent;
|
||||
nodes[parentIndex] = item;
|
||||
currentIndex = parentIndex;
|
||||
}
|
||||
}
|
||||
poll() {
|
||||
const nodes = this._heap;
|
||||
const result = nodes[0];
|
||||
const lastElement = nodes.pop();
|
||||
|
||||
// heap was empty or removed the last element
|
||||
if (result == null || nodes.length === 0) {
|
||||
return result ?? null;
|
||||
}
|
||||
let index = 0;
|
||||
nodes[0] = lastElement ?? null;
|
||||
const element = nodes[0];
|
||||
while (true) {
|
||||
let swapIndex = null;
|
||||
const rightChildIndex = (index + 1) * 2;
|
||||
const leftChildIndex = rightChildIndex - 1;
|
||||
const rightChild = nodes[rightChildIndex];
|
||||
const leftChild = nodes[leftChildIndex];
|
||||
|
||||
// if the left child is smaller, swap with the left
|
||||
if (leftChild != null && leftChild.priority < element.priority) {
|
||||
swapIndex = leftChildIndex;
|
||||
}
|
||||
|
||||
// If the right child is smaller or the right child is smaller than the left
|
||||
// then swap with the right child
|
||||
if (
|
||||
rightChild != null &&
|
||||
rightChild.priority < (swapIndex == null ? element : leftChild).priority
|
||||
) {
|
||||
swapIndex = rightChildIndex;
|
||||
}
|
||||
if (swapIndex == null) {
|
||||
break;
|
||||
}
|
||||
nodes[index] = nodes[swapIndex];
|
||||
nodes[swapIndex] = element;
|
||||
index = swapIndex;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
34
node_modules/@jest/reporters/node_modules/jest-worker/build/WorkerPool.js
generated
vendored
Normal file
34
node_modules/@jest/reporters/node_modules/jest-worker/build/WorkerPool.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
var _BaseWorkerPool = _interopRequireDefault(require('./base/BaseWorkerPool'));
|
||||
function _interopRequireDefault(obj) {
|
||||
return obj && obj.__esModule ? obj : {default: obj};
|
||||
}
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
class WorkerPool extends _BaseWorkerPool.default {
|
||||
send(workerId, request, onStart, onEnd, onCustomMessage) {
|
||||
this.restartWorkerIfShutDown(workerId);
|
||||
this.getWorkerById(workerId).send(request, onStart, onEnd, onCustomMessage);
|
||||
}
|
||||
createWorker(workerOptions) {
|
||||
let Worker;
|
||||
if (this._options.enableWorkerThreads) {
|
||||
Worker = require('./workers/NodeThreadsWorker').default;
|
||||
} else {
|
||||
Worker = require('./workers/ChildProcessWorker').default;
|
||||
}
|
||||
return new Worker(workerOptions);
|
||||
}
|
||||
}
|
||||
var _default = WorkerPool;
|
||||
exports.default = _default;
|
||||
156
node_modules/@jest/reporters/node_modules/jest-worker/build/base/BaseWorkerPool.js
generated
vendored
Normal file
156
node_modules/@jest/reporters/node_modules/jest-worker/build/base/BaseWorkerPool.js
generated
vendored
Normal file
@@ -0,0 +1,156 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
function _mergeStream() {
|
||||
const data = _interopRequireDefault(require('merge-stream'));
|
||||
_mergeStream = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
var _types = require('../types');
|
||||
function _interopRequireDefault(obj) {
|
||||
return obj && obj.__esModule ? obj : {default: obj};
|
||||
}
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
// How long to wait for the child process to terminate
|
||||
// after CHILD_MESSAGE_END before sending force exiting.
|
||||
const FORCE_EXIT_DELAY = 500;
|
||||
|
||||
/* istanbul ignore next */
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
const emptyMethod = () => {};
|
||||
class BaseWorkerPool {
|
||||
_stderr;
|
||||
_stdout;
|
||||
_options;
|
||||
_workers;
|
||||
_workerPath;
|
||||
constructor(workerPath, options) {
|
||||
this._options = options;
|
||||
this._workerPath = workerPath;
|
||||
this._workers = new Array(options.numWorkers);
|
||||
const stdout = (0, _mergeStream().default)();
|
||||
const stderr = (0, _mergeStream().default)();
|
||||
const {forkOptions, maxRetries, resourceLimits, setupArgs} = options;
|
||||
for (let i = 0; i < options.numWorkers; i++) {
|
||||
const workerOptions = {
|
||||
forkOptions,
|
||||
idleMemoryLimit: this._options.idleMemoryLimit,
|
||||
maxRetries,
|
||||
resourceLimits,
|
||||
setupArgs,
|
||||
workerId: i,
|
||||
workerPath
|
||||
};
|
||||
const worker = this.createWorker(workerOptions);
|
||||
const workerStdout = worker.getStdout();
|
||||
const workerStderr = worker.getStderr();
|
||||
if (workerStdout) {
|
||||
stdout.add(workerStdout);
|
||||
}
|
||||
if (workerStderr) {
|
||||
stderr.add(workerStderr);
|
||||
}
|
||||
this._workers[i] = worker;
|
||||
}
|
||||
this._stdout = stdout;
|
||||
this._stderr = stderr;
|
||||
}
|
||||
getStderr() {
|
||||
return this._stderr;
|
||||
}
|
||||
getStdout() {
|
||||
return this._stdout;
|
||||
}
|
||||
getWorkers() {
|
||||
return this._workers;
|
||||
}
|
||||
getWorkerById(workerId) {
|
||||
return this._workers[workerId];
|
||||
}
|
||||
restartWorkerIfShutDown(workerId) {
|
||||
if (this._workers[workerId].state === _types.WorkerStates.SHUT_DOWN) {
|
||||
const {forkOptions, maxRetries, resourceLimits, setupArgs} =
|
||||
this._options;
|
||||
const workerOptions = {
|
||||
forkOptions,
|
||||
idleMemoryLimit: this._options.idleMemoryLimit,
|
||||
maxRetries,
|
||||
resourceLimits,
|
||||
setupArgs,
|
||||
workerId,
|
||||
workerPath: this._workerPath
|
||||
};
|
||||
const worker = this.createWorker(workerOptions);
|
||||
this._workers[workerId] = worker;
|
||||
}
|
||||
}
|
||||
createWorker(_workerOptions) {
|
||||
throw Error('Missing method createWorker in WorkerPool');
|
||||
}
|
||||
async start() {
|
||||
await Promise.all(
|
||||
this._workers.map(async worker => {
|
||||
await worker.waitForWorkerReady();
|
||||
await new Promise((resolve, reject) => {
|
||||
worker.send(
|
||||
[_types.CHILD_MESSAGE_CALL_SETUP],
|
||||
emptyMethod,
|
||||
error => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
},
|
||||
emptyMethod
|
||||
);
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
async end() {
|
||||
// We do not cache the request object here. If so, it would only be only
|
||||
// processed by one of the workers, and we want them all to close.
|
||||
const workerExitPromises = this._workers.map(async worker => {
|
||||
worker.send(
|
||||
[_types.CHILD_MESSAGE_END, false],
|
||||
emptyMethod,
|
||||
emptyMethod,
|
||||
emptyMethod
|
||||
);
|
||||
|
||||
// Schedule a force exit in case worker fails to exit gracefully so
|
||||
// await worker.waitForExit() never takes longer than FORCE_EXIT_DELAY
|
||||
let forceExited = false;
|
||||
const forceExitTimeout = setTimeout(() => {
|
||||
worker.forceExit();
|
||||
forceExited = true;
|
||||
}, FORCE_EXIT_DELAY);
|
||||
await worker.waitForExit();
|
||||
// Worker ideally exited gracefully, don't send force exit then
|
||||
clearTimeout(forceExitTimeout);
|
||||
return forceExited;
|
||||
});
|
||||
const workerExits = await Promise.all(workerExitPromises);
|
||||
return workerExits.reduce(
|
||||
(result, forceExited) => ({
|
||||
forceExited: result.forceExited || forceExited
|
||||
}),
|
||||
{
|
||||
forceExited: false
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
exports.default = BaseWorkerPool;
|
||||
355
node_modules/@jest/reporters/node_modules/jest-worker/build/index.d.ts
generated
vendored
Normal file
355
node_modules/@jest/reporters/node_modules/jest-worker/build/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,355 @@
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
/// <reference types="node" />
|
||||
|
||||
import type {ForkOptions} from 'child_process';
|
||||
import type {ResourceLimits} from 'worker_threads';
|
||||
|
||||
declare const CHILD_MESSAGE_CALL = 1;
|
||||
|
||||
declare const CHILD_MESSAGE_CALL_SETUP = 4;
|
||||
|
||||
declare const CHILD_MESSAGE_END = 2;
|
||||
|
||||
declare const CHILD_MESSAGE_INITIALIZE = 0;
|
||||
|
||||
declare const CHILD_MESSAGE_MEM_USAGE = 3;
|
||||
|
||||
declare type ChildMessage =
|
||||
| ChildMessageInitialize
|
||||
| ChildMessageCall
|
||||
| ChildMessageEnd
|
||||
| ChildMessageMemUsage
|
||||
| ChildMessageCallSetup;
|
||||
|
||||
declare type ChildMessageCall = [
|
||||
type: typeof CHILD_MESSAGE_CALL,
|
||||
isProcessed: boolean,
|
||||
methodName: string,
|
||||
args: Array<unknown>,
|
||||
];
|
||||
|
||||
declare type ChildMessageCallSetup = [type: typeof CHILD_MESSAGE_CALL_SETUP];
|
||||
|
||||
declare type ChildMessageEnd = [
|
||||
type: typeof CHILD_MESSAGE_END,
|
||||
isProcessed: boolean,
|
||||
];
|
||||
|
||||
declare type ChildMessageInitialize = [
|
||||
type: typeof CHILD_MESSAGE_INITIALIZE,
|
||||
isProcessed: boolean,
|
||||
fileName: string,
|
||||
setupArgs: Array<unknown>,
|
||||
workerId: string | undefined,
|
||||
];
|
||||
|
||||
declare type ChildMessageMemUsage = [type: typeof CHILD_MESSAGE_MEM_USAGE];
|
||||
|
||||
declare type ComputeTaskPriorityCallback = (
|
||||
method: string,
|
||||
...args: Array<unknown>
|
||||
) => number;
|
||||
|
||||
declare type ExcludeReservedKeys<K> = Exclude<K, ReservedKeys>;
|
||||
|
||||
/**
|
||||
* First-in, First-out task queue that manages a dedicated pool
|
||||
* for each worker as well as a shared queue. The FIFO ordering is guaranteed
|
||||
* across the worker specific and shared queue.
|
||||
*/
|
||||
export declare class FifoQueue implements TaskQueue {
|
||||
private _workerQueues;
|
||||
private readonly _sharedQueue;
|
||||
enqueue(task: QueueChildMessage, workerId?: number): void;
|
||||
dequeue(workerId: number): QueueChildMessage | null;
|
||||
}
|
||||
|
||||
declare type FunctionLike = (...args: any) => unknown;
|
||||
|
||||
declare type HeapItem = {
|
||||
priority: number;
|
||||
};
|
||||
|
||||
export declare type JestWorkerFarm<T extends Record<string, unknown>> =
|
||||
Worker_2 & WorkerModule<T>;
|
||||
|
||||
export declare function messageParent(
|
||||
message: unknown,
|
||||
parentProcess?: NodeJS.Process,
|
||||
): void;
|
||||
|
||||
declare type MethodLikeKeys<T> = {
|
||||
[K in keyof T]: T[K] extends FunctionLike ? K : never;
|
||||
}[keyof T];
|
||||
|
||||
declare class MinHeap<TItem extends HeapItem> {
|
||||
private readonly _heap;
|
||||
peek(): TItem | null;
|
||||
add(item: TItem): void;
|
||||
poll(): TItem | null;
|
||||
}
|
||||
|
||||
declare type OnCustomMessage = (message: Array<unknown> | unknown) => void;
|
||||
|
||||
declare type OnEnd = (err: Error | null, result: unknown) => void;
|
||||
|
||||
declare type OnStart = (worker: WorkerInterface) => void;
|
||||
|
||||
declare type OnStateChangeHandler = (
|
||||
state: WorkerStates,
|
||||
oldState: WorkerStates,
|
||||
) => void;
|
||||
|
||||
declare type PoolExitResult = {
|
||||
forceExited: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
* Priority queue that processes tasks in natural ordering (lower priority first)
|
||||
* according to the priority computed by the function passed in the constructor.
|
||||
*
|
||||
* FIFO ordering isn't guaranteed for tasks with the same priority.
|
||||
*
|
||||
* Worker specific tasks with the same priority as a non-worker specific task
|
||||
* are always processed first.
|
||||
*/
|
||||
export declare class PriorityQueue implements TaskQueue {
|
||||
private readonly _computePriority;
|
||||
private _queue;
|
||||
private readonly _sharedQueue;
|
||||
constructor(_computePriority: ComputeTaskPriorityCallback);
|
||||
enqueue(task: QueueChildMessage, workerId?: number): void;
|
||||
_enqueue(task: QueueChildMessage, queue: MinHeap<QueueItem>): void;
|
||||
dequeue(workerId: number): QueueChildMessage | null;
|
||||
_getWorkerQueue(workerId: number): MinHeap<QueueItem>;
|
||||
}
|
||||
|
||||
export declare interface PromiseWithCustomMessage<T> extends Promise<T> {
|
||||
UNSTABLE_onCustomMessage?: (listener: OnCustomMessage) => () => void;
|
||||
}
|
||||
|
||||
declare type Promisify<T extends FunctionLike> = ReturnType<T> extends Promise<
|
||||
infer R
|
||||
>
|
||||
? (...args: Parameters<T>) => Promise<R>
|
||||
: (...args: Parameters<T>) => Promise<ReturnType<T>>;
|
||||
|
||||
declare type QueueChildMessage = {
|
||||
request: ChildMessageCall;
|
||||
onStart: OnStart;
|
||||
onEnd: OnEnd;
|
||||
onCustomMessage: OnCustomMessage;
|
||||
};
|
||||
|
||||
declare type QueueItem = {
|
||||
task: QueueChildMessage;
|
||||
priority: number;
|
||||
};
|
||||
|
||||
declare type ReservedKeys =
|
||||
| 'end'
|
||||
| 'getStderr'
|
||||
| 'getStdout'
|
||||
| 'setup'
|
||||
| 'teardown';
|
||||
|
||||
export declare interface TaskQueue {
|
||||
/**
|
||||
* Enqueues the task in the queue for the specified worker or adds it to the
|
||||
* queue shared by all workers
|
||||
* @param task the task to queue
|
||||
* @param workerId the id of the worker that should process this task or undefined
|
||||
* if there's no preference.
|
||||
*/
|
||||
enqueue(task: QueueChildMessage, workerId?: number): void;
|
||||
/**
|
||||
* Dequeues the next item from the queue for the specified worker
|
||||
* @param workerId the id of the worker for which the next task should be retrieved
|
||||
*/
|
||||
dequeue(workerId: number): QueueChildMessage | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Jest farm (publicly called "Worker") is a class that allows you to queue
|
||||
* methods across multiple child processes, in order to parallelize work. This
|
||||
* is done by providing an absolute path to a module that will be loaded on each
|
||||
* of the child processes, and bridged to the main process.
|
||||
*
|
||||
* Bridged methods are specified by using the "exposedMethods" property of the
|
||||
* "options" object. This is an array of strings, where each of them corresponds
|
||||
* to the exported name in the loaded module.
|
||||
*
|
||||
* You can also control the amount of workers by using the "numWorkers" property
|
||||
* of the "options" object, and the settings passed to fork the process through
|
||||
* the "forkOptions" property. The amount of workers defaults to the amount of
|
||||
* CPUS minus one.
|
||||
*
|
||||
* Queueing calls can be done in two ways:
|
||||
* - Standard method: calls will be redirected to the first available worker,
|
||||
* so they will get executed as soon as they can.
|
||||
*
|
||||
* - Sticky method: if a "computeWorkerKey" method is provided within the
|
||||
* config, the resulting string of this method will be used as a key.
|
||||
* Every time this key is returned, it is guaranteed that your job will be
|
||||
* processed by the same worker. This is specially useful if your workers
|
||||
* are caching results.
|
||||
*/
|
||||
declare class Worker_2 {
|
||||
private _ending;
|
||||
private readonly _farm;
|
||||
private readonly _options;
|
||||
private readonly _workerPool;
|
||||
constructor(workerPath: string | URL, options?: WorkerFarmOptions);
|
||||
private _bindExposedWorkerMethods;
|
||||
private _callFunctionWithArgs;
|
||||
getStderr(): NodeJS.ReadableStream;
|
||||
getStdout(): NodeJS.ReadableStream;
|
||||
start(): Promise<void>;
|
||||
end(): Promise<PoolExitResult>;
|
||||
}
|
||||
export {Worker_2 as Worker};
|
||||
|
||||
declare type WorkerCallback = (
|
||||
workerId: number,
|
||||
request: ChildMessage,
|
||||
onStart: OnStart,
|
||||
onEnd: OnEnd,
|
||||
onCustomMessage: OnCustomMessage,
|
||||
) => void;
|
||||
|
||||
declare enum WorkerEvents {
|
||||
STATE_CHANGE = 'state-change',
|
||||
}
|
||||
|
||||
export declare type WorkerFarmOptions = {
|
||||
computeWorkerKey?: (method: string, ...args: Array<unknown>) => string | null;
|
||||
enableWorkerThreads?: boolean;
|
||||
exposedMethods?: ReadonlyArray<string>;
|
||||
forkOptions?: ForkOptions;
|
||||
maxRetries?: number;
|
||||
numWorkers?: number;
|
||||
resourceLimits?: ResourceLimits;
|
||||
setupArgs?: Array<unknown>;
|
||||
taskQueue?: TaskQueue;
|
||||
WorkerPool?: new (
|
||||
workerPath: string,
|
||||
options?: WorkerPoolOptions,
|
||||
) => WorkerPoolInterface;
|
||||
workerSchedulingPolicy?: WorkerSchedulingPolicy;
|
||||
idleMemoryLimit?: number;
|
||||
};
|
||||
|
||||
declare interface WorkerInterface {
|
||||
get state(): WorkerStates;
|
||||
send(
|
||||
request: ChildMessage,
|
||||
onProcessStart: OnStart,
|
||||
onProcessEnd: OnEnd,
|
||||
onCustomMessage: OnCustomMessage,
|
||||
): void;
|
||||
waitForExit(): Promise<void>;
|
||||
forceExit(): void;
|
||||
getWorkerId(): number;
|
||||
getStderr(): NodeJS.ReadableStream | null;
|
||||
getStdout(): NodeJS.ReadableStream | null;
|
||||
/**
|
||||
* Some system level identifier for the worker. IE, process id, thread id, etc.
|
||||
*/
|
||||
getWorkerSystemId(): number;
|
||||
getMemoryUsage(): Promise<number | null>;
|
||||
/**
|
||||
* Checks to see if the child worker is actually running.
|
||||
*/
|
||||
isWorkerRunning(): boolean;
|
||||
/**
|
||||
* When the worker child is started and ready to start handling requests.
|
||||
*
|
||||
* @remarks
|
||||
* This mostly exists to help with testing so that you don't check the status
|
||||
* of things like isWorkerRunning before it actually is.
|
||||
*/
|
||||
waitForWorkerReady(): Promise<void>;
|
||||
}
|
||||
|
||||
declare type WorkerModule<T> = {
|
||||
[K in keyof T as Extract<
|
||||
ExcludeReservedKeys<K>,
|
||||
MethodLikeKeys<T>
|
||||
>]: T[K] extends FunctionLike ? Promisify<T[K]> : never;
|
||||
};
|
||||
|
||||
declare type WorkerOptions_2 = {
|
||||
forkOptions: ForkOptions;
|
||||
resourceLimits: ResourceLimits;
|
||||
setupArgs: Array<unknown>;
|
||||
maxRetries: number;
|
||||
workerId: number;
|
||||
workerData?: unknown;
|
||||
workerPath: string;
|
||||
/**
|
||||
* After a job has executed the memory usage it should return to.
|
||||
*
|
||||
* @remarks
|
||||
* Note this is different from ResourceLimits in that it checks at idle, after
|
||||
* a job is complete. So you could have a resource limit of 500MB but an idle
|
||||
* limit of 50MB. The latter will only trigger if after a job has completed the
|
||||
* memory usage hasn't returned back down under 50MB.
|
||||
*/
|
||||
idleMemoryLimit?: number;
|
||||
/**
|
||||
* This mainly exists so the path can be changed during testing.
|
||||
* https://github.com/jestjs/jest/issues/9543
|
||||
*/
|
||||
childWorkerPath?: string;
|
||||
/**
|
||||
* This is useful for debugging individual tests allowing you to see
|
||||
* the raw output of the worker.
|
||||
*/
|
||||
silent?: boolean;
|
||||
/**
|
||||
* Used to immediately bind event handlers.
|
||||
*/
|
||||
on?: {
|
||||
[WorkerEvents.STATE_CHANGE]:
|
||||
| OnStateChangeHandler
|
||||
| ReadonlyArray<OnStateChangeHandler>;
|
||||
};
|
||||
};
|
||||
|
||||
export declare interface WorkerPoolInterface {
|
||||
getStderr(): NodeJS.ReadableStream;
|
||||
getStdout(): NodeJS.ReadableStream;
|
||||
getWorkers(): Array<WorkerInterface>;
|
||||
createWorker(options: WorkerOptions_2): WorkerInterface;
|
||||
send: WorkerCallback;
|
||||
start(): Promise<void>;
|
||||
end(): Promise<PoolExitResult>;
|
||||
}
|
||||
|
||||
export declare type WorkerPoolOptions = {
|
||||
setupArgs: Array<unknown>;
|
||||
forkOptions: ForkOptions;
|
||||
resourceLimits: ResourceLimits;
|
||||
maxRetries: number;
|
||||
numWorkers: number;
|
||||
enableWorkerThreads: boolean;
|
||||
idleMemoryLimit?: number;
|
||||
};
|
||||
|
||||
declare type WorkerSchedulingPolicy = 'round-robin' | 'in-order';
|
||||
|
||||
declare enum WorkerStates {
|
||||
STARTING = 'starting',
|
||||
OK = 'ok',
|
||||
OUT_OF_MEMORY = 'oom',
|
||||
RESTARTING = 'restarting',
|
||||
SHUTTING_DOWN = 'shutting-down',
|
||||
SHUT_DOWN = 'shut-down',
|
||||
}
|
||||
|
||||
export {};
|
||||
192
node_modules/@jest/reporters/node_modules/jest-worker/build/index.js
generated
vendored
Normal file
192
node_modules/@jest/reporters/node_modules/jest-worker/build/index.js
generated
vendored
Normal file
@@ -0,0 +1,192 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, 'FifoQueue', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _FifoQueue.default;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'PriorityQueue', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _PriorityQueue.default;
|
||||
}
|
||||
});
|
||||
exports.Worker = void 0;
|
||||
Object.defineProperty(exports, 'messageParent', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _messageParent.default;
|
||||
}
|
||||
});
|
||||
function _os() {
|
||||
const data = require('os');
|
||||
_os = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _path() {
|
||||
const data = require('path');
|
||||
_path = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _url() {
|
||||
const data = require('url');
|
||||
_url = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
var _Farm = _interopRequireDefault(require('./Farm'));
|
||||
var _WorkerPool = _interopRequireDefault(require('./WorkerPool'));
|
||||
var _PriorityQueue = _interopRequireDefault(require('./PriorityQueue'));
|
||||
var _FifoQueue = _interopRequireDefault(require('./FifoQueue'));
|
||||
var _messageParent = _interopRequireDefault(require('./workers/messageParent'));
|
||||
function _interopRequireDefault(obj) {
|
||||
return obj && obj.__esModule ? obj : {default: obj};
|
||||
}
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
function getExposedMethods(workerPath, options) {
|
||||
let exposedMethods = options.exposedMethods;
|
||||
|
||||
// If no methods list is given, try getting it by auto-requiring the module.
|
||||
if (!exposedMethods) {
|
||||
const module = require(workerPath);
|
||||
exposedMethods = Object.keys(module).filter(
|
||||
name => typeof module[name] === 'function'
|
||||
);
|
||||
if (typeof module === 'function') {
|
||||
exposedMethods = [...exposedMethods, 'default'];
|
||||
}
|
||||
}
|
||||
return exposedMethods;
|
||||
}
|
||||
function getNumberOfCpus() {
|
||||
return typeof _os().availableParallelism === 'function'
|
||||
? (0, _os().availableParallelism)()
|
||||
: (0, _os().cpus)().length;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Jest farm (publicly called "Worker") is a class that allows you to queue
|
||||
* methods across multiple child processes, in order to parallelize work. This
|
||||
* is done by providing an absolute path to a module that will be loaded on each
|
||||
* of the child processes, and bridged to the main process.
|
||||
*
|
||||
* Bridged methods are specified by using the "exposedMethods" property of the
|
||||
* "options" object. This is an array of strings, where each of them corresponds
|
||||
* to the exported name in the loaded module.
|
||||
*
|
||||
* You can also control the amount of workers by using the "numWorkers" property
|
||||
* of the "options" object, and the settings passed to fork the process through
|
||||
* the "forkOptions" property. The amount of workers defaults to the amount of
|
||||
* CPUS minus one.
|
||||
*
|
||||
* Queueing calls can be done in two ways:
|
||||
* - Standard method: calls will be redirected to the first available worker,
|
||||
* so they will get executed as soon as they can.
|
||||
*
|
||||
* - Sticky method: if a "computeWorkerKey" method is provided within the
|
||||
* config, the resulting string of this method will be used as a key.
|
||||
* Every time this key is returned, it is guaranteed that your job will be
|
||||
* processed by the same worker. This is specially useful if your workers
|
||||
* are caching results.
|
||||
*/
|
||||
class Worker {
|
||||
_ending;
|
||||
_farm;
|
||||
_options;
|
||||
_workerPool;
|
||||
constructor(workerPath, options) {
|
||||
this._options = {
|
||||
...options
|
||||
};
|
||||
this._ending = false;
|
||||
if (typeof workerPath !== 'string') {
|
||||
workerPath = workerPath.href;
|
||||
}
|
||||
if (workerPath.startsWith('file:')) {
|
||||
workerPath = (0, _url().fileURLToPath)(workerPath);
|
||||
} else if (!(0, _path().isAbsolute)(workerPath)) {
|
||||
throw new Error(`'workerPath' must be absolute, got '${workerPath}'`);
|
||||
}
|
||||
const workerPoolOptions = {
|
||||
enableWorkerThreads: this._options.enableWorkerThreads ?? false,
|
||||
forkOptions: this._options.forkOptions ?? {},
|
||||
idleMemoryLimit: this._options.idleMemoryLimit,
|
||||
maxRetries: this._options.maxRetries ?? 3,
|
||||
numWorkers:
|
||||
this._options.numWorkers ?? Math.max(getNumberOfCpus() - 1, 1),
|
||||
resourceLimits: this._options.resourceLimits ?? {},
|
||||
setupArgs: this._options.setupArgs ?? []
|
||||
};
|
||||
if (this._options.WorkerPool) {
|
||||
this._workerPool = new this._options.WorkerPool(
|
||||
workerPath,
|
||||
workerPoolOptions
|
||||
);
|
||||
} else {
|
||||
this._workerPool = new _WorkerPool.default(workerPath, workerPoolOptions);
|
||||
}
|
||||
this._farm = new _Farm.default(
|
||||
workerPoolOptions.numWorkers,
|
||||
this._workerPool.send.bind(this._workerPool),
|
||||
{
|
||||
computeWorkerKey: this._options.computeWorkerKey,
|
||||
taskQueue: this._options.taskQueue,
|
||||
workerSchedulingPolicy: this._options.workerSchedulingPolicy
|
||||
}
|
||||
);
|
||||
this._bindExposedWorkerMethods(workerPath, this._options);
|
||||
}
|
||||
_bindExposedWorkerMethods(workerPath, options) {
|
||||
getExposedMethods(workerPath, options).forEach(name => {
|
||||
if (name.startsWith('_')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-prototype-builtins
|
||||
if (this.constructor.prototype.hasOwnProperty(name)) {
|
||||
throw new TypeError(`Cannot define a method called ${name}`);
|
||||
}
|
||||
|
||||
// @ts-expect-error: dynamic extension of the class instance is expected.
|
||||
this[name] = this._callFunctionWithArgs.bind(this, name);
|
||||
});
|
||||
}
|
||||
_callFunctionWithArgs(method, ...args) {
|
||||
if (this._ending) {
|
||||
throw new Error('Farm is ended, no more calls can be done to it');
|
||||
}
|
||||
return this._farm.doWork(method, ...args);
|
||||
}
|
||||
getStderr() {
|
||||
return this._workerPool.getStderr();
|
||||
}
|
||||
getStdout() {
|
||||
return this._workerPool.getStdout();
|
||||
}
|
||||
async start() {
|
||||
await this._workerPool.start();
|
||||
}
|
||||
async end() {
|
||||
if (this._ending) {
|
||||
throw new Error('Farm is ended, no more calls can be done to it');
|
||||
}
|
||||
this._ending = true;
|
||||
return this._workerPool.end();
|
||||
}
|
||||
}
|
||||
exports.Worker = Worker;
|
||||
72
node_modules/@jest/reporters/node_modules/jest-worker/build/types.js
generated
vendored
Normal file
72
node_modules/@jest/reporters/node_modules/jest-worker/build/types.js
generated
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true
|
||||
});
|
||||
exports.WorkerStates =
|
||||
exports.WorkerEvents =
|
||||
exports.PARENT_MESSAGE_SETUP_ERROR =
|
||||
exports.PARENT_MESSAGE_OK =
|
||||
exports.PARENT_MESSAGE_MEM_USAGE =
|
||||
exports.PARENT_MESSAGE_CUSTOM =
|
||||
exports.PARENT_MESSAGE_CLIENT_ERROR =
|
||||
exports.CHILD_MESSAGE_MEM_USAGE =
|
||||
exports.CHILD_MESSAGE_INITIALIZE =
|
||||
exports.CHILD_MESSAGE_END =
|
||||
exports.CHILD_MESSAGE_CALL_SETUP =
|
||||
exports.CHILD_MESSAGE_CALL =
|
||||
void 0;
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
// Because of the dynamic nature of a worker communication process, all messages
|
||||
// coming from any of the other processes cannot be typed. Thus, many types
|
||||
// include "unknown" as a TS type, which is (unfortunately) correct here.
|
||||
|
||||
const CHILD_MESSAGE_INITIALIZE = 0;
|
||||
exports.CHILD_MESSAGE_INITIALIZE = CHILD_MESSAGE_INITIALIZE;
|
||||
const CHILD_MESSAGE_CALL = 1;
|
||||
exports.CHILD_MESSAGE_CALL = CHILD_MESSAGE_CALL;
|
||||
const CHILD_MESSAGE_END = 2;
|
||||
exports.CHILD_MESSAGE_END = CHILD_MESSAGE_END;
|
||||
const CHILD_MESSAGE_MEM_USAGE = 3;
|
||||
exports.CHILD_MESSAGE_MEM_USAGE = CHILD_MESSAGE_MEM_USAGE;
|
||||
const CHILD_MESSAGE_CALL_SETUP = 4;
|
||||
exports.CHILD_MESSAGE_CALL_SETUP = CHILD_MESSAGE_CALL_SETUP;
|
||||
const PARENT_MESSAGE_OK = 0;
|
||||
exports.PARENT_MESSAGE_OK = PARENT_MESSAGE_OK;
|
||||
const PARENT_MESSAGE_CLIENT_ERROR = 1;
|
||||
exports.PARENT_MESSAGE_CLIENT_ERROR = PARENT_MESSAGE_CLIENT_ERROR;
|
||||
const PARENT_MESSAGE_SETUP_ERROR = 2;
|
||||
exports.PARENT_MESSAGE_SETUP_ERROR = PARENT_MESSAGE_SETUP_ERROR;
|
||||
const PARENT_MESSAGE_CUSTOM = 3;
|
||||
exports.PARENT_MESSAGE_CUSTOM = PARENT_MESSAGE_CUSTOM;
|
||||
const PARENT_MESSAGE_MEM_USAGE = 4;
|
||||
|
||||
// Option objects.
|
||||
|
||||
// Messages passed from the parent to the children.
|
||||
|
||||
// Messages passed from the children to the parent.
|
||||
|
||||
// Queue types.
|
||||
exports.PARENT_MESSAGE_MEM_USAGE = PARENT_MESSAGE_MEM_USAGE;
|
||||
let WorkerStates = /*#__PURE__*/ (function (WorkerStates) {
|
||||
WorkerStates['STARTING'] = 'starting';
|
||||
WorkerStates['OK'] = 'ok';
|
||||
WorkerStates['OUT_OF_MEMORY'] = 'oom';
|
||||
WorkerStates['RESTARTING'] = 'restarting';
|
||||
WorkerStates['SHUTTING_DOWN'] = 'shutting-down';
|
||||
WorkerStates['SHUT_DOWN'] = 'shut-down';
|
||||
return WorkerStates;
|
||||
})({});
|
||||
exports.WorkerStates = WorkerStates;
|
||||
let WorkerEvents = /*#__PURE__*/ (function (WorkerEvents) {
|
||||
WorkerEvents['STATE_CHANGE'] = 'state-change';
|
||||
return WorkerEvents;
|
||||
})({});
|
||||
exports.WorkerEvents = WorkerEvents;
|
||||
490
node_modules/@jest/reporters/node_modules/jest-worker/build/workers/ChildProcessWorker.js
generated
vendored
Normal file
490
node_modules/@jest/reporters/node_modules/jest-worker/build/workers/ChildProcessWorker.js
generated
vendored
Normal file
@@ -0,0 +1,490 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true
|
||||
});
|
||||
exports.default = exports.SIGKILL_DELAY = void 0;
|
||||
function _child_process() {
|
||||
const data = require('child_process');
|
||||
_child_process = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _os() {
|
||||
const data = require('os');
|
||||
_os = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _mergeStream() {
|
||||
const data = _interopRequireDefault(require('merge-stream'));
|
||||
_mergeStream = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _supportsColor() {
|
||||
const data = require('supports-color');
|
||||
_supportsColor = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
var _types = require('../types');
|
||||
var _WorkerAbstract = _interopRequireDefault(require('./WorkerAbstract'));
|
||||
function _interopRequireDefault(obj) {
|
||||
return obj && obj.__esModule ? obj : {default: obj};
|
||||
}
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
const SIGNAL_BASE_EXIT_CODE = 128;
|
||||
const SIGKILL_EXIT_CODE = SIGNAL_BASE_EXIT_CODE + 9;
|
||||
const SIGTERM_EXIT_CODE = SIGNAL_BASE_EXIT_CODE + 15;
|
||||
|
||||
// How long to wait after SIGTERM before sending SIGKILL
|
||||
const SIGKILL_DELAY = 500;
|
||||
|
||||
/**
|
||||
* This class wraps the child process and provides a nice interface to
|
||||
* communicate with. It takes care of:
|
||||
*
|
||||
* - Re-spawning the process if it dies.
|
||||
* - Queues calls while the worker is busy.
|
||||
* - Re-sends the requests if the worker blew up.
|
||||
*
|
||||
* The reason for queueing them here (since childProcess.send also has an
|
||||
* internal queue) is because the worker could be doing asynchronous work, and
|
||||
* this would lead to the child process to read its receiving buffer and start a
|
||||
* second call. By queueing calls here, we don't send the next call to the
|
||||
* children until we receive the result of the previous one.
|
||||
*
|
||||
* As soon as a request starts to be processed by a worker, its "processed"
|
||||
* field is changed to "true", so that other workers which might encounter the
|
||||
* same call skip it.
|
||||
*/
|
||||
exports.SIGKILL_DELAY = SIGKILL_DELAY;
|
||||
class ChildProcessWorker extends _WorkerAbstract.default {
|
||||
_child;
|
||||
_options;
|
||||
_request;
|
||||
_retries;
|
||||
_onProcessEnd;
|
||||
_onCustomMessage;
|
||||
_stdout;
|
||||
_stderr;
|
||||
_stderrBuffer = [];
|
||||
_memoryUsagePromise;
|
||||
_resolveMemoryUsage;
|
||||
_childIdleMemoryUsage;
|
||||
_childIdleMemoryUsageLimit;
|
||||
_memoryUsageCheck = false;
|
||||
_childWorkerPath;
|
||||
constructor(options) {
|
||||
super(options);
|
||||
this._options = options;
|
||||
this._request = null;
|
||||
this._stdout = null;
|
||||
this._stderr = null;
|
||||
this._childIdleMemoryUsage = null;
|
||||
this._childIdleMemoryUsageLimit = options.idleMemoryLimit || null;
|
||||
this._childWorkerPath =
|
||||
options.childWorkerPath || require.resolve('./processChild');
|
||||
this.state = _types.WorkerStates.STARTING;
|
||||
this.initialize();
|
||||
}
|
||||
initialize() {
|
||||
if (
|
||||
this.state === _types.WorkerStates.OUT_OF_MEMORY ||
|
||||
this.state === _types.WorkerStates.SHUTTING_DOWN ||
|
||||
this.state === _types.WorkerStates.SHUT_DOWN
|
||||
) {
|
||||
return;
|
||||
}
|
||||
if (this._child && this._child.connected) {
|
||||
this._child.kill('SIGKILL');
|
||||
}
|
||||
this.state = _types.WorkerStates.STARTING;
|
||||
const forceColor = _supportsColor().stdout
|
||||
? {
|
||||
FORCE_COLOR: '1'
|
||||
}
|
||||
: {};
|
||||
const silent = this._options.silent ?? true;
|
||||
if (!silent) {
|
||||
// NOTE: Detecting an out of memory crash is independent of idle memory usage monitoring. We want to
|
||||
// monitor for a crash occurring so that it can be handled as required and so we can tell the difference
|
||||
// between an OOM crash and another kind of crash. We need to do this because if a worker crashes due to
|
||||
// an OOM event sometimes it isn't seen by the worker pool and it just sits there waiting for the worker
|
||||
// to respond and it never will.
|
||||
console.warn('Unable to detect out of memory event if silent === false');
|
||||
}
|
||||
this._stderrBuffer = [];
|
||||
const options = {
|
||||
cwd: process.cwd(),
|
||||
env: {
|
||||
...process.env,
|
||||
JEST_WORKER_ID: String(this._options.workerId + 1),
|
||||
// 0-indexed workerId, 1-indexed JEST_WORKER_ID
|
||||
...forceColor
|
||||
},
|
||||
// Suppress --debug / --inspect flags while preserving others (like --harmony).
|
||||
execArgv: process.execArgv.filter(v => !/^--(debug|inspect)/.test(v)),
|
||||
// default to advanced serialization in order to match worker threads
|
||||
serialization: 'advanced',
|
||||
silent,
|
||||
...this._options.forkOptions
|
||||
};
|
||||
this._child = (0, _child_process().fork)(
|
||||
this._childWorkerPath,
|
||||
[],
|
||||
options
|
||||
);
|
||||
if (this._child.stdout) {
|
||||
if (!this._stdout) {
|
||||
// We need to add a permanent stream to the merged stream to prevent it
|
||||
// from ending when the subprocess stream ends
|
||||
this._stdout = (0, _mergeStream().default)(this._getFakeStream());
|
||||
}
|
||||
this._stdout.add(this._child.stdout);
|
||||
}
|
||||
if (this._child.stderr) {
|
||||
if (!this._stderr) {
|
||||
// We need to add a permanent stream to the merged stream to prevent it
|
||||
// from ending when the subprocess stream ends
|
||||
this._stderr = (0, _mergeStream().default)(this._getFakeStream());
|
||||
}
|
||||
this._stderr.add(this._child.stderr);
|
||||
this._child.stderr.on('data', this.stderrDataHandler.bind(this));
|
||||
}
|
||||
this._child.on('message', this._onMessage.bind(this));
|
||||
this._child.on('exit', this._onExit.bind(this));
|
||||
this._child.on('disconnect', this._onDisconnect.bind(this));
|
||||
this._child.send([
|
||||
_types.CHILD_MESSAGE_INITIALIZE,
|
||||
false,
|
||||
this._options.workerPath,
|
||||
this._options.setupArgs
|
||||
]);
|
||||
this._retries++;
|
||||
|
||||
// If we exceeded the amount of retries, we will emulate an error reply
|
||||
// coming from the child. This avoids code duplication related with cleaning
|
||||
// the queue, and scheduling the next call.
|
||||
if (this._retries > this._options.maxRetries) {
|
||||
const error = new Error(
|
||||
`Jest worker encountered ${this._retries} child process exceptions, exceeding retry limit`
|
||||
);
|
||||
this._onMessage([
|
||||
_types.PARENT_MESSAGE_CLIENT_ERROR,
|
||||
error.name,
|
||||
error.message,
|
||||
error.stack,
|
||||
{
|
||||
type: 'WorkerError'
|
||||
}
|
||||
]);
|
||||
|
||||
// Clear the request so we don't keep executing it.
|
||||
this._request = null;
|
||||
}
|
||||
this.state = _types.WorkerStates.OK;
|
||||
if (this._resolveWorkerReady) {
|
||||
this._resolveWorkerReady();
|
||||
}
|
||||
}
|
||||
stderrDataHandler(chunk) {
|
||||
if (chunk) {
|
||||
this._stderrBuffer.push(Buffer.from(chunk));
|
||||
}
|
||||
this._detectOutOfMemoryCrash();
|
||||
if (this.state === _types.WorkerStates.OUT_OF_MEMORY) {
|
||||
this._workerReadyPromise = undefined;
|
||||
this._resolveWorkerReady = undefined;
|
||||
this.killChild();
|
||||
this._shutdown();
|
||||
}
|
||||
}
|
||||
_detectOutOfMemoryCrash() {
|
||||
try {
|
||||
const bufferStr = Buffer.concat(this._stderrBuffer).toString('utf8');
|
||||
if (
|
||||
bufferStr.includes('heap out of memory') ||
|
||||
bufferStr.includes('allocation failure;') ||
|
||||
bufferStr.includes('Last few GCs')
|
||||
) {
|
||||
if (
|
||||
this.state === _types.WorkerStates.OK ||
|
||||
this.state === _types.WorkerStates.STARTING
|
||||
) {
|
||||
this.state = _types.WorkerStates.OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Error looking for out of memory crash', err);
|
||||
}
|
||||
}
|
||||
_onDisconnect() {
|
||||
this._workerReadyPromise = undefined;
|
||||
this._resolveWorkerReady = undefined;
|
||||
this._detectOutOfMemoryCrash();
|
||||
if (this.state === _types.WorkerStates.OUT_OF_MEMORY) {
|
||||
this.killChild();
|
||||
this._shutdown();
|
||||
}
|
||||
}
|
||||
_onMessage(response) {
|
||||
// Ignore messages not intended for us
|
||||
if (!Array.isArray(response)) return;
|
||||
|
||||
// TODO: Add appropriate type check
|
||||
let error;
|
||||
switch (response[0]) {
|
||||
case _types.PARENT_MESSAGE_OK:
|
||||
this._onProcessEnd(null, response[1]);
|
||||
break;
|
||||
case _types.PARENT_MESSAGE_CLIENT_ERROR:
|
||||
error = response[4];
|
||||
if (error != null && typeof error === 'object') {
|
||||
const extra = error;
|
||||
// @ts-expect-error: no index
|
||||
const NativeCtor = globalThis[response[1]];
|
||||
const Ctor = typeof NativeCtor === 'function' ? NativeCtor : Error;
|
||||
error = new Ctor(response[2]);
|
||||
error.type = response[1];
|
||||
error.stack = response[3];
|
||||
for (const key in extra) {
|
||||
error[key] = extra[key];
|
||||
}
|
||||
}
|
||||
this._onProcessEnd(error, null);
|
||||
break;
|
||||
case _types.PARENT_MESSAGE_SETUP_ERROR:
|
||||
error = new Error(`Error when calling setup: ${response[2]}`);
|
||||
error.type = response[1];
|
||||
error.stack = response[3];
|
||||
this._onProcessEnd(error, null);
|
||||
break;
|
||||
case _types.PARENT_MESSAGE_CUSTOM:
|
||||
this._onCustomMessage(response[1]);
|
||||
break;
|
||||
case _types.PARENT_MESSAGE_MEM_USAGE:
|
||||
this._childIdleMemoryUsage = response[1];
|
||||
if (this._resolveMemoryUsage) {
|
||||
this._resolveMemoryUsage(response[1]);
|
||||
this._resolveMemoryUsage = undefined;
|
||||
this._memoryUsagePromise = undefined;
|
||||
}
|
||||
this._performRestartIfRequired();
|
||||
break;
|
||||
default:
|
||||
// Ignore messages not intended for us
|
||||
break;
|
||||
}
|
||||
}
|
||||
_performRestartIfRequired() {
|
||||
if (this._memoryUsageCheck) {
|
||||
this._memoryUsageCheck = false;
|
||||
let limit = this._childIdleMemoryUsageLimit;
|
||||
|
||||
// TODO: At some point it would make sense to make use of
|
||||
// stringToBytes found in jest-config, however as this
|
||||
// package does not have any dependencies on an other jest
|
||||
// packages that can wait until some other time.
|
||||
if (limit && limit > 0 && limit <= 1) {
|
||||
limit = Math.floor((0, _os().totalmem)() * limit);
|
||||
} else if (limit) {
|
||||
limit = Math.floor(limit);
|
||||
}
|
||||
if (
|
||||
limit &&
|
||||
this._childIdleMemoryUsage &&
|
||||
this._childIdleMemoryUsage > limit
|
||||
) {
|
||||
this.state = _types.WorkerStates.RESTARTING;
|
||||
this.killChild();
|
||||
}
|
||||
}
|
||||
}
|
||||
_onExit(exitCode, signal) {
|
||||
this._workerReadyPromise = undefined;
|
||||
this._resolveWorkerReady = undefined;
|
||||
this._detectOutOfMemoryCrash();
|
||||
if (exitCode !== 0 && this.state === _types.WorkerStates.OUT_OF_MEMORY) {
|
||||
this._onProcessEnd(
|
||||
new Error('Jest worker ran out of memory and crashed'),
|
||||
null
|
||||
);
|
||||
this._shutdown();
|
||||
} else if (
|
||||
(exitCode !== 0 &&
|
||||
exitCode !== null &&
|
||||
exitCode !== SIGTERM_EXIT_CODE &&
|
||||
exitCode !== SIGKILL_EXIT_CODE &&
|
||||
this.state !== _types.WorkerStates.SHUTTING_DOWN) ||
|
||||
this.state === _types.WorkerStates.RESTARTING
|
||||
) {
|
||||
this.state = _types.WorkerStates.RESTARTING;
|
||||
this.initialize();
|
||||
if (this._request) {
|
||||
this._child.send(this._request);
|
||||
}
|
||||
} else {
|
||||
// At this point, it's not clear why the child process exited. There could
|
||||
// be several reasons:
|
||||
//
|
||||
// 1. The child process exited successfully after finishing its work.
|
||||
// This is the most likely case.
|
||||
// 2. The child process crashed in a manner that wasn't caught through
|
||||
// any of the heuristic-based checks above.
|
||||
// 3. The child process was killed by another process or daemon unrelated
|
||||
// to Jest. For example, oom-killer on Linux may have picked the child
|
||||
// process to kill because overall system memory is constrained.
|
||||
//
|
||||
// If there's a pending request to the child process in any of those
|
||||
// situations, the request still needs to be handled in some manner before
|
||||
// entering the shutdown phase. Otherwise the caller expecting a response
|
||||
// from the worker will never receive indication that something unexpected
|
||||
// happened and hang forever.
|
||||
//
|
||||
// In normal operation, the request is handled and cleared before the
|
||||
// child process exits. If it's still present, it's not clear what
|
||||
// happened and probably best to throw an error. In practice, this usually
|
||||
// happens when the child process is killed externally.
|
||||
//
|
||||
// There's a reasonable argument that the child process should be retried
|
||||
// with request re-sent in this scenario. However, if the problem was due
|
||||
// to situations such as oom-killer attempting to free up system
|
||||
// resources, retrying would exacerbate the problem.
|
||||
const isRequestStillPending = !!this._request;
|
||||
if (isRequestStillPending) {
|
||||
// If a signal is present, we can be reasonably confident the process
|
||||
// was killed externally. Log this fact so it's more clear to users that
|
||||
// something went wrong externally, rather than a bug in Jest itself.
|
||||
const error = new Error(
|
||||
signal != null
|
||||
? `A jest worker process (pid=${this._child.pid}) was terminated by another process: signal=${signal}, exitCode=${exitCode}. Operating system logs may contain more information on why this occurred.`
|
||||
: `A jest worker process (pid=${this._child.pid}) crashed for an unknown reason: exitCode=${exitCode}`
|
||||
);
|
||||
this._onProcessEnd(error, null);
|
||||
}
|
||||
this._shutdown();
|
||||
}
|
||||
}
|
||||
send(request, onProcessStart, onProcessEnd, onCustomMessage) {
|
||||
this._stderrBuffer = [];
|
||||
onProcessStart(this);
|
||||
this._onProcessEnd = (...args) => {
|
||||
const hasRequest = !!this._request;
|
||||
|
||||
// Clean the request to avoid sending past requests to workers that fail
|
||||
// while waiting for a new request (timers, unhandled rejections...)
|
||||
this._request = null;
|
||||
if (
|
||||
this._childIdleMemoryUsageLimit &&
|
||||
this._child.connected &&
|
||||
hasRequest
|
||||
) {
|
||||
this.checkMemoryUsage();
|
||||
}
|
||||
return onProcessEnd(...args);
|
||||
};
|
||||
this._onCustomMessage = (...arg) => onCustomMessage(...arg);
|
||||
this._request = request;
|
||||
this._retries = 0;
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
this._child.send(request, () => {});
|
||||
}
|
||||
waitForExit() {
|
||||
return this._exitPromise;
|
||||
}
|
||||
killChild() {
|
||||
// We store a reference so that there's no way we can accidentally
|
||||
// kill a new worker that has been spawned.
|
||||
const childToKill = this._child;
|
||||
childToKill.kill('SIGTERM');
|
||||
return setTimeout(() => childToKill.kill('SIGKILL'), SIGKILL_DELAY);
|
||||
}
|
||||
forceExit() {
|
||||
this.state = _types.WorkerStates.SHUTTING_DOWN;
|
||||
const sigkillTimeout = this.killChild();
|
||||
this._exitPromise.then(() => clearTimeout(sigkillTimeout));
|
||||
}
|
||||
getWorkerId() {
|
||||
return this._options.workerId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the process id of the worker.
|
||||
*
|
||||
* @returns Process id.
|
||||
*/
|
||||
getWorkerSystemId() {
|
||||
return this._child.pid;
|
||||
}
|
||||
getStdout() {
|
||||
return this._stdout;
|
||||
}
|
||||
getStderr() {
|
||||
return this._stderr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the last reported memory usage.
|
||||
*
|
||||
* @returns Memory usage in bytes.
|
||||
*/
|
||||
getMemoryUsage() {
|
||||
if (!this._memoryUsagePromise) {
|
||||
let rejectCallback;
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
this._resolveMemoryUsage = resolve;
|
||||
rejectCallback = reject;
|
||||
});
|
||||
this._memoryUsagePromise = promise;
|
||||
if (!this._child.connected && rejectCallback) {
|
||||
rejectCallback(new Error('Child process is not running.'));
|
||||
this._memoryUsagePromise = undefined;
|
||||
this._resolveMemoryUsage = undefined;
|
||||
return promise;
|
||||
}
|
||||
this._child.send([_types.CHILD_MESSAGE_MEM_USAGE], err => {
|
||||
if (err && rejectCallback) {
|
||||
this._memoryUsagePromise = undefined;
|
||||
this._resolveMemoryUsage = undefined;
|
||||
rejectCallback(err);
|
||||
}
|
||||
});
|
||||
return promise;
|
||||
}
|
||||
return this._memoryUsagePromise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets updated memory usage and restarts if required
|
||||
*/
|
||||
checkMemoryUsage() {
|
||||
if (this._childIdleMemoryUsageLimit) {
|
||||
this._memoryUsageCheck = true;
|
||||
this._child.send([_types.CHILD_MESSAGE_MEM_USAGE], err => {
|
||||
if (err) {
|
||||
console.error('Unable to check memory usage', err);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.warn(
|
||||
'Memory usage of workers can only be checked if a limit is set'
|
||||
);
|
||||
}
|
||||
}
|
||||
isWorkerRunning() {
|
||||
return this._child.connected && !this._child.killed;
|
||||
}
|
||||
}
|
||||
exports.default = ChildProcessWorker;
|
||||
359
node_modules/@jest/reporters/node_modules/jest-worker/build/workers/NodeThreadsWorker.js
generated
vendored
Normal file
359
node_modules/@jest/reporters/node_modules/jest-worker/build/workers/NodeThreadsWorker.js
generated
vendored
Normal file
@@ -0,0 +1,359 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
function _os() {
|
||||
const data = require('os');
|
||||
_os = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _worker_threads() {
|
||||
const data = require('worker_threads');
|
||||
_worker_threads = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _mergeStream() {
|
||||
const data = _interopRequireDefault(require('merge-stream'));
|
||||
_mergeStream = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
var _types = require('../types');
|
||||
var _WorkerAbstract = _interopRequireDefault(require('./WorkerAbstract'));
|
||||
function _interopRequireDefault(obj) {
|
||||
return obj && obj.__esModule ? obj : {default: obj};
|
||||
}
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
class ExperimentalWorker extends _WorkerAbstract.default {
|
||||
_worker;
|
||||
_options;
|
||||
_request;
|
||||
_retries;
|
||||
_onProcessEnd;
|
||||
_onCustomMessage;
|
||||
_stdout;
|
||||
_stderr;
|
||||
_memoryUsagePromise;
|
||||
_resolveMemoryUsage;
|
||||
_childWorkerPath;
|
||||
_childIdleMemoryUsage;
|
||||
_childIdleMemoryUsageLimit;
|
||||
_memoryUsageCheck = false;
|
||||
constructor(options) {
|
||||
super(options);
|
||||
this._options = options;
|
||||
this._request = null;
|
||||
this._stdout = null;
|
||||
this._stderr = null;
|
||||
this._childWorkerPath =
|
||||
options.childWorkerPath || require.resolve('./threadChild');
|
||||
this._childIdleMemoryUsage = null;
|
||||
this._childIdleMemoryUsageLimit = options.idleMemoryLimit || null;
|
||||
this.initialize();
|
||||
}
|
||||
initialize() {
|
||||
if (
|
||||
this.state === _types.WorkerStates.OUT_OF_MEMORY ||
|
||||
this.state === _types.WorkerStates.SHUTTING_DOWN ||
|
||||
this.state === _types.WorkerStates.SHUT_DOWN
|
||||
) {
|
||||
return;
|
||||
}
|
||||
if (this._worker) {
|
||||
this._worker.terminate();
|
||||
}
|
||||
this.state = _types.WorkerStates.STARTING;
|
||||
this._worker = new (_worker_threads().Worker)(this._childWorkerPath, {
|
||||
eval: false,
|
||||
resourceLimits: this._options.resourceLimits,
|
||||
stderr: true,
|
||||
stdout: true,
|
||||
workerData: this._options.workerData,
|
||||
...this._options.forkOptions
|
||||
});
|
||||
if (this._worker.stdout) {
|
||||
if (!this._stdout) {
|
||||
// We need to add a permanent stream to the merged stream to prevent it
|
||||
// from ending when the subprocess stream ends
|
||||
this._stdout = (0, _mergeStream().default)(this._getFakeStream());
|
||||
}
|
||||
this._stdout.add(this._worker.stdout);
|
||||
}
|
||||
if (this._worker.stderr) {
|
||||
if (!this._stderr) {
|
||||
// We need to add a permanent stream to the merged stream to prevent it
|
||||
// from ending when the subprocess stream ends
|
||||
this._stderr = (0, _mergeStream().default)(this._getFakeStream());
|
||||
}
|
||||
this._stderr.add(this._worker.stderr);
|
||||
}
|
||||
|
||||
// This can be useful for debugging.
|
||||
if (!(this._options.silent ?? true)) {
|
||||
this._worker.stdout.setEncoding('utf8');
|
||||
// eslint-disable-next-line no-console
|
||||
this._worker.stdout.on('data', console.log);
|
||||
this._worker.stderr.setEncoding('utf8');
|
||||
this._worker.stderr.on('data', console.error);
|
||||
}
|
||||
this._worker.on('message', this._onMessage.bind(this));
|
||||
this._worker.on('exit', this._onExit.bind(this));
|
||||
this._worker.on('error', this._onError.bind(this));
|
||||
this._worker.postMessage([
|
||||
_types.CHILD_MESSAGE_INITIALIZE,
|
||||
false,
|
||||
this._options.workerPath,
|
||||
this._options.setupArgs,
|
||||
String(this._options.workerId + 1) // 0-indexed workerId, 1-indexed JEST_WORKER_ID
|
||||
]);
|
||||
|
||||
this._retries++;
|
||||
|
||||
// If we exceeded the amount of retries, we will emulate an error reply
|
||||
// coming from the child. This avoids code duplication related with cleaning
|
||||
// the queue, and scheduling the next call.
|
||||
if (this._retries > this._options.maxRetries) {
|
||||
const error = new Error('Call retries were exceeded');
|
||||
this._onMessage([
|
||||
_types.PARENT_MESSAGE_CLIENT_ERROR,
|
||||
error.name,
|
||||
error.message,
|
||||
error.stack,
|
||||
{
|
||||
type: 'WorkerError'
|
||||
}
|
||||
]);
|
||||
}
|
||||
this.state = _types.WorkerStates.OK;
|
||||
if (this._resolveWorkerReady) {
|
||||
this._resolveWorkerReady();
|
||||
}
|
||||
}
|
||||
_onError(error) {
|
||||
if (error.message.includes('heap out of memory')) {
|
||||
this.state = _types.WorkerStates.OUT_OF_MEMORY;
|
||||
|
||||
// Threads don't behave like processes, they don't crash when they run out of
|
||||
// memory. But for consistency we want them to behave like processes so we call
|
||||
// terminate to simulate a crash happening that was not planned
|
||||
this._worker.terminate();
|
||||
}
|
||||
}
|
||||
_onMessage(response) {
|
||||
// Ignore messages not intended for us
|
||||
if (!Array.isArray(response)) return;
|
||||
let error;
|
||||
switch (response[0]) {
|
||||
case _types.PARENT_MESSAGE_OK:
|
||||
this._onProcessEnd(null, response[1]);
|
||||
break;
|
||||
case _types.PARENT_MESSAGE_CLIENT_ERROR:
|
||||
error = response[4];
|
||||
if (error != null && typeof error === 'object') {
|
||||
const extra = error;
|
||||
// @ts-expect-error: no index
|
||||
const NativeCtor = globalThis[response[1]];
|
||||
const Ctor = typeof NativeCtor === 'function' ? NativeCtor : Error;
|
||||
error = new Ctor(response[2]);
|
||||
error.type = response[1];
|
||||
error.stack = response[3];
|
||||
for (const key in extra) {
|
||||
// @ts-expect-error: no index
|
||||
error[key] = extra[key];
|
||||
}
|
||||
}
|
||||
this._onProcessEnd(error, null);
|
||||
break;
|
||||
case _types.PARENT_MESSAGE_SETUP_ERROR:
|
||||
error = new Error(`Error when calling setup: ${response[2]}`);
|
||||
|
||||
// @ts-expect-error: adding custom properties to errors.
|
||||
error.type = response[1];
|
||||
error.stack = response[3];
|
||||
this._onProcessEnd(error, null);
|
||||
break;
|
||||
case _types.PARENT_MESSAGE_CUSTOM:
|
||||
this._onCustomMessage(response[1]);
|
||||
break;
|
||||
case _types.PARENT_MESSAGE_MEM_USAGE:
|
||||
this._childIdleMemoryUsage = response[1];
|
||||
if (this._resolveMemoryUsage) {
|
||||
this._resolveMemoryUsage(response[1]);
|
||||
this._resolveMemoryUsage = undefined;
|
||||
this._memoryUsagePromise = undefined;
|
||||
}
|
||||
this._performRestartIfRequired();
|
||||
break;
|
||||
default:
|
||||
// Ignore messages not intended for us
|
||||
break;
|
||||
}
|
||||
}
|
||||
_onExit(exitCode) {
|
||||
this._workerReadyPromise = undefined;
|
||||
this._resolveWorkerReady = undefined;
|
||||
if (exitCode !== 0 && this.state === _types.WorkerStates.OUT_OF_MEMORY) {
|
||||
this._onProcessEnd(
|
||||
new Error('Jest worker ran out of memory and crashed'),
|
||||
null
|
||||
);
|
||||
this._shutdown();
|
||||
} else if (
|
||||
(exitCode !== 0 &&
|
||||
this.state !== _types.WorkerStates.SHUTTING_DOWN &&
|
||||
this.state !== _types.WorkerStates.SHUT_DOWN) ||
|
||||
this.state === _types.WorkerStates.RESTARTING
|
||||
) {
|
||||
this.initialize();
|
||||
if (this._request) {
|
||||
this._worker.postMessage(this._request);
|
||||
}
|
||||
} else {
|
||||
// If the worker thread exits while a request is still pending, throw an
|
||||
// error. This is unexpected and tests may not have run to completion.
|
||||
const isRequestStillPending = !!this._request;
|
||||
if (isRequestStillPending) {
|
||||
this._onProcessEnd(
|
||||
new Error(
|
||||
'A Jest worker thread exited unexpectedly before finishing tests for an unknown reason. One of the ways this can happen is if process.exit() was called in testing code.'
|
||||
),
|
||||
null
|
||||
);
|
||||
}
|
||||
this._shutdown();
|
||||
}
|
||||
}
|
||||
waitForExit() {
|
||||
return this._exitPromise;
|
||||
}
|
||||
forceExit() {
|
||||
this.state = _types.WorkerStates.SHUTTING_DOWN;
|
||||
this._worker.terminate();
|
||||
}
|
||||
send(request, onProcessStart, onProcessEnd, onCustomMessage) {
|
||||
onProcessStart(this);
|
||||
this._onProcessEnd = (...args) => {
|
||||
const hasRequest = !!this._request;
|
||||
|
||||
// Clean the request to avoid sending past requests to workers that fail
|
||||
// while waiting for a new request (timers, unhandled rejections...)
|
||||
this._request = null;
|
||||
if (this._childIdleMemoryUsageLimit && hasRequest) {
|
||||
this.checkMemoryUsage();
|
||||
}
|
||||
const res = onProcessEnd?.(...args);
|
||||
|
||||
// Clean up the reference so related closures can be garbage collected.
|
||||
onProcessEnd = null;
|
||||
return res;
|
||||
};
|
||||
this._onCustomMessage = (...arg) => onCustomMessage(...arg);
|
||||
this._request = request;
|
||||
this._retries = 0;
|
||||
this._worker.postMessage(request);
|
||||
}
|
||||
getWorkerId() {
|
||||
return this._options.workerId;
|
||||
}
|
||||
getStdout() {
|
||||
return this._stdout;
|
||||
}
|
||||
getStderr() {
|
||||
return this._stderr;
|
||||
}
|
||||
_performRestartIfRequired() {
|
||||
if (this._memoryUsageCheck) {
|
||||
this._memoryUsageCheck = false;
|
||||
let limit = this._childIdleMemoryUsageLimit;
|
||||
|
||||
// TODO: At some point it would make sense to make use of
|
||||
// stringToBytes found in jest-config, however as this
|
||||
// package does not have any dependencies on an other jest
|
||||
// packages that can wait until some other time.
|
||||
if (limit && limit > 0 && limit <= 1) {
|
||||
limit = Math.floor((0, _os().totalmem)() * limit);
|
||||
} else if (limit) {
|
||||
limit = Math.floor(limit);
|
||||
}
|
||||
if (
|
||||
limit &&
|
||||
this._childIdleMemoryUsage &&
|
||||
this._childIdleMemoryUsage > limit
|
||||
) {
|
||||
this.state = _types.WorkerStates.RESTARTING;
|
||||
this._worker.terminate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the last reported memory usage.
|
||||
*
|
||||
* @returns Memory usage in bytes.
|
||||
*/
|
||||
getMemoryUsage() {
|
||||
if (!this._memoryUsagePromise) {
|
||||
let rejectCallback;
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
this._resolveMemoryUsage = resolve;
|
||||
rejectCallback = reject;
|
||||
});
|
||||
this._memoryUsagePromise = promise;
|
||||
if (!this._worker.threadId) {
|
||||
rejectCallback(new Error('Child process is not running.'));
|
||||
this._memoryUsagePromise = undefined;
|
||||
this._resolveMemoryUsage = undefined;
|
||||
return promise;
|
||||
}
|
||||
try {
|
||||
this._worker.postMessage([_types.CHILD_MESSAGE_MEM_USAGE]);
|
||||
} catch (err) {
|
||||
this._memoryUsagePromise = undefined;
|
||||
this._resolveMemoryUsage = undefined;
|
||||
rejectCallback(err);
|
||||
}
|
||||
return promise;
|
||||
}
|
||||
return this._memoryUsagePromise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets updated memory usage and restarts if required
|
||||
*/
|
||||
checkMemoryUsage() {
|
||||
if (this._childIdleMemoryUsageLimit) {
|
||||
this._memoryUsageCheck = true;
|
||||
this._worker.postMessage([_types.CHILD_MESSAGE_MEM_USAGE]);
|
||||
} else {
|
||||
console.warn(
|
||||
'Memory usage of workers can only be checked if a limit is set'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the thread id of the worker.
|
||||
*
|
||||
* @returns Thread id.
|
||||
*/
|
||||
getWorkerSystemId() {
|
||||
return this._worker.threadId;
|
||||
}
|
||||
isWorkerRunning() {
|
||||
return this._worker.threadId >= 0;
|
||||
}
|
||||
}
|
||||
exports.default = ExperimentalWorker;
|
||||
135
node_modules/@jest/reporters/node_modules/jest-worker/build/workers/WorkerAbstract.js
generated
vendored
Normal file
135
node_modules/@jest/reporters/node_modules/jest-worker/build/workers/WorkerAbstract.js
generated
vendored
Normal file
@@ -0,0 +1,135 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
function _stream() {
|
||||
const data = require('stream');
|
||||
_stream = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
var _types = require('../types');
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
class WorkerAbstract extends _stream().EventEmitter {
|
||||
/**
|
||||
* DO NOT WRITE TO THIS DIRECTLY.
|
||||
* Use this.state getter/setters so events are emitted correctly.
|
||||
*/
|
||||
#state = _types.WorkerStates.STARTING;
|
||||
_fakeStream = null;
|
||||
_exitPromise;
|
||||
_resolveExitPromise;
|
||||
_workerReadyPromise;
|
||||
_resolveWorkerReady;
|
||||
get state() {
|
||||
return this.#state;
|
||||
}
|
||||
set state(value) {
|
||||
if (this.#state !== value) {
|
||||
const oldState = this.#state;
|
||||
this.#state = value;
|
||||
this.emit(_types.WorkerEvents.STATE_CHANGE, value, oldState);
|
||||
}
|
||||
}
|
||||
constructor(options) {
|
||||
super();
|
||||
if (typeof options.on === 'object') {
|
||||
for (const [event, handlers] of Object.entries(options.on)) {
|
||||
// Can't do Array.isArray on a ReadonlyArray<T>.
|
||||
// https://github.com/microsoft/TypeScript/issues/17002
|
||||
if (typeof handlers === 'function') {
|
||||
super.on(event, handlers);
|
||||
} else {
|
||||
for (const handler of handlers) {
|
||||
super.on(event, handler);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this._exitPromise = new Promise(resolve => {
|
||||
this._resolveExitPromise = resolve;
|
||||
});
|
||||
this._exitPromise.then(() => {
|
||||
this.state = _types.WorkerStates.SHUT_DOWN;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for the worker child process to be ready to handle requests.
|
||||
*
|
||||
* @returns Promise which resolves when ready.
|
||||
*/
|
||||
waitForWorkerReady() {
|
||||
if (!this._workerReadyPromise) {
|
||||
this._workerReadyPromise = new Promise((resolve, reject) => {
|
||||
let settled = false;
|
||||
let to;
|
||||
switch (this.state) {
|
||||
case _types.WorkerStates.OUT_OF_MEMORY:
|
||||
case _types.WorkerStates.SHUTTING_DOWN:
|
||||
case _types.WorkerStates.SHUT_DOWN:
|
||||
settled = true;
|
||||
reject(
|
||||
new Error(
|
||||
`Worker state means it will never be ready: ${this.state}`
|
||||
)
|
||||
);
|
||||
break;
|
||||
case _types.WorkerStates.STARTING:
|
||||
case _types.WorkerStates.RESTARTING:
|
||||
this._resolveWorkerReady = () => {
|
||||
settled = true;
|
||||
resolve();
|
||||
if (to) {
|
||||
clearTimeout(to);
|
||||
}
|
||||
};
|
||||
break;
|
||||
case _types.WorkerStates.OK:
|
||||
settled = true;
|
||||
resolve();
|
||||
break;
|
||||
}
|
||||
if (!settled) {
|
||||
to = setTimeout(() => {
|
||||
if (!settled) {
|
||||
reject(new Error('Timeout starting worker'));
|
||||
}
|
||||
}, 500);
|
||||
}
|
||||
});
|
||||
}
|
||||
return this._workerReadyPromise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to shut down the current working instance once the children have been
|
||||
* killed off.
|
||||
*/
|
||||
_shutdown() {
|
||||
this.state === _types.WorkerStates.SHUT_DOWN;
|
||||
|
||||
// End the permanent stream so the merged stream end too
|
||||
if (this._fakeStream) {
|
||||
this._fakeStream.end();
|
||||
this._fakeStream = null;
|
||||
}
|
||||
this._resolveExitPromise();
|
||||
}
|
||||
_getFakeStream() {
|
||||
if (!this._fakeStream) {
|
||||
this._fakeStream = new (_stream().PassThrough)();
|
||||
}
|
||||
return this._fakeStream;
|
||||
}
|
||||
}
|
||||
exports.default = WorkerAbstract;
|
||||
33
node_modules/@jest/reporters/node_modules/jest-worker/build/workers/messageParent.js
generated
vendored
Normal file
33
node_modules/@jest/reporters/node_modules/jest-worker/build/workers/messageParent.js
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true
|
||||
});
|
||||
exports.default = messageParent;
|
||||
function _worker_threads() {
|
||||
const data = require('worker_threads');
|
||||
_worker_threads = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
var _types = require('../types');
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
function messageParent(message, parentProcess = process) {
|
||||
if (!_worker_threads().isMainThread && _worker_threads().parentPort != null) {
|
||||
_worker_threads().parentPort.postMessage([
|
||||
_types.PARENT_MESSAGE_CUSTOM,
|
||||
message
|
||||
]);
|
||||
} else if (typeof parentProcess.send === 'function') {
|
||||
parentProcess.send([_types.PARENT_MESSAGE_CUSTOM, message]);
|
||||
} else {
|
||||
throw new Error('"messageParent" can only be used inside a worker');
|
||||
}
|
||||
}
|
||||
159
node_modules/@jest/reporters/node_modules/jest-worker/build/workers/processChild.js
generated
vendored
Normal file
159
node_modules/@jest/reporters/node_modules/jest-worker/build/workers/processChild.js
generated
vendored
Normal file
@@ -0,0 +1,159 @@
|
||||
'use strict';
|
||||
|
||||
function _jestUtil() {
|
||||
const data = require('jest-util');
|
||||
_jestUtil = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
var _types = require('../types');
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
let file = null;
|
||||
let setupArgs = [];
|
||||
let initialized = false;
|
||||
|
||||
/**
|
||||
* This file is a small bootstrapper for workers. It sets up the communication
|
||||
* between the worker and the parent process, interpreting parent messages and
|
||||
* sending results back.
|
||||
*
|
||||
* The file loaded will be lazily initialized the first time any of the workers
|
||||
* is called. This is done for optimal performance: if the farm is initialized,
|
||||
* but no call is made to it, child Node processes will be consuming the least
|
||||
* possible amount of memory.
|
||||
*
|
||||
* If an invalid message is detected, the child will exit (by throwing) with a
|
||||
* non-zero exit code.
|
||||
*/
|
||||
const messageListener = request => {
|
||||
switch (request[0]) {
|
||||
case _types.CHILD_MESSAGE_INITIALIZE:
|
||||
const init = request;
|
||||
file = init[2];
|
||||
setupArgs = init[3];
|
||||
break;
|
||||
case _types.CHILD_MESSAGE_CALL:
|
||||
const call = request;
|
||||
execMethod(call[2], call[3]);
|
||||
break;
|
||||
case _types.CHILD_MESSAGE_END:
|
||||
end();
|
||||
break;
|
||||
case _types.CHILD_MESSAGE_MEM_USAGE:
|
||||
reportMemoryUsage();
|
||||
break;
|
||||
case _types.CHILD_MESSAGE_CALL_SETUP:
|
||||
if (initialized) {
|
||||
reportSuccess(void 0);
|
||||
} else {
|
||||
const main = require(file);
|
||||
initialized = true;
|
||||
if (main.setup) {
|
||||
execFunction(
|
||||
main.setup,
|
||||
main,
|
||||
setupArgs,
|
||||
reportSuccess,
|
||||
reportInitializeError
|
||||
);
|
||||
} else {
|
||||
reportSuccess(void 0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new TypeError(
|
||||
`Unexpected request from parent process: ${request[0]}`
|
||||
);
|
||||
}
|
||||
};
|
||||
process.on('message', messageListener);
|
||||
function reportSuccess(result) {
|
||||
if (!process || !process.send) {
|
||||
throw new Error('Child can only be used on a forked process');
|
||||
}
|
||||
process.send([_types.PARENT_MESSAGE_OK, result]);
|
||||
}
|
||||
function reportClientError(error) {
|
||||
return reportError(error, _types.PARENT_MESSAGE_CLIENT_ERROR);
|
||||
}
|
||||
function reportInitializeError(error) {
|
||||
return reportError(error, _types.PARENT_MESSAGE_SETUP_ERROR);
|
||||
}
|
||||
function reportMemoryUsage() {
|
||||
if (!process || !process.send) {
|
||||
throw new Error('Child can only be used on a forked process');
|
||||
}
|
||||
const msg = [_types.PARENT_MESSAGE_MEM_USAGE, process.memoryUsage().heapUsed];
|
||||
process.send(msg);
|
||||
}
|
||||
function reportError(error, type) {
|
||||
if (!process || !process.send) {
|
||||
throw new Error('Child can only be used on a forked process');
|
||||
}
|
||||
if (error == null) {
|
||||
error = new Error('"null" or "undefined" thrown');
|
||||
}
|
||||
process.send([
|
||||
type,
|
||||
error.constructor && error.constructor.name,
|
||||
error.message,
|
||||
error.stack,
|
||||
typeof error === 'object'
|
||||
? {
|
||||
...error
|
||||
}
|
||||
: error
|
||||
]);
|
||||
}
|
||||
function end() {
|
||||
const main = require(file);
|
||||
if (!main.teardown) {
|
||||
exitProcess();
|
||||
return;
|
||||
}
|
||||
execFunction(main.teardown, main, [], exitProcess, exitProcess);
|
||||
}
|
||||
function exitProcess() {
|
||||
// Clean up open handles so the process ideally exits gracefully
|
||||
process.removeListener('message', messageListener);
|
||||
}
|
||||
function execMethod(method, args) {
|
||||
const main = require(file);
|
||||
let fn;
|
||||
if (method === 'default') {
|
||||
fn = main.__esModule ? main.default : main;
|
||||
} else {
|
||||
fn = main[method];
|
||||
}
|
||||
function execHelper() {
|
||||
execFunction(fn, main, args, reportSuccess, reportClientError);
|
||||
}
|
||||
if (initialized || !main.setup) {
|
||||
execHelper();
|
||||
return;
|
||||
}
|
||||
initialized = true;
|
||||
execFunction(main.setup, main, setupArgs, execHelper, reportInitializeError);
|
||||
}
|
||||
function execFunction(fn, ctx, args, onResult, onError) {
|
||||
let result;
|
||||
try {
|
||||
result = fn.apply(ctx, args);
|
||||
} catch (err) {
|
||||
onError(err);
|
||||
return;
|
||||
}
|
||||
if ((0, _jestUtil().isPromise)(result)) {
|
||||
result.then(onResult, onError);
|
||||
} else {
|
||||
onResult(result);
|
||||
}
|
||||
}
|
||||
177
node_modules/@jest/reporters/node_modules/jest-worker/build/workers/threadChild.js
generated
vendored
Normal file
177
node_modules/@jest/reporters/node_modules/jest-worker/build/workers/threadChild.js
generated
vendored
Normal file
@@ -0,0 +1,177 @@
|
||||
'use strict';
|
||||
|
||||
function _worker_threads() {
|
||||
const data = require('worker_threads');
|
||||
_worker_threads = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _jestUtil() {
|
||||
const data = require('jest-util');
|
||||
_jestUtil = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
var _types = require('../types');
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
let file = null;
|
||||
let setupArgs = [];
|
||||
let initialized = false;
|
||||
|
||||
/**
|
||||
* This file is a small bootstrapper for workers. It sets up the communication
|
||||
* between the worker and the parent process, interpreting parent messages and
|
||||
* sending results back.
|
||||
*
|
||||
* The file loaded will be lazily initialized the first time any of the workers
|
||||
* is called. This is done for optimal performance: if the farm is initialized,
|
||||
* but no call is made to it, child Node processes will be consuming the least
|
||||
* possible amount of memory.
|
||||
*
|
||||
* If an invalid message is detected, the child will exit (by throwing) with a
|
||||
* non-zero exit code.
|
||||
*/
|
||||
const messageListener = request => {
|
||||
switch (request[0]) {
|
||||
case _types.CHILD_MESSAGE_INITIALIZE:
|
||||
const init = request;
|
||||
file = init[2];
|
||||
setupArgs = init[3];
|
||||
process.env.JEST_WORKER_ID = init[4];
|
||||
break;
|
||||
case _types.CHILD_MESSAGE_CALL:
|
||||
const call = request;
|
||||
execMethod(call[2], call[3]);
|
||||
break;
|
||||
case _types.CHILD_MESSAGE_END:
|
||||
end();
|
||||
break;
|
||||
case _types.CHILD_MESSAGE_MEM_USAGE:
|
||||
reportMemoryUsage();
|
||||
break;
|
||||
case _types.CHILD_MESSAGE_CALL_SETUP:
|
||||
if (initialized) {
|
||||
reportSuccess(void 0);
|
||||
} else {
|
||||
const main = require(file);
|
||||
initialized = true;
|
||||
if (main.setup) {
|
||||
execFunction(
|
||||
main.setup,
|
||||
main,
|
||||
setupArgs,
|
||||
reportSuccess,
|
||||
reportInitializeError
|
||||
);
|
||||
} else {
|
||||
reportSuccess(void 0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new TypeError(
|
||||
`Unexpected request from parent process: ${request[0]}`
|
||||
);
|
||||
}
|
||||
};
|
||||
_worker_threads().parentPort.on('message', messageListener);
|
||||
function reportMemoryUsage() {
|
||||
if (_worker_threads().isMainThread) {
|
||||
throw new Error('Child can only be used on a forked process');
|
||||
}
|
||||
const msg = [_types.PARENT_MESSAGE_MEM_USAGE, process.memoryUsage().heapUsed];
|
||||
_worker_threads().parentPort.postMessage(msg);
|
||||
}
|
||||
function reportSuccess(result) {
|
||||
if (_worker_threads().isMainThread) {
|
||||
throw new Error('Child can only be used on a forked process');
|
||||
}
|
||||
try {
|
||||
_worker_threads().parentPort.postMessage([
|
||||
_types.PARENT_MESSAGE_OK,
|
||||
result
|
||||
]);
|
||||
} catch (err) {
|
||||
// Handling it here to avoid unhandled `DataCloneError` rejection
|
||||
// which is hard to distinguish on the parent side
|
||||
// (such error doesn't have any message or stack trace)
|
||||
reportClientError(err);
|
||||
}
|
||||
}
|
||||
function reportClientError(error) {
|
||||
return reportError(error, _types.PARENT_MESSAGE_CLIENT_ERROR);
|
||||
}
|
||||
function reportInitializeError(error) {
|
||||
return reportError(error, _types.PARENT_MESSAGE_SETUP_ERROR);
|
||||
}
|
||||
function reportError(error, type) {
|
||||
if (_worker_threads().isMainThread) {
|
||||
throw new Error('Child can only be used on a forked process');
|
||||
}
|
||||
if (error == null) {
|
||||
error = new Error('"null" or "undefined" thrown');
|
||||
}
|
||||
_worker_threads().parentPort.postMessage([
|
||||
type,
|
||||
error.constructor && error.constructor.name,
|
||||
error.message,
|
||||
error.stack,
|
||||
typeof error === 'object'
|
||||
? {
|
||||
...error
|
||||
}
|
||||
: error
|
||||
]);
|
||||
}
|
||||
function end() {
|
||||
const main = require(file);
|
||||
if (!main.teardown) {
|
||||
exitProcess();
|
||||
return;
|
||||
}
|
||||
execFunction(main.teardown, main, [], exitProcess, exitProcess);
|
||||
}
|
||||
function exitProcess() {
|
||||
// Clean up open handles so the worker ideally exits gracefully
|
||||
_worker_threads().parentPort.removeListener('message', messageListener);
|
||||
}
|
||||
function execMethod(method, args) {
|
||||
const main = require(file);
|
||||
let fn;
|
||||
if (method === 'default') {
|
||||
fn = main.__esModule ? main.default : main;
|
||||
} else {
|
||||
fn = main[method];
|
||||
}
|
||||
function execHelper() {
|
||||
execFunction(fn, main, args, reportSuccess, reportClientError);
|
||||
}
|
||||
if (initialized || !main.setup) {
|
||||
execHelper();
|
||||
return;
|
||||
}
|
||||
initialized = true;
|
||||
execFunction(main.setup, main, setupArgs, execHelper, reportInitializeError);
|
||||
}
|
||||
function execFunction(fn, ctx, args, onResult, onError) {
|
||||
let result;
|
||||
try {
|
||||
result = fn.apply(ctx, args);
|
||||
} catch (err) {
|
||||
onError(err);
|
||||
return;
|
||||
}
|
||||
if ((0, _jestUtil().isPromise)(result)) {
|
||||
result.then(onResult, onError);
|
||||
} else {
|
||||
onResult(result);
|
||||
}
|
||||
}
|
||||
42
node_modules/@jest/reporters/node_modules/jest-worker/package.json
generated
vendored
Normal file
42
node_modules/@jest/reporters/node_modules/jest-worker/package.json
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"name": "jest-worker",
|
||||
"version": "29.7.0",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/jestjs/jest.git",
|
||||
"directory": "packages/jest-worker"
|
||||
},
|
||||
"license": "MIT",
|
||||
"main": "./build/index.js",
|
||||
"types": "./build/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./build/index.d.ts",
|
||||
"default": "./build/index.js"
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/node": "*",
|
||||
"jest-util": "^29.7.0",
|
||||
"merge-stream": "^2.0.0",
|
||||
"supports-color": "^8.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.11.6",
|
||||
"@tsd/typescript": "^5.0.4",
|
||||
"@types/merge-stream": "^1.1.2",
|
||||
"@types/supports-color": "^8.1.0",
|
||||
"get-stream": "^6.0.0",
|
||||
"jest-leak-detector": "^29.7.0",
|
||||
"tsd-lite": "^0.7.0",
|
||||
"worker-farm": "^1.6.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^14.15.0 || ^16.10.0 || >=18.0.0"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"gitHead": "4e56991693da7cd4c3730dc3579a1dd1403ee630"
|
||||
}
|
||||
24
node_modules/@jest/reporters/node_modules/supports-color/browser.js
generated
vendored
Normal file
24
node_modules/@jest/reporters/node_modules/supports-color/browser.js
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
/* eslint-env browser */
|
||||
'use strict';
|
||||
|
||||
function getChromeVersion() {
|
||||
const matches = /(Chrome|Chromium)\/(?<chromeVersion>\d+)\./.exec(navigator.userAgent);
|
||||
|
||||
if (!matches) {
|
||||
return;
|
||||
}
|
||||
|
||||
return Number.parseInt(matches.groups.chromeVersion, 10);
|
||||
}
|
||||
|
||||
const colorSupport = getChromeVersion() >= 69 ? {
|
||||
level: 1,
|
||||
hasBasic: true,
|
||||
has256: false,
|
||||
has16m: false
|
||||
} : false;
|
||||
|
||||
module.exports = {
|
||||
stdout: colorSupport,
|
||||
stderr: colorSupport
|
||||
};
|
||||
152
node_modules/@jest/reporters/node_modules/supports-color/index.js
generated
vendored
Normal file
152
node_modules/@jest/reporters/node_modules/supports-color/index.js
generated
vendored
Normal file
@@ -0,0 +1,152 @@
|
||||
'use strict';
|
||||
const os = require('os');
|
||||
const tty = require('tty');
|
||||
const hasFlag = require('has-flag');
|
||||
|
||||
const {env} = process;
|
||||
|
||||
let flagForceColor;
|
||||
if (hasFlag('no-color') ||
|
||||
hasFlag('no-colors') ||
|
||||
hasFlag('color=false') ||
|
||||
hasFlag('color=never')) {
|
||||
flagForceColor = 0;
|
||||
} else if (hasFlag('color') ||
|
||||
hasFlag('colors') ||
|
||||
hasFlag('color=true') ||
|
||||
hasFlag('color=always')) {
|
||||
flagForceColor = 1;
|
||||
}
|
||||
|
||||
function envForceColor() {
|
||||
if ('FORCE_COLOR' in env) {
|
||||
if (env.FORCE_COLOR === 'true') {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (env.FORCE_COLOR === 'false') {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
|
||||
}
|
||||
}
|
||||
|
||||
function translateLevel(level) {
|
||||
if (level === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return {
|
||||
level,
|
||||
hasBasic: true,
|
||||
has256: level >= 2,
|
||||
has16m: level >= 3
|
||||
};
|
||||
}
|
||||
|
||||
function supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {
|
||||
const noFlagForceColor = envForceColor();
|
||||
if (noFlagForceColor !== undefined) {
|
||||
flagForceColor = noFlagForceColor;
|
||||
}
|
||||
|
||||
const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
|
||||
|
||||
if (forceColor === 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (sniffFlags) {
|
||||
if (hasFlag('color=16m') ||
|
||||
hasFlag('color=full') ||
|
||||
hasFlag('color=truecolor')) {
|
||||
return 3;
|
||||
}
|
||||
|
||||
if (hasFlag('color=256')) {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
if (haveStream && !streamIsTTY && forceColor === undefined) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const min = forceColor || 0;
|
||||
|
||||
if (env.TERM === 'dumb') {
|
||||
return min;
|
||||
}
|
||||
|
||||
if (process.platform === 'win32') {
|
||||
// Windows 10 build 10586 is the first Windows release that supports 256 colors.
|
||||
// Windows 10 build 14931 is the first release that supports 16m/TrueColor.
|
||||
const osRelease = os.release().split('.');
|
||||
if (
|
||||
Number(osRelease[0]) >= 10 &&
|
||||
Number(osRelease[2]) >= 10586
|
||||
) {
|
||||
return Number(osRelease[2]) >= 14931 ? 3 : 2;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ('CI' in env) {
|
||||
if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI', 'GITHUB_ACTIONS', 'BUILDKITE', 'DRONE'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return min;
|
||||
}
|
||||
|
||||
if ('TEAMCITY_VERSION' in env) {
|
||||
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
|
||||
}
|
||||
|
||||
if (env.COLORTERM === 'truecolor') {
|
||||
return 3;
|
||||
}
|
||||
|
||||
if ('TERM_PROGRAM' in env) {
|
||||
const version = Number.parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
|
||||
|
||||
switch (env.TERM_PROGRAM) {
|
||||
case 'iTerm.app':
|
||||
return version >= 3 ? 3 : 2;
|
||||
case 'Apple_Terminal':
|
||||
return 2;
|
||||
// No default
|
||||
}
|
||||
}
|
||||
|
||||
if (/-256(color)?$/i.test(env.TERM)) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ('COLORTERM' in env) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return min;
|
||||
}
|
||||
|
||||
function getSupportLevel(stream, options = {}) {
|
||||
const level = supportsColor(stream, {
|
||||
streamIsTTY: stream && stream.isTTY,
|
||||
...options
|
||||
});
|
||||
|
||||
return translateLevel(level);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
supportsColor: getSupportLevel,
|
||||
stdout: getSupportLevel({isTTY: tty.isatty(1)}),
|
||||
stderr: getSupportLevel({isTTY: tty.isatty(2)})
|
||||
};
|
||||
9
node_modules/@jest/reporters/node_modules/supports-color/license
generated
vendored
Normal file
9
node_modules/@jest/reporters/node_modules/supports-color/license
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
58
node_modules/@jest/reporters/node_modules/supports-color/package.json
generated
vendored
Normal file
58
node_modules/@jest/reporters/node_modules/supports-color/package.json
generated
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
{
|
||||
"name": "supports-color",
|
||||
"version": "8.1.1",
|
||||
"description": "Detect whether a terminal supports color",
|
||||
"license": "MIT",
|
||||
"repository": "chalk/supports-color",
|
||||
"funding": "https://github.com/chalk/supports-color?sponsor=1",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "https://sindresorhus.com"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"browser.js"
|
||||
],
|
||||
"exports": {
|
||||
"node": "./index.js",
|
||||
"default": "./browser.js"
|
||||
},
|
||||
"keywords": [
|
||||
"color",
|
||||
"colour",
|
||||
"colors",
|
||||
"terminal",
|
||||
"console",
|
||||
"cli",
|
||||
"ansi",
|
||||
"styles",
|
||||
"tty",
|
||||
"rgb",
|
||||
"256",
|
||||
"shell",
|
||||
"xterm",
|
||||
"command-line",
|
||||
"support",
|
||||
"supports",
|
||||
"capability",
|
||||
"detect",
|
||||
"truecolor",
|
||||
"16m"
|
||||
],
|
||||
"dependencies": {
|
||||
"has-flag": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ava": "^2.4.0",
|
||||
"import-fresh": "^3.2.2",
|
||||
"xo": "^0.35.0"
|
||||
},
|
||||
"browser": "browser.js"
|
||||
}
|
||||
77
node_modules/@jest/reporters/node_modules/supports-color/readme.md
generated
vendored
Normal file
77
node_modules/@jest/reporters/node_modules/supports-color/readme.md
generated
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
# supports-color
|
||||
|
||||
> Detect whether a terminal supports color
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install supports-color
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const supportsColor = require('supports-color');
|
||||
|
||||
if (supportsColor.stdout) {
|
||||
console.log('Terminal stdout supports color');
|
||||
}
|
||||
|
||||
if (supportsColor.stdout.has256) {
|
||||
console.log('Terminal stdout supports 256 colors');
|
||||
}
|
||||
|
||||
if (supportsColor.stderr.has16m) {
|
||||
console.log('Terminal stderr supports 16 million colors (truecolor)');
|
||||
}
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
Returns an `Object` with a `stdout` and `stderr` property for testing either streams. Each property is an `Object`, or `false` if color is not supported.
|
||||
|
||||
The `stdout`/`stderr` objects specifies a level of support for color through a `.level` property and a corresponding flag:
|
||||
|
||||
- `.level = 1` and `.hasBasic = true`: Basic color support (16 colors)
|
||||
- `.level = 2` and `.has256 = true`: 256 color support
|
||||
- `.level = 3` and `.has16m = true`: Truecolor support (16 million colors)
|
||||
|
||||
### `require('supports-color').supportsColor(stream, options?)`
|
||||
|
||||
Additionally, `supports-color` exposes the `.supportsColor()` function that takes an arbitrary write stream (e.g. `process.stdout`) and an optional options object to (re-)evaluate color support for an arbitrary stream.
|
||||
|
||||
For example, `require('supports-color').stdout` is the equivalent of `require('supports-color').supportsColor(process.stdout)`.
|
||||
|
||||
The options object supports a single boolean property `sniffFlags`. By default it is `true`, which instructs `supportsColor()` to sniff `process.argv` for the multitude of `--color` flags (see _Info_ below). If `false`, then `process.argv` is not considered when determining color support.
|
||||
|
||||
## Info
|
||||
|
||||
It obeys the `--color` and `--no-color` CLI flags.
|
||||
|
||||
For situations where using `--color` is not possible, use the environment variable `FORCE_COLOR=1` (level 1), `FORCE_COLOR=2` (level 2), or `FORCE_COLOR=3` (level 3) to forcefully enable color, or `FORCE_COLOR=0` to forcefully disable. The use of `FORCE_COLOR` overrides all other color support checks.
|
||||
|
||||
Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=16m` flags, respectively.
|
||||
|
||||
## Related
|
||||
|
||||
- [supports-color-cli](https://github.com/chalk/supports-color-cli) - CLI for this module
|
||||
- [chalk](https://github.com/chalk/chalk) - Terminal string styling done right
|
||||
|
||||
## Maintainers
|
||||
|
||||
- [Sindre Sorhus](https://github.com/sindresorhus)
|
||||
- [Josh Junon](https://github.com/qix-)
|
||||
|
||||
---
|
||||
|
||||
<div align="center">
|
||||
<b>
|
||||
<a href="https://tidelift.com/subscription/pkg/npm-supports-color?utm_source=npm-supports-color&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
|
||||
</b>
|
||||
<br>
|
||||
<sub>
|
||||
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
|
||||
</sub>
|
||||
</div>
|
||||
|
||||
---
|
||||
82
node_modules/@jest/reporters/package.json
generated
vendored
Normal file
82
node_modules/@jest/reporters/package.json
generated
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
{
|
||||
"name": "@jest/reporters",
|
||||
"description": "Jest's reporters",
|
||||
"version": "29.7.0",
|
||||
"main": "./build/index.js",
|
||||
"types": "./build/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./build/index.d.ts",
|
||||
"default": "./build/index.js"
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"dependencies": {
|
||||
"@bcoe/v8-coverage": "^0.2.3",
|
||||
"@jest/console": "^29.7.0",
|
||||
"@jest/test-result": "^29.7.0",
|
||||
"@jest/transform": "^29.7.0",
|
||||
"@jest/types": "^29.6.3",
|
||||
"@jridgewell/trace-mapping": "^0.3.18",
|
||||
"@types/node": "*",
|
||||
"chalk": "^4.0.0",
|
||||
"collect-v8-coverage": "^1.0.0",
|
||||
"exit": "^0.1.2",
|
||||
"glob": "^7.1.3",
|
||||
"graceful-fs": "^4.2.9",
|
||||
"istanbul-lib-coverage": "^3.0.0",
|
||||
"istanbul-lib-instrument": "^6.0.0",
|
||||
"istanbul-lib-report": "^3.0.0",
|
||||
"istanbul-lib-source-maps": "^4.0.0",
|
||||
"istanbul-reports": "^3.1.3",
|
||||
"jest-message-util": "^29.7.0",
|
||||
"jest-util": "^29.7.0",
|
||||
"jest-worker": "^29.7.0",
|
||||
"slash": "^3.0.0",
|
||||
"string-length": "^4.0.1",
|
||||
"strip-ansi": "^6.0.0",
|
||||
"v8-to-istanbul": "^9.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@jest/test-utils": "^29.7.0",
|
||||
"@tsd/typescript": "^5.0.4",
|
||||
"@types/exit": "^0.1.30",
|
||||
"@types/glob": "^7.1.1",
|
||||
"@types/graceful-fs": "^4.1.3",
|
||||
"@types/istanbul-lib-coverage": "^2.0.0",
|
||||
"@types/istanbul-lib-instrument": "^1.7.2",
|
||||
"@types/istanbul-lib-report": "^3.0.0",
|
||||
"@types/istanbul-lib-source-maps": "^4.0.0",
|
||||
"@types/istanbul-reports": "^3.0.0",
|
||||
"@types/node-notifier": "^8.0.0",
|
||||
"jest-resolve": "^29.7.0",
|
||||
"mock-fs": "^5.1.2",
|
||||
"node-notifier": "^10.0.0",
|
||||
"tsd-lite": "^0.7.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"node-notifier": "^8.0.1 || ^9.0.0 || ^10.0.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"node-notifier": {
|
||||
"optional": true
|
||||
}
|
||||
},
|
||||
"engines": {
|
||||
"node": "^14.15.0 || ^16.10.0 || >=18.0.0"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/jestjs/jest.git",
|
||||
"directory": "packages/jest-reporters"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/jestjs/jest/issues"
|
||||
},
|
||||
"homepage": "https://jestjs.io/",
|
||||
"license": "MIT",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"gitHead": "4e56991693da7cd4c3730dc3579a1dd1403ee630"
|
||||
}
|
||||
Reference in New Issue
Block a user