Skip to content

Commit 2bd7089

Browse files
committed
working case of Jest augmentation with wdio matchers
1 parent 5253014 commit 2bd7089

31 files changed

Lines changed: 9534 additions & 4294 deletions

playgrounds/jest/.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

playgrounds/jest/global.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export declare global {
2+
var standalone: WebdriverIO.Browser;
3+
}

playgrounds/jest/jest.config.mjs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { inject } from "vitest";
2+
3+
export default {
4+
preset: 'ts-jest/presets/default-esm',
5+
moduleNameMapper: {
6+
'^(\\.{1,2}/.*)\\.[jt]s$': '$1',
7+
},
8+
testEnvironment: 'node',
9+
maxWorkers: 1,
10+
setupFilesAfterEnv: ['./jest.setup.after-env.ts'],
11+
testPathIgnorePatterns: ['.history', 'node_modules'],
12+
extensionsToTreatAsEsm: ['.ts'],
13+
transform: {
14+
'^.+\\.ts$': ['ts-jest', {
15+
useESM: true,
16+
injectGlobals: true
17+
}]
18+
}
19+
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { jest, beforeAll, afterAll, expect } from "@jest/globals";
2+
import { remote } from "webdriverio";
3+
import { config } from "./wdio.conf";
4+
import { matchers } from "expect-webdriverio";
5+
6+
jest.setTimeout(30000);
7+
8+
beforeAll(async () => {
9+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
10+
expect.extend(matchers as Record<string, any>);
11+
12+
// The enhanced expect already has matchers extended, no need to extend again
13+
globalThis.standalone = await remote(config);
14+
console.log('Browser session started with sessionId:', globalThis.standalone.sessionId);
15+
});
16+
17+
afterAll(async () => {
18+
console.log('Ending browser session with sessionId:', globalThis.standalone?.sessionId);
19+
await globalThis.standalone?.deleteSession();
20+
});

0 commit comments

Comments
 (0)