From 9cc7e32e37e6708980abc051f2cb71526c175d88 Mon Sep 17 00:00:00 2001 From: Casper Beyer Date: Wed, 24 Feb 2021 20:55:50 +0800 Subject: feat: add exit sanitizer to Deno.test (#9529) This adds an exit sanitizer to ensure that code being tested or dependencies of that code can't accidentally call "Deno.exit" leading to partial test runs and false results. --- docs/testing.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'docs') diff --git a/docs/testing.md b/docs/testing.md index 8df183a34..9b53c4c82 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -92,6 +92,31 @@ Deno.test({ }); ``` +### Exit sanitizer + +There's also the exit sanitizer which ensures that tested code doesn't call +Deno.exit() signaling a false test success. + +This is enabled by default for all tests, but can be disabled by setting the +`sanitizeExit` boolean to false in thetest definition. + +```ts +Deno.test({ + name: "false success", + fn() { + Deno.exit(0); + }, + sanitizeExit: false, +}); + +Deno.test({ + name: "failing test", + fn() { + throw new Error("this test fails"); + }, +}); +``` + ## Running tests To run the test, call `deno test` with the file that contains your test -- cgit v1.2.3