-
-
Notifications
You must be signed in to change notification settings - Fork 268
WIP: Use Polly to mock HTTP requests in tests #741
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| * text=auto | ||
|
|
||
| yarn.lock linguist-generated=false | ||
| # Collapse changes to Polly recordings in PRs. | ||
| tests/__recordings__/** linguist-generated | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| #!/usr/bin/env node | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Polly has an |
||
|
|
||
| const path = require('path'); | ||
| const fs = require('fs'); | ||
| const glob = require('glob'); | ||
|
|
||
| const getThirtyDaysAgo = () => { | ||
| const now = new Date(); | ||
| now.setMonth(now.getMonth() - 1); | ||
| return now; | ||
| }; | ||
|
|
||
| /** | ||
| * This script scans tests/__recordings__, which is where Polly captures | ||
| * recordings of requests, and looks for files that have captured requests that | ||
| * are older than 30 days. If any are found, the script will report the names of | ||
| * the tests that have these recordings and exit with 1. Otherwise, it will | ||
| * exit with 0. | ||
| */ | ||
| function main() { | ||
| const thirtyDaysAgoTimestamp = getThirtyDaysAgo().getTime(); | ||
| const outdatedTests = []; | ||
| const filePaths = glob.sync( | ||
| path.resolve(__dirname, '../tests/__recordings__/**/*.har'), | ||
| { realpath: true }, | ||
| ); | ||
| filePaths.forEach((filePath) => { | ||
| const encodedJson = fs.readFileSync(filePath, 'utf8'); | ||
| const decodedJson = JSON.parse(encodedJson); | ||
| const isOutdated = decodedJson.log.entries.some((entry) => { | ||
| const timestamp = Date.parse(entry.startedDateTime); | ||
| return timestamp < thirtyDaysAgoTimestamp; | ||
| }); | ||
| if (isOutdated) { | ||
| outdatedTests.push(decodedJson.log._recordingName); | ||
| } | ||
| }); | ||
|
|
||
| if (outdatedTests.length > 0) { | ||
| console.log('Some tests have outdated Polly recordings!'); | ||
| outdatedTests.forEach((test) => { | ||
| console.log(`- ${test.replace(/\//gu, ' -> ')}`); | ||
| }); | ||
| process.exit(1); | ||
| } else { | ||
| console.log('No tests have outdated Polly recordings, all good!'); | ||
| } | ||
| } | ||
|
|
||
| main(); | ||
Uh oh!
There was an error while loading. Please reload this page.