Skip to content

Commit

Permalink
chore(ssr): disable snapshot updates in fixtures (#4968)
Browse files Browse the repository at this point in the history
  • Loading branch information
cardoso authored Nov 27, 2024
1 parent 33b7737 commit 2b42245
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/@lwc/ssr-compiler/src/__tests__/utils/runner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { VitestTestRunner } from 'vitest/runners';
import type { RunnerTask } from 'vitest';

export default class SsrTestRunner extends VitestTestRunner {
override onAfterRunTask(task: RunnerTask): void {
// In the test file `src/__tests__/fixtures.spec.ts` we are matching snapshots from engine-server
// We want to avoid updating snapshots here, so we replace 'Snapshot' with 'SSR Fixture' in error messages
// This is a workaround while vitest does not provide a way to skip updating snapshots for specific tests
// https://github.com/vitest-dev/vitest/blob/main/packages/vitest/src/utils/tasks.ts#L12-L20
// This shouldn't be a problem in CI, as updating snapshots is globally disabled
if (task.file.name === 'src/__tests__/fixtures.spec.ts') {
task.result?.errors?.forEach((error) => {
error.message = error.message.replaceAll('Snapshot', 'SSR Fixture');
});
}

return super.onAfterRunTask(task);
}
}
1 change: 1 addition & 0 deletions packages/@lwc/ssr-compiler/vitest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default mergeConfig(
baseConfig,
defineProject({
test: {
runner: './src/__tests__/utils/runner.ts',
name: 'lwc-ssr-compiler',
},
})
Expand Down

0 comments on commit 2b42245

Please sign in to comment.