Skip to content

Commit 0ba7eab

Browse files
committed
fix(testing): restore jest build compatibility
1 parent caf351f commit 0ba7eab

File tree

4 files changed

+48
-10
lines changed

4 files changed

+48
-10
lines changed

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
import type { Circus } from '@jest/types';
22
import type { E2EProcessEnv, JestEnvironmentGlobal } from '@stencil/core/internal';
3-
import { TestEnvironment as NodeEnvironment } from 'jest-environment-node';
3+
import NodeEnvironment from 'jest-environment-node';
44

55
import { connectBrowser, disconnectBrowser, newBrowserPage } from '../../puppeteer/puppeteer-browser';
66
import { JestPuppeteerEnvironmentConstructor } from '../jest-apis';
77

88
export function createJestPuppeteerEnvironment(): JestPuppeteerEnvironmentConstructor {
9-
const JestEnvironment = class extends NodeEnvironment {
9+
const NodeEnvironmentBase = NodeEnvironment as unknown as {
10+
new (
11+
config: any,
12+
context: any,
13+
): {
14+
global: JestEnvironmentGlobal;
15+
setup(): Promise<void>;
16+
teardown(): Promise<void>;
17+
getVmContext(): any | null;
18+
};
19+
};
20+
21+
const JestEnvironment = class extends NodeEnvironmentBase {
1022
browser: any;
1123
pages: any[];
1224
testPath: string | null;

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,14 @@ export async function runJest(config: d.ValidatedConfig, env: d.E2EProcessEnv) {
5353
*/
5454
export function createTestRunner(): JestTestRunnerConstructor {
5555
class StencilTestRunner extends TestRunner {
56-
override async runTests(tests: { context: any; path: string }[], watcher: any, options: any) {
56+
override async runTests(
57+
tests: { context: any; path: string }[],
58+
watcher: any,
59+
onStart: any,
60+
onResult: any,
61+
onFailure: any,
62+
options: any,
63+
) {
5764
const env = process.env as d.E2EProcessEnv;
5865

5966
// filter out only the tests the flags said we should run
@@ -75,12 +82,12 @@ export function createTestRunner(): JestTestRunnerConstructor {
7582
setScreenshotEmulateData(emulateConfig, env);
7683

7784
// run the test for each emulate config
78-
await super.runTests(tests, watcher, options);
85+
await super.runTests(tests, watcher, onStart, onResult, onFailure, options);
7986
}
8087
} else {
8188
// not doing e2e screenshot tests
8289
// so just run each test once
83-
await super.runTests(tests, watcher, options);
90+
await super.runTests(tests, watcher, onStart, onResult, onFailure, options);
8491
}
8592
}
8693
}

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
import type { Circus } from '@jest/types';
22
import type { E2EProcessEnv, JestEnvironmentGlobal } from '@stencil/core/internal';
3-
import { TestEnvironment as NodeEnvironment } from 'jest-environment-node';
3+
import NodeEnvironment from 'jest-environment-node';
44

55
import { connectBrowser, disconnectBrowser, newBrowserPage } from '../../puppeteer/puppeteer-browser';
66
import { JestPuppeteerEnvironmentConstructor } from '../jest-apis';
77

88
export function createJestPuppeteerEnvironment(): JestPuppeteerEnvironmentConstructor {
9-
const JestEnvironment = class extends NodeEnvironment {
9+
const NodeEnvironmentBase = NodeEnvironment as unknown as {
10+
new (
11+
config: any,
12+
context: any,
13+
): {
14+
global: JestEnvironmentGlobal;
15+
setup(): Promise<void>;
16+
teardown(): Promise<void>;
17+
getVmContext(): any | null;
18+
};
19+
};
20+
21+
const JestEnvironment = class extends NodeEnvironmentBase {
1022
browser: any;
1123
pages: any[];
1224
testPath: string | null;

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,14 @@ export async function runJest(config: d.ValidatedConfig, env: d.E2EProcessEnv) {
5353
*/
5454
export function createTestRunner(): JestTestRunnerConstructor {
5555
class StencilTestRunner extends TestRunner {
56-
override async runTests(tests: { context: any; path: string }[], watcher: any, options: any) {
56+
override async runTests(
57+
tests: { context: any; path: string }[],
58+
watcher: any,
59+
onStart: any,
60+
onResult: any,
61+
onFailure: any,
62+
options: any,
63+
) {
5764
const env = process.env as d.E2EProcessEnv;
5865

5966
// filter out only the tests the flags said we should run
@@ -75,12 +82,12 @@ export function createTestRunner(): JestTestRunnerConstructor {
7582
setScreenshotEmulateData(emulateConfig, env);
7683

7784
// run the test for each emulate config
78-
await super.runTests(tests, watcher, options);
85+
await super.runTests(tests, watcher, onStart, onResult, onFailure, options);
7986
}
8087
} else {
8188
// not doing e2e screenshot tests
8289
// so just run each test once
83-
await super.runTests(tests, watcher, options);
90+
await super.runTests(tests, watcher, onStart, onResult, onFailure, options);
8491
}
8592
}
8693
}

0 commit comments

Comments
 (0)