Behavior
deno task test --parallel can fail one of the #159 cases in src/server.test.tsx:
data requests React Router rejects before a loader or action runs ... after middleware has read the response ... answers a GET data request whose route id /unknown is not on the URL with a 404 data error
error: AssertionError: the body leaks "does not match URL"
at assertDataError (src/server.test.tsx)
Seen once in four full parallel runs on the branch for #157 (juniper main 0.16.6 plus new tests in src/server.test.tsx). The same suite passes when run alone.
Cause
src/utils/testing.test.tsx, in the simulateEnvironment suite, has an afterEach that deletes every key in Deno.env and then sets the saved values back:
afterEach(() => {
for (const key of Object.keys(Deno.env.toObject())) {
Deno.env.delete(key);
}
for (const [key, value] of Object.entries(originalEnv)) {
Deno.env.set(key, value);
}
});
Deno.env is shared by the whole process, so under --parallel every other test module sees it too. For the moment between the delete and the restore, APP_ENV is unset. isDevelopment() in src/utils/env.ts returns true when APP_ENV is unset. serializeError in src/_serialization.ts then adds stack to the error it sends. The stack begins with React Router's message, which the #159 test asserts is never in the body outside development.
Any other test in any module that reads APP_ENV, or another variable from example/.env.test, through getEnv during that moment can fail the same way.
Fix
In that suite, set and remove only the keys it owns (FOO, BAZ, QUUX, ABCD), and put back their saved values. Don't clear the whole environment. Or move the suite onto simulateEnvironment, which scopes changes to the test with AsyncLocalStorage.
Behavior
deno task test --parallelcan fail one of the #159 cases insrc/server.test.tsx:Seen once in four full parallel runs on the branch for #157 (juniper main 0.16.6 plus new tests in
src/server.test.tsx). The same suite passes when run alone.Cause
src/utils/testing.test.tsx, in thesimulateEnvironmentsuite, has anafterEachthat deletes every key inDeno.envand then sets the saved values back:Deno.envis shared by the whole process, so under--parallelevery other test module sees it too. For the moment between the delete and the restore,APP_ENVis unset.isDevelopment()insrc/utils/env.tsreturnstruewhenAPP_ENVis unset.serializeErrorinsrc/_serialization.tsthen addsstackto the error it sends. The stack begins with React Router's message, which the #159 test asserts is never in the body outside development.Any other test in any module that reads
APP_ENV, or another variable fromexample/.env.test, throughgetEnvduring that moment can fail the same way.Fix
In that suite, set and remove only the keys it owns (
FOO,BAZ,QUUX,ABCD), and put back their saved values. Don't clear the whole environment. Or move the suite ontosimulateEnvironment, which scopes changes to the test with AsyncLocalStorage.