Skip to content

Commit b7885ff

Browse files
committed
test(web): verify cached guide query revalidation
1 parent 60b5c39 commit b7885ff

2 files changed

Lines changed: 33 additions & 6 deletions

File tree

‎apps/web/src/components/pullRequest/guide/useGuideDiffFiles.browser.test.tsx‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,10 @@ it.each([
5757
"old-next",
5858
Atom.make<AsyncResult.AsyncResult<PullRequestDiffResult>>(AsyncResult.initial(true)),
5959
);
60-
const screen = stack.use(
61-
await render(
62-
<RegistryContext.Provider value={registry}>
63-
<Probe wantedPaths={["wanted.ts"]} />
64-
</RegistryContext.Provider>,
65-
),
60+
await using screen = await render(
61+
<RegistryContext.Provider value={registry}>
62+
<Probe wantedPaths={["wanted.ts"]} />
63+
</RegistryContext.Provider>,
6664
);
6765
const result = () => JSON.parse(screen.container.querySelector("output")!.textContent!);
6866
expect(result()).toEqual({ loading: true, files: [] });

‎packages/client-runtime/src/state/runtime.test.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,35 @@ describe("runtime command runner", () => {
11221122
});
11231123

11241124
describe("persisted environment queries", () => {
1125+
it.effect("keeps an in-memory cached page pending until revalidation settles", () =>
1126+
Effect.scoped(
1127+
Effect.gen(function* () {
1128+
const refreshStarted = Latch.makeUnsafe();
1129+
const finishRefresh = Latch.makeUnsafe();
1130+
let executions = 0;
1131+
const harness = yield* makeEnvironmentQueryHarness(
1132+
Effect.suspend(() => {
1133+
if (++executions === 1) return Effect.succeed("cached");
1134+
refreshStarted.openUnsafe();
1135+
return finishRefresh.await.pipe(Effect.as("fresh"));
1136+
}),
1137+
{ persistence: { load: () => Effect.succeedNone, save: () => Effect.void } },
1138+
);
1139+
const registry = yield* mountEnvironmentQuery(harness.atom);
1140+
expect(yield* readEnvironmentQuery(registry, harness.atom)).toBe("cached");
1141+
registry.refresh(harness.atom);
1142+
yield* refreshStarted.await;
1143+
expect(registry.get(harness.atom)).toMatchObject({
1144+
_tag: "Success",
1145+
value: "cached",
1146+
waiting: true,
1147+
});
1148+
finishRefresh.openUnsafe();
1149+
expect(yield* readEnvironmentQuery(registry, harness.atom)).toBe("fresh");
1150+
}),
1151+
),
1152+
);
1153+
11251154
it.effect(
11261155
"restores cached data in a new registry while offline, then refreshes on reconnect",
11271156
() =>

0 commit comments

Comments
 (0)