I am writing some e2e tests using Playwright, and I have defined two fixtures:
- one is for launching a browser with my chrome extension installed
- other is for mocking an external api call so I can test an authenticated state
fixtures-auth.js
import { test } from './fixtures.js';
export { test, expect } from './fixtures.js';
test.beforeEach(async ({ context }) => {
await context.route(
'https://some.url.com/api/some-endpoint',
async (route) => {
if (route.request().serviceWorker()) {
const json = {
//json content
};
await route.fulfill({ json });
}
},
);
});
Currently I have two tests located in separate directories, but both of them having the same path to the fixture file. When I run them both, the fixture-auth
is only applied to the first test and in the second one, despite the fixture being imported, it simply does not run the test.beforeEach
.
import { test, expect } from '../fixtures-auth.js';
I want to run this beforeEach
in every test to avoid code duplication, what am I doing wrong?