Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: advanced matchers with postprocess option
- Loading branch information
Showing
4 changed files
with
92 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { customMatcher, test } from "../lib/index"; | ||
|
||
test("largest number squared - using explicit findEntry", async ({ page, advancedRouteFromHAR }) => { | ||
// the file contains 3 responses - 42, 1234, 5 | ||
await advancedRouteFromHAR("tests/har/differentNumbers.har", { | ||
matcher: { | ||
findEntry(har, request) { | ||
Check failure on line 7 in tests/advancedMatchers.spec.ts GitHub Actions / test-package
|
||
const chosen = har.log.entries.reduce((max, entry) => { | ||
const number = parseInt(entry.response.content.text || "0"); | ||
const maxNumber = parseInt(max.response.content.text || "0"); | ||
return number > maxNumber ? entry : max; | ||
}); | ||
return { | ||
...chosen, | ||
response: { | ||
...chosen.response, | ||
content: { | ||
...chosen.response.content, | ||
text: (parseInt(chosen.response.content.text || "0") ** 2).toString(), | ||
}, | ||
}, | ||
} | ||
Check failure on line 22 in tests/advancedMatchers.spec.ts GitHub Actions / test-package
|
||
} | ||
} | ||
}); | ||
await page.goto("https://noam-gaash.co.il"); | ||
await page.getByText((1234**2).toString()).waitFor(); | ||
}); | ||
|
||
test("largest number squared - using postprocess", async ({ page, advancedRouteFromHAR }) => { | ||
// the file contains 3 responses - 42, 1234, 5 | ||
await advancedRouteFromHAR("tests/har/differentNumbers.har", { | ||
matcher: { | ||
postProcess(entry) { | ||
entry.response.content.text = (parseInt(entry.response.content.text || "0") ** 2).toString(); | ||
return entry; | ||
}, | ||
matchFunction: customMatcher({ | ||
scoring: (request, entry) => parseInt(entry.response.content.text || "0"), | ||
}), | ||
} | ||
}); | ||
await page.goto("https://noam-gaash.co.il"); | ||
await page.getByText((1234**2).toString()).waitFor(); | ||
await page.reload(); | ||
// note - the postProcess is called again, and the number is squared again each time the response is used | ||
await page.getByText((1234**4).toString()).waitFor(); | ||
}); | ||
|
||
|