Skip to content

Commit 1541ce0

Browse files
committed
test: improve test isolation and cleanup console.log handling
1 parent 1e0d51b commit 1541ce0

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

integration/middleware-revaildate-test.ts

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -132,34 +132,43 @@ const files = {
132132
};
133133

134134
test.describe("shouldRevalidate with middleware", () => {
135+
let originalConsoleLog: typeof console.log;
136+
137+
test.beforeEach(() => {
138+
originalConsoleLog = console.log;
139+
});
140+
141+
test.afterEach(() => {
142+
console.log = originalConsoleLog;
143+
});
144+
135145
test("v8_middleware false - parent loader called once", async ({ page }) => {
136146
let fixture = await createFixture({
137147
files,
138148
});
139149
let appFixture = await createAppFixture(fixture);
140150
let app = new PlaywrightFixture(appFixture, page);
141151

152+
const parentLoaderRegex = /\[PARENT_LOADER\] Called: (\d+) times/;
153+
let maxParentLoaderCount = 0;
154+
155+
console.log = (...args) => {
156+
const message = args.join(" ");
157+
const match = message.match(parentLoaderRegex);
158+
if (match) {
159+
maxParentLoaderCount = Math.max(
160+
maxParentLoaderCount,
161+
parseInt(match[1]),
162+
);
163+
}
164+
};
165+
142166
await app.goto("/parent/1");
143167
await app.clickLink("/parent/2");
144168
await app.clickLink("/parent/3");
145169
await app.clickLink("/parent/4");
146170

147-
const initialParentCount = await page
148-
.locator("#parent-loader-count")
149-
.getAttribute("data-count");
150-
expect(initialParentCount).toBe("1");
151-
152-
const secondParentCount = await page
153-
.locator("#parent-loader-count")
154-
.getAttribute("data-count");
155-
156-
expect(secondParentCount).toBe("1");
157-
158-
const thirdParentCount = await page
159-
.locator("#parent-loader-count")
160-
.getAttribute("data-count");
161-
162-
expect(thirdParentCount).toBe("1");
171+
expect(maxParentLoaderCount).toBe(1);
163172
});
164173

165174
test("v8_middleware true - server execution tracking", async ({ page }) => {
@@ -180,7 +189,6 @@ test.describe("shouldRevalidate with middleware", () => {
180189
const parentLoaderRegex = /\[PARENT_LOADER\] Called: (\d+) times/;
181190
let maxParentLoaderCount = 0;
182191

183-
const originalLog = console.log;
184192
console.log = (...args) => {
185193
const message = args.join(" ");
186194
const match = message.match(parentLoaderRegex);
@@ -190,7 +198,6 @@ test.describe("shouldRevalidate with middleware", () => {
190198
parseInt(match[1]),
191199
);
192200
}
193-
originalLog(...args);
194201
};
195202

196203
await app.goto("/parent/1");

0 commit comments

Comments
 (0)