Skip to content

Commit

Permalink
Make the test timeout configurable
Browse files Browse the repository at this point in the history
The test timeouts were previously hardcoded to 60s for playback tests and 240s
while recording. Recording the tests has been takes ~5 minutes on CI and
bumping into this timeout. This PR updates the default while recording to 10
minutes and makes it configurable with a `TEST_TIMEOUT` environment variable.
If `TEST_TIMEOUT` is a raw number, the units will be assumed to be seconds. You
can also specify a units suffix like `TEST_TIMEOUT=10m`.

Merges #148

LGTM given by: @KPreisner
  • Loading branch information
sangaline authored Sep 5, 2024
1 parent ee78454 commit db57edb
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions ava.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,33 @@ const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
process.env.TSX_TSCONFIG_PATH = path.join(__dirname, "tsconfig.test.json");

let timeout;
if (process.env.TEST_TIMEOUT) {
// Allow the timeout to be specified with the `TEST_TIMEOUT` environment variable.
timeout = process.env.TEST_TIMEOUT;
// Default to seconds if no unit is specified.
if (/^\d+$/.test(timeout)) {
timeout = `${timeout}s`;
}
} else {
// Set the default fallback timeout and increase it if we expect to make live API calls.
if (
["dryrun", "record", "update", "wild"].includes(
process.env.NOCK_BACK_MODE ?? "lockdown",
)
) {
timeout = "10m";
} else {
timeout = "60s";
}
}

export default {
extensions: {
ts: "module",
},
files: ["test/**/*.test.ts"],
// Increase the timeout if we expect to make live API calls.
timeout: ["dryrun", "record", "update", "wild"].includes(
process.env.NOCK_BACK_MODE ?? "lockdown",
)
? "240s"
: "60s",
timeout,
// Use child processes instead of threads because notch isn't thread safe.
workerThreads: false,
};

0 comments on commit db57edb

Please sign in to comment.