I want to write some tests using jest and use some more capabilities using test fixtures.
// tests/sample.test.ts
jest.setTimeout(60 * 1000);
import { test } from './jest-fixture';
import { chromium } from 'playwright';
describe("Sample test", () => {
test(`sample test on chromium`, async ({ connect }) => {
const browser = await connect('chromium');
const page = await browser.newPage();
const page.close();
});
});
// jest-fixture.ts
import * as playwright from 'playwright';
import { Browser } from 'playwright';
import {test as base} from '@jest/globals';
export type SampleFixture = {
wsEndpoint: string;
}
export type Options = {
connect: (browserName: string) => Promise<Browser>;
};
export const test = base.extend<SampleFixtures & Options>({
wsEndpoint: async (use) => {
const wsEndpoint = getEndpoint();
await use(wsEndpoint);
},
connect: async ({ wsEndpoint }, use) => {
const browsers: Browser[] = [];
await use(async (browserName: string) => {
const browser = await playwright[browserName as 'chromium'].connect(wsEndpoint);
browsers.push(browser);
return browser;
});
for (const browser of browsers)
await browser.close();
}
});
I tried to make the above fixture file and extended the test from jest but I am getting the error message - Property 'extend' does not exist on type 'ItConcurrent'. Is there any other way to extend the test from jest or am I doing something wrong here?
There is a way to extend the expect from jest globals here but how to extend "test"?