@jest/test-sequencer
Advanced tools
Comparing version 29.7.0 to 30.0.0-alpha.1
@@ -8,2 +8,3 @@ /** | ||
import type {AggregatedResult} from '@jest/test-result'; | ||
import type {Config} from '@jest/types'; | ||
import type {Test} from '@jest/test-result'; | ||
@@ -42,2 +43,3 @@ import type {TestContext} from '@jest/test-result'; | ||
private readonly _cache; | ||
constructor(_options: TestSequencerOptions); | ||
_getCachePath(testContext: TestContext): string; | ||
@@ -93,2 +95,7 @@ _getCache(test: Test): Cache_2; | ||
export declare type TestSequencerOptions = { | ||
contexts: ReadonlyArray<TestContext>; | ||
globalConfig: Config.GlobalConfig; | ||
}; | ||
export {}; |
@@ -1,9 +0,23 @@ | ||
'use strict'; | ||
/*! | ||
* /** | ||
* * 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. | ||
* * / | ||
*/ | ||
/******/ (() => { // webpackBootstrap | ||
/******/ "use strict"; | ||
var __webpack_exports__ = {}; | ||
// This entry need to be wrapped in an IIFE because it uses a non-standard name for the exports (exports). | ||
(() => { | ||
var exports = __webpack_exports__; | ||
Object.defineProperty(exports, '__esModule', { | ||
Object.defineProperty(exports, "__esModule", ({ | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
})); | ||
exports["default"] = void 0; | ||
function crypto() { | ||
const data = _interopRequireWildcard(require('crypto')); | ||
const data = _interopRequireWildcard(require("crypto")); | ||
crypto = function () { | ||
@@ -15,3 +29,3 @@ return data; | ||
function path() { | ||
const data = _interopRequireWildcard(require('path')); | ||
const data = _interopRequireWildcard(require("path")); | ||
path = function () { | ||
@@ -23,3 +37,3 @@ return data; | ||
function fs() { | ||
const data = _interopRequireWildcard(require('graceful-fs')); | ||
const data = _interopRequireWildcard(require("graceful-fs")); | ||
fs = function () { | ||
@@ -31,3 +45,3 @@ return data; | ||
function _slash() { | ||
const data = _interopRequireDefault(require('slash')); | ||
const data = _interopRequireDefault(require("slash")); | ||
_slash = function () { | ||
@@ -39,3 +53,3 @@ return data; | ||
function _jestHasteMap() { | ||
const data = _interopRequireDefault(require('jest-haste-map')); | ||
const data = _interopRequireDefault(require("jest-haste-map")); | ||
_jestHasteMap = function () { | ||
@@ -46,45 +60,5 @@ return data; | ||
} | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : {default: obj}; | ||
} | ||
function _getRequireWildcardCache(nodeInterop) { | ||
if (typeof WeakMap !== 'function') return null; | ||
var cacheBabelInterop = new WeakMap(); | ||
var cacheNodeInterop = new WeakMap(); | ||
return (_getRequireWildcardCache = function (nodeInterop) { | ||
return nodeInterop ? cacheNodeInterop : cacheBabelInterop; | ||
})(nodeInterop); | ||
} | ||
function _interopRequireWildcard(obj, nodeInterop) { | ||
if (!nodeInterop && obj && obj.__esModule) { | ||
return obj; | ||
} | ||
if (obj === null || (typeof obj !== 'object' && typeof obj !== 'function')) { | ||
return {default: obj}; | ||
} | ||
var cache = _getRequireWildcardCache(nodeInterop); | ||
if (cache && cache.has(obj)) { | ||
return cache.get(obj); | ||
} | ||
var newObj = {}; | ||
var hasPropertyDescriptor = | ||
Object.defineProperty && Object.getOwnPropertyDescriptor; | ||
for (var key in obj) { | ||
if (key !== 'default' && Object.prototype.hasOwnProperty.call(obj, key)) { | ||
var desc = hasPropertyDescriptor | ||
? Object.getOwnPropertyDescriptor(obj, key) | ||
: null; | ||
if (desc && (desc.get || desc.set)) { | ||
Object.defineProperty(newObj, key, desc); | ||
} else { | ||
newObj[key] = obj[key]; | ||
} | ||
} | ||
} | ||
newObj.default = obj; | ||
if (cache) { | ||
cache.set(obj, newObj); | ||
} | ||
return newObj; | ||
} | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } | ||
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } | ||
/** | ||
@@ -114,12 +88,16 @@ * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
_cache = new Map(); | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function,@typescript-eslint/no-useless-constructor | ||
constructor(_options) {} | ||
_getCachePath(testContext) { | ||
const {config} = testContext; | ||
const { | ||
config | ||
} = testContext; | ||
const HasteMapClass = _jestHasteMap().default.getStatic(config); | ||
return HasteMapClass.getCacheFilePath( | ||
config.cacheDirectory, | ||
`perf-cache-${config.id}` | ||
); | ||
return HasteMapClass.getCacheFilePath(config.cacheDirectory, `perf-cache-${config.id}`); | ||
} | ||
_getCache(test) { | ||
const {context} = test; | ||
const { | ||
context | ||
} = test; | ||
if (!this._cache.has(context) && context.config.cache) { | ||
@@ -129,6 +107,3 @@ const cachePath = this._getCachePath(context); | ||
try { | ||
this._cache.set( | ||
context, | ||
JSON.parse(fs().readFileSync(cachePath, 'utf8')) | ||
); | ||
this._cache.set(context, JSON.parse(fs().readFileSync(cachePath, 'utf8'))); | ||
} catch {} | ||
@@ -147,9 +122,7 @@ } | ||
const ratio = options.suiteLength / options.shardCount; | ||
return new Array(options.shardIndex) | ||
.fill(true) | ||
.reduce((acc, _, shardIndex) => { | ||
const dangles = shardIndex < shardRest; | ||
const shardSize = dangles ? Math.ceil(ratio) : Math.floor(ratio); | ||
return acc + shardSize; | ||
}, 0); | ||
return new Array(options.shardIndex).fill(true).reduce((acc, _, shardIndex) => { | ||
const dangles = shardIndex < shardRest; | ||
const shardSize = dangles ? Math.ceil(ratio) : Math.floor(ratio); | ||
return acc + shardSize; | ||
}, 0); | ||
} | ||
@@ -189,19 +162,9 @@ | ||
}); | ||
return tests | ||
.map(test => { | ||
const relativeTestPath = path().posix.relative( | ||
(0, _slash().default)(test.context.config.rootDir), | ||
(0, _slash().default)(test.path) | ||
); | ||
return { | ||
hash: crypto() | ||
.createHash('sha1') | ||
.update(relativeTestPath) | ||
.digest('hex'), | ||
test | ||
}; | ||
}) | ||
.sort((a, b) => (a.hash < b.hash ? -1 : a.hash > b.hash ? 1 : 0)) | ||
.slice(shardStart, shardEnd) | ||
.map(result => result.test); | ||
return tests.map(test => { | ||
const relativeTestPath = path().posix.relative((0, _slash().default)(test.context.config.rootDir), (0, _slash().default)(test.path)); | ||
return { | ||
hash: crypto().createHash('sha1').update(relativeTestPath).digest('hex'), | ||
test | ||
}; | ||
}).sort((a, b) => a.hash < b.hash ? -1 : a.hash > b.hash ? 1 : 0).slice(shardStart, shardEnd).map(result => result.test); | ||
} | ||
@@ -243,7 +206,11 @@ | ||
const stats = {}; | ||
const fileSize = ({path, context: {hasteFS}}) => | ||
stats[path] || (stats[path] = hasteFS.getSize(path) ?? 0); | ||
tests.forEach(test => { | ||
const fileSize = ({ | ||
path, | ||
context: { | ||
hasteFS | ||
} | ||
}) => stats[path] || (stats[path] = hasteFS.getSize(path) ?? 0); | ||
for (const test of tests) { | ||
test.duration = this.time(test); | ||
}); | ||
} | ||
return tests.sort((testA, testB) => { | ||
@@ -270,4 +237,4 @@ const failedA = this.hasFailed(testA); | ||
const map = Object.create(null); | ||
tests.forEach(test => (map[test.path] = test)); | ||
results.testResults.forEach(testResult => { | ||
for (const test of tests) map[test.path] = test; | ||
for (const testResult of results.testResults) { | ||
const test = map[testResult.testFilePath]; | ||
@@ -277,13 +244,7 @@ if (test != null && !testResult.skipped) { | ||
const perf = testResult.perfStats; | ||
const testRuntime = | ||
perf.runtime ?? test.duration ?? perf.end - perf.start; | ||
cache[testResult.testFilePath] = [ | ||
testResult.numFailingTests > 0 ? FAIL : SUCCESS, | ||
testRuntime || 0 | ||
]; | ||
const testRuntime = perf.runtime ?? test.duration ?? perf.end - perf.start; | ||
cache[testResult.testFilePath] = [testResult.numFailingTests > 0 ? FAIL : SUCCESS, testRuntime || 0]; | ||
} | ||
}); | ||
this._cache.forEach((cache, context) => | ||
fs().writeFileSync(this._getCachePath(context), JSON.stringify(cache)) | ||
); | ||
} | ||
for (const [context, cache] of this._cache.entries()) fs().writeFileSync(this._getCachePath(context), JSON.stringify(cache)); | ||
} | ||
@@ -299,2 +260,7 @@ hasFailed(test) { | ||
} | ||
exports.default = TestSequencer; | ||
exports["default"] = TestSequencer; | ||
})(); | ||
module.exports = __webpack_exports__; | ||
/******/ })() | ||
; |
{ | ||
"name": "@jest/test-sequencer", | ||
"version": "29.7.0", | ||
"version": "30.0.0-alpha.1", | ||
"repository": { | ||
@@ -15,2 +15,4 @@ "type": "git", | ||
"types": "./build/index.d.ts", | ||
"require": "./build/index.js", | ||
"import": "./build/index.mjs", | ||
"default": "./build/index.js" | ||
@@ -21,13 +23,13 @@ }, | ||
"dependencies": { | ||
"@jest/test-result": "^29.7.0", | ||
"@jest/test-result": "30.0.0-alpha.1", | ||
"graceful-fs": "^4.2.9", | ||
"jest-haste-map": "^29.7.0", | ||
"jest-haste-map": "30.0.0-alpha.1", | ||
"slash": "^3.0.0" | ||
}, | ||
"devDependencies": { | ||
"@jest/test-utils": "^29.7.0", | ||
"@jest/test-utils": "30.0.0-alpha.1", | ||
"@types/graceful-fs": "^4.1.3" | ||
}, | ||
"engines": { | ||
"node": "^14.15.0 || ^16.10.0 || >=18.0.0" | ||
"node": "^16.10.0 || ^18.12.0 || >=20.0.0" | ||
}, | ||
@@ -37,3 +39,3 @@ "publishConfig": { | ||
}, | ||
"gitHead": "4e56991693da7cd4c3730dc3579a1dd1403ee630" | ||
"gitHead": "d005cb2505c041583e0c5636d006e08666a54b63" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14021
5
339
2
+ Added@jest/console@30.0.0-alpha.1(transitive)
+ Added@jest/schemas@30.0.0-alpha.1(transitive)
+ Added@jest/test-result@30.0.0-alpha.1(transitive)
+ Added@jest/types@30.0.0-alpha.1(transitive)
+ Added@sinclair/typebox@0.31.28(transitive)
+ Addedci-info@4.0.0(transitive)
+ Addedjest-haste-map@30.0.0-alpha.1(transitive)
+ Addedjest-message-util@30.0.0-alpha.1(transitive)
+ Addedjest-regex-util@30.0.0-alpha.1(transitive)
+ Addedjest-util@30.0.0-alpha.1(transitive)
+ Addedjest-worker@30.0.0-alpha.1(transitive)
+ Addedpretty-format@30.0.0-alpha.1(transitive)
- Removed@jest/console@29.7.0(transitive)
- Removed@jest/schemas@29.6.3(transitive)
- Removed@jest/test-result@29.7.0(transitive)
- Removed@jest/types@29.6.3(transitive)
- Removed@sinclair/typebox@0.27.8(transitive)
- Removed@types/graceful-fs@4.1.9(transitive)
- Removedci-info@3.9.0(transitive)
- Removedjest-haste-map@29.7.0(transitive)
- Removedjest-message-util@29.7.0(transitive)
- Removedjest-regex-util@29.6.3(transitive)
- Removedjest-util@29.7.0(transitive)
- Removedjest-worker@29.7.0(transitive)
- Removedpretty-format@29.7.0(transitive)