Skip to content

Commit 3154114

Browse files
authored
test: fix system locale override (#7317)
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 ```
1 parent 31729ee commit 3154114

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export function setup(): void {
2+
// Set `LC_ALL` to fix the language as English for the messages thrown by Yargs,
3+
// and to make any uses of datetimes in snapshots consistent.
4+
// This needs to be in a globalSetup script - it won't work in a setupFile script.
5+
// https://github.com/vitest-dev/vitest/issues/1575#issuecomment-1439286286
6+
process.env.LC_ALL = "C";
7+
}

packages/wrangler/src/__tests__/vitest.setup.ts

-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ chalk.level = 0;
2222
global as unknown as { __RELATIVE_PACKAGE_PATH__: string }
2323
).__RELATIVE_PACKAGE_PATH__ = "..";
2424

25-
// Set `LC_ALL` to fix the language as English for the messages thrown by Yargs.
26-
process.env.LC_ALL = "en";
27-
2825
vi.mock("ansi-escapes", () => {
2926
return {
3027
__esModule: true,

packages/wrangler/vitest.config.mts

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export default defineConfig({
6565
// eslint-disable-next-line turbo/no-undeclared-env-vars
6666
outputFile: process.env.TEST_REPORT_PATH ?? ".e2e-test-report/index.html",
6767
setupFiles: path.resolve(__dirname, "src/__tests__/vitest.setup.ts"),
68+
globalSetup: path.resolve(__dirname, "src/__tests__/vitest.global.ts"),
6869
reporters: ["default", "html"],
6970
globals: true,
7071
snapshotFormat: {

0 commit comments

Comments
 (0)