Skip to content

Commit ca90c71

Browse files
committed
test(jest): normalize runner args across Jest versions; forward 3 or 6 args
1 parent 8ef9648 commit ca90c71

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

src/testing/jest/jest-28/jest-runner.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,10 @@ export async function runJest(config: d.ValidatedConfig, env: d.E2EProcessEnv) {
5454
export function createTestRunner(): JestTestRunnerConstructor {
5555
class StencilTestRunner extends TestRunner {
5656
override async runTests(...args: any[]) {
57-
// Normalize to 6-arg shape used by jest-runner types
5857
const [testsArg, watcher] = args;
5958
let onStart: any, onResult: any, onFailure: any, options: any;
60-
if (args.length === 3) {
61-
// (tests, watcher, options)
62-
onStart = undefined;
63-
onResult = undefined;
64-
onFailure = undefined;
59+
const isThreeArg = args.length === 3;
60+
if (isThreeArg) {
6561
options = args[2];
6662
} else {
6763
[, , onStart, onResult, onFailure, options] = args;
@@ -89,12 +85,14 @@ export function createTestRunner(): JestTestRunnerConstructor {
8985
setScreenshotEmulateData(emulateConfig, env);
9086

9187
// run the test for each emulate config
92-
await (super.runTests as any)(tests, watcher, onStart, onResult, onFailure, options);
88+
const forwarded = isThreeArg ? [tests, watcher, options] : [tests, watcher, onStart, onResult, onFailure, options];
89+
await (super.runTests as any).apply(this, forwarded);
9390
}
9491
} else {
9592
// not doing e2e screenshot tests
9693
// so just run each test once
97-
await (super.runTests as any)(tests, watcher, onStart, onResult, onFailure, options);
94+
const forwarded = isThreeArg ? [tests, watcher, options] : [tests, watcher, onStart, onResult, onFailure, options];
95+
await (super.runTests as any).apply(this, forwarded);
9896
}
9997
}
10098
}

src/testing/jest/jest-29/jest-runner.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,10 @@ export async function runJest(config: d.ValidatedConfig, env: d.E2EProcessEnv) {
5454
export function createTestRunner(): JestTestRunnerConstructor {
5555
class StencilTestRunner extends TestRunner {
5656
override async runTests(...args: any[]) {
57-
// Normalize to 6-arg shape used by jest-runner types
5857
const [testsArg, watcher] = args;
5958
let onStart: any, onResult: any, onFailure: any, options: any;
60-
if (args.length === 3) {
61-
// (tests, watcher, options)
62-
onStart = undefined;
63-
onResult = undefined;
64-
onFailure = undefined;
59+
const isThreeArg = args.length === 3;
60+
if (isThreeArg) {
6561
options = args[2];
6662
} else {
6763
[, , onStart, onResult, onFailure, options] = args;
@@ -89,12 +85,14 @@ export function createTestRunner(): JestTestRunnerConstructor {
8985
setScreenshotEmulateData(emulateConfig, env);
9086

9187
// run the test for each emulate config
92-
await (super.runTests as any)(tests, watcher, onStart, onResult, onFailure, options);
88+
const forwarded = isThreeArg ? [tests, watcher, options] : [tests, watcher, onStart, onResult, onFailure, options];
89+
await (super.runTests as any).apply(this, forwarded);
9390
}
9491
} else {
9592
// not doing e2e screenshot tests
9693
// so just run each test once
97-
await (super.runTests as any)(tests, watcher, onStart, onResult, onFailure, options);
94+
const forwarded = isThreeArg ? [tests, watcher, options] : [tests, watcher, onStart, onResult, onFailure, options];
95+
await (super.runTests as any).apply(this, forwarded);
9896
}
9997
}
10098
}

0 commit comments

Comments
 (0)