Skip to content

Commit af069d4

Browse files
authored
fix: don't record unnecessary URLs (#17)
1 parent 0279a8e commit af069d4

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const test = base.extend<{
3030
}
3131
// on update, we want to record the HAR just like the original playwright method
3232
return originalRouteFromHAR(filename, {
33+
url: options.url,
3334
update: true,
3435
updateContent: options?.updateContent,
3536
updateMode: options?.updateMode,

tests/setup.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ test("record", async ({ page, advancedRouteFromHAR }) => {
44
await advancedRouteFromHAR("tests/har/temp/demo.playwright.dev.har", {
55
update: true,
66
updateContent: "embed",
7+
updateMode: "minimal"
8+
});
9+
await page.goto("https://demo.playwright.dev/todomvc");
10+
await page.close();
11+
});
12+
13+
test("record css only", async ({ page, advancedRouteFromHAR }) => {
14+
await advancedRouteFromHAR("tests/har/temp/demo.playwright.dev.css.har", {
15+
update: true,
16+
updateContent: "embed",
17+
updateMode: "minimal",
18+
url: /.*\.css/
719
});
820
await page.goto("https://demo.playwright.dev/todomvc");
921
await page.close();
@@ -13,6 +25,7 @@ test("record test with a joke", async ({ page, advancedRouteFromHAR }) => {
1325
await advancedRouteFromHAR("tests/har/temp/joke.har", {
1426
update: true,
1527
updateContent: "embed",
28+
updateMode: "minimal"
1629
});
1730
await page.goto("https://v2.jokeapi.dev/joke/Any?blacklistFlags=nsfw,religious,political,racist,sexist,explicit");
1831
await page.close();
@@ -22,6 +35,7 @@ test("record test with a joke and postprocess", async ({ page, advancedRouteFrom
2235
await advancedRouteFromHAR("tests/har/temp/joke-postprocess.har", {
2336
update: true,
2437
updateContent: "embed",
38+
updateMode: "minimal",
2539
matcher: {
2640
postProcess(entry) {
2741
entry.response.content.text = "This is a joke";

tests/test.spec.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ test("sanity with content attached", async ({ page, advancedRouteFromHAR }) => {
2424
await page.getByRole("heading", { name: "Example Domain" }).waitFor();
2525
});
2626

27+
test("only css was recorded", async () => {
28+
const fileContent = await waitForFile("tests/har/temp/demo.playwright.dev.css.har");
29+
const har = JSON.parse(fileContent);
30+
expect(har.log.entries.length).toBeGreaterThan(0);
31+
for (const entry of har.log.entries) {
32+
expect(entry.request.url).toMatch(/.*\.css/);
33+
}
34+
});
35+
2736
test("validate recorded har", async ({}) => {
2837
const data = await waitForFile("tests/har/temp/demo.playwright.dev.har");
2938
const har = JSON.parse(data);
@@ -210,8 +219,6 @@ test("test a postprocess that change only part of the output", async ({ page, ad
210219
matcher: {
211220
postProcess(entry) {
212221
const json = JSON.parse(entry.response.content.text ?? "{}");
213-
console.log(json);
214-
console.log(entry.response.content.text);
215222
json.flags.custom = true;
216223
entry.response.content.text = JSON.stringify(json);
217224
return entry;

0 commit comments

Comments
 (0)