Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for setupFiles and snapshotSerializers #4

Merged
merged 4 commits into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The lists below are not comprehensive: feel free to [start a discussion](https:/
- Jest function mocks: `jest.fn`, `jest.spyOn`
- Inline and external snapshots
- `--testNamePattern`/`-t`, to only run some specific tests
- Jest config options: `setupFiles`, `snapshotSerializers`

### Unsupported Jest features

Expand Down
16 changes: 16 additions & 0 deletions src/worker-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ export default async function ({
}) {
port.postMessage("start");

const {setupFiles, snapshotSerializers} = test.context.config;

// https://github.com/facebook/jest/issues/11038
for (const setupFile of setupFiles) {
const { default: setup } = await import(pathToFileURL(setupFile));

if (typeof setup === 'function') {
await setup();
}
}

for (const snapshotSerializer of [...snapshotSerializers].reverse()) {
const { default: serializer } = await import(pathToFileURL(snapshotSerializer));
snapshot.addSerializer(serializer);
}

const testNamePatternRE =
testNamePattern != null ? new RegExp(testNamePattern, "i") : null;

Expand Down