Skip to content

Commit

Permalink
test: fix system locale override (#7317)
Browse files Browse the repository at this point in the history
Apparently setting `LC_ALL` in `vitest.setup.ts` doesn't work, as this
is after the locale settings are read, but it does work in a
`globalSetup` file.

This can be observed locally with the Workflows tests:
```
➜  wrangler git:(fix-test-locale) npx vitest run src/__tests__/workflows.test.ts >&/dev/null; echo $?
0
➜  wrangler git:(fix-test-locale) git checkout origin/main vitest.config.mts && LC_ALL=en_UK npx vitest run src/__tests__/workflows.test.ts >&/dev/null; echo $?
Updated 1 path from e1554242a
1
```
  • Loading branch information
ns476 authored Nov 22, 2024
1 parent 31729ee commit 3154114
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
7 changes: 7 additions & 0 deletions packages/wrangler/src/__tests__/vitest.global.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function setup(): void {
// Set `LC_ALL` to fix the language as English for the messages thrown by Yargs,
// and to make any uses of datetimes in snapshots consistent.
// This needs to be in a globalSetup script - it won't work in a setupFile script.
// https://github.com/vitest-dev/vitest/issues/1575#issuecomment-1439286286
process.env.LC_ALL = "C";
}
3 changes: 0 additions & 3 deletions packages/wrangler/src/__tests__/vitest.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ chalk.level = 0;
global as unknown as { __RELATIVE_PACKAGE_PATH__: string }
).__RELATIVE_PACKAGE_PATH__ = "..";

// Set `LC_ALL` to fix the language as English for the messages thrown by Yargs.
process.env.LC_ALL = "en";

vi.mock("ansi-escapes", () => {
return {
__esModule: true,
Expand Down
1 change: 1 addition & 0 deletions packages/wrangler/vitest.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export default defineConfig({
// eslint-disable-next-line turbo/no-undeclared-env-vars
outputFile: process.env.TEST_REPORT_PATH ?? ".e2e-test-report/index.html",
setupFiles: path.resolve(__dirname, "src/__tests__/vitest.setup.ts"),
globalSetup: path.resolve(__dirname, "src/__tests__/vitest.global.ts"),
reporters: ["default", "html"],
globals: true,
snapshotFormat: {
Expand Down

0 comments on commit 3154114

Please sign in to comment.