test(i18n): 语言检测用例每个都从空存储开始,Node 22 下不再读到模块加载时缓存的英文

This commit is contained in:
Lemon-miaow committed 2026-09-29 02:28:50 +08:00
1 parent 6b5bd7055b
commit d31fbae3cf
1 file changed
+8 -1
+8 -1
View File
@@ -1,5 +1,5 @@
// @vitest-environment jsdom
import { describe, it, expect, vi, afterEach } from "vitest";
import { describe, it, expect, vi, afterEach, beforeEach } from "vitest";
import i18next from "i18next";
import LanguageDetector from "i18next-browser-languagedetector";
import { i18nOptions } from "./index";
@@ -15,6 +15,13 @@ async function boot(languages: string[]) {
return instance;
}
// Importing ./index boots the app's own instance, which on some Node versions (22,
// which CI runs) caches jsdom's en-US in storage before the first test; a first
// visit starts from empty storage, and no test may inherit another's choice.
beforeEach(() => {
localStorage.clear();
});
afterEach(() => {
vi.restoreAllMocks();
});