Skip to content

Commit

Permalink
fix: don't record unneccessary URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
NoamGaash committed Feb 26, 2024
1 parent 0279a8e commit fc40ae4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const test = base.extend<{
}
// on update, we want to record the HAR just like the original playwright method
return originalRouteFromHAR(filename, {
url: options.url,
update: true,
updateContent: options?.updateContent,
updateMode: options?.updateMode,
Expand Down
14 changes: 14 additions & 0 deletions tests/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ test("record", async ({ page, advancedRouteFromHAR }) => {
await advancedRouteFromHAR("tests/har/temp/demo.playwright.dev.har", {
update: true,
updateContent: "embed",
updateMode: "minimal"
});
await page.goto("https://demo.playwright.dev/todomvc");
await page.close();
});

test("record css only", async ({ page, advancedRouteFromHAR }) => {
await advancedRouteFromHAR("tests/har/temp/demo.playwright.dev.css.har", {
update: true,
updateContent: "embed",
updateMode: "minimal",
url: /.*\.css/
});
await page.goto("https://demo.playwright.dev/todomvc");
await page.close();
Expand All @@ -13,6 +25,7 @@ test("record test with a joke", async ({ page, advancedRouteFromHAR }) => {
await advancedRouteFromHAR("tests/har/temp/joke.har", {
update: true,
updateContent: "embed",
updateMode: "minimal"
});
await page.goto("https://v2.jokeapi.dev/joke/Any?blacklistFlags=nsfw,religious,political,racist,sexist,explicit");
await page.close();
Expand All @@ -22,6 +35,7 @@ test("record test with a joke and postprocess", async ({ page, advancedRouteFrom
await advancedRouteFromHAR("tests/har/temp/joke-postprocess.har", {
update: true,
updateContent: "embed",
updateMode: "minimal",
matcher: {
postProcess(entry) {
entry.response.content.text = "This is a joke";
Expand Down
11 changes: 9 additions & 2 deletions tests/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ test("sanity with content attached", async ({ page, advancedRouteFromHAR }) => {
await page.getByRole("heading", { name: "Example Domain" }).waitFor();
});

test("only css was recorded", async () => {
const fileContent = await waitForFile("tests/har/temp/demo.playwright.dev.css.har");
const har = JSON.parse(fileContent);
expect(har.log.entries.length).toBeGreaterThan(0);
for (const entry of har.log.entries) {
expect(entry.request.url).toMatch(/.*\.css/);
}
});

test("validate recorded har", async ({}) => {
const data = await waitForFile("tests/har/temp/demo.playwright.dev.har");
const har = JSON.parse(data);
Expand Down Expand Up @@ -210,8 +219,6 @@ test("test a postprocess that change only part of the output", async ({ page, ad
matcher: {
postProcess(entry) {
const json = JSON.parse(entry.response.content.text ?? "{}");
console.log(json);
console.log(entry.response.content.text);
json.flags.custom = true;
entry.response.content.text = JSON.stringify(json);
return entry;
Expand Down

0 comments on commit fc40ae4

Please sign in to comment.