Skip to content

Commit

Permalink
Add test about rate limit warnings in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jfmengels committed Feb 22, 2025
1 parent c2bed6b commit 7e80962
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"test": "turbo run testing check-engines --continue",
"test-sync": "npm run jest && npm run test-run",
"test-run": "(cd test/ && node ./run.mjs)",
"test-check-rate-limit-snapshots": "(cd test/ && node ./check-rate-limit-snapshots.mjs)",
"test-run-record": "(cd test/ && node ./run.mjs record)",
"tsc": "tsc",
"tsc-watch": "tsc --watch"
Expand Down
33 changes: 33 additions & 0 deletions test/check-rate-limit-snapshots.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/node

/* eslint n/no-process-exit: "off" -- WIP */
import * as fsp from 'node:fs/promises';
import * as path from 'node:path';
import {fileURLToPath} from 'node:url';
import {glob} from 'tinyglobby';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const SNAPSHOTS = path.join(__dirname, 'run-snapshots');

const snapshotFiles = await glob('**/*.txt', {
caseSensitiveMatch: true,
ignore: [`**/elm-stuff/**`],
cwd: SNAPSHOTS
});

for await (const file of snapshotFiles) {
const filePath = path.join(SNAPSHOTS, file);
const fileHandle = await fsp.readFile(filePath);
const content = fileHandle.toString();
if (content.includes('RATE LIMIT')) {
console.error('INCORRECT SNAPSHOT\n');
console.error('This file contains a rate limit error:\n');
console.error(filePath);
console.error(
'\nThis likely means you hit a GitHub rate limit error while re-generating snapshots.'
);
process.exit(1);
}
}
1 change: 1 addition & 0 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"tsc",
"eslint-check",
"prettier-check",
"test-check-rate-limit-snapshots",
"test-sync"
]
},
Expand Down

0 comments on commit 7e80962

Please # to comment.