Skip to content

Commit d58af6a

Browse files
test(webview): await the on-demand locale fetch instead of timing it
platform-unit-test (windows-latest) job 126079240255 failed on the warm-switch case: expected `Une erreur s'est produite`, received `Etwas ist schiefgelaufen` with `active-language` still `de`, i.e. the french fetch had not resolved rather than resolving wrong. The locale-loading suite asserted that a switch to a non-fallback locale lands inside `waitFor`'s fixed 1000 ms window. That switch is an on-demand import() of the locale's bundles, so its duration is a property of the machine and the load on it, not of the code under test: the ubuntu lane finished the fetch inside the window and the windows lane did not, which is why the same suite was green on one required check and red on the other. The assertion now awaits the memoized `loadLanguage` promise the provider itself waits on - the idiom the unmount case at the end of this file already uses - so it has no deadline. `waitFor` still covers the render that `languageChanged` triggers, which is microtask-bound rather than disk-bound. Control: forcing every lazy locale module load to take 1500 ms reproduces the runner failure exactly on the previous test - 4 failures at lines 51, 71, 88 and 127, the four `waitFor` sites, with `Something went wrong` and `Etwas ist schiefgelaufen` as the received text - while the updated suite stays green under the same harness and under a 3000 ms delay with CI settings (testTimeout 15000, maxWorkers 1). The harness was reverted byte-identically; no test was skipped and nothing was suppressed.
1 parent fda1600 commit d58af6a

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

‎webview-ui/src/i18n/__tests__/TranslationContext.locale-loading.spec.tsx‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ describe("TranslationProvider locale loading", () => {
4747
// through the English fallback and the switch lands after the fetch.
4848
expect(screen.getByTestId("error-title")).toHaveTextContent("Something went wrong")
4949

50+
// A locale outside the entry chunk is fetched on demand, so how long the switch
51+
// takes is a property of the machine and the load on it, not of the code under
52+
// test: on a contended runner the fetch can outlast any fixed wall-clock window,
53+
// which is what made this suite flake. Awaiting the memoized promise the provider
54+
// itself waits on - the idiom the unmount case at the end of this file uses - takes
55+
// the clock out of the assertion. What `waitFor` has left to catch is the render
56+
// that `languageChanged` triggers, which settles in the same task.
57+
await loadLanguage("ko")
58+
5059
await waitFor(() => {
5160
expect(screen.getByTestId("error-title")).toHaveTextContent("문제가 발생했습니다")
5261
})
@@ -67,6 +76,9 @@ describe("TranslationProvider locale loading", () => {
6776
)
6877
})
6978

79+
// Await the fetch instead of racing a fixed window (note in the first case).
80+
await loadLanguage("ja")
81+
7082
await waitFor(() => {
7183
expect(screen.getByTestId("error-title")).toHaveTextContent("問題が発生しました")
7284
})
@@ -84,6 +96,9 @@ describe("TranslationProvider locale loading", () => {
8496
it("keeps English available after switching away and back", async () => {
8597
const { rerender } = renderProbe("de")
8698

99+
// German is loaded on demand as well: await it rather than time it.
100+
await loadLanguage("de")
101+
87102
await waitFor(() => {
88103
expect(screen.getByTestId("error-title")).toHaveTextContent("Etwas ist schiefgelaufen")
89104
})
@@ -105,6 +120,9 @@ describe("TranslationProvider locale loading", () => {
105120
it("keeps the previous locale rendered while a warm switch is still loading", async () => {
106121
const { rerender } = renderProbe("de")
107122

123+
// The cold locale is awaited here too (see the note in the first case).
124+
await loadLanguage("de")
125+
108126
await waitFor(() => {
109127
expect(screen.getByTestId("error-title")).toHaveTextContent("Etwas ist schiefgelaufen")
110128
})
@@ -123,6 +141,10 @@ describe("TranslationProvider locale loading", () => {
123141
// resolves would paint the English fallback here instead of German.
124142
expect(screen.getByTestId("error-title")).toHaveTextContent("Etwas ist schiefgelaufen")
125143

144+
// Awaiting the fetch through the promise the provider waits on keeps the assertion
145+
// above a statement about ordering rather than about the clock.
146+
await loadLanguage("fr")
147+
126148
await waitFor(() => {
127149
expect(screen.getByTestId("error-title")).toHaveTextContent("Une erreur s'est produite")
128150
})

0 commit comments

Comments
 (0)