Skip to content

Commit e1708ff

Browse files
[test runner] Restore TEST_GREP support (jest -t parameter) (#14170)
1 parent b2cfc5b commit e1708ff

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

test/jest-light-runner/src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default class LightRunner {
3131
* @param {*} onFailure
3232
*/
3333
runTests(tests, watcher, onStart, onResult, onFailure) {
34-
const { updateSnapshot } = this.#config;
34+
const { updateSnapshot, testNamePattern } = this.#config;
3535

3636
return Promise.all(
3737
tests.map(test => {
@@ -41,7 +41,7 @@ export default class LightRunner {
4141

4242
return piscina
4343
.run(
44-
{ test, updateSnapshot, port: mc.port1 },
44+
{ test, updateSnapshot, testNamePattern, port: mc.port1 },
4545
{ transferList: [mc.port1] }
4646
)
4747
.then(

test/jest-light-runner/src/worker-runner.js

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,17 @@ import "./global-setup.js";
2323
};
2424
}
2525

26-
export default async function ({ test, updateSnapshot, port }) {
26+
export default async function ({
27+
test,
28+
updateSnapshot,
29+
testNamePattern,
30+
port,
31+
}) {
2732
port.postMessage("start");
2833

34+
const testNamePatternRE =
35+
testNamePattern != null ? new RegExp(testNamePattern, "i") : null;
36+
2937
/** @type {Stats} */
3038
const stats = { passes: 0, failures: 0, pending: 0, start: 0, end: 0 };
3139
/** @type {Array<InternalTestResult>} */
@@ -40,7 +48,7 @@ export default async function ({ test, updateSnapshot, port }) {
4048
expect.setState({ snapshotState });
4149

4250
stats.start = performance.now();
43-
await runTestBlock(tests, hasFocusedTests, results, stats);
51+
await runTestBlock(tests, hasFocusedTests, testNamePatternRE, results, stats);
4452
stats.end = performance.now();
4553

4654
snapshotState._inlineSnapshots.forEach(({ frame }) => {
@@ -63,6 +71,7 @@ async function loadTests(testFile) {
6371
async function runTestBlock(
6472
block,
6573
hasFocusedTests,
74+
testNamePatternRE,
6675
results,
6776
stats,
6877
ancestors = []
@@ -75,12 +84,20 @@ async function runTestBlock(
7584

7685
if (
7786
mode === "skip" ||
78-
(hasFocusedTests && type === "test" && mode !== "only")
87+
(hasFocusedTests && type === "test" && mode !== "only") ||
88+
shouldSkip(testNamePatternRE, getFullName(nextAncestors))
7989
) {
8090
stats.pending++;
8191
results.push({ ancestors, title: name, errors: [], skipped: true });
8292
} else if (type === "describeBlock") {
83-
await runTestBlock(child, hasFocusedTests, results, stats, nextAncestors);
93+
await runTestBlock(
94+
child,
95+
hasFocusedTests,
96+
testNamePatternRE,
97+
results,
98+
stats,
99+
nextAncestors
100+
);
84101
} else if (type === "test") {
85102
await runHooks("beforeEach", block, results, stats, nextAncestors, true);
86103
await runTest(fn, stats, results, ancestors, name);
@@ -93,6 +110,17 @@ async function runTestBlock(
93110
return results;
94111
}
95112

113+
function shouldSkip(testNamePatternRE, testName) {
114+
return testNamePatternRE && !testNamePatternRE.test(testName);
115+
}
116+
117+
/**
118+
* @param {string[]} pieces
119+
*/
120+
function getFullName(pieces) {
121+
return pieces.join(" ");
122+
}
123+
96124
/**
97125
* @param {Function} fn
98126
* @param {Stats} stats
@@ -103,7 +131,7 @@ async function runTestBlock(
103131
async function runTest(fn, stats, results, ancestors, name) {
104132
expect.setState({
105133
suppressedErrors: [],
106-
currentTestName: ancestors.concat(name).join(" "),
134+
currentTestName: getFullName(ancestors.concat(name)),
107135
});
108136

109137
const errors = [];

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy