Deno Isolated Test Case lets you run test cases in an isolated Deno process.
Sometimes you need to ensure that other running tests are not interfering with
the execution of your code, or visa versa. For instance, maybe your code
pollutes the global scope, or maybe you need to make assertions about memory
usage. Whatever your reason, Deno Isolated Test Case lets you run your test case
in a separate process, while still being able to use standard assertions like
assertEquals
.
In your test file, you can add an isolated test case at the top level as follows:
import { isolatedTestCase } from "@bcheidemann/deno-isolated-test-case";
isolatedTestCase("test name", () => {
// Your test case
});
The minimum permissions required to run an isolated test case are
--allow-env=DENO_ISOLATED_TEST_CASE_CTX --allow-net --allow-run=deno
.
Option | Description |
---|---|
assertFailure | If truthy, the test is expected to fail. A function can be passed to assert against the error. |
denoFlags | Flags to pass to deno run . |
Test cases must be at the top level and run unconditionally. They can not be
nested in describe
blocks or as steps of other Deno.test
cases.
Since your test runs in an isolated Deno process, it will not be aware of other snapshots in your test file. If you assert snapshots across multiple tests, only the last tests snapshots will be captured. The solution is to manually override the snapshot file name to be unique per test.
Deno for whatever reason doesn't allow us to override the Error.stack
property. In order to ensure useful stack traces in our tests, we manually
append the stack trace to the error message. This ensures stack traces are
reported properly in tests, but it means that the message includes the stack
trace.