diff options
Diffstat (limited to 'tests/specs')
291 files changed, 3776 insertions, 1 deletions
diff --git a/tests/specs/test/aggregate_error/__test__.jsonc b/tests/specs/test/aggregate_error/__test__.jsonc new file mode 100644 index 000000000..a02376f87 --- /dev/null +++ b/tests/specs/test/aggregate_error/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test --quiet main.ts", + "exitCode": 1, + "output": "main.out" +} diff --git a/tests/specs/test/aggregate_error/main.out b/tests/specs/test/aggregate_error/main.out new file mode 100644 index 000000000..aa790e550 --- /dev/null +++ b/tests/specs/test/aggregate_error/main.out @@ -0,0 +1,22 @@ +running 1 test from ./main.ts +aggregate ... FAILED ([WILDCARD]) + + ERRORS + +aggregate => ./main.ts:[WILDCARD] +error: AggregateError + Error: Error 1 + at [WILDCARD]/main.ts:2:18 + Error: Error 2 + at [WILDCARD]/main.ts:3:18 + throw new AggregateError([error1, error2]); + ^ + at [WILDCARD]/main.ts:5:9 + + FAILURES + +aggregate => ./main.ts:[WILDCARD] + +FAILED | 0 passed | 1 failed ([WILDCARD]) + +error: Test failed diff --git a/tests/specs/test/aggregate_error/main.ts b/tests/specs/test/aggregate_error/main.ts new file mode 100644 index 000000000..0661ea249 --- /dev/null +++ b/tests/specs/test/aggregate_error/main.ts @@ -0,0 +1,6 @@ +Deno.test("aggregate", function () { + const error1 = new Error("Error 1"); + const error2 = new Error("Error 2"); + + throw new AggregateError([error1, error2]); +}); diff --git a/tests/specs/test/allow_all/__test__.jsonc b/tests/specs/test/allow_all/__test__.jsonc new file mode 100644 index 000000000..badffe7c4 --- /dev/null +++ b/tests/specs/test/allow_all/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test --config deno.json --allow-all main.ts", + "exitCode": 0, + "output": "main.out" +} diff --git a/tests/specs/test/allow_all/deno.json b/tests/specs/test/allow_all/deno.json new file mode 100644 index 000000000..105514e13 --- /dev/null +++ b/tests/specs/test/allow_all/deno.json @@ -0,0 +1,4 @@ +{ + "lock": false, + "importMap": "../../../../import_map.json" +} diff --git a/tests/specs/test/allow_all/main.out b/tests/specs/test/allow_all/main.out new file mode 100644 index 000000000..b3bf5275f --- /dev/null +++ b/tests/specs/test/allow_all/main.out @@ -0,0 +1,16 @@ +[WILDCARD] +running 12 tests from [WILDCARD] +read false ... ok [WILDCARD] +read true ... ok [WILDCARD] +write false ... ok [WILDCARD] +write true ... ok [WILDCARD] +net false ... ok [WILDCARD] +net true ... ok [WILDCARD] +env false ... ok [WILDCARD] +env true ... ok [WILDCARD] +run false ... ok [WILDCARD] +run true ... ok [WILDCARD] +ffi false ... ok [WILDCARD] +ffi true ... ok [WILDCARD] + +ok | 12 passed | 0 failed [WILDCARD] diff --git a/tests/specs/test/allow_all/main.ts b/tests/specs/test/allow_all/main.ts new file mode 100644 index 000000000..7faa58c61 --- /dev/null +++ b/tests/specs/test/allow_all/main.ts @@ -0,0 +1,42 @@ +import { assertEquals } from "@std/assert"; + +const permissions: Deno.PermissionName[] = [ + "read", + "write", + "net", + "env", + "run", + "ffi", +]; + +for (const name of permissions) { + Deno.test({ + name: `${name} false`, + permissions: { + [name]: false, + }, + async fn() { + for await (const n of permissions) { + const status = await Deno.permissions.query({ name: n }); + assertEquals(status.state, "prompt"); + } + }, + }); + + Deno.test({ + name: `${name} true`, + permissions: { + [name]: true, + }, + async fn() { + for await (const n of permissions) { + const status = await Deno.permissions.query({ name: n }); + if (n === name) { + assertEquals(status.state, "granted"); + } else { + assertEquals(status.state, "prompt"); + } + } + }, + }); +} diff --git a/tests/specs/test/allow_none/__test__.jsonc b/tests/specs/test/allow_none/__test__.jsonc new file mode 100644 index 000000000..5e21e8943 --- /dev/null +++ b/tests/specs/test/allow_none/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test --config deno.json main.ts", + "exitCode": 1, + "output": "main.out" +} diff --git a/tests/specs/test/allow_none/deno.json b/tests/specs/test/allow_none/deno.json new file mode 100644 index 000000000..105514e13 --- /dev/null +++ b/tests/specs/test/allow_none/deno.json @@ -0,0 +1,4 @@ +{ + "lock": false, + "importMap": "../../../../import_map.json" +} diff --git a/tests/specs/test/allow_none/main.out b/tests/specs/test/allow_none/main.out new file mode 100644 index 000000000..1914997cd --- /dev/null +++ b/tests/specs/test/allow_none/main.out @@ -0,0 +1,45 @@ +[WILDCARD] +running 6 tests from [WILDCARD] +read ... FAILED [WILDCARD] +write ... FAILED [WILDCARD] +net ... FAILED [WILDCARD] +env ... FAILED [WILDCARD] +run ... FAILED [WILDCARD] +ffi ... FAILED [WILDCARD] + + ERRORS + +read => ./main.ts:[WILDCARD] +error: NotCapable: Can't escalate parent thread permissions +[WILDCARD] + +write => ./main.ts:[WILDCARD] +error: NotCapable: Can't escalate parent thread permissions +[WILDCARD] + +net => ./main.ts:[WILDCARD] +error: NotCapable: Can't escalate parent thread permissions +[WILDCARD] + +env => ./main.ts:[WILDCARD] +error: NotCapable: Can't escalate parent thread permissions +[WILDCARD] + +run => ./main.ts:[WILDCARD] +error: NotCapable: Can't escalate parent thread permissions +[WILDCARD] + +ffi => ./main.ts:[WILDCARD] +error: NotCapable: Can't escalate parent thread permissions +[WILDCARD] + + FAILURES + +read => ./main.ts:[WILDCARD] +write => ./main.ts:[WILDCARD] +net => ./main.ts:[WILDCARD] +env => ./main.ts:[WILDCARD] +run => ./main.ts:[WILDCARD] +ffi => ./main.ts:[WILDCARD] + +FAILED | 0 passed | 6 failed [WILDCARD] diff --git a/tests/specs/test/allow_none/main.ts b/tests/specs/test/allow_none/main.ts new file mode 100644 index 000000000..e59a30c4d --- /dev/null +++ b/tests/specs/test/allow_none/main.ts @@ -0,0 +1,22 @@ +import { unreachable } from "@std/assert"; + +const permissions: Deno.PermissionName[] = [ + "read", + "write", + "net", + "env", + "run", + "ffi", +]; + +for (const name of permissions) { + Deno.test({ + name, + permissions: { + [name]: true, + }, + fn() { + unreachable(); + }, + }); +} diff --git a/tests/specs/test/before_unload_prevent_default/__test__.jsonc b/tests/specs/test/before_unload_prevent_default/__test__.jsonc new file mode 100644 index 000000000..602250082 --- /dev/null +++ b/tests/specs/test/before_unload_prevent_default/__test__.jsonc @@ -0,0 +1,4 @@ +{ + "args": "test --quiet main.ts", + "output": "main.out" +} diff --git a/tests/specs/test/before_unload_prevent_default/main.out b/tests/specs/test/before_unload_prevent_default/main.out new file mode 100644 index 000000000..9ccad312d --- /dev/null +++ b/tests/specs/test/before_unload_prevent_default/main.out @@ -0,0 +1,5 @@ +running 1 test from [WILDCARD]/main.ts +foo ... ok ([WILDCARD]) + +ok | 1 passed | 0 failed ([WILDCARD]) + diff --git a/tests/specs/test/before_unload_prevent_default/main.ts b/tests/specs/test/before_unload_prevent_default/main.ts new file mode 100644 index 000000000..421ded520 --- /dev/null +++ b/tests/specs/test/before_unload_prevent_default/main.ts @@ -0,0 +1,6 @@ +addEventListener("beforeunload", (e) => { + // The worker should be killed once tests are done regardless of this. + e.preventDefault(); +}); + +Deno.test("foo", () => {}); diff --git a/tests/specs/test/captured_output/__test__.jsonc b/tests/specs/test/captured_output/__test__.jsonc new file mode 100644 index 000000000..d620f61aa --- /dev/null +++ b/tests/specs/test/captured_output/__test__.jsonc @@ -0,0 +1,6 @@ +{ + "args": "test --allow-run --allow-read captured_output.ts", + "output": "main.out", + "envs": { "NO_COLOR": "1" }, + "exitCode": 0 +} diff --git a/tests/specs/test/captured_output/captured_output.ts b/tests/specs/test/captured_output/captured_output.ts new file mode 100644 index 000000000..77e1d1b08 --- /dev/null +++ b/tests/specs/test/captured_output/captured_output.ts @@ -0,0 +1,33 @@ +Deno.test("output", async () => { + await new Deno.Command(Deno.execPath(), { + args: ["eval", "console.log(0); console.error(1);"], + }).spawn().status; + new Deno.Command(Deno.execPath(), { + args: ["eval", "console.log(2); console.error(3);"], + stdout: "inherit", + stderr: "inherit", + }).outputSync(); + await new Deno.Command(Deno.execPath(), { + args: ["eval", "console.log(4); console.error(5);"], + stdout: "inherit", + stderr: "inherit", + }).output(); + const c = new Deno.Command(Deno.execPath(), { + args: ["eval", "console.log(6); console.error(7);"], + stdout: "inherit", + stderr: "inherit", + }).spawn(); + await c.status; + const worker = new Worker( + import.meta.resolve("./captured_output.worker.ts"), + { type: "module" }, + ); + + // ensure worker output is captured + const response = new Promise<void>((resolve) => + worker.onmessage = () => resolve() + ); + worker.postMessage({}); + await response; + worker.terminate(); +}); diff --git a/tests/specs/test/captured_output/captured_output.worker.ts b/tests/specs/test/captured_output/captured_output.worker.ts new file mode 100644 index 000000000..f49f26880 --- /dev/null +++ b/tests/specs/test/captured_output/captured_output.worker.ts @@ -0,0 +1,6 @@ +self.onmessage = () => { + console.log(8); + console.error(9); + self.postMessage({}); + self.close(); +}; diff --git a/tests/specs/test/captured_output/main.out b/tests/specs/test/captured_output/main.out new file mode 100644 index 000000000..ba313beaf --- /dev/null +++ b/tests/specs/test/captured_output/main.out @@ -0,0 +1,22 @@ +Check [WILDCARD]/captured_output.ts +running 1 test from ./captured_output.ts +output ... +------- output ------- +[UNORDERED_START] +1 +0 +3 +2 +5 +4 +7 +6 +Check [WILDLINE]/captured_output.worker.ts +9 +8 +[UNORDERED_END] +----- output end ----- +output ... ok ([WILDCARD]) + +ok | 1 passed | 0 failed ([WILDCARD]) + diff --git a/tests/specs/test/check_local_by_default/__test__.jsonc b/tests/specs/test/check_local_by_default/__test__.jsonc new file mode 100644 index 000000000..602250082 --- /dev/null +++ b/tests/specs/test/check_local_by_default/__test__.jsonc @@ -0,0 +1,4 @@ +{ + "args": "test --quiet main.ts", + "output": "main.out" +} diff --git a/tests/specs/test/check_local_by_default/main.out b/tests/specs/test/check_local_by_default/main.out new file mode 100644 index 000000000..be21aa963 --- /dev/null +++ b/tests/specs/test/check_local_by_default/main.out @@ -0,0 +1,4 @@ +running 0 tests from ./main.ts + +ok | 0 passed | 0 failed ([WILDCARD]) + diff --git a/tests/specs/test/check_local_by_default/main.ts b/tests/specs/test/check_local_by_default/main.ts new file mode 100644 index 000000000..2ae8c2692 --- /dev/null +++ b/tests/specs/test/check_local_by_default/main.ts @@ -0,0 +1,3 @@ +import * as a from "http://localhost:4545/subdir/type_error.ts"; + +console.log(a.a); diff --git a/tests/specs/test/check_local_by_default2/__test__.jsonc b/tests/specs/test/check_local_by_default2/__test__.jsonc new file mode 100644 index 000000000..59774f938 --- /dev/null +++ b/tests/specs/test/check_local_by_default2/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test --quiet main.ts", + "output": "main.out", + "exitCode": 1 +} diff --git a/tests/specs/test/check_local_by_default2/main.out b/tests/specs/test/check_local_by_default2/main.out new file mode 100644 index 000000000..5b145afd2 --- /dev/null +++ b/tests/specs/test/check_local_by_default2/main.out @@ -0,0 +1,4 @@ +error: TS2322 [ERROR]: Type '12' is not assignable to type '"b"'. +const b: "b" = 12; + ^ + at [WILDCARD]/main.ts:3:7 diff --git a/tests/specs/test/check_local_by_default2/main.ts b/tests/specs/test/check_local_by_default2/main.ts new file mode 100644 index 000000000..5177ff944 --- /dev/null +++ b/tests/specs/test/check_local_by_default2/main.ts @@ -0,0 +1,6 @@ +import * as a from "http://localhost:4545/subdir/type_error.ts"; + +const b: "b" = 12; + +console.log(a.a); +console.log(b); diff --git a/tests/specs/test/clean_flag/__test__.jsonc b/tests/specs/test/clean_flag/__test__.jsonc index b94612d36..6283a44e1 100644 --- a/tests/specs/test/clean_flag/__test__.jsonc +++ b/tests/specs/test/clean_flag/__test__.jsonc @@ -1,5 +1,5 @@ { - "args": "run -A --config ../../../config/deno.json main.js", + "args": "run -A --config deno.json main.js", "exitCode": 0, "output": "main.out" } diff --git a/tests/specs/test/clean_flag/deno.json b/tests/specs/test/clean_flag/deno.json new file mode 100644 index 000000000..105514e13 --- /dev/null +++ b/tests/specs/test/clean_flag/deno.json @@ -0,0 +1,4 @@ +{ + "lock": false, + "importMap": "../../../../import_map.json" +} diff --git a/tests/specs/test/clear_timeout/__test__.jsonc b/tests/specs/test/clear_timeout/__test__.jsonc new file mode 100644 index 000000000..d7ed453a9 --- /dev/null +++ b/tests/specs/test/clear_timeout/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test main.ts", + "exitCode": 0, + "output": "main.out" +} diff --git a/tests/specs/test/clear_timeout/main.out b/tests/specs/test/clear_timeout/main.out new file mode 100644 index 000000000..be639f728 --- /dev/null +++ b/tests/specs/test/clear_timeout/main.out @@ -0,0 +1,8 @@ +Check [WILDCARD]/main.ts +running 3 tests from ./main.ts +test 1 ... ok ([WILDCARD]) +test 2 ... ok ([WILDCARD]) +test 3 ... ok ([WILDCARD]) + +ok | 3 passed | 0 failed ([WILDCARD]) + diff --git a/tests/specs/test/clear_timeout/main.ts b/tests/specs/test/clear_timeout/main.ts new file mode 100644 index 000000000..00056e853 --- /dev/null +++ b/tests/specs/test/clear_timeout/main.ts @@ -0,0 +1,5 @@ +clearTimeout(setTimeout(() => {}, 1000)); + +Deno.test("test 1", () => {}); +Deno.test("test 2", () => {}); +Deno.test("test 3", () => {}); diff --git a/tests/specs/test/collect/__test__.jsonc b/tests/specs/test/collect/__test__.jsonc new file mode 100644 index 000000000..3a45c41a4 --- /dev/null +++ b/tests/specs/test/collect/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test --ignore=collect/ignore collect", + "exitCode": 0, + "output": "main.out" +} diff --git a/tests/specs/test/collect/collect/deno.jsonc b/tests/specs/test/collect/collect/deno.jsonc new file mode 100644 index 000000000..e14ce86da --- /dev/null +++ b/tests/specs/test/collect/collect/deno.jsonc @@ -0,0 +1,5 @@ +{ + "test": { + "exclude": ["./ignore"] + } +} diff --git a/tests/specs/test/collect/collect/deno.malformed.jsonc b/tests/specs/test/collect/collect/deno.malformed.jsonc new file mode 100644 index 000000000..f2d8cbc65 --- /dev/null +++ b/tests/specs/test/collect/collect/deno.malformed.jsonc @@ -0,0 +1,5 @@ +{ + "test": { + "dont_know_this_field": {} + } +} diff --git a/tests/specs/test/collect/collect/deno2.jsonc b/tests/specs/test/collect/collect/deno2.jsonc new file mode 100644 index 000000000..b7af09d1c --- /dev/null +++ b/tests/specs/test/collect/collect/deno2.jsonc @@ -0,0 +1,6 @@ +{ + "test": { + "include": ["./include/"], + "exclude": ["./ignore", "./include/2_test.ts"] + } +} diff --git a/tests/specs/test/collect/collect/ignore/test.ts b/tests/specs/test/collect/collect/ignore/test.ts new file mode 100644 index 000000000..16fb63ba7 --- /dev/null +++ b/tests/specs/test/collect/collect/ignore/test.ts @@ -0,0 +1 @@ +throw new Error("this module should be ignored"); diff --git a/tests/specs/test/collect/collect/include.ts b/tests/specs/test/collect/collect/include.ts new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/specs/test/collect/collect/include.ts diff --git a/tests/specs/test/collect/collect/include/2_test.ts b/tests/specs/test/collect/collect/include/2_test.ts new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/specs/test/collect/collect/include/2_test.ts diff --git a/tests/specs/test/collect/collect/include/test.ts b/tests/specs/test/collect/collect/include/test.ts new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/specs/test/collect/collect/include/test.ts diff --git a/tests/specs/test/collect/collect/test.ts b/tests/specs/test/collect/collect/test.ts new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/specs/test/collect/collect/test.ts diff --git a/tests/specs/test/collect/main.out b/tests/specs/test/collect/main.out new file mode 100644 index 000000000..13a76fc37 --- /dev/null +++ b/tests/specs/test/collect/main.out @@ -0,0 +1,9 @@ +Check [WILDCARD]/collect/include/2_test.ts +Check [WILDCARD]/collect/include/test.ts +Check [WILDCARD]/collect/test.ts +running 0 tests from [WILDCARD]/collect/include/2_test.ts +running 0 tests from [WILDCARD]/collect/include/test.ts +running 0 tests from [WILDCARD]/collect/test.ts + +ok | 0 passed | 0 failed ([WILDCARD]) + diff --git a/tests/specs/test/doc/__test__.jsonc b/tests/specs/test/doc/__test__.jsonc new file mode 100644 index 000000000..095ab4c59 --- /dev/null +++ b/tests/specs/test/doc/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test --doc --allow-all main.ts", + "exitCode": 1, + "output": "main.out" +} diff --git a/tests/specs/test/doc/main.out b/tests/specs/test/doc/main.out new file mode 100644 index 000000000..b55989f96 --- /dev/null +++ b/tests/specs/test/doc/main.out @@ -0,0 +1,9 @@ +Check [WILDCARD]/main.ts$6-9.js +Check [WILDCARD]/main.ts$10-13.jsx +Check [WILDCARD]/main.ts$14-17.ts +Check [WILDCARD]/main.ts$18-21.tsx +Check [WILDCARD]/main.ts$30-35.ts +error: TS2367 [ERROR]: This comparison appears to be unintentional because the types 'string' and 'number' have no overlap. +console.assert(check() == 42); + ~~~~~~~~~~~~~ + at [WILDCARD]/main.ts$30-35.ts:3:16 diff --git a/tests/specs/test/doc/main.ts b/tests/specs/test/doc/main.ts new file mode 100644 index 000000000..213a9f44d --- /dev/null +++ b/tests/specs/test/doc/main.ts @@ -0,0 +1,38 @@ +/** + * ``` + * import * as doc from "./main.ts"; + * ``` + * + * ```js + * import * as doc from "./main.ts"; + * ``` + * + * ```jsx + * import * as doc from "./main.ts"; + * ``` + * + * ```ts + * import * as doc from "./main.ts"; + * ``` + * + * ```tsx + * import * as doc from "./main.ts"; + * ``` + * + * ```text + * import * as doc from "./main.ts"; + * ``` + * + * @module doc + */ + +/** + * ```ts + * import { check } from "./main.ts"; + * + * console.assert(check() == 42); + * ``` + */ +export function check(): string { + return "check"; +} diff --git a/tests/specs/test/doc_only/__test__.jsonc b/tests/specs/test/doc_only/__test__.jsonc new file mode 100644 index 000000000..077b733a3 --- /dev/null +++ b/tests/specs/test/doc_only/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test --doc --allow-all doc_only", + "exitCode": 0, + "output": "main.out" +} diff --git a/tests/specs/test/doc_only/doc_only/mod.ts b/tests/specs/test/doc_only/doc_only/mod.ts new file mode 100644 index 000000000..467d850a2 --- /dev/null +++ b/tests/specs/test/doc_only/doc_only/mod.ts @@ -0,0 +1,10 @@ +/** + * ```ts + * import "./mod.ts"; + * ``` + */ +Deno.test("unreachable", function () { + throw new Error( + "modules that don't end with _test are scanned for documentation tests only should not be executed", + ); +}); diff --git a/tests/specs/test/doc_only/main.out b/tests/specs/test/doc_only/main.out new file mode 100644 index 000000000..a2eff5e89 --- /dev/null +++ b/tests/specs/test/doc_only/main.out @@ -0,0 +1,4 @@ +Check [WILDCARD]/doc_only/mod.ts$2-5.ts + +ok | 0 passed | 0 failed ([WILDCARD]) + diff --git a/tests/specs/test/exit_sanitizer/__test__.jsonc b/tests/specs/test/exit_sanitizer/__test__.jsonc new file mode 100644 index 000000000..79d075d67 --- /dev/null +++ b/tests/specs/test/exit_sanitizer/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test exit_sanitizer.ts", + "output": "exit_sanitizer.out", + "exitCode": 1 +} diff --git a/tests/specs/test/exit_sanitizer/exit_sanitizer.out b/tests/specs/test/exit_sanitizer/exit_sanitizer.out new file mode 100644 index 000000000..305d51cc8 --- /dev/null +++ b/tests/specs/test/exit_sanitizer/exit_sanitizer.out @@ -0,0 +1,38 @@ +Check [WILDCARD]/exit_sanitizer.ts +running 3 tests from [WILDCARD]/exit_sanitizer.ts +exit(0) ... FAILED ([WILDCARD]) +exit(1) ... FAILED ([WILDCARD]) +exit(2) ... FAILED ([WILDCARD]) + + ERRORS + +exit(0) => [WILDCARD]/exit_sanitizer.ts:[WILDCARD] +error: Error: Test case attempted to exit with exit code: 0 + Deno.exit(0); + ^ + at [WILDCARD] + at [WILDCARD]/exit_sanitizer.ts:2:8 + +exit(1) => [WILDCARD]/exit_sanitizer.ts:[WILDCARD] +error: Error: Test case attempted to exit with exit code: 1 + Deno.exit(1); + ^ + at [WILDCARD] + at [WILDCARD]/exit_sanitizer.ts:6:8 + +exit(2) => [WILDCARD]/exit_sanitizer.ts:[WILDCARD] +error: Error: Test case attempted to exit with exit code: 2 + Deno.exit(2); + ^ + at [WILDCARD] + at [WILDCARD]/exit_sanitizer.ts:10:8 + + FAILURES + +exit(0) => [WILDCARD]/exit_sanitizer.ts:[WILDCARD] +exit(1) => [WILDCARD]/exit_sanitizer.ts:[WILDCARD] +exit(2) => [WILDCARD]/exit_sanitizer.ts:[WILDCARD] + +FAILED | 0 passed | 3 failed ([WILDCARD]) + +error: Test failed diff --git a/tests/specs/test/exit_sanitizer/exit_sanitizer.ts b/tests/specs/test/exit_sanitizer/exit_sanitizer.ts new file mode 100644 index 000000000..186406a9d --- /dev/null +++ b/tests/specs/test/exit_sanitizer/exit_sanitizer.ts @@ -0,0 +1,11 @@ +Deno.test("exit(0)", function () { + Deno.exit(0); +}); + +Deno.test("exit(1)", function () { + Deno.exit(1); +}); + +Deno.test("exit(2)", function () { + Deno.exit(2); +}); diff --git a/tests/specs/test/fail/__test__.jsonc b/tests/specs/test/fail/__test__.jsonc new file mode 100644 index 000000000..2c4ae3868 --- /dev/null +++ b/tests/specs/test/fail/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test main.ts", + "exitCode": 1, + "output": "main.out" +} diff --git a/tests/specs/test/fail/main.out b/tests/specs/test/fail/main.out new file mode 100644 index 000000000..e305f93bd --- /dev/null +++ b/tests/specs/test/fail/main.out @@ -0,0 +1,91 @@ +Check [WILDCARD]/main.ts +running 10 tests from ./main.ts +test 0 ... FAILED ([WILDCARD]) +test 1 ... FAILED ([WILDCARD]) +test 2 ... FAILED ([WILDCARD]) +test 3 ... FAILED ([WILDCARD]) +test 4 ... FAILED ([WILDCARD]) +test 5 ... FAILED ([WILDCARD]) +test 6 ... FAILED ([WILDCARD]) +test 7 ... FAILED ([WILDCARD]) +test 8 ... FAILED ([WILDCARD]) +test 9 ... FAILED ([WILDCARD]) + + ERRORS + +test 0 => ./main.ts:1:6 +error: Error + throw new Error(); + ^ + at [WILDCARD]/main.ts:2:9 + +test 1 => ./main.ts:4:6 +error: Error + throw new Error(); + ^ + at [WILDCARD]/main.ts:5:9 + +test 2 => ./main.ts:7:6 +error: Error + throw new Error(); + ^ + at [WILDCARD]/main.ts:8:9 + +test 3 => ./main.ts:10:6 +error: Error + throw new Error(); + ^ + at [WILDCARD]/main.ts:11:9 + +test 4 => ./main.ts:13:6 +error: Error + throw new Error(); + ^ + at [WILDCARD]/main.ts:14:9 + +test 5 => ./main.ts:16:6 +error: Error + throw new Error(); + ^ + at [WILDCARD]/main.ts:17:9 + +test 6 => ./main.ts:19:6 +error: Error + throw new Error(); + ^ + at [WILDCARD]/main.ts:20:9 + +test 7 => ./main.ts:22:6 +error: Error + throw new Error(); + ^ + at [WILDCARD]/main.ts:23:9 + +test 8 => ./main.ts:25:6 +error: Error + throw new Error(); + ^ + at [WILDCARD]/main.ts:26:9 + +test 9 => ./main.ts:28:6 +error: Error + throw new Error(); + ^ + at [WILDCARD]/main.ts:29:9 + + FAILURES + +test 0 => ./main.ts:1:6 +test 1 => ./main.ts:4:6 +test 2 => ./main.ts:7:6 +test 3 => ./main.ts:10:6 +test 4 => ./main.ts:13:6 +test 5 => ./main.ts:16:6 +test 6 => ./main.ts:19:6 +test 7 => ./main.ts:22:6 +test 8 => ./main.ts:25:6 +test 9 => ./main.ts:28:6 + +FAILED | 0 passed | 10 failed ([WILDCARD]) + +error: Test failed diff --git a/tests/specs/test/fail/main.ts b/tests/specs/test/fail/main.ts new file mode 100644 index 000000000..9340db556 --- /dev/null +++ b/tests/specs/test/fail/main.ts @@ -0,0 +1,30 @@ +Deno.test("test 0", () => { + throw new Error(); +}); +Deno.test("test 1", () => { + throw new Error(); +}); +Deno.test("test 2", () => { + throw new Error(); +}); +Deno.test("test 3", () => { + throw new Error(); +}); +Deno.test("test 4", () => { + throw new Error(); +}); +Deno.test("test 5", () => { + throw new Error(); +}); +Deno.test("test 6", () => { + throw new Error(); +}); +Deno.test("test 7", () => { + throw new Error(); +}); +Deno.test("test 8", () => { + throw new Error(); +}); +Deno.test("test 9", () => { + throw new Error(); +}); diff --git a/tests/specs/test/fail_fast/__test__.jsonc b/tests/specs/test/fail_fast/__test__.jsonc new file mode 100644 index 000000000..a819df39f --- /dev/null +++ b/tests/specs/test/fail_fast/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test --fail-fast fail_fast.ts fail_fast_other.ts", + "exitCode": 1, + "output": "fail_fast.out" +} diff --git a/tests/specs/test/fail_fast/fail_fast.out b/tests/specs/test/fail_fast/fail_fast.out new file mode 100644 index 000000000..164c9c6a6 --- /dev/null +++ b/tests/specs/test/fail_fast/fail_fast.out @@ -0,0 +1,20 @@ +Check [WILDCARD]/fail_fast.ts +Check [WILDCARD]/fail_fast_other.ts +running 10 tests from ./fail_fast.ts +test 1 ... FAILED ([WILDCARD]) + + ERRORS + +test 1 => ./fail_fast.ts:[WILDCARD] +error: Error + throw new Error(); + ^ + at [WILDCARD]/fail_fast.ts:2:9 + + FAILURES + +test 1 => ./fail_fast.ts:[WILDCARD] + +FAILED | 0 passed | 1 failed ([WILDCARD]) + +error: Test failed diff --git a/tests/specs/test/fail_fast/fail_fast.ts b/tests/specs/test/fail_fast/fail_fast.ts new file mode 100644 index 000000000..637e825ec --- /dev/null +++ b/tests/specs/test/fail_fast/fail_fast.ts @@ -0,0 +1,30 @@ +Deno.test("test 1", () => { + throw new Error(); +}); +Deno.test("test 2", () => { + throw new Error(); +}); +Deno.test("test 3", () => { + throw new Error(); +}); +Deno.test("test 4", () => { + throw new Error(); +}); +Deno.test("test 5", () => { + throw new Error(); +}); +Deno.test("test 6", () => { + throw new Error(); +}); +Deno.test("test 7", () => { + throw new Error(); +}); +Deno.test("test 8", () => { + throw new Error(); +}); +Deno.test("test 9", () => { + throw new Error(); +}); +Deno.test("test 0", () => { + throw new Error(); +}); diff --git a/tests/specs/test/fail_fast/fail_fast_other.ts b/tests/specs/test/fail_fast/fail_fast_other.ts new file mode 100644 index 000000000..02aa878cf --- /dev/null +++ b/tests/specs/test/fail_fast/fail_fast_other.ts @@ -0,0 +1,3 @@ +Deno.test("test 11", () => { + throw new Error(); +}); diff --git a/tests/specs/test/fail_with_contain_unicode_filename/__test__.jsonc b/tests/specs/test/fail_with_contain_unicode_filename/__test__.jsonc new file mode 100644 index 000000000..d8887f753 --- /dev/null +++ b/tests/specs/test/fail_with_contain_unicode_filename/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test main.ts", + "output": "main.out", + "exitCode": 1 +} diff --git a/tests/specs/test/fail_with_contain_unicode_filename/main.out b/tests/specs/test/fail_with_contain_unicode_filename/main.out new file mode 100644 index 000000000..5cea77dc0 --- /dev/null +++ b/tests/specs/test/fail_with_contain_unicode_filename/main.out @@ -0,0 +1,19 @@ +Check [WILDCARD]/main.ts +running 1 test from ./main.ts +test 0 ... FAILED ([WILDCARD]) + + ERRORS + +test 0 => ./main.ts:[WILDCARD] +error: Error + throw new Error(); + ^ + at [WILDCARD]/main.ts:[WILDCARD] + + FAILURES + +test 0 => ./main.ts:[WILDCARD] + +FAILED | 0 passed | 1 failed ([WILDCARD]) + +error: Test failed diff --git a/tests/specs/test/fail_with_contain_unicode_filename/main.ts b/tests/specs/test/fail_with_contain_unicode_filename/main.ts new file mode 100644 index 000000000..9fe04c131 --- /dev/null +++ b/tests/specs/test/fail_with_contain_unicode_filename/main.ts @@ -0,0 +1,3 @@ +Deno.test("test 0", () => { + throw new Error(); +}); diff --git a/tests/specs/test/file_protocol/__test__.jsonc b/tests/specs/test/file_protocol/__test__.jsonc new file mode 100644 index 000000000..931a8c64e --- /dev/null +++ b/tests/specs/test/file_protocol/__test__.jsonc @@ -0,0 +1,4 @@ +{ + "args": "test main.ts", + "output": "main.out" +} diff --git a/tests/specs/test/file_protocol/main.out b/tests/specs/test/file_protocol/main.out new file mode 100644 index 000000000..d02b728d1 --- /dev/null +++ b/tests/specs/test/file_protocol/main.out @@ -0,0 +1,6 @@ +Check file://[WILDCARD]/main.ts +running 1 test from ./main.ts +test 0 ... ok ([WILDCARD]) + +ok | 1 passed | 0 failed ([WILDCARD]) + diff --git a/tests/specs/test/file_protocol/main.ts b/tests/specs/test/file_protocol/main.ts new file mode 100644 index 000000000..79128c2b3 --- /dev/null +++ b/tests/specs/test/file_protocol/main.ts @@ -0,0 +1 @@ +Deno.test("test 0", () => {}); diff --git a/tests/specs/test/filter/__test__.jsonc b/tests/specs/test/filter/__test__.jsonc new file mode 100644 index 000000000..b7c1bb9fe --- /dev/null +++ b/tests/specs/test/filter/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test --filter=foo filter", + "exitCode": 0, + "output": "main.out" +} diff --git a/tests/specs/test/filter/filter/a_test.ts b/tests/specs/test/filter/filter/a_test.ts new file mode 100644 index 000000000..a3f32968a --- /dev/null +++ b/tests/specs/test/filter/filter/a_test.ts @@ -0,0 +1,3 @@ +Deno.test("foo", function () {}); +Deno.test("bar", function () {}); +Deno.test("baz", function () {}); diff --git a/tests/specs/test/filter/filter/b_test.ts b/tests/specs/test/filter/filter/b_test.ts new file mode 100644 index 000000000..a3f32968a --- /dev/null +++ b/tests/specs/test/filter/filter/b_test.ts @@ -0,0 +1,3 @@ +Deno.test("foo", function () {}); +Deno.test("bar", function () {}); +Deno.test("baz", function () {}); diff --git a/tests/specs/test/filter/filter/c_test.ts b/tests/specs/test/filter/filter/c_test.ts new file mode 100644 index 000000000..a3f32968a --- /dev/null +++ b/tests/specs/test/filter/filter/c_test.ts @@ -0,0 +1,3 @@ +Deno.test("foo", function () {}); +Deno.test("bar", function () {}); +Deno.test("baz", function () {}); diff --git a/tests/specs/test/filter/main.out b/tests/specs/test/filter/main.out new file mode 100644 index 000000000..605214b8e --- /dev/null +++ b/tests/specs/test/filter/main.out @@ -0,0 +1,12 @@ +Check [WILDCARD]/filter/a_test.ts +Check [WILDCARD]/filter/b_test.ts +Check [WILDCARD]/filter/c_test.ts +running 1 test from [WILDCARD]/filter/a_test.ts +foo ... ok ([WILDCARD]) +running 1 test from [WILDCARD]/filter/b_test.ts +foo ... ok ([WILDCARD]) +running 1 test from [WILDCARD]/filter/c_test.ts +foo ... ok ([WILDCARD]) + +ok | 3 passed | 0 failed | 6 filtered out ([WILDCARD]) + diff --git a/tests/specs/test/finally_timeout/__test__.jsonc b/tests/specs/test/finally_timeout/__test__.jsonc new file mode 100644 index 000000000..2c4ae3868 --- /dev/null +++ b/tests/specs/test/finally_timeout/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test main.ts", + "exitCode": 1, + "output": "main.out" +} diff --git a/tests/specs/test/finally_timeout/main.out b/tests/specs/test/finally_timeout/main.out new file mode 100644 index 000000000..cdc081f47 --- /dev/null +++ b/tests/specs/test/finally_timeout/main.out @@ -0,0 +1,20 @@ +Check [WILDCARD]/main.ts +running 2 tests from ./main.ts +error ... FAILED ([WILDCARD]) +success ... ok ([WILDCARD]) + + ERRORS + +error => ./main.ts:[WILDCARD] +error: Error: fail + throw new Error("fail"); + ^ + at [WILDCARD]/main.ts:4:11 + + FAILURES + +error => ./main.ts:[WILDCARD] + +FAILED | 1 passed | 1 failed ([WILDCARD]) + +error: Test failed diff --git a/tests/specs/test/finally_timeout/main.ts b/tests/specs/test/finally_timeout/main.ts new file mode 100644 index 000000000..dcc0a4d64 --- /dev/null +++ b/tests/specs/test/finally_timeout/main.ts @@ -0,0 +1,11 @@ +Deno.test("error", function () { + const timer = setTimeout(() => null, 10000); + try { + throw new Error("fail"); + } finally { + clearTimeout(timer); + } +}); + +Deno.test("success", function () { +}); diff --git a/tests/specs/test/hide_empty_suites/__test__.jsonc b/tests/specs/test/hide_empty_suites/__test__.jsonc new file mode 100644 index 000000000..4abef9205 --- /dev/null +++ b/tests/specs/test/hide_empty_suites/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test --filter none main.ts", + "exitCode": 0, + "output": "main.out" +} diff --git a/tests/specs/test/hide_empty_suites/main.out b/tests/specs/test/hide_empty_suites/main.out new file mode 100644 index 000000000..bfc30e084 --- /dev/null +++ b/tests/specs/test/hide_empty_suites/main.out @@ -0,0 +1,4 @@ +Check [WILDCARD]/main.ts + +ok | 0 passed | 0 failed | 16 filtered out ([WILDCARD]) + diff --git a/tests/specs/test/hide_empty_suites/main.ts b/tests/specs/test/hide_empty_suites/main.ts new file mode 100644 index 000000000..c4c0f45dc --- /dev/null +++ b/tests/specs/test/hide_empty_suites/main.ts @@ -0,0 +1,37 @@ +Deno.test("test 0", () => {}); +Deno.test("test 1", () => {}); +Deno.test("test 2", () => {}); +Deno.test("test 3", () => {}); +Deno.test("test 4", () => {}); +Deno.test("test 5", () => {}); +Deno.test("test 6", () => {}); +Deno.test("test 7", () => {}); +Deno.test("test 8", () => { + console.log("console.log"); +}); +Deno.test("test 9", () => { + console.error("console.error"); +}); + +Deno.test("test\b", () => { + console.error("console.error"); +}); +Deno.test("test\f", () => { + console.error("console.error"); +}); + +Deno.test("test\t", () => { + console.error("console.error"); +}); + +Deno.test("test\n", () => { + console.error("console.error"); +}); + +Deno.test("test\r", () => { + console.error("console.error"); +}); + +Deno.test("test\v", () => { + console.error("console.error"); +}); diff --git a/tests/specs/test/ignore/__test__.jsonc b/tests/specs/test/ignore/__test__.jsonc new file mode 100644 index 000000000..e1ed1b926 --- /dev/null +++ b/tests/specs/test/ignore/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test main.ts", + "exitCode": 0, + "output": "main.out" +} diff --git a/tests/specs/test/ignore/main.out b/tests/specs/test/ignore/main.out new file mode 100644 index 000000000..390d4f916 --- /dev/null +++ b/tests/specs/test/ignore/main.out @@ -0,0 +1,15 @@ +Check [WILDCARD]/main.ts +running 10 tests from ./main.ts +test 0 ... ignored ([WILDCARD]) +test 1 ... ignored ([WILDCARD]) +test 2 ... ignored ([WILDCARD]) +test 3 ... ignored ([WILDCARD]) +test 4 ... ignored ([WILDCARD]) +test 5 ... ignored ([WILDCARD]) +test 6 ... ignored ([WILDCARD]) +test 7 ... ignored ([WILDCARD]) +test 8 ... ignored ([WILDCARD]) +test 9 ... ignored ([WILDCARD]) + +ok | 0 passed | 0 failed | 10 ignored ([WILDCARD]) + diff --git a/tests/specs/test/ignore/main.ts b/tests/specs/test/ignore/main.ts new file mode 100644 index 000000000..2339835db --- /dev/null +++ b/tests/specs/test/ignore/main.ts @@ -0,0 +1,17 @@ +for (let i = 0; i < 5; i++) { + Deno.test({ + name: `test ${i}`, + ignore: true, + fn() { + throw new Error("unreachable"); + }, + }); +} +for (let i = 5; i < 10; i++) { + Deno.test.ignore({ + name: `test ${i}`, + fn() { + throw new Error("unreachable"); + }, + }); +} diff --git a/tests/specs/test/ignore_persmissions/__test__.jsonc b/tests/specs/test/ignore_persmissions/__test__.jsonc new file mode 100644 index 000000000..e1ed1b926 --- /dev/null +++ b/tests/specs/test/ignore_persmissions/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test main.ts", + "exitCode": 0, + "output": "main.out" +} diff --git a/tests/specs/test/ignore_persmissions/main.out b/tests/specs/test/ignore_persmissions/main.out new file mode 100644 index 000000000..d5cec67c0 --- /dev/null +++ b/tests/specs/test/ignore_persmissions/main.out @@ -0,0 +1,6 @@ +Check [WILDCARD]/main.ts +running 1 test from ./main.ts +ignore ... ignored ([WILDCARD]) + +ok | 0 passed | 0 failed | 1 ignored ([WILDCARD]) + diff --git a/tests/specs/test/ignore_persmissions/main.ts b/tests/specs/test/ignore_persmissions/main.ts new file mode 100644 index 000000000..e9ade6dfe --- /dev/null +++ b/tests/specs/test/ignore_persmissions/main.ts @@ -0,0 +1,15 @@ +Deno.test({ + name: "ignore", + permissions: { + read: true, + write: true, + net: true, + env: true, + run: true, + ffi: true, + }, + ignore: true, + fn() { + throw new Error("unreachable"); + }, +}); diff --git a/tests/specs/test/interval/__test__.jsonc b/tests/specs/test/interval/__test__.jsonc new file mode 100644 index 000000000..e1ed1b926 --- /dev/null +++ b/tests/specs/test/interval/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test main.ts", + "exitCode": 0, + "output": "main.out" +} diff --git a/tests/specs/test/interval/main.out b/tests/specs/test/interval/main.out new file mode 100644 index 000000000..7e5ef2914 --- /dev/null +++ b/tests/specs/test/interval/main.out @@ -0,0 +1,5 @@ +Check [WILDCARD]/main.ts +running 0 tests from ./main.ts + +ok | 0 passed | 0 failed ([WILDCARD]) + diff --git a/tests/specs/test/interval/main.ts b/tests/specs/test/interval/main.ts new file mode 100644 index 000000000..7eb588c59 --- /dev/null +++ b/tests/specs/test/interval/main.ts @@ -0,0 +1 @@ +setInterval(function () {}, 0); diff --git a/tests/specs/test/junit/__test__.jsonc b/tests/specs/test/junit/__test__.jsonc new file mode 100644 index 000000000..5e91e5287 --- /dev/null +++ b/tests/specs/test/junit/__test__.jsonc @@ -0,0 +1,4 @@ +{ + "args": "test --reporter junit main.ts", + "output": "main.out" +} diff --git a/tests/specs/test/junit/main.out b/tests/specs/test/junit/main.out new file mode 100644 index 000000000..ca9558118 --- /dev/null +++ b/tests/specs/test/junit/main.out @@ -0,0 +1,38 @@ +Check file:///[WILDCARD]/main.ts +<?xml version="1.0" encoding="UTF-8"?> +<testsuites name="deno test" tests="16" failures="0" errors="0" time="[WILDCARD]"> + <testsuite name="./main.ts" tests="16" disabled="0" errors="0" failures="0"> + <testcase name="test 0" classname="./main.ts" time="[WILDCARD]" line="1" col="6"> + </testcase> + <testcase name="test 1" classname="./main.ts" time="[WILDCARD]" line="2" col="6"> + </testcase> + <testcase name="test 2" classname="./main.ts" time="[WILDCARD]" line="3" col="6"> + </testcase> + <testcase name="test 3" classname="./main.ts" time="[WILDCARD]" line="4" col="6"> + </testcase> + <testcase name="test 4" classname="./main.ts" time="[WILDCARD]" line="5" col="6"> + </testcase> + <testcase name="test 5" classname="./main.ts" time="[WILDCARD]" line="6" col="6"> + </testcase> + <testcase name="test 6" classname="./main.ts" time="[WILDCARD]" line="7" col="6"> + </testcase> + <testcase name="test 7" classname="./main.ts" time="[WILDCARD]" line="8" col="6"> + </testcase> + <testcase name="test 8" classname="./main.ts" time="[WILDCARD]" line="9" col="6"> + </testcase> + <testcase name="test 9" classname="./main.ts" time="[WILDCARD]" line="12" col="6"> + </testcase> + <testcase name="test\b" classname="./main.ts" time="[WILDCARD]" line="16" col="6"> + </testcase> + <testcase name="test\f" classname="./main.ts" time="[WILDCARD]" line="19" col="6"> + </testcase> + <testcase name="test\t" classname="./main.ts" time="[WILDCARD]" line="23" col="6"> + </testcase> + <testcase name="test\n" classname="./main.ts" time="[WILDCARD]" line="27" col="6"> + </testcase> + <testcase name="test\r" classname="./main.ts" time="[WILDCARD]" line="31" col="6"> + </testcase> + <testcase name="test\v" classname="./main.ts" time="[WILDCARD]" line="35" col="6"> + </testcase> + </testsuite> +</testsuites> diff --git a/tests/specs/test/junit/main.ts b/tests/specs/test/junit/main.ts new file mode 100644 index 000000000..c4c0f45dc --- /dev/null +++ b/tests/specs/test/junit/main.ts @@ -0,0 +1,37 @@ +Deno.test("test 0", () => {}); +Deno.test("test 1", () => {}); +Deno.test("test 2", () => {}); +Deno.test("test 3", () => {}); +Deno.test("test 4", () => {}); +Deno.test("test 5", () => {}); +Deno.test("test 6", () => {}); +Deno.test("test 7", () => {}); +Deno.test("test 8", () => { + console.log("console.log"); +}); +Deno.test("test 9", () => { + console.error("console.error"); +}); + +Deno.test("test\b", () => { + console.error("console.error"); +}); +Deno.test("test\f", () => { + console.error("console.error"); +}); + +Deno.test("test\t", () => { + console.error("console.error"); +}); + +Deno.test("test\n", () => { + console.error("console.error"); +}); + +Deno.test("test\r", () => { + console.error("console.error"); +}); + +Deno.test("test\v", () => { + console.error("console.error"); +}); diff --git a/tests/specs/test/junit_multiple_test_files/__test__.jsonc b/tests/specs/test/junit_multiple_test_files/__test__.jsonc new file mode 100644 index 000000000..d9b01bcb4 --- /dev/null +++ b/tests/specs/test/junit_multiple_test_files/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test --reporter junit pass.ts fail.ts", + "exitCode": 1, + "output": "main.out" +} diff --git a/tests/specs/test/junit_multiple_test_files/fail.ts b/tests/specs/test/junit_multiple_test_files/fail.ts new file mode 100644 index 000000000..9340db556 --- /dev/null +++ b/tests/specs/test/junit_multiple_test_files/fail.ts @@ -0,0 +1,30 @@ +Deno.test("test 0", () => { + throw new Error(); +}); +Deno.test("test 1", () => { + throw new Error(); +}); +Deno.test("test 2", () => { + throw new Error(); +}); +Deno.test("test 3", () => { + throw new Error(); +}); +Deno.test("test 4", () => { + throw new Error(); +}); +Deno.test("test 5", () => { + throw new Error(); +}); +Deno.test("test 6", () => { + throw new Error(); +}); +Deno.test("test 7", () => { + throw new Error(); +}); +Deno.test("test 8", () => { + throw new Error(); +}); +Deno.test("test 9", () => { + throw new Error(); +}); diff --git a/tests/specs/test/junit_multiple_test_files/main.out b/tests/specs/test/junit_multiple_test_files/main.out new file mode 100644 index 000000000..4ca962fd8 --- /dev/null +++ b/tests/specs/test/junit_multiple_test_files/main.out @@ -0,0 +1,102 @@ +Check file:///[WILDCARD]/pass.ts +Check file:///[WILDCARD]/fail.ts +<?xml version="1.0" encoding="UTF-8"?> +<testsuites name="deno test" tests="26" failures="10" errors="0" time="[WILDCARD]"> + <testsuite name="./pass.ts" tests="16" disabled="0" errors="0" failures="0"> + <testcase name="test 0" classname="./pass.ts" time="[WILDCARD]" line="1" col="6"> + </testcase> + <testcase name="test 1" classname="./pass.ts" time="[WILDCARD]" line="2" col="6"> + </testcase> + <testcase name="test 2" classname="./pass.ts" time="[WILDCARD]" line="3" col="6"> + </testcase> + <testcase name="test 3" classname="./pass.ts" time="[WILDCARD]" line="4" col="6"> + </testcase> + <testcase name="test 4" classname="./pass.ts" time="[WILDCARD]" line="5" col="6"> + </testcase> + <testcase name="test 5" classname="./pass.ts" time="[WILDCARD]" line="6" col="6"> + </testcase> + <testcase name="test 6" classname="./pass.ts" time="[WILDCARD]" line="7" col="6"> + </testcase> + <testcase name="test 7" classname="./pass.ts" time="[WILDCARD]" line="8" col="6"> + </testcase> + <testcase name="test 8" classname="./pass.ts" time="[WILDCARD]" line="9" col="6"> + </testcase> + <testcase name="test 9" classname="./pass.ts" time="[WILDCARD]" line="12" col="6"> + </testcase> + <testcase name="test\b" classname="./pass.ts" time="[WILDCARD]" line="16" col="6"> + </testcase> + <testcase name="test\f" classname="./pass.ts" time="[WILDCARD]" line="19" col="6"> + </testcase> + <testcase name="test\t" classname="./pass.ts" time="[WILDCARD]" line="23" col="6"> + </testcase> + <testcase name="test\n" classname="./pass.ts" time="[WILDCARD]" line="27" col="6"> + </testcase> + <testcase name="test\r" classname="./pass.ts" time="[WILDCARD]" line="31" col="6"> + </testcase> + <testcase name="test\v" classname="./pass.ts" time="[WILDCARD]" line="35" col="6"> + </testcase> + </testsuite> + <testsuite name="./fail.ts" tests="10" disabled="0" errors="0" failures="10"> + <testcase name="test 0" classname="./fail.ts" time="[WILDCARD]" line="1" col="6"> + <failure message="Uncaught Error">Error + throw new Error(); + ^ + at file:///[WILDCARD]/fail.ts:2:9</failure> + </testcase> + <testcase name="test 1" classname="./fail.ts" time="[WILDCARD]" line="4" col="6"> + <failure message="Uncaught Error">Error + throw new Error(); + ^ + at file:///[WILDCARD]/fail.ts:5:9</failure> + </testcase> + <testcase name="test 2" classname="./fail.ts" time="[WILDCARD]" line="7" col="6"> + <failure message="Uncaught Error">Error + throw new Error(); + ^ + at file:///[WILDCARD]/fail.ts:8:9</failure> + </testcase> + <testcase name="test 3" classname="./fail.ts" time="[WILDCARD]" line="10" col="6"> + <failure message="Uncaught Error">Error + throw new Error(); + ^ + at file:///[WILDCARD]/fail.ts:11:9</failure> + </testcase> + <testcase name="test 4" classname="./fail.ts" time="[WILDCARD]" line="13" col="6"> + <failure message="Uncaught Error">Error + throw new Error(); + ^ + at file:///[WILDCARD]/fail.ts:14:9</failure> + </testcase> + <testcase name="test 5" classname="./fail.ts" time="[WILDCARD]" line="16" col="6"> + <failure message="Uncaught Error">Error + throw new Error(); + ^ + at file:///[WILDCARD]/fail.ts:17:9</failure> + </testcase> + <testcase name="test 6" classname="./fail.ts" time="[WILDCARD]" line="19" col="6"> + <failure message="Uncaught Error">Error + throw new Error(); + ^ + at file:///[WILDCARD]/fail.ts:20:9</failure> + </testcase> + <testcase name="test 7" classname="./fail.ts" time="[WILDCARD]" line="22" col="6"> + <failure message="Uncaught Error">Error + throw new Error(); + ^ + at file:///[WILDCARD]/fail.ts:23:9</failure> + </testcase> + <testcase name="test 8" classname="./fail.ts" time="[WILDCARD]" line="25" col="6"> + <failure message="Uncaught Error">Error + throw new Error(); + ^ + at file:///[WILDCARD]/fail.ts:26:9</failure> + </testcase> + <testcase name="test 9" classname="./fail.ts" time="[WILDCARD]" line="28" col="6"> + <failure message="Uncaught Error">Error + throw new Error(); + ^ + at file:///[WILDCARD]/fail.ts:29:9</failure> + </testcase> + </testsuite> +</testsuites> +error: Test failed diff --git a/tests/specs/test/junit_multiple_test_files/pass.ts b/tests/specs/test/junit_multiple_test_files/pass.ts new file mode 100644 index 000000000..c4c0f45dc --- /dev/null +++ b/tests/specs/test/junit_multiple_test_files/pass.ts @@ -0,0 +1,37 @@ +Deno.test("test 0", () => {}); +Deno.test("test 1", () => {}); +Deno.test("test 2", () => {}); +Deno.test("test 3", () => {}); +Deno.test("test 4", () => {}); +Deno.test("test 5", () => {}); +Deno.test("test 6", () => {}); +Deno.test("test 7", () => {}); +Deno.test("test 8", () => { + console.log("console.log"); +}); +Deno.test("test 9", () => { + console.error("console.error"); +}); + +Deno.test("test\b", () => { + console.error("console.error"); +}); +Deno.test("test\f", () => { + console.error("console.error"); +}); + +Deno.test("test\t", () => { + console.error("console.error"); +}); + +Deno.test("test\n", () => { + console.error("console.error"); +}); + +Deno.test("test\r", () => { + console.error("console.error"); +}); + +Deno.test("test\v", () => { + console.error("console.error"); +}); diff --git a/tests/specs/test/junit_nested/__test__.jsonc b/tests/specs/test/junit_nested/__test__.jsonc new file mode 100644 index 000000000..79b73474d --- /dev/null +++ b/tests/specs/test/junit_nested/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test --reporter junit main.ts", + "exitCode": 1, + "output": "main.out" +} diff --git a/tests/specs/test/junit_nested/main.out b/tests/specs/test/junit_nested/main.out new file mode 100644 index 000000000..f2ac00f29 --- /dev/null +++ b/tests/specs/test/junit_nested/main.out @@ -0,0 +1,47 @@ +Check file:///[WILDCARD]/main.ts +<?xml version="1.0" encoding="UTF-8"?> +<testsuites name="deno test" tests="11" failures="6" errors="0" time="[WILDCARD]"> + <testsuite name="./main.ts" tests="11" disabled="0" errors="0" failures="6"> + <testcase name="parent 1" classname="./main.ts" time="[WILDCARD]" line="1" col="6"> + <failure message="1 test step failed">1 test step failed.</failure> + </testcase> + <testcase name="parent 2" classname="./main.ts" time="[WILDCARD]" line="8" col="6"> + <failure message="2 test steps failed">2 test steps failed.</failure> + </testcase> + <testcase name="parent 3" classname="./main.ts" time="[WILDCARD]" line="20" col="6"> + </testcase> + <testcase name="parent 1 > child 1" classname="./main.ts" time="[WILDCARD]" line="2" col="11"> + </testcase> + <testcase name="parent 1 > child 2" classname="./main.ts" time="[WILDCARD]" line="3" col="11"> + <failure message="Uncaught Error: Fail.">Error: Fail. + throw new Error("Fail."); + ^ + at file:///[WILDCARD]/main.ts:4:11 + [WILDCARD]</failure> + </testcase> + <testcase name="parent 2 > child 1" classname="./main.ts" time="[WILDCARD]" line="9" col="11"> + <failure message="1 test step failed">1 test step failed.</failure> + </testcase> + <testcase name="parent 2 > child 1 > grandchild 1" classname="[WILDCARD]/main.ts" time="[WILDCARD]" line="10" col="13"> + </testcase> + <testcase name="parent 2 > child 1 > grandchild 2" classname="[WILDCARD]/main.ts" time="[WILDCARD]" line="11" col="13"> + <failure message="Uncaught Error: Fail.">Error: Fail. + throw new Error("Fail."); + ^ + at file:///[WILDCARD]/main.ts:12:13 + [WILDCARD]</failure> + </testcase> + <testcase name="parent 2 > child 2" classname="./main.ts" time="[WILDCARD]" line="15" col="11"> + <failure message="Uncaught Error: Fail.">Error: Fail. + throw new Error("Fail."); + ^ + at file:///[WILDCARD]/main.ts:16:11 + [WILDCARD]</failure> + </testcase> + <testcase name="parent 3 > child 1" classname="./main.ts" time="[WILDCARD]" line="21" col="11"> + </testcase> + <testcase name="parent 3 > child 2" classname="./main.ts" time="[WILDCARD]" line="22" col="11"> + </testcase> + </testsuite> +</testsuites> +error: Test failed diff --git a/tests/specs/test/junit_nested/main.ts b/tests/specs/test/junit_nested/main.ts new file mode 100644 index 000000000..128e48aef --- /dev/null +++ b/tests/specs/test/junit_nested/main.ts @@ -0,0 +1,23 @@ +Deno.test("parent 1", async (t) => { + await t.step("child 1", () => {}); + await t.step("child 2", () => { + throw new Error("Fail."); + }); +}); + +Deno.test("parent 2", async (t) => { + await t.step("child 1", async (t) => { + await t.step("grandchild 1", () => {}); + await t.step("grandchild 2", () => { + throw new Error("Fail."); + }); + }); + await t.step("child 2", () => { + throw new Error("Fail."); + }); +}); + +Deno.test("parent 3", async (t) => { + await t.step("child 1", () => {}); + await t.step("child 2", () => {}); +}); diff --git a/tests/specs/test/load_unload/__test__.jsonc b/tests/specs/test/load_unload/__test__.jsonc new file mode 100644 index 000000000..e1ed1b926 --- /dev/null +++ b/tests/specs/test/load_unload/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test main.ts", + "exitCode": 0, + "output": "main.out" +} diff --git a/tests/specs/test/load_unload/main.out b/tests/specs/test/load_unload/main.out new file mode 100644 index 000000000..6a818d911 --- /dev/null +++ b/tests/specs/test/load_unload/main.out @@ -0,0 +1,16 @@ +Check [WILDCARD]/main.ts +------- pre-test output ------- +load +----- pre-test output end ----- +running 1 test from [WILDCARD]/main.ts +test ... +------- output ------- +test +----- output end ----- +test ... ok ([WILDCARD]) +------- post-test output ------- +unload +----- post-test output end ----- + +ok | 1 passed | 0 failed ([WILDCARD]) + diff --git a/tests/specs/test/load_unload/main.ts b/tests/specs/test/load_unload/main.ts new file mode 100644 index 000000000..5027b949a --- /dev/null +++ b/tests/specs/test/load_unload/main.ts @@ -0,0 +1,25 @@ +let interval: number | null = null; +addEventListener("load", () => { + if (interval) { + throw new Error("Interval is already set"); + } + + console.log("load"); + interval = setInterval(() => {}, 0); +}); + +addEventListener("unload", () => { + if (!interval) { + throw new Error("Interval was not set"); + } + + console.log("unload"); + clearInterval(interval); +}); + +Deno.test("test", () => { + console.log("test"); + if (!interval) { + throw new Error("Interval was not set"); + } +}); diff --git a/tests/specs/test/markdown/__test__.jsonc b/tests/specs/test/markdown/__test__.jsonc new file mode 100644 index 000000000..558106d55 --- /dev/null +++ b/tests/specs/test/markdown/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test --doc --allow-all main.md", + "exitCode": 1, + "output": "main.out" +} diff --git a/tests/specs/test/markdown/main.md b/tests/specs/test/markdown/main.md new file mode 100644 index 000000000..d18dbd108 --- /dev/null +++ b/tests/specs/test/markdown/main.md @@ -0,0 +1,31 @@ +# Documentation + +The following block does not have a language attribute and should be ignored: + +``` +This is a fenced block without attributes, it's invalid and it should be ignored. +``` + +The following block should be given a js extension on extraction: + +```js +console.log("js"); +``` + +The following block should be given a ts extension on extraction: + +```ts +console.log("ts"); +``` + +The following example contains the ignore attribute and will be ignored: + +```ts ignore +const value: Invalid = "ignored"; +``` + +The following example will trigger the type-checker to fail: + +```ts +const a: string = 42; +``` diff --git a/tests/specs/test/markdown/main.out b/tests/specs/test/markdown/main.out new file mode 100644 index 000000000..30327c72f --- /dev/null +++ b/tests/specs/test/markdown/main.out @@ -0,0 +1,7 @@ +Check [WILDCARD]/main.md$11-14.js +Check [WILDCARD]/main.md$17-20.ts +Check [WILDCARD]/main.md$29-32.ts +error: TS2322 [ERROR]: Type 'number' is not assignable to type 'string'. +const a: string = 42; + ^ + at [WILDCARD]/main.md$29-32.ts:1:7 diff --git a/tests/specs/test/markdown_full_block_names/__test__.jsonc b/tests/specs/test/markdown_full_block_names/__test__.jsonc new file mode 100644 index 000000000..558106d55 --- /dev/null +++ b/tests/specs/test/markdown_full_block_names/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test --doc --allow-all main.md", + "exitCode": 1, + "output": "main.out" +} diff --git a/tests/specs/test/markdown_full_block_names/main.md b/tests/specs/test/markdown_full_block_names/main.md new file mode 100644 index 000000000..4f9e1ea51 --- /dev/null +++ b/tests/specs/test/markdown_full_block_names/main.md @@ -0,0 +1,19 @@ +# Documentation + +The following block should be given a js extension on extraction: + +```javascript +console.log("js"); +``` + +The following example contains the ignore attribute and will be ignored: + +```typescript ignore +const value: Invalid = "ignored"; +``` + +The following example will trigger the type-checker to fail: + +```typescript +const a: string = 42; +``` diff --git a/tests/specs/test/markdown_full_block_names/main.out b/tests/specs/test/markdown_full_block_names/main.out new file mode 100644 index 000000000..9e64522dd --- /dev/null +++ b/tests/specs/test/markdown_full_block_names/main.out @@ -0,0 +1,6 @@ +Check [WILDCARD]/main.md$5-8.js +Check [WILDCARD]/main.md$17-20.ts +error: TS2322 [ERROR]: Type 'number' is not assignable to type 'string'. +const a: string = 42; + ^ + at [WILDCARD]/main.md$17-20.ts:1:7 diff --git a/tests/specs/test/markdown_ignore_html_comment/__test__.jsonc b/tests/specs/test/markdown_ignore_html_comment/__test__.jsonc new file mode 100644 index 000000000..558106d55 --- /dev/null +++ b/tests/specs/test/markdown_ignore_html_comment/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test --doc --allow-all main.md", + "exitCode": 1, + "output": "main.out" +} diff --git a/tests/specs/test/markdown_ignore_html_comment/main.md b/tests/specs/test/markdown_ignore_html_comment/main.md new file mode 100644 index 000000000..886e88103 --- /dev/null +++ b/tests/specs/test/markdown_ignore_html_comment/main.md @@ -0,0 +1,36 @@ +# Documentation + +The following examples are inside HTML comments and will not trigger the +type-checker: + +<!-- ```ts ignore +const value: Invalid = "ignored"; +``` --> + +<!-- +```ts +const a: string = 42; +``` +--> + +<!-- + +This is a comment. + +```ts +const a: string = 42; +``` + +Something something more comments. + +```typescript +const a: boolean = "true"; +``` + +--> + +The following example will trigger the type-checker to fail: + +```ts +const a: string = 42; +``` diff --git a/tests/specs/test/markdown_ignore_html_comment/main.out b/tests/specs/test/markdown_ignore_html_comment/main.out new file mode 100644 index 000000000..4de738845 --- /dev/null +++ b/tests/specs/test/markdown_ignore_html_comment/main.out @@ -0,0 +1,5 @@ +Check [WILDCARD]/main.md$34-37.ts +error: TS2322 [ERROR]: Type 'number' is not assignable to type 'string'. +const a: string = 42; + ^ + at [WILDCARD]/main.md$34-37.ts:1:7 diff --git a/tests/specs/test/markdown_windows/__test__.jsonc b/tests/specs/test/markdown_windows/__test__.jsonc new file mode 100644 index 000000000..558106d55 --- /dev/null +++ b/tests/specs/test/markdown_windows/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test --doc --allow-all main.md", + "exitCode": 1, + "output": "main.out" +} diff --git a/tests/specs/test/markdown_windows/main.md b/tests/specs/test/markdown_windows/main.md new file mode 100644 index 000000000..d18dbd108 --- /dev/null +++ b/tests/specs/test/markdown_windows/main.md @@ -0,0 +1,31 @@ +# Documentation + +The following block does not have a language attribute and should be ignored: + +``` +This is a fenced block without attributes, it's invalid and it should be ignored. +``` + +The following block should be given a js extension on extraction: + +```js +console.log("js"); +``` + +The following block should be given a ts extension on extraction: + +```ts +console.log("ts"); +``` + +The following example contains the ignore attribute and will be ignored: + +```ts ignore +const value: Invalid = "ignored"; +``` + +The following example will trigger the type-checker to fail: + +```ts +const a: string = 42; +``` diff --git a/tests/specs/test/markdown_windows/main.out b/tests/specs/test/markdown_windows/main.out new file mode 100644 index 000000000..30327c72f --- /dev/null +++ b/tests/specs/test/markdown_windows/main.out @@ -0,0 +1,7 @@ +Check [WILDCARD]/main.md$11-14.js +Check [WILDCARD]/main.md$17-20.ts +Check [WILDCARD]/main.md$29-32.ts +error: TS2322 [ERROR]: Type 'number' is not assignable to type 'string'. +const a: string = 42; + ^ + at [WILDCARD]/main.md$29-32.ts:1:7 diff --git a/tests/specs/test/meta/__test__.jsonc b/tests/specs/test/meta/__test__.jsonc new file mode 100644 index 000000000..e1ed1b926 --- /dev/null +++ b/tests/specs/test/meta/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test main.ts", + "exitCode": 0, + "output": "main.out" +} diff --git a/tests/specs/test/meta/main.out b/tests/specs/test/meta/main.out new file mode 100644 index 000000000..06a0daa7b --- /dev/null +++ b/tests/specs/test/meta/main.out @@ -0,0 +1,11 @@ +Check [WILDCARD]/main.ts +running 1 test from ./main.ts +check values ... +------- output ------- +import.meta.main: false +import.meta.url: [WILDCARD]/main.ts +----- output end ----- +check values ... ok ([WILDCARD]) + +ok | 1 passed | 0 failed ([WILDCARD]) + diff --git a/tests/specs/test/meta/main.ts b/tests/specs/test/meta/main.ts new file mode 100644 index 000000000..f2433a96d --- /dev/null +++ b/tests/specs/test/meta/main.ts @@ -0,0 +1,7 @@ +const main = import.meta.main; +const url = import.meta.url; + +Deno.test("check values", () => { + console.log("import.meta.main: %s", main); + console.log("import.meta.url: %s", url); +}); diff --git a/tests/specs/test/no_check/__test__.jsonc b/tests/specs/test/no_check/__test__.jsonc new file mode 100644 index 000000000..3d0c74336 --- /dev/null +++ b/tests/specs/test/no_check/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test --no-check main.ts", + "exitCode": 1, + "output": "main.out" +} diff --git a/tests/specs/test/no_check/main.out b/tests/specs/test/no_check/main.out new file mode 100644 index 000000000..cd9e7d0fa --- /dev/null +++ b/tests/specs/test/no_check/main.out @@ -0,0 +1,19 @@ +Uncaught error from ./main.ts FAILED + + ERRORS + +./main.ts (uncaught error) +error: (in promise) TypeError: Cannot read properties of undefined (reading 'fn') +Deno.test(); + ^ + at [WILDCARD] +This error was not caught from a test and caused the test runner to fail on the referenced module. +It most likely originated from a dangling promise, event/timeout handler or top-level code. + + FAILURES + +./main.ts (uncaught error) + +FAILED | 0 passed | 1 failed ([WILDCARD]) + +error: Test failed diff --git a/tests/specs/test/no_check/main.ts b/tests/specs/test/no_check/main.ts new file mode 100644 index 000000000..79d75f989 --- /dev/null +++ b/tests/specs/test/no_check/main.ts @@ -0,0 +1 @@ +Deno.test(); diff --git a/tests/specs/test/no_color/__test__.jsonc b/tests/specs/test/no_color/__test__.jsonc new file mode 100644 index 000000000..154baa8c1 --- /dev/null +++ b/tests/specs/test/no_color/__test__.jsonc @@ -0,0 +1,8 @@ +{ + "args": "test main.ts", + "exitCode": 1, + "envs": { + "NO_COLOR": "1" + }, + "output": "main.out" +} diff --git a/tests/specs/test/no_color/main.out b/tests/specs/test/no_color/main.out new file mode 100644 index 000000000..834bbaf6e --- /dev/null +++ b/tests/specs/test/no_color/main.out @@ -0,0 +1,21 @@ +Check [WILDCARD]/main.ts +running 3 tests from ./main.ts +success ... ok ([WILDCARD]) +fail ... FAILED ([WILDCARD]) +ignored ... ignored ([WILDCARD]) + + ERRORS + +fail => ./main.ts:6:6 +error: Error: fail + throw new Error("fail"); + ^ + at fn ([WILDCARD]/main.ts:9:11) + + FAILURES + +fail => ./main.ts:6:6 + +FAILED | 1 passed | 1 failed | 1 ignored ([WILDCARD]) + +error: Test failed diff --git a/tests/specs/test/no_color/main.ts b/tests/specs/test/no_color/main.ts new file mode 100644 index 000000000..38c531ee9 --- /dev/null +++ b/tests/specs/test/no_color/main.ts @@ -0,0 +1,17 @@ +Deno.test({ + name: "success", + fn() {}, +}); + +Deno.test({ + name: "fail", + fn() { + throw new Error("fail"); + }, +}); + +Deno.test({ + name: "ignored", + ignore: true, + fn() {}, +}); diff --git a/tests/specs/test/no_prompt_by_default/__test__.jsonc b/tests/specs/test/no_prompt_by_default/__test__.jsonc new file mode 100644 index 000000000..a02376f87 --- /dev/null +++ b/tests/specs/test/no_prompt_by_default/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test --quiet main.ts", + "exitCode": 1, + "output": "main.out" +} diff --git a/tests/specs/test/no_prompt_by_default/main.out b/tests/specs/test/no_prompt_by_default/main.out new file mode 100644 index 000000000..e0d1290ec --- /dev/null +++ b/tests/specs/test/no_prompt_by_default/main.out @@ -0,0 +1,16 @@ +running 1 test from ./main.ts +no prompt ... FAILED ([WILDCARD]s) + + ERRORS + +no prompt => ./main.ts:[WILDCARD] +error: NotCapable: Requires read access to "./some_file.txt", run again with the --allow-read flag +[WILDCARD] + + FAILURES + +no prompt => ./main.ts:[WILDCARD] + +FAILED | 0 passed | 1 failed ([WILDCARD]s) + +error: Test failed diff --git a/tests/specs/test/no_prompt_by_default/main.ts b/tests/specs/test/no_prompt_by_default/main.ts new file mode 100644 index 000000000..83837825d --- /dev/null +++ b/tests/specs/test/no_prompt_by_default/main.ts @@ -0,0 +1,3 @@ +Deno.test("no prompt", async () => { + await Deno.readTextFile("./some_file.txt"); +}); diff --git a/tests/specs/test/no_prompt_with_denied_perms/__test__.jsonc b/tests/specs/test/no_prompt_with_denied_perms/__test__.jsonc new file mode 100644 index 000000000..26050de00 --- /dev/null +++ b/tests/specs/test/no_prompt_with_denied_perms/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test --quiet --allow-read main.ts", + "exitCode": 1, + "output": "main.out" +} diff --git a/tests/specs/test/no_prompt_with_denied_perms/main.out b/tests/specs/test/no_prompt_with_denied_perms/main.out new file mode 100644 index 000000000..e0d1290ec --- /dev/null +++ b/tests/specs/test/no_prompt_with_denied_perms/main.out @@ -0,0 +1,16 @@ +running 1 test from ./main.ts +no prompt ... FAILED ([WILDCARD]s) + + ERRORS + +no prompt => ./main.ts:[WILDCARD] +error: NotCapable: Requires read access to "./some_file.txt", run again with the --allow-read flag +[WILDCARD] + + FAILURES + +no prompt => ./main.ts:[WILDCARD] + +FAILED | 0 passed | 1 failed ([WILDCARD]s) + +error: Test failed diff --git a/tests/specs/test/no_prompt_with_denied_perms/main.ts b/tests/specs/test/no_prompt_with_denied_perms/main.ts new file mode 100644 index 000000000..7fe5577cb --- /dev/null +++ b/tests/specs/test/no_prompt_with_denied_perms/main.ts @@ -0,0 +1,3 @@ +Deno.test("no prompt", { permissions: { read: false } }, async () => { + await Deno.readTextFile("./some_file.txt"); +}); diff --git a/tests/specs/test/no_run/__test__.jsonc b/tests/specs/test/no_run/__test__.jsonc new file mode 100644 index 000000000..6a6d714ee --- /dev/null +++ b/tests/specs/test/no_run/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test --no-run main.ts", + "exitCode": 1, + "output": "main.out" +} diff --git a/tests/specs/test/no_run/main.out b/tests/specs/test/no_run/main.out new file mode 100644 index 000000000..ff9884943 --- /dev/null +++ b/tests/specs/test/no_run/main.out @@ -0,0 +1,5 @@ +Check [WILDCARD]/main.ts +error: TS2322 [ERROR]: Type 'number' is not assignable to type 'string'. +const _value: string = 1; + ~~~~~~ + at [WILDCARD]/main.ts:1:7 diff --git a/tests/specs/test/no_run/main.ts b/tests/specs/test/no_run/main.ts new file mode 100644 index 000000000..b75915753 --- /dev/null +++ b/tests/specs/test/no_run/main.ts @@ -0,0 +1 @@ +const _value: string = 1; diff --git a/tests/specs/test/non_error_thrown/__test__.jsonc b/tests/specs/test/non_error_thrown/__test__.jsonc new file mode 100644 index 000000000..a02376f87 --- /dev/null +++ b/tests/specs/test/non_error_thrown/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test --quiet main.ts", + "exitCode": 1, + "output": "main.out" +} diff --git a/tests/specs/test/non_error_thrown/main.out b/tests/specs/test/non_error_thrown/main.out new file mode 100644 index 000000000..7e0de8028 --- /dev/null +++ b/tests/specs/test/non_error_thrown/main.out @@ -0,0 +1,40 @@ +running 6 tests from [WILDCARD]/main.ts +foo ... FAILED ([WILDCARD]) +bar ... FAILED ([WILDCARD]) +baz ... FAILED ([WILDCARD]) +qux ... FAILED ([WILDCARD]) +quux ... FAILED ([WILDCARD]) +quuz ... FAILED ([WILDCARD]) + + ERRORS + +foo => [WILDCARD]/main.ts:1:6 +error: undefined + +bar => [WILDCARD]/main.ts:5:6 +error: null + +baz => [WILDCARD]/main.ts:9:6 +error: 123 + +qux => [WILDCARD]/main.ts:13:6 +error: "Hello, world!" + +quux => [WILDCARD]/main.ts:17:6 +error: [ 1, 2, 3 ] + +quuz => [WILDCARD]/main.ts:21:6 +error: { a: "Hello, world!", b: [ 1, 2, 3 ] } + + FAILURES + +foo => [WILDCARD]/main.ts:1:6 +bar => [WILDCARD]/main.ts:5:6 +baz => [WILDCARD]/main.ts:9:6 +qux => [WILDCARD]/main.ts:13:6 +quux => [WILDCARD]/main.ts:17:6 +quuz => [WILDCARD]/main.ts:21:6 + +FAILED | 0 passed | 6 failed ([WILDCARD]) + +error: Test failed diff --git a/tests/specs/test/non_error_thrown/main.ts b/tests/specs/test/non_error_thrown/main.ts new file mode 100644 index 000000000..85dc8d179 --- /dev/null +++ b/tests/specs/test/non_error_thrown/main.ts @@ -0,0 +1,23 @@ +Deno.test("foo", () => { + throw undefined; +}); + +Deno.test("bar", () => { + throw null; +}); + +Deno.test("baz", () => { + throw 123; +}); + +Deno.test("qux", () => { + throw "Hello, world!"; +}); + +Deno.test("quux", () => { + throw [1, 2, 3]; +}); + +Deno.test("quuz", () => { + throw { a: "Hello, world!", b: [1, 2, 3] }; +}); diff --git a/tests/specs/test/only/__test__.jsonc b/tests/specs/test/only/__test__.jsonc new file mode 100644 index 000000000..2c4ae3868 --- /dev/null +++ b/tests/specs/test/only/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test main.ts", + "exitCode": 1, + "output": "main.out" +} diff --git a/tests/specs/test/only/main.out b/tests/specs/test/only/main.out new file mode 100644 index 000000000..e1c745bcd --- /dev/null +++ b/tests/specs/test/only/main.out @@ -0,0 +1,8 @@ +Check [WILDCARD]/main.ts +running 2 tests from ./main.ts +only ... ok ([WILDCARD]) +only2 ... ok ([WILDCARD]) + +ok | 2 passed | 0 failed | 2 filtered out ([WILDCARD]) + +error: Test failed because the "only" option was used diff --git a/tests/specs/test/only/main.ts b/tests/specs/test/only/main.ts new file mode 100644 index 000000000..26b4cd425 --- /dev/null +++ b/tests/specs/test/only/main.ts @@ -0,0 +1,20 @@ +Deno.test({ + name: "before", + fn() {}, +}); + +Deno.test({ + only: true, + name: "only", + fn() {}, +}); + +Deno.test.only({ + name: "only2", + fn() {}, +}); + +Deno.test({ + name: "after", + fn() {}, +}); diff --git a/tests/specs/test/ops_sanitizer_closed_inside_started_before/__test__.jsonc b/tests/specs/test/ops_sanitizer_closed_inside_started_before/__test__.jsonc new file mode 100644 index 000000000..a427ea6b8 --- /dev/null +++ b/tests/specs/test/ops_sanitizer_closed_inside_started_before/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test --trace-leaks ops_sanitizer_closed_inside_started_before.ts", + "exitCode": 1, + "output": "ops_sanitizer_closed_inside_started_before.out" +} diff --git a/tests/specs/test/ops_sanitizer_closed_inside_started_before/ops_sanitizer_closed_inside_started_before.out b/tests/specs/test/ops_sanitizer_closed_inside_started_before/ops_sanitizer_closed_inside_started_before.out new file mode 100644 index 000000000..ffccd8422 --- /dev/null +++ b/tests/specs/test/ops_sanitizer_closed_inside_started_before/ops_sanitizer_closed_inside_started_before.out @@ -0,0 +1,19 @@ +Check [WILDCARD]/ops_sanitizer_closed_inside_started_before.ts +running 1 test from [WILDCARD]/ops_sanitizer_closed_inside_started_before.ts +test 1 ... FAILED [WILDCARD] + + ERRORS + +test 1 => [WILDCARD]/ops_sanitizer_closed_inside_started_before.ts:[WILDCARD] +error: Leaks detected: + - A timer was started before the test, but completed during the test. Intervals and timers should not complete in a test if they were not started in that test. This is often caused by not calling `clearTimeout`. The operation was started here: + at [WILDCARD] + at [WILDCARD]/ops_sanitizer_closed_inside_started_before.ts:[WILDCARD] + + FAILURES + +test 1 => [WILDCARD]/ops_sanitizer_closed_inside_started_before.ts:[WILDCARD] + +FAILED | 0 passed | 1 failed [WILDCARD] + +error: Test failed diff --git a/tests/specs/test/ops_sanitizer_closed_inside_started_before/ops_sanitizer_closed_inside_started_before.ts b/tests/specs/test/ops_sanitizer_closed_inside_started_before/ops_sanitizer_closed_inside_started_before.ts new file mode 100644 index 000000000..97d3d72c8 --- /dev/null +++ b/tests/specs/test/ops_sanitizer_closed_inside_started_before/ops_sanitizer_closed_inside_started_before.ts @@ -0,0 +1,5 @@ +const timer = setTimeout(() => {}, 10000000000); + +Deno.test("test 1", () => { + clearTimeout(timer); +}); diff --git a/tests/specs/test/ops_sanitizer_multiple_timeout_tests/__test__.jsonc b/tests/specs/test/ops_sanitizer_multiple_timeout_tests/__test__.jsonc new file mode 100644 index 000000000..71776d566 --- /dev/null +++ b/tests/specs/test/ops_sanitizer_multiple_timeout_tests/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test --trace-leaks ops_sanitizer_multiple_timeout_tests.ts", + "exitCode": 1, + "output": "ops_sanitizer_multiple_timeout_tests.out" +} diff --git a/tests/specs/test/ops_sanitizer_multiple_timeout_tests/ops_sanitizer_multiple_timeout_tests.out b/tests/specs/test/ops_sanitizer_multiple_timeout_tests/ops_sanitizer_multiple_timeout_tests.out new file mode 100644 index 000000000..38d7fbb52 --- /dev/null +++ b/tests/specs/test/ops_sanitizer_multiple_timeout_tests/ops_sanitizer_multiple_timeout_tests.out @@ -0,0 +1,45 @@ +Check [WILDCARD]/ops_sanitizer_multiple_timeout_tests.ts +running 2 tests from [WILDCARD]/ops_sanitizer_multiple_timeout_tests.ts +test 1 ... FAILED ([WILDCARD]) +test 2 ... FAILED ([WILDCARD]) + + ERRORS + +test 1 => [WILDCARD]/ops_sanitizer_multiple_timeout_tests.ts:[WILDCARD] +error: Leaks detected: + - A timer was started in this test, but never completed. This is often caused by not calling `clearTimeout`. The operation was started here: + at [WILDCARD] + at setTimeout ([WILDCARD]) + at test ([WILDCARD]/ops_sanitizer_multiple_timeout_tests.ts:[WILDCARD]) + at [WILDCARD]/ops_sanitizer_multiple_timeout_tests.ts:8:27 + at [WILDCARD] + - A timer was started in this test, but never completed. This is often caused by not calling `clearTimeout`. The operation was started here: + at [WILDCARD] + at setTimeout ([WILDCARD]) + at test ([WILDCARD]/ops_sanitizer_multiple_timeout_tests.ts:[WILDCARD]) + at [WILDCARD]/ops_sanitizer_multiple_timeout_tests.ts:8:27 + at [WILDCARD] + +test 2 => [WILDCARD]/ops_sanitizer_multiple_timeout_tests.ts:[WILDCARD] +error: Leaks detected: + - A timer was started in this test, but never completed. This is often caused by not calling `clearTimeout`. The operation was started here: + at [WILDCARD] + at setTimeout ([WILDCARD]) + at test ([WILDCARD]/ops_sanitizer_multiple_timeout_tests.ts:[WILDCARD]) + at [WILDCARD]/ops_sanitizer_multiple_timeout_tests.ts:10:27 + at [WILDCARD] + - A timer was started in this test, but never completed. This is often caused by not calling `clearTimeout`. The operation was started here: + at [WILDCARD] + at setTimeout ([WILDCARD]) + at test ([WILDCARD]/ops_sanitizer_multiple_timeout_tests.ts:[WILDCARD]) + at [WILDCARD]/ops_sanitizer_multiple_timeout_tests.ts:10:27 + at [WILDCARD] + + FAILURES + +test 1 => [WILDCARD]/ops_sanitizer_multiple_timeout_tests.ts:[WILDCARD] +test 2 => [WILDCARD]/ops_sanitizer_multiple_timeout_tests.ts:[WILDCARD] + +FAILED | 0 passed | 2 failed ([WILDCARD]) + +error: Test failed diff --git a/tests/specs/test/ops_sanitizer_multiple_timeout_tests/ops_sanitizer_multiple_timeout_tests.ts b/tests/specs/test/ops_sanitizer_multiple_timeout_tests/ops_sanitizer_multiple_timeout_tests.ts new file mode 100644 index 000000000..1f52d481f --- /dev/null +++ b/tests/specs/test/ops_sanitizer_multiple_timeout_tests/ops_sanitizer_multiple_timeout_tests.ts @@ -0,0 +1,10 @@ +// https://github.com/denoland/deno/issues/8965 + +function test() { + setTimeout(() => {}, 10000); + setTimeout(() => {}, 10001); +} + +Deno.test("test 1", () => test()); + +Deno.test("test 2", () => test()); diff --git a/tests/specs/test/ops_sanitizer_multiple_timeout_tests_no_trace/__test__.jsonc b/tests/specs/test/ops_sanitizer_multiple_timeout_tests_no_trace/__test__.jsonc new file mode 100644 index 000000000..c1e1438cd --- /dev/null +++ b/tests/specs/test/ops_sanitizer_multiple_timeout_tests_no_trace/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test ops_sanitizer_multiple_timeout_tests.ts", + "exitCode": 1, + "output": "ops_sanitizer_multiple_timeout_tests_no_trace.out" +} diff --git a/tests/specs/test/ops_sanitizer_multiple_timeout_tests_no_trace/ops_sanitizer_multiple_timeout_tests.ts b/tests/specs/test/ops_sanitizer_multiple_timeout_tests_no_trace/ops_sanitizer_multiple_timeout_tests.ts new file mode 100644 index 000000000..1f52d481f --- /dev/null +++ b/tests/specs/test/ops_sanitizer_multiple_timeout_tests_no_trace/ops_sanitizer_multiple_timeout_tests.ts @@ -0,0 +1,10 @@ +// https://github.com/denoland/deno/issues/8965 + +function test() { + setTimeout(() => {}, 10000); + setTimeout(() => {}, 10001); +} + +Deno.test("test 1", () => test()); + +Deno.test("test 2", () => test()); diff --git a/tests/specs/test/ops_sanitizer_multiple_timeout_tests_no_trace/ops_sanitizer_multiple_timeout_tests_no_trace.out b/tests/specs/test/ops_sanitizer_multiple_timeout_tests_no_trace/ops_sanitizer_multiple_timeout_tests_no_trace.out new file mode 100644 index 000000000..c87cd0025 --- /dev/null +++ b/tests/specs/test/ops_sanitizer_multiple_timeout_tests_no_trace/ops_sanitizer_multiple_timeout_tests_no_trace.out @@ -0,0 +1,25 @@ +Check [WILDCARD]/ops_sanitizer_multiple_timeout_tests.ts +running 2 tests from [WILDCARD]/ops_sanitizer_multiple_timeout_tests.ts +test 1 ... FAILED ([WILDCARD]) +test 2 ... FAILED ([WILDCARD]) + + ERRORS + +test 1 => [WILDCARD]/ops_sanitizer_multiple_timeout_tests.ts:[WILDCARD] +error: Leaks detected: + - 2 timers were started in this test, but never completed. This is often caused by not calling `clearTimeout`. +To get more details where leaks occurred, run again with the --trace-leaks flag. + +test 2 => [WILDCARD]/ops_sanitizer_multiple_timeout_tests.ts:[WILDCARD] +error: Leaks detected: + - 2 timers were started in this test, but never completed. This is often caused by not calling `clearTimeout`. +To get more details where leaks occurred, run again with the --trace-leaks flag. + + FAILURES + +test 1 => [WILDCARD]/ops_sanitizer_multiple_timeout_tests.ts:[WILDCARD] +test 2 => [WILDCARD]/ops_sanitizer_multiple_timeout_tests.ts:[WILDCARD] + +FAILED | 0 passed | 2 failed ([WILDCARD]) + +error: Test failed diff --git a/tests/specs/test/ops_sanitizer_nexttick/__test__.jsonc b/tests/specs/test/ops_sanitizer_nexttick/__test__.jsonc new file mode 100644 index 000000000..29604e2fd --- /dev/null +++ b/tests/specs/test/ops_sanitizer_nexttick/__test__.jsonc @@ -0,0 +1,4 @@ +{ + "args": "test --no-check ops_sanitizer_nexttick.ts", + "output": "ops_sanitizer_nexttick.out" +} diff --git a/tests/specs/test/ops_sanitizer_nexttick/ops_sanitizer_nexttick.out b/tests/specs/test/ops_sanitizer_nexttick/ops_sanitizer_nexttick.out new file mode 100644 index 000000000..407699b6a --- /dev/null +++ b/tests/specs/test/ops_sanitizer_nexttick/ops_sanitizer_nexttick.out @@ -0,0 +1,6 @@ +running 2 tests from [WILDCARD]/ops_sanitizer_nexttick.ts +test 1 ... ok ([WILDCARD]) +test 2 ... ok ([WILDCARD]) + +ok | 2 passed | 0 failed ([WILDCARD]) + diff --git a/tests/specs/test/ops_sanitizer_nexttick/ops_sanitizer_nexttick.ts b/tests/specs/test/ops_sanitizer_nexttick/ops_sanitizer_nexttick.ts new file mode 100644 index 000000000..9ad3a7b28 --- /dev/null +++ b/tests/specs/test/ops_sanitizer_nexttick/ops_sanitizer_nexttick.ts @@ -0,0 +1,11 @@ +import { nextTick } from "node:process"; + +// https://github.com/denoland/deno_std/issues/1651 + +Deno.test("test 1", async () => { + await new Promise<void>((resolve) => nextTick(resolve)); +}); + +Deno.test("test 2", async () => { + await new Promise<void>((resolve) => nextTick(resolve)); +}); diff --git a/tests/specs/test/ops_sanitizer_tcp/__test__.jsonc b/tests/specs/test/ops_sanitizer_tcp/__test__.jsonc new file mode 100644 index 000000000..48f9404f4 --- /dev/null +++ b/tests/specs/test/ops_sanitizer_tcp/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test --allow-net --trace-leaks ops_sanitizer_tcp.ts", + "exitCode": 1, + "output": "ops_sanitizer_tcp.out" +} diff --git a/tests/specs/test/ops_sanitizer_tcp/ops_sanitizer_tcp.out b/tests/specs/test/ops_sanitizer_tcp/ops_sanitizer_tcp.out new file mode 100644 index 000000000..7b5660379 --- /dev/null +++ b/tests/specs/test/ops_sanitizer_tcp/ops_sanitizer_tcp.out @@ -0,0 +1,24 @@ +Check [WILDCARD]/ops_sanitizer_tcp.ts +running 1 test from [WILDCARD]/ops_sanitizer_tcp.ts +testLeakTcpOps ... FAILED ([WILDCARD]) + + ERRORS + +testLeakTcpOps => [WILDCARD]/ops_sanitizer_tcp.ts:[WILDCARD] +error: Leaks detected: + - A TCP listener was opened during the test, but not closed during the test. Close the TCP listener by calling `tcpListener.close()`. + - An async operation to accept a TCP stream was started in this test, but never completed. This is often caused by not closing a `Deno.Listener`. The operation was started here: + at op_net_accept_tcp ([WILDCARD]) + at Listener.accept ([WILDCARD]) + at testLeakTcpOps ([WILDCARD]) + at innerWrapped ([WILDCARD]) + at exitSanitizer ([WILDCARD]) + at outerWrapped ([WILDCARD]) + + FAILURES + +testLeakTcpOps => [WILDCARD]/ops_sanitizer_tcp.ts:[WILDCARD] + +FAILED | 0 passed | 1 failed ([WILDCARD]) + +error: Test failed diff --git a/tests/specs/test/ops_sanitizer_tcp/ops_sanitizer_tcp.ts b/tests/specs/test/ops_sanitizer_tcp/ops_sanitizer_tcp.ts new file mode 100644 index 000000000..ec2df9fd5 --- /dev/null +++ b/tests/specs/test/ops_sanitizer_tcp/ops_sanitizer_tcp.ts @@ -0,0 +1,4 @@ +Deno.test(function testLeakTcpOps() { + const listener1 = Deno.listen({ port: 0 }); + listener1.accept(); +}); diff --git a/tests/specs/test/ops_sanitizer_timeout_failure/__test__.jsonc b/tests/specs/test/ops_sanitizer_timeout_failure/__test__.jsonc new file mode 100644 index 000000000..c044382ba --- /dev/null +++ b/tests/specs/test/ops_sanitizer_timeout_failure/__test__.jsonc @@ -0,0 +1,4 @@ +{ + "args": "test ops_sanitizer_timeout_failure.ts", + "output": "ops_sanitizer_timeout_failure.out" +} diff --git a/tests/specs/test/ops_sanitizer_timeout_failure/ops_sanitizer_timeout_failure.out b/tests/specs/test/ops_sanitizer_timeout_failure/ops_sanitizer_timeout_failure.out new file mode 100644 index 000000000..e6e527112 --- /dev/null +++ b/tests/specs/test/ops_sanitizer_timeout_failure/ops_sanitizer_timeout_failure.out @@ -0,0 +1,6 @@ +Check [WILDCARD]/ops_sanitizer_timeout_failure.ts +running 1 test from [WILDCARD]/ops_sanitizer_timeout_failure.ts +wait ... ok ([WILDCARD]) + +ok | 1 passed | 0 failed ([WILDCARD]) + diff --git a/tests/specs/test/ops_sanitizer_timeout_failure/ops_sanitizer_timeout_failure.ts b/tests/specs/test/ops_sanitizer_timeout_failure/ops_sanitizer_timeout_failure.ts new file mode 100644 index 000000000..d40a5a258 --- /dev/null +++ b/tests/specs/test/ops_sanitizer_timeout_failure/ops_sanitizer_timeout_failure.ts @@ -0,0 +1,22 @@ +let intervalHandle: number; +let firstIntervalPromise: Promise<void>; + +addEventListener("load", () => { + firstIntervalPromise = new Promise((resolve) => { + let firstIntervalCalled = false; + intervalHandle = setInterval(() => { + if (!firstIntervalCalled) { + resolve(); + firstIntervalCalled = true; + } + }, 5); + }); +}); + +addEventListener("unload", () => { + clearInterval(intervalHandle); +}); + +Deno.test("wait", async function () { + await firstIntervalPromise; +}); diff --git a/tests/specs/test/ops_sanitizer_unstable/__test__.jsonc b/tests/specs/test/ops_sanitizer_unstable/__test__.jsonc new file mode 100644 index 000000000..b9ec3c878 --- /dev/null +++ b/tests/specs/test/ops_sanitizer_unstable/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test --trace-leaks ops_sanitizer_unstable.ts", + "exitCode": 1, + "output": "ops_sanitizer_unstable.out" +} diff --git a/tests/specs/test/ops_sanitizer_unstable/ops_sanitizer_unstable.out b/tests/specs/test/ops_sanitizer_unstable/ops_sanitizer_unstable.out new file mode 100644 index 000000000..a09f34592 --- /dev/null +++ b/tests/specs/test/ops_sanitizer_unstable/ops_sanitizer_unstable.out @@ -0,0 +1,22 @@ +Check [WILDCARD]/ops_sanitizer_unstable.ts +running 2 tests from [WILDCARD]/ops_sanitizer_unstable.ts +no-op ... ok ([WILDCARD]) +leak interval ... FAILED ([WILDCARD]) + + ERRORS + +leak interval => [WILDCARD]/ops_sanitizer_unstable.ts:[WILDCARD] +error: Leaks detected: + - An interval was started in this test, but never completed. This is often caused by not calling `clearInterval`. The operation was started here: + at [WILDCARD] + at setInterval ([WILDCARD]) + at fn ([WILDCARD]/ops_sanitizer_unstable.ts:[WILDCARD]) + at [WILDCARD] + + FAILURES + +leak interval => [WILDCARD]/ops_sanitizer_unstable.ts:[WILDCARD] + +FAILED | 1 passed | 1 failed ([WILDCARD]) + +error: Test failed diff --git a/tests/specs/test/ops_sanitizer_unstable/ops_sanitizer_unstable.ts b/tests/specs/test/ops_sanitizer_unstable/ops_sanitizer_unstable.ts new file mode 100644 index 000000000..1deb1d5a7 --- /dev/null +++ b/tests/specs/test/ops_sanitizer_unstable/ops_sanitizer_unstable.ts @@ -0,0 +1,10 @@ +Deno.test("no-op", function () {}); +Deno.test({ + name: "leak interval", + // regression test for sanitizer errors being swallowed with permissions. + // https://github.com/denoland/deno/pull/18550 + permissions: {}, + fn() { + setInterval(function () {}, 100000); + }, +}); diff --git a/tests/specs/test/opt_out_top_level_exclude_via_test_unexclude/__test__.jsonc b/tests/specs/test/opt_out_top_level_exclude_via_test_unexclude/__test__.jsonc new file mode 100644 index 000000000..ec4ab0127 --- /dev/null +++ b/tests/specs/test/opt_out_top_level_exclude_via_test_unexclude/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test", + "output": "main.out", + "exitCode": 0 +} diff --git a/tests/specs/test/opt_out_top_level_exclude_via_test_unexclude/actually_excluded.test.ts b/tests/specs/test/opt_out_top_level_exclude_via_test_unexclude/actually_excluded.test.ts new file mode 100644 index 000000000..da1a8f7a0 --- /dev/null +++ b/tests/specs/test/opt_out_top_level_exclude_via_test_unexclude/actually_excluded.test.ts @@ -0,0 +1 @@ +Deno.test("test3", () => {}); diff --git a/tests/specs/test/opt_out_top_level_exclude_via_test_unexclude/deno.json b/tests/specs/test/opt_out_top_level_exclude_via_test_unexclude/deno.json new file mode 100644 index 000000000..e9c181e77 --- /dev/null +++ b/tests/specs/test/opt_out_top_level_exclude_via_test_unexclude/deno.json @@ -0,0 +1,6 @@ +{ + "test": { + "exclude": ["!excluded.test.ts"] + }, + "exclude": ["excluded.test.ts", "actually_excluded.test.ts"] +} diff --git a/tests/specs/test/opt_out_top_level_exclude_via_test_unexclude/excluded.test.ts b/tests/specs/test/opt_out_top_level_exclude_via_test_unexclude/excluded.test.ts new file mode 100644 index 000000000..afb582199 --- /dev/null +++ b/tests/specs/test/opt_out_top_level_exclude_via_test_unexclude/excluded.test.ts @@ -0,0 +1 @@ +Deno.test("test2", () => {}); diff --git a/tests/specs/test/opt_out_top_level_exclude_via_test_unexclude/main.out b/tests/specs/test/opt_out_top_level_exclude_via_test_unexclude/main.out new file mode 100644 index 000000000..6ed39696e --- /dev/null +++ b/tests/specs/test/opt_out_top_level_exclude_via_test_unexclude/main.out @@ -0,0 +1,9 @@ +Check [WILDCARD]/excluded.test.ts +Check [WILDCARD]/main.test.ts +running 1 test from ./excluded.test.ts +test2 ... ok ([WILDCARD]) +running 1 test from ./main.test.ts +test1 ... ok ([WILDCARD]) + +ok | 2 passed | 0 failed ([WILDCARD]) + diff --git a/tests/specs/test/opt_out_top_level_exclude_via_test_unexclude/main.test.ts b/tests/specs/test/opt_out_top_level_exclude_via_test_unexclude/main.test.ts new file mode 100644 index 000000000..8d0131f75 --- /dev/null +++ b/tests/specs/test/opt_out_top_level_exclude_via_test_unexclude/main.test.ts @@ -0,0 +1 @@ +Deno.test("test1", () => {}); diff --git a/tests/specs/test/overloads/__test__.jsonc b/tests/specs/test/overloads/__test__.jsonc new file mode 100644 index 000000000..955107ebc --- /dev/null +++ b/tests/specs/test/overloads/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test main.ts", + "output": "main.out", + "exitCode": 0 +} diff --git a/tests/specs/test/overloads/main.out b/tests/specs/test/overloads/main.out new file mode 100644 index 000000000..92ec46d0b --- /dev/null +++ b/tests/specs/test/overloads/main.out @@ -0,0 +1,11 @@ +Check [WILDCARD]/overloads/main.ts +running 6 tests from ./main.ts +test0 ... ok ([WILDCARD]) +test1 ... ok ([WILDCARD]) +test2 ... ok ([WILDCARD]) +test3 ... ok ([WILDCARD]) +test4 ... ok ([WILDCARD]) +test5 ... ignored ([WILDCARD]) + +ok | 5 passed | 0 failed | 1 ignored ([WILDCARD]) + diff --git a/tests/specs/test/overloads/main.ts b/tests/specs/test/overloads/main.ts new file mode 100644 index 000000000..eb7b3dccc --- /dev/null +++ b/tests/specs/test/overloads/main.ts @@ -0,0 +1,6 @@ +Deno.test("test0", () => {}); +Deno.test(function test1() {}); +Deno.test({ name: "test2", fn: () => {} }); +Deno.test("test3", { permissions: "none" }, () => {}); +Deno.test({ name: "test4" }, () => {}); +Deno.test({ ignore: true }, function test5() {}); diff --git a/tests/specs/test/parallel_flag/__test__.jsonc b/tests/specs/test/parallel_flag/__test__.jsonc new file mode 100644 index 000000000..0c279e11d --- /dev/null +++ b/tests/specs/test/parallel_flag/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test main.ts --parallel", + "exitCode": 0, + "output": "main.out" +} diff --git a/tests/specs/test/parallel_flag/main.out b/tests/specs/test/parallel_flag/main.out new file mode 100644 index 000000000..54efc4cad --- /dev/null +++ b/tests/specs/test/parallel_flag/main.out @@ -0,0 +1,5 @@ +Check [WILDCARD]/main.ts +./main.ts => test ... ok ([WILDCARD]) + +ok | 1 passed | 0 failed ([WILDCARD]) + diff --git a/tests/specs/test/parallel_flag/main.ts b/tests/specs/test/parallel_flag/main.ts new file mode 100644 index 000000000..03818ae8d --- /dev/null +++ b/tests/specs/test/parallel_flag/main.ts @@ -0,0 +1 @@ +Deno.test("test", () => {}); diff --git a/tests/specs/test/parallel_flag_with_env_variables/__test__.jsonc b/tests/specs/test/parallel_flag_with_env_variables/__test__.jsonc new file mode 100644 index 000000000..330313467 --- /dev/null +++ b/tests/specs/test/parallel_flag_with_env_variables/__test__.jsonc @@ -0,0 +1,6 @@ +{ + "args": "test main.ts --parallel", + "exitCode": 0, + "envs": { "DENO_JOBS": "2" }, + "output": "main.out" +} diff --git a/tests/specs/test/parallel_flag_with_env_variables/main.out b/tests/specs/test/parallel_flag_with_env_variables/main.out new file mode 100644 index 000000000..54efc4cad --- /dev/null +++ b/tests/specs/test/parallel_flag_with_env_variables/main.out @@ -0,0 +1,5 @@ +Check [WILDCARD]/main.ts +./main.ts => test ... ok ([WILDCARD]) + +ok | 1 passed | 0 failed ([WILDCARD]) + diff --git a/tests/specs/test/parallel_flag_with_env_variables/main.ts b/tests/specs/test/parallel_flag_with_env_variables/main.ts new file mode 100644 index 000000000..03818ae8d --- /dev/null +++ b/tests/specs/test/parallel_flag_with_env_variables/main.ts @@ -0,0 +1 @@ +Deno.test("test", () => {}); diff --git a/tests/specs/test/parallel_output/__test__.jsonc b/tests/specs/test/parallel_output/__test__.jsonc new file mode 100644 index 000000000..dde5a1c6f --- /dev/null +++ b/tests/specs/test/parallel_output/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test --parallel --reload main.ts", + "exitCode": 1, + "output": "main.out" +} diff --git a/tests/specs/test/parallel_output/main.out b/tests/specs/test/parallel_output/main.out new file mode 100644 index 000000000..3d020a71f --- /dev/null +++ b/tests/specs/test/parallel_output/main.out @@ -0,0 +1,56 @@ +Check [WILDCARD]/main.ts +./main.ts => step output ... step 1 ... ok ([WILDCARD]s) +./main.ts => step output ... step 2 ... ok ([WILDCARD]s) +------- output ------- +Hello, world! (from step 3) +----- output end ----- +./main.ts => step output ... step 3 ... ok ([WILDCARD]s) +------- output ------- +Hello, world! (from step 4) +----- output end ----- +./main.ts => step output ... step 4 ... ok ([WILDCARD]s) +./main.ts => step output ... ok ([WILDCARD]s) +./main.ts => step failures ... step 1 ... ok ([WILDCARD]s) +./main.ts => step failures ... step 2 ... FAILED ([WILDCARD]s) +./main.ts => step failures ... step 3 ... FAILED ([WILDCARD]s) +./main.ts => step failures ... FAILED (due to 2 failed steps) ([WILDCARD]s) +./main.ts => step nested failure ... step 1 ... inner 1 ... ok ([WILDCARD]s) +./main.ts => step nested failure ... step 1 ... inner 2 ... FAILED ([WILDCARD]s) +./main.ts => step nested failure ... step 1 ... FAILED (due to 1 failed step) ([WILDCARD]s) +./main.ts => step nested failure ... FAILED (due to 1 failed step) ([WILDCARD]s) + + ERRORS + +step failures ... step 2 => ./main.ts:14:11 +error: Error: Fail. + throw new Error("Fail."); + ^ + at file:///[WILDCARD]/main.ts:15:11 + at [WILDCARD] + at file:///[WILDCARD]/main.ts:14:11 + +step failures ... step 3 => ./main.ts:17:11 +error: Error: Fail. + await t.step("step 3", () => Promise.reject(new Error("Fail."))); + ^ + at file:///[WILDCARD]/main.ts:17:47 + at [WILDCARD] + at file:///[WILDCARD]/main.ts:17:11 + +step nested failure ... step 1 ... inner 2 => ./main.ts:23:13 +error: Error: Failed. + throw new Error("Failed."); + ^ + at file:///[WILDCARD]/main.ts:24:13 + at [WILDCARD] + at file:///[WILDCARD]/main.ts:23:13 + + FAILURES + +step failures ... step 2 => ./main.ts:14:11 +step failures ... step 3 => ./main.ts:17:11 +step nested failure ... step 1 ... inner 2 => ./main.ts:23:13 + +FAILED | 1 passed (6 steps) | 2 failed (4 steps) ([WILDCARD]s) + +error: Test failed diff --git a/tests/specs/test/parallel_output/main.ts b/tests/specs/test/parallel_output/main.ts new file mode 100644 index 000000000..5de733aad --- /dev/null +++ b/tests/specs/test/parallel_output/main.ts @@ -0,0 +1,27 @@ +Deno.test("step output", async (t) => { + await t.step("step 1", () => {}); + await t.step("step 2", () => {}); + await t.step("step 3", () => { + console.log("Hello, world! (from step 3)"); + }); + await t.step("step 4", () => { + console.log("Hello, world! (from step 4)"); + }); +}); + +Deno.test("step failures", async (t) => { + await t.step("step 1", () => {}); + await t.step("step 2", () => { + throw new Error("Fail."); + }); + await t.step("step 3", () => Promise.reject(new Error("Fail."))); +}); + +Deno.test("step nested failure", async (t) => { + await t.step("step 1", async (t) => { + await t.step("inner 1", () => {}); + await t.step("inner 2", () => { + throw new Error("Failed."); + }); + }); +}); diff --git a/tests/specs/test/pass/__test__.jsonc b/tests/specs/test/pass/__test__.jsonc new file mode 100644 index 000000000..955107ebc --- /dev/null +++ b/tests/specs/test/pass/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test main.ts", + "output": "main.out", + "exitCode": 0 +} diff --git a/tests/specs/test/pass/main.out b/tests/specs/test/pass/main.out new file mode 100644 index 000000000..d2541d08d --- /dev/null +++ b/tests/specs/test/pass/main.out @@ -0,0 +1,53 @@ +Check [WILDCARD]/main.ts +running 16 tests from ./main.ts +test 0 ... ok ([WILDCARD]) +test 1 ... ok ([WILDCARD]) +test 2 ... ok ([WILDCARD]) +test 3 ... ok ([WILDCARD]) +test 4 ... ok ([WILDCARD]) +test 5 ... ok ([WILDCARD]) +test 6 ... ok ([WILDCARD]) +test 7 ... ok ([WILDCARD]) +test 8 ... +------- output ------- +console.log +----- output end ----- +test 8 ... ok ([WILDCARD]) +test 9 ... +------- output ------- +console.error +----- output end ----- +test 9 ... ok ([WILDCARD]) +test\b ... +------- output ------- +console.error +----- output end ----- +test\b ... ok ([WILDCARD]) +test\f ... +------- output ------- +console.error +----- output end ----- +test\f ... ok ([WILDCARD]) +test\t ... +------- output ------- +console.error +----- output end ----- +test\t ... ok ([WILDCARD]) +test\n ... +------- output ------- +console.error +----- output end ----- +test\n ... ok ([WILDCARD]) +test\r ... +------- output ------- +console.error +----- output end ----- +test\r ... ok ([WILDCARD]) +test\v ... +------- output ------- +console.error +----- output end ----- +test\v ... ok ([WILDCARD]) + +ok | 16 passed | 0 failed ([WILDCARD]) + diff --git a/tests/specs/test/pass/main.ts b/tests/specs/test/pass/main.ts new file mode 100644 index 000000000..c4c0f45dc --- /dev/null +++ b/tests/specs/test/pass/main.ts @@ -0,0 +1,37 @@ +Deno.test("test 0", () => {}); +Deno.test("test 1", () => {}); +Deno.test("test 2", () => {}); +Deno.test("test 3", () => {}); +Deno.test("test 4", () => {}); +Deno.test("test 5", () => {}); +Deno.test("test 6", () => {}); +Deno.test("test 7", () => {}); +Deno.test("test 8", () => { + console.log("console.log"); +}); +Deno.test("test 9", () => { + console.error("console.error"); +}); + +Deno.test("test\b", () => { + console.error("console.error"); +}); +Deno.test("test\f", () => { + console.error("console.error"); +}); + +Deno.test("test\t", () => { + console.error("console.error"); +}); + +Deno.test("test\n", () => { + console.error("console.error"); +}); + +Deno.test("test\r", () => { + console.error("console.error"); +}); + +Deno.test("test\v", () => { + console.error("console.error"); +}); diff --git a/tests/specs/test/quiet/__test__.jsonc b/tests/specs/test/quiet/__test__.jsonc new file mode 100644 index 000000000..799bc6ff2 --- /dev/null +++ b/tests/specs/test/quiet/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test --quiet main.ts", + "exitCode": 0, + "output": "main.out" +} diff --git a/tests/specs/test/quiet/main.out b/tests/specs/test/quiet/main.out new file mode 100644 index 000000000..5c72317f6 --- /dev/null +++ b/tests/specs/test/quiet/main.out @@ -0,0 +1,8 @@ +running 4 tests from ./main.ts +console.log ... ok ([WILDCARD]) +console.error ... ok ([WILDCARD]) +console.info ... ok ([WILDCARD]) +console.warn ... ok ([WILDCARD]) + +ok | 4 passed | 0 failed ([WILDCARD]) + diff --git a/tests/specs/test/quiet/main.ts b/tests/specs/test/quiet/main.ts new file mode 100644 index 000000000..f40805bfb --- /dev/null +++ b/tests/specs/test/quiet/main.ts @@ -0,0 +1,15 @@ +Deno.test("console.log", function () { + console.log("log"); +}); + +Deno.test("console.error", function () { + console.error("error"); +}); + +Deno.test("console.info", function () { + console.info("info"); +}); + +Deno.test("console.warn", function () { + console.info("warn"); +}); diff --git a/tests/specs/test/recursive_permissions_pledge/__test__.jsonc b/tests/specs/test/recursive_permissions_pledge/__test__.jsonc new file mode 100644 index 000000000..7dfb5b7ff --- /dev/null +++ b/tests/specs/test/recursive_permissions_pledge/__test__.jsonc @@ -0,0 +1,8 @@ +{ + "args": "test main.js", + "exitCode": 1, + "envs": { + "RUST_BACKTRACE": "0" + }, + "output": "\n============================================================\nDeno has panicked. This is a bug in Deno. Please report this\nat https://github.com/denoland/deno/issues/new.\nIf you can reliably reproduce this panic, include the\nreproduction steps and re-run with the RUST_BACKTRACE=1 env\nvar set and include the backtrace in your report.\n\nPlatform: [WILDCARD]\nVersion: [WILDCARD]\nArgs: [[WILDCARD], \"test\", \"main.js\"]\n\nthread 'tokio-runtime-worker' panicked at [WILDCARD]testing.rs:[WILDCARD]:\npledge test permissions called before restoring previous pledge\nnote: run with `RUST_BACKTRACE=1` environment variable to display a backtrace\n" +} diff --git a/tests/specs/test/recursive_permissions_pledge/main.js b/tests/specs/test/recursive_permissions_pledge/main.js new file mode 100644 index 000000000..9bf320c37 --- /dev/null +++ b/tests/specs/test/recursive_permissions_pledge/main.js @@ -0,0 +1,6 @@ +Deno[Deno.internal].core.ops.op_pledge_test_permissions( + "none", +); +Deno[Deno.internal].core.ops.op_pledge_test_permissions( + "inherit", +); diff --git a/tests/specs/test/report_error/__test__.jsonc b/tests/specs/test/report_error/__test__.jsonc new file mode 100644 index 000000000..59774f938 --- /dev/null +++ b/tests/specs/test/report_error/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test --quiet main.ts", + "output": "main.out", + "exitCode": 1 +} diff --git a/tests/specs/test/report_error/main.out b/tests/specs/test/report_error/main.out new file mode 100644 index 000000000..5fe3a4423 --- /dev/null +++ b/tests/specs/test/report_error/main.out @@ -0,0 +1,23 @@ +running 2 tests from [WILDCARD]/main.ts +foo ... +Uncaught error from [WILDCARD]/main.ts FAILED +foo ... cancelled (0ms) +bar ... cancelled (0ms) + + ERRORS + +[WILDCARD]/main.ts (uncaught error) +error: Error: foo + reportError(new Error("foo")); + ^ + at [WILDCARD]/main.ts:2:15 +This error was not caught from a test and caused the test runner to fail on the referenced module. +It most likely originated from a dangling promise, event/timeout handler or top-level code. + + FAILURES + +[WILDCARD]/main.ts (uncaught error) + +FAILED | 0 passed | 3 failed ([WILDCARD]) + +error: Test failed diff --git a/tests/specs/test/report_error/main.ts b/tests/specs/test/report_error/main.ts new file mode 100644 index 000000000..56b6db26c --- /dev/null +++ b/tests/specs/test/report_error/main.ts @@ -0,0 +1,6 @@ +Deno.test("foo", () => { + reportError(new Error("foo")); + console.log(1); +}); + +Deno.test("bar", () => {}); diff --git a/tests/specs/test/resource_sanitizer/__test__.jsonc b/tests/specs/test/resource_sanitizer/__test__.jsonc new file mode 100644 index 000000000..38417fba2 --- /dev/null +++ b/tests/specs/test/resource_sanitizer/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test --allow-read resource_sanitizer.ts", + "output": "resource_sanitizer.out", + "exitCode": 1 +} diff --git a/tests/specs/test/resource_sanitizer/resource_sanitizer.out b/tests/specs/test/resource_sanitizer/resource_sanitizer.out new file mode 100644 index 000000000..128bbc7b6 --- /dev/null +++ b/tests/specs/test/resource_sanitizer/resource_sanitizer.out @@ -0,0 +1,20 @@ +Check [WILDCARD]/resource_sanitizer.ts +running 1 test from [WILDCARD]/resource_sanitizer.ts +leak ... FAILED ([WILDCARD]) + + ERRORS + +leak => [WILDCARD]/resource_sanitizer.ts:[WILDCARD] +error: Leaks detected: +[UNORDERED_START] + - The stdin pipe was opened before the test started, but was closed during the test. Do not close resources in a test that were not created during that test. + - A file was opened during the test, but not closed during the test. Close the file handle by calling `file.close()`. +[UNORDERED_END] + + FAILURES + +leak => [WILDCARD]/resource_sanitizer.ts:[WILDCARD] + +FAILED | 0 passed | 1 failed ([WILDCARD]) + +error: Test failed diff --git a/tests/specs/test/resource_sanitizer/resource_sanitizer.ts b/tests/specs/test/resource_sanitizer/resource_sanitizer.ts new file mode 100644 index 000000000..7fa1bd8ad --- /dev/null +++ b/tests/specs/test/resource_sanitizer/resource_sanitizer.ts @@ -0,0 +1,4 @@ +Deno.test("leak", function () { + Deno.openSync("../../../testdata/run/001_hello.js"); + Deno.stdin.close(); +}); diff --git a/tests/specs/test/sanitizer_trace_ops_catch_error/__test__.jsonc b/tests/specs/test/sanitizer_trace_ops_catch_error/__test__.jsonc new file mode 100644 index 000000000..a7ec0907c --- /dev/null +++ b/tests/specs/test/sanitizer_trace_ops_catch_error/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test -A --trace-leaks main.ts", + "output": "main.out", + "exitCode": 0 +} diff --git a/tests/specs/test/sanitizer_trace_ops_catch_error/main.out b/tests/specs/test/sanitizer_trace_ops_catch_error/main.out new file mode 100644 index 000000000..c2c67605d --- /dev/null +++ b/tests/specs/test/sanitizer_trace_ops_catch_error/main.out @@ -0,0 +1,6 @@ +Check file:///[WILDCARD]main.ts +running 1 test from [WILDCARD]main.ts +handle thrown error in async function ... ok ([WILDCARD]) + +ok | 1 passed | 0 failed ([WILDCARD]) + diff --git a/tests/specs/test/sanitizer_trace_ops_catch_error/main.ts b/tests/specs/test/sanitizer_trace_ops_catch_error/main.ts new file mode 100644 index 000000000..043018688 --- /dev/null +++ b/tests/specs/test/sanitizer_trace_ops_catch_error/main.ts @@ -0,0 +1,13 @@ +// https://github.com/denoland/deno/pull/16970 +Deno.test("handle thrown error in async function", async () => { + const dirPath = Deno.makeTempDirSync(); + const filePath = `${dirPath}/file.txt`; + try { + await Deno.stat(filePath); + } catch { + await Deno.writeTextFile(filePath, ""); + } finally { + await Deno.remove(filePath); + await Deno.remove(dirPath); + } +}); diff --git a/tests/specs/test/shuffle/__test__.jsonc b/tests/specs/test/shuffle/__test__.jsonc new file mode 100644 index 000000000..975865e50 --- /dev/null +++ b/tests/specs/test/shuffle/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test --shuffle shuffle", + "output": "[WILDCARD]", + "exitCode": 0 +} diff --git a/tests/specs/test/shuffle/shuffle/bar_test.ts b/tests/specs/test/shuffle/shuffle/bar_test.ts new file mode 100644 index 000000000..ca118dc0d --- /dev/null +++ b/tests/specs/test/shuffle/shuffle/bar_test.ts @@ -0,0 +1,3 @@ +for (let i = 0; i < 10; i++) { + Deno.test(`test ${i}`, () => {}); +} diff --git a/tests/specs/test/shuffle/shuffle/baz_test.ts b/tests/specs/test/shuffle/shuffle/baz_test.ts new file mode 100644 index 000000000..ca118dc0d --- /dev/null +++ b/tests/specs/test/shuffle/shuffle/baz_test.ts @@ -0,0 +1,3 @@ +for (let i = 0; i < 10; i++) { + Deno.test(`test ${i}`, () => {}); +} diff --git a/tests/specs/test/shuffle/shuffle/foo_test.ts b/tests/specs/test/shuffle/shuffle/foo_test.ts new file mode 100644 index 000000000..ca118dc0d --- /dev/null +++ b/tests/specs/test/shuffle/shuffle/foo_test.ts @@ -0,0 +1,3 @@ +for (let i = 0; i < 10; i++) { + Deno.test(`test ${i}`, () => {}); +} diff --git a/tests/specs/test/shuffle_with_seed/__test__.jsonc b/tests/specs/test/shuffle_with_seed/__test__.jsonc new file mode 100644 index 000000000..477f1dbcf --- /dev/null +++ b/tests/specs/test/shuffle_with_seed/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test --shuffle=42 shuffle", + "output": "main.out", + "exitCode": 0 +} diff --git a/tests/specs/test/shuffle_with_seed/main.out b/tests/specs/test/shuffle_with_seed/main.out new file mode 100644 index 000000000..375b9bae2 --- /dev/null +++ b/tests/specs/test/shuffle_with_seed/main.out @@ -0,0 +1,39 @@ +Check [WILDCARD]/test/shuffle_with_seed/shuffle/bar_test.ts +Check [WILDCARD]/test/shuffle_with_seed/shuffle/baz_test.ts +Check [WILDCARD]/test/shuffle_with_seed/shuffle/foo_test.ts +running 10 tests from [WILDCARD]shuffle/foo_test.ts +test 3 ... ok ([WILDCARD]) +test 2 ... ok ([WILDCARD]) +test 7 ... ok ([WILDCARD]) +test 5 ... ok ([WILDCARD]) +test 8 ... ok ([WILDCARD]) +test 0 ... ok ([WILDCARD]) +test 9 ... ok ([WILDCARD]) +test 4 ... ok ([WILDCARD]) +test 6 ... ok ([WILDCARD]) +test 1 ... ok ([WILDCARD]) +running 10 tests from [WILDCARD]shuffle/baz_test.ts +test 3 ... ok ([WILDCARD]) +test 2 ... ok ([WILDCARD]) +test 7 ... ok ([WILDCARD]) +test 5 ... ok ([WILDCARD]) +test 8 ... ok ([WILDCARD]) +test 0 ... ok ([WILDCARD]) +test 9 ... ok ([WILDCARD]) +test 4 ... ok ([WILDCARD]) +test 6 ... ok ([WILDCARD]) +test 1 ... ok ([WILDCARD]) +running 10 tests from [WILDCARD]shuffle/bar_test.ts +test 3 ... ok ([WILDCARD]) +test 2 ... ok ([WILDCARD]) +test 7 ... ok ([WILDCARD]) +test 5 ... ok ([WILDCARD]) +test 8 ... ok ([WILDCARD]) +test 0 ... ok ([WILDCARD]) +test 9 ... ok ([WILDCARD]) +test 4 ... ok ([WILDCARD]) +test 6 ... ok ([WILDCARD]) +test 1 ... ok ([WILDCARD]) + +ok | 30 passed | 0 failed ([WILDCARD]) + diff --git a/tests/specs/test/shuffle_with_seed/shuffle/bar_test.ts b/tests/specs/test/shuffle_with_seed/shuffle/bar_test.ts new file mode 100644 index 000000000..ca118dc0d --- /dev/null +++ b/tests/specs/test/shuffle_with_seed/shuffle/bar_test.ts @@ -0,0 +1,3 @@ +for (let i = 0; i < 10; i++) { + Deno.test(`test ${i}`, () => {}); +} diff --git a/tests/specs/test/shuffle_with_seed/shuffle/baz_test.ts b/tests/specs/test/shuffle_with_seed/shuffle/baz_test.ts new file mode 100644 index 000000000..ca118dc0d --- /dev/null +++ b/tests/specs/test/shuffle_with_seed/shuffle/baz_test.ts @@ -0,0 +1,3 @@ +for (let i = 0; i < 10; i++) { + Deno.test(`test ${i}`, () => {}); +} diff --git a/tests/specs/test/shuffle_with_seed/shuffle/foo_test.ts b/tests/specs/test/shuffle_with_seed/shuffle/foo_test.ts new file mode 100644 index 000000000..ca118dc0d --- /dev/null +++ b/tests/specs/test/shuffle_with_seed/shuffle/foo_test.ts @@ -0,0 +1,3 @@ +for (let i = 0; i < 10; i++) { + Deno.test(`test ${i}`, () => {}); +} diff --git a/tests/specs/test/steps_dot_failing_steps/__test__.jsonc b/tests/specs/test/steps_dot_failing_steps/__test__.jsonc new file mode 100644 index 000000000..58ef6339a --- /dev/null +++ b/tests/specs/test/steps_dot_failing_steps/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test --reporter=dot failing_steps.ts", + "exitCode": 1, + "output": "failing_steps.dot.out" +} diff --git a/tests/specs/test/steps_dot_failing_steps/failing_steps.dot.out b/tests/specs/test/steps_dot_failing_steps/failing_steps.dot.out new file mode 100644 index 000000000..8222c13ae --- /dev/null +++ b/tests/specs/test/steps_dot_failing_steps/failing_steps.dot.out @@ -0,0 +1,53 @@ +! +. +! +! +! +! +! +! +! + + ERRORS + +nested failure ... step 1 ... inner 1 => [WILDCARD]failing_steps.ts:[WILDCARD] +error: Error: Failed. + throw new Error("Failed."); + ^ + at [WILDCARD]/failing_steps.ts:[WILDCARD] + +multiple test step failures ... step 1 => [WILDCARD]failing_steps.ts:[WILDCARD] +error: Error: Fail. + throw new Error("Fail."); + ^ + at [WILDCARD]/failing_steps.ts:[WILDCARD] + +multiple test step failures ... step 2 => [WILDCARD]failing_steps.ts:[WILDCARD] +error: Error: Fail. + await t.step("step 2", () => Promise.reject(new Error("Fail."))); + ^ + at [WILDCARD]/failing_steps.ts:[WILDCARD] + +failing step in failing test ... step 1 => [WILDCARD]failing_steps.ts:[WILDCARD] +error: Error: Fail. + throw new Error("Fail."); + ^ + at [WILDCARD]/failing_steps.ts:[WILDCARD] + +failing step in failing test => [WILDCARD]failing_steps.ts:[WILDCARD] +error: Error: Fail test. + throw new Error("Fail test."); + ^ + at [WILDCARD]/failing_steps.ts:[WILDCARD] + + FAILURES + +nested failure ... step 1 ... inner 1 => [WILDCARD]failing_steps.ts:[WILDCARD] +multiple test step failures ... step 1 => [WILDCARD]failing_steps.ts:[WILDCARD] +multiple test step failures ... step 2 => [WILDCARD]failing_steps.ts:[WILDCARD] +failing step in failing test ... step 1 => [WILDCARD]failing_steps.ts:[WILDCARD] +failing step in failing test => [WILDCARD]failing_steps.ts:[WILDCARD] + +FAILED | 0 passed (1 step) | 3 failed (5 steps) ([WILDCARD]) + +error: Test failed diff --git a/tests/specs/test/steps_dot_failing_steps/failing_steps.ts b/tests/specs/test/steps_dot_failing_steps/failing_steps.ts new file mode 100644 index 000000000..efa18d54e --- /dev/null +++ b/tests/specs/test/steps_dot_failing_steps/failing_steps.ts @@ -0,0 +1,27 @@ +Deno.test("nested failure", async (t) => { + const success = await t.step("step 1", async (t) => { + let success = await t.step("inner 1", () => { + throw new Error("Failed."); + }); + if (success) throw new Error("Expected failure"); + + success = await t.step("inner 2", () => {}); + if (!success) throw new Error("Expected success"); + }); + + if (success) throw new Error("Expected failure"); +}); + +Deno.test("multiple test step failures", async (t) => { + await t.step("step 1", () => { + throw new Error("Fail."); + }); + await t.step("step 2", () => Promise.reject(new Error("Fail."))); +}); + +Deno.test("failing step in failing test", async (t) => { + await t.step("step 1", () => { + throw new Error("Fail."); + }); + throw new Error("Fail test."); +}); diff --git a/tests/specs/test/steps_dot_ignored_steps/__test__.jsonc b/tests/specs/test/steps_dot_ignored_steps/__test__.jsonc new file mode 100644 index 000000000..672cc56f2 --- /dev/null +++ b/tests/specs/test/steps_dot_ignored_steps/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test --reporter=dot ignored_steps.ts", + "exitCode": 0, + "output": "ignored_steps.dot.out" +} diff --git a/tests/specs/test/steps_dot_ignored_steps/ignored_steps.dot.out b/tests/specs/test/steps_dot_ignored_steps/ignored_steps.dot.out new file mode 100644 index 000000000..442a06c62 --- /dev/null +++ b/tests/specs/test/steps_dot_ignored_steps/ignored_steps.dot.out @@ -0,0 +1,5 @@ +, +. +. + +ok | 1 passed (1 step) | 0 failed | 0 ignored (1 step) [WILDCARD] diff --git a/tests/specs/test/steps_dot_ignored_steps/ignored_steps.ts b/tests/specs/test/steps_dot_ignored_steps/ignored_steps.ts new file mode 100644 index 000000000..102b481fb --- /dev/null +++ b/tests/specs/test/steps_dot_ignored_steps/ignored_steps.ts @@ -0,0 +1,16 @@ +Deno.test("ignored step", async (t) => { + let result = await t.step({ + name: "step 1", + ignore: true, + fn: () => { + throw new Error("Fail."); + }, + }); + if (result !== false) throw new Error("Expected false."); + result = await t.step({ + name: "step 2", + ignore: false, + fn: () => {}, + }); + if (result !== true) throw new Error("Expected true."); +}); diff --git a/tests/specs/test/steps_dot_passing_steps/__test__.jsonc b/tests/specs/test/steps_dot_passing_steps/__test__.jsonc new file mode 100644 index 000000000..0ba87a6b2 --- /dev/null +++ b/tests/specs/test/steps_dot_passing_steps/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test --reporter=dot passing_steps.ts", + "exitCode": 0, + "output": "passing_steps.dot.out" +} diff --git a/tests/specs/test/steps_dot_passing_steps/passing_steps.dot.out b/tests/specs/test/steps_dot_passing_steps/passing_steps.dot.out new file mode 100644 index 000000000..243cacd69 --- /dev/null +++ b/tests/specs/test/steps_dot_passing_steps/passing_steps.dot.out @@ -0,0 +1,17 @@ +[WILDCARD] +. +. +. +. +. +. +. +. +. +. +. +. +. + +ok | 6 passed (21 steps) | 0 failed ([WILDCARD]) + diff --git a/tests/specs/test/steps_dot_passing_steps/passing_steps.ts b/tests/specs/test/steps_dot_passing_steps/passing_steps.ts new file mode 100644 index 000000000..fd145954b --- /dev/null +++ b/tests/specs/test/steps_dot_passing_steps/passing_steps.ts @@ -0,0 +1,127 @@ +Deno.test("description", async (t) => { + const success = await t.step("step 1", async (t) => { + await t.step("inner 1", () => {}); + await t.step("inner 2", () => {}); + }); + + if (!success) throw new Error("Expected the step to return true."); +}); + +Deno.test("description function as first arg", async (t) => { + const success = await t.step(async function step1(t) { + await t.step(function inner1() {}); + await t.step(function inner1() {}); + }); + + if (!success) throw new Error("Expected the step to return true."); +}); + +Deno.test("parallel steps without sanitizers", async (t) => { + // allowed + await Promise.all([ + t.step({ + name: "step 1", + fn: async () => { + await new Promise((resolve) => setTimeout(resolve, 10)); + }, + sanitizeOps: false, + sanitizeResources: false, + sanitizeExit: false, + }), + t.step({ + name: "step 2", + fn: async () => { + await new Promise((resolve) => setTimeout(resolve, 10)); + }, + sanitizeOps: false, + sanitizeResources: false, + sanitizeExit: false, + }), + ]); +}); + +Deno.test({ + name: "parallel steps without sanitizers due to parent", + fn: async (t) => { + // allowed because parent disabled the sanitizers + await Promise.all([ + t.step("step 1", async () => { + await new Promise((resolve) => setTimeout(resolve, 10)); + }), + t.step("step 2", async () => { + await new Promise((resolve) => setTimeout(resolve, 10)); + }), + ]); + }, + sanitizeResources: false, + sanitizeOps: false, + sanitizeExit: false, +}); + +Deno.test({ + name: "steps with disabled sanitizers, then enabled, then parallel disabled", + fn: async (t) => { + await t.step("step 1", async (t) => { + await t.step({ + name: "step 1", + fn: async (t) => { + await Promise.all([ + t.step({ + name: "step 1", + fn: async (t) => { + await new Promise((resolve) => setTimeout(resolve, 10)); + await Promise.all([ + t.step("step 1", () => {}), + t.step("step 1", () => {}), + ]); + }, + sanitizeExit: false, + sanitizeResources: false, + sanitizeOps: false, + }), + t.step({ + name: "step 2", + fn: () => {}, + sanitizeResources: false, + sanitizeOps: false, + sanitizeExit: false, + }), + ]); + }, + sanitizeResources: true, + sanitizeOps: true, + sanitizeExit: true, + }); + }); + }, + sanitizeResources: false, + sanitizeOps: false, + sanitizeExit: false, +}); + +Deno.test("steps buffered then streaming reporting", async (t) => { + // no sanitizers so this will be buffered + await t.step({ + name: "step 1", + fn: async (t) => { + // also ensure the buffered tests display in order regardless of the second one finishing first + const step2Finished = Promise.withResolvers<void>(); + const step1 = t.step("step 1 - 1", async () => { + await step2Finished.promise; + }); + const step2 = t.step("step 1 - 2", async (t) => { + await t.step("step 1 - 2 - 1", () => {}); + }); + await step2; + step2Finished.resolve(); + await step1; + }, + sanitizeResources: false, + sanitizeOps: false, + sanitizeExit: false, + }); + + // now this will start streaming and we want to + // ensure it flushes the buffer of the last test + await t.step("step 2", async () => {}); +}); diff --git a/tests/specs/test/steps_failing_steps/__test__.jsonc b/tests/specs/test/steps_failing_steps/__test__.jsonc new file mode 100644 index 000000000..f4194c50c --- /dev/null +++ b/tests/specs/test/steps_failing_steps/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test failing_steps.ts", + "exitCode": 1, + "output": "failing_steps.out" +} diff --git a/tests/specs/test/steps_failing_steps/failing_steps.out b/tests/specs/test/steps_failing_steps/failing_steps.out new file mode 100644 index 000000000..f66e089bc --- /dev/null +++ b/tests/specs/test/steps_failing_steps/failing_steps.out @@ -0,0 +1,59 @@ +[WILDCARD] +running 3 tests from [WILDCARD]failing_steps.ts +nested failure ... + step 1 ... + inner 1 ... FAILED ([WILDCARD]) + inner 2 ... ok ([WILDCARD]) + step 1 ... FAILED (due to 1 failed step) ([WILDCARD]) +nested failure ... FAILED (due to 1 failed step) ([WILDCARD]) +multiple test step failures ... + step 1 ... FAILED ([WILDCARD]) + step 2 ... FAILED ([WILDCARD]) +multiple test step failures ... FAILED (due to 2 failed steps) ([WILDCARD]) +failing step in failing test ... + step 1 ... FAILED ([WILDCARD]) +failing step in failing test ... FAILED ([WILDCARD]) + + ERRORS + +nested failure ... step 1 ... inner 1 => [WILDCARD]failing_steps.ts:[WILDCARD] +error: Error: Failed. + throw new Error("Failed."); + ^ + at [WILDCARD]/failing_steps.ts:[WILDCARD] + +multiple test step failures ... step 1 => [WILDCARD]failing_steps.ts:[WILDCARD] +error: Error: Fail. + throw new Error("Fail."); + ^ + at [WILDCARD]/failing_steps.ts:[WILDCARD] + +multiple test step failures ... step 2 => [WILDCARD]failing_steps.ts:[WILDCARD] +error: Error: Fail. + await t.step("step 2", () => Promise.reject(new Error("Fail."))); + ^ + at [WILDCARD]/failing_steps.ts:[WILDCARD] + +failing step in failing test ... step 1 => [WILDCARD]failing_steps.ts:[WILDCARD] +error: Error: Fail. + throw new Error("Fail."); + ^ + at [WILDCARD]/failing_steps.ts:[WILDCARD] + +failing step in failing test => [WILDCARD]failing_steps.ts:[WILDCARD] +error: Error: Fail test. + throw new Error("Fail test."); + ^ + at [WILDCARD]/failing_steps.ts:[WILDCARD] + + FAILURES + +nested failure ... step 1 ... inner 1 => [WILDCARD]failing_steps.ts:[WILDCARD] +multiple test step failures ... step 1 => [WILDCARD]failing_steps.ts:[WILDCARD] +multiple test step failures ... step 2 => [WILDCARD]failing_steps.ts:[WILDCARD] +failing step in failing test ... step 1 => [WILDCARD]failing_steps.ts:[WILDCARD] +failing step in failing test => [WILDCARD]failing_steps.ts:[WILDCARD] + +FAILED | 0 passed (1 step) | 3 failed (5 steps) ([WILDCARD]) + +error: Test failed diff --git a/tests/specs/test/steps_failing_steps/failing_steps.ts b/tests/specs/test/steps_failing_steps/failing_steps.ts new file mode 100644 index 000000000..efa18d54e --- /dev/null +++ b/tests/specs/test/steps_failing_steps/failing_steps.ts @@ -0,0 +1,27 @@ +Deno.test("nested failure", async (t) => { + const success = await t.step("step 1", async (t) => { + let success = await t.step("inner 1", () => { + throw new Error("Failed."); + }); + if (success) throw new Error("Expected failure"); + + success = await t.step("inner 2", () => {}); + if (!success) throw new Error("Expected success"); + }); + + if (success) throw new Error("Expected failure"); +}); + +Deno.test("multiple test step failures", async (t) => { + await t.step("step 1", () => { + throw new Error("Fail."); + }); + await t.step("step 2", () => Promise.reject(new Error("Fail."))); +}); + +Deno.test("failing step in failing test", async (t) => { + await t.step("step 1", () => { + throw new Error("Fail."); + }); + throw new Error("Fail test."); +}); diff --git a/tests/specs/test/steps_ignored_steps/__test__.jsonc b/tests/specs/test/steps_ignored_steps/__test__.jsonc new file mode 100644 index 000000000..d3f5a81cf --- /dev/null +++ b/tests/specs/test/steps_ignored_steps/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test ignored_steps.ts", + "exitCode": 0, + "output": "ignored_steps.out" +} diff --git a/tests/specs/test/steps_ignored_steps/ignored_steps.out b/tests/specs/test/steps_ignored_steps/ignored_steps.out new file mode 100644 index 000000000..0960e6256 --- /dev/null +++ b/tests/specs/test/steps_ignored_steps/ignored_steps.out @@ -0,0 +1,8 @@ +[WILDCARD] +running 1 test from [WILDCARD]ignored_steps.ts +ignored step ... + step 1 ... ignored ([WILDCARD]) + step 2 ... ok ([WILDCARD]) +ignored step ... ok ([WILDCARD]) + +ok | 1 passed (1 step) | 0 failed | 0 ignored (1 step) [WILDCARD] diff --git a/tests/specs/test/steps_ignored_steps/ignored_steps.ts b/tests/specs/test/steps_ignored_steps/ignored_steps.ts new file mode 100644 index 000000000..102b481fb --- /dev/null +++ b/tests/specs/test/steps_ignored_steps/ignored_steps.ts @@ -0,0 +1,16 @@ +Deno.test("ignored step", async (t) => { + let result = await t.step({ + name: "step 1", + ignore: true, + fn: () => { + throw new Error("Fail."); + }, + }); + if (result !== false) throw new Error("Expected false."); + result = await t.step({ + name: "step 2", + ignore: false, + fn: () => {}, + }); + if (result !== true) throw new Error("Expected true."); +}); diff --git a/tests/specs/test/steps_invalid_usage/__test__.jsonc b/tests/specs/test/steps_invalid_usage/__test__.jsonc new file mode 100644 index 000000000..763ec2a20 --- /dev/null +++ b/tests/specs/test/steps_invalid_usage/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test invalid_usage.ts", + "exitCode": 1, + "output": "invalid_usage.out" +} diff --git a/tests/specs/test/steps_invalid_usage/invalid_usage.out b/tests/specs/test/steps_invalid_usage/invalid_usage.out new file mode 100644 index 000000000..413a97cfd --- /dev/null +++ b/tests/specs/test/steps_invalid_usage/invalid_usage.out @@ -0,0 +1,82 @@ +[WILDCARD] +running 7 tests from [WILDCARD]invalid_usage.ts +capturing ... + some step ... ok ([WILDCARD]) +capturing ... FAILED ([WILDCARD]) +top level missing await ... + step ... INCOMPLETE +top level missing await ... FAILED (due to incomplete steps) ([WILDCARD]) +inner missing await ... + step ... + inner ... INCOMPLETE + step ... FAILED (due to incomplete steps) ([WILDCARD]) +inner missing await ... FAILED (due to 1 failed step) ([WILDCARD]) +parallel steps with sanitizers ... + step 1 ... INCOMPLETE + step 2 ... FAILED ([WILDCARD]) +parallel steps with sanitizers ... FAILED (due to incomplete steps) ([WILDCARD]) +parallel steps when first has sanitizer ... + step 1 ... ok ([WILDCARD]) + step 2 ... FAILED ([WILDCARD]) +parallel steps when first has sanitizer ... FAILED (due to 1 failed step) ([WILDCARD]) +parallel steps when second has sanitizer ... + step 1 ... ok ([WILDCARD]) + step 2 ... FAILED ([WILDCARD]) +parallel steps when second has sanitizer ... FAILED (due to 1 failed step) ([WILDCARD]) +parallel steps where only inner tests have sanitizers ... + step 1 ... + step inner ... ok ([WILDCARD]) + step 1 ... ok ([WILDCARD]) + step 2 ... + step inner ... FAILED ([WILDCARD]) + step 2 ... FAILED (due to 1 failed step) ([WILDCARD]) +parallel steps where only inner tests have sanitizers ... FAILED (due to 1 failed step) ([WILDCARD]) + + ERRORS + +capturing => [WILDCARD]invalid_usage.ts:[WILDCARD] +error: Error: Cannot run test step after parent scope has finished execution. Ensure any `.step(...)` calls are executed before their parent scope completes execution. + await capturedContext.step("next step", () => {}); + ^ + at TestContext.step ([WILDCARD]) + at [WILDCARD]/invalid_usage.ts:[WILDCARD] + +top level missing await ... step => [WILDCARD]invalid_usage.ts:[WILDCARD] +error: Didn't complete before parent. Await step with `await t.step(...)`. + +inner missing await ... step ... inner => [WILDCARD]invalid_usage.ts:[WILDCARD] +error: Didn't complete before parent. Await step with `await t.step(...)`. + +parallel steps with sanitizers ... step 2 => [WILDCARD]invalid_usage.ts:[WILDCARD] +error: Started test step while another test step with sanitizers was running: + * parallel steps with sanitizers ... step 1 + +parallel steps with sanitizers ... step 1 => [WILDCARD]invalid_usage.ts:[WILDCARD] +error: Didn't complete before parent. Await step with `await t.step(...)`. + +parallel steps when first has sanitizer ... step 2 => [WILDCARD]invalid_usage.ts:[WILDCARD] +error: Started test step while another test step with sanitizers was running: + * parallel steps when first has sanitizer ... step 1 + +parallel steps when second has sanitizer ... step 2 => [WILDCARD]invalid_usage.ts:[WILDCARD] +error: Started test step with sanitizers while another test step was running: + * parallel steps when second has sanitizer ... step 1 + +parallel steps where only inner tests have sanitizers ... step 2 ... step inner => [WILDCARD]invalid_usage.ts:[WILDCARD] +error: Started test step with sanitizers while another test step was running: + * parallel steps where only inner tests have sanitizers ... step 1 + + FAILURES + +capturing => [WILDCARD]invalid_usage.ts:1:6 +top level missing await ... step => [WILDCARD]invalid_usage.ts:[WILDCARD] +inner missing await ... step ... inner => [WILDCARD]invalid_usage.ts:[WILDCARD] +parallel steps with sanitizers ... step 2 => [WILDCARD]invalid_usage.ts:[WILDCARD] +parallel steps with sanitizers ... step 1 => [WILDCARD]invalid_usage.ts:[WILDCARD] +parallel steps when first has sanitizer ... step 2 => [WILDCARD]invalid_usage.ts:[WILDCARD] +parallel steps when second has sanitizer ... step 2 => [WILDCARD]invalid_usage.ts:[WILDCARD] +parallel steps where only inner tests have sanitizers ... step 2 ... step inner => [WILDCARD]invalid_usage.ts:[WILDCARD] + +FAILED | 0 passed (5 steps) | 7 failed (9 steps) ([WILDCARD]) + +error: Test failed diff --git a/tests/specs/test/steps_invalid_usage/invalid_usage.ts b/tests/specs/test/steps_invalid_usage/invalid_usage.ts new file mode 100644 index 000000000..1acfc874c --- /dev/null +++ b/tests/specs/test/steps_invalid_usage/invalid_usage.ts @@ -0,0 +1,118 @@ +Deno.test("capturing", async (t) => { + let capturedContext!: Deno.TestContext; + await t.step("some step", (t) => { + capturedContext = t; + }); + // this should error because the scope of the tester has already completed + await capturedContext.step("next step", () => {}); +}); + +Deno.test("top level missing await", (t) => { + t.step("step", () => { + return new Promise(() => {}); + }); +}); + +Deno.test({ + name: "inner missing await", + fn: async (t) => { + await t.step("step", (t) => { + t.step("inner", () => { + return new Promise((resolve) => setTimeout(resolve, 10)); + }); + }); + await new Promise((resolve) => setTimeout(resolve, 10)); + }, + sanitizeResources: false, + sanitizeOps: false, + sanitizeExit: false, +}); + +Deno.test("parallel steps with sanitizers", async (t) => { + // not allowed because steps with sanitizers cannot be run in parallel + const step1Entered = Promise.withResolvers<void>(); + const testFinished = Promise.withResolvers<void>(); + t.step("step 1", async () => { + step1Entered.resolve(); + await testFinished.promise; + }); + await step1Entered.promise; + await t.step("step 2", () => {}); +}); + +Deno.test("parallel steps when first has sanitizer", async (t) => { + const step1Entered = Promise.withResolvers<void>(); + const step2Finished = Promise.withResolvers<void>(); + const step1 = t.step({ + name: "step 1", + fn: async () => { + step1Entered.resolve(); + await step2Finished.promise; + }, + }); + await step1Entered.promise; + await t.step({ + name: "step 2", + fn: () => {}, + sanitizeOps: false, + sanitizeResources: false, + sanitizeExit: false, + }); + step2Finished.resolve(); + await step1; +}); + +Deno.test("parallel steps when second has sanitizer", async (t) => { + const step1Entered = Promise.withResolvers<void>(); + const step2Finished = Promise.withResolvers<void>(); + const step1 = t.step({ + name: "step 1", + fn: async () => { + step1Entered.resolve(); + await step2Finished.promise; + }, + sanitizeOps: false, + sanitizeResources: false, + sanitizeExit: false, + }); + await step1Entered.promise; + await t.step({ + name: "step 2", + fn: async () => { + await new Promise((resolve) => setTimeout(resolve, 100)); + }, + }); + step2Finished.resolve(); + await step1; +}); + +Deno.test({ + name: "parallel steps where only inner tests have sanitizers", + fn: async (t) => { + const step1Entered = Promise.withResolvers<void>(); + const step2Finished = Promise.withResolvers<void>(); + const step1 = t.step("step 1", async (t) => { + await t.step({ + name: "step inner", + fn: async () => { + step1Entered.resolve(); + await step2Finished.promise; + }, + sanitizeOps: true, + }); + }); + await step1Entered.promise; + await t.step("step 2", async (t) => { + await t.step({ + name: "step inner", + fn: () => {}, + sanitizeOps: true, + }); + }); + step2Finished.resolve(); + await step1; + }, + sanitizeResources: false, + sanitizeOps: false, + sanitizeExit: false, +}); diff --git a/tests/specs/test/steps_output_within/__test__.jsonc b/tests/specs/test/steps_output_within/__test__.jsonc new file mode 100644 index 000000000..2141b6b45 --- /dev/null +++ b/tests/specs/test/steps_output_within/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test output_within.ts", + "exitCode": 0, + "output": "output_within.out" +} diff --git a/tests/specs/test/steps_output_within/output_within.out b/tests/specs/test/steps_output_within/output_within.out new file mode 100644 index 000000000..7c83b816f --- /dev/null +++ b/tests/specs/test/steps_output_within/output_within.out @@ -0,0 +1,29 @@ +[WILDCARD] +running 1 test from [WILDCARD]output_within.ts +description ... +------- output ------- +1 +----- output end ----- + step 1 ... +------- output ------- +2 +----- output end ----- + inner 1 ... +------- output ------- +3 +----- output end ----- + inner 1 ... ok ([WILDCARD]s) + inner 2 ... +------- output ------- +4 +----- output end ----- + inner 2 ... ok ([WILDCARD]s) +------- output ------- +5 +----- output end ----- + step 1 ... ok ([WILDCARD]s) +------- output ------- +6 +----- output end ----- +description ... ok ([WILDCARD]s) +[WILDCARD] diff --git a/tests/specs/test/steps_output_within/output_within.ts b/tests/specs/test/steps_output_within/output_within.ts new file mode 100644 index 000000000..d3438a8ad --- /dev/null +++ b/tests/specs/test/steps_output_within/output_within.ts @@ -0,0 +1,15 @@ +Deno.test("description", async (t) => { + // the output is not great, but this is an extreme scenario + console.log(1); + await t.step("step 1", async (t) => { + console.log(2); + await t.step("inner 1", () => { + console.log(3); + }); + await t.step("inner 2", () => { + console.log(4); + }); + console.log(5); + }); + console.log(6); +}); diff --git a/tests/specs/test/steps_passing_steps/__test__.jsonc b/tests/specs/test/steps_passing_steps/__test__.jsonc new file mode 100644 index 000000000..daa801392 --- /dev/null +++ b/tests/specs/test/steps_passing_steps/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test passing_steps.ts", + "exitCode": 0, + "output": "passing_steps.out" +} diff --git a/tests/specs/test/steps_passing_steps/passing_steps.out b/tests/specs/test/steps_passing_steps/passing_steps.out new file mode 100644 index 000000000..c59be298e --- /dev/null +++ b/tests/specs/test/steps_passing_steps/passing_steps.out @@ -0,0 +1,44 @@ +[WILDCARD] +running 6 tests from [WILDCARD]passing_steps.ts +description ... + step 1 ... + inner 1 ... ok ([WILDCARD]s) + inner 2 ... ok ([WILDCARD]s) + step 1 ... ok ([WILDCARD]s) +description ... ok ([WILDCARD]s) +description function as first arg ... + step1 ... + inner1 ... ok ([WILDCARD]s) + inner1 ... ok ([WILDCARD]s) + step1 ... ok ([WILDCARD]s) +description function as first arg ... ok ([WILDCARD]s) +parallel steps without sanitizers ... + step 1 ... ok ([WILDCARD]) + step 2 ... ok ([WILDCARD]) +parallel steps without sanitizers ... ok ([WILDCARD]) +parallel steps without sanitizers due to parent ... + step 1 ... ok ([WILDCARD]) + step 2 ... ok ([WILDCARD]) +parallel steps without sanitizers due to parent ... ok ([WILDCARD]) +steps with disabled sanitizers, then enabled, then parallel disabled ... + step 1 ... + step 1 ... + step 1 ... + step 1 ... ok ([WILDCARD]) + step 1 ... ok ([WILDCARD]) + step 1 ... ok ([WILDCARD]) + step 2 ... ok ([WILDCARD]) + step 1 ... ok ([WILDCARD]) + step 1 ... ok ([WILDCARD]) +steps with disabled sanitizers, then enabled, then parallel disabled ... ok ([WILDCARD]) +steps buffered then streaming reporting ... + step 1 ... + step 1 - 1 ... ok ([WILDCARD]) + step 1 - 2 ... + step 1 - 2 - 1 ... ok ([WILDCARD]) + step 1 - 2 ... ok ([WILDCARD]) + step 1 ... ok ([WILDCARD]) + step 2 ... ok ([WILDCARD]) +steps buffered then streaming reporting ... ok ([WILDCARD]) + +ok | 6 passed (21 steps) | 0 failed [WILDCARD] diff --git a/tests/specs/test/steps_passing_steps/passing_steps.ts b/tests/specs/test/steps_passing_steps/passing_steps.ts new file mode 100644 index 000000000..fd145954b --- /dev/null +++ b/tests/specs/test/steps_passing_steps/passing_steps.ts @@ -0,0 +1,127 @@ +Deno.test("description", async (t) => { + const success = await t.step("step 1", async (t) => { + await t.step("inner 1", () => {}); + await t.step("inner 2", () => {}); + }); + + if (!success) throw new Error("Expected the step to return true."); +}); + +Deno.test("description function as first arg", async (t) => { + const success = await t.step(async function step1(t) { + await t.step(function inner1() {}); + await t.step(function inner1() {}); + }); + + if (!success) throw new Error("Expected the step to return true."); +}); + +Deno.test("parallel steps without sanitizers", async (t) => { + // allowed + await Promise.all([ + t.step({ + name: "step 1", + fn: async () => { + await new Promise((resolve) => setTimeout(resolve, 10)); + }, + sanitizeOps: false, + sanitizeResources: false, + sanitizeExit: false, + }), + t.step({ + name: "step 2", + fn: async () => { + await new Promise((resolve) => setTimeout(resolve, 10)); + }, + sanitizeOps: false, + sanitizeResources: false, + sanitizeExit: false, + }), + ]); +}); + +Deno.test({ + name: "parallel steps without sanitizers due to parent", + fn: async (t) => { + // allowed because parent disabled the sanitizers + await Promise.all([ + t.step("step 1", async () => { + await new Promise((resolve) => setTimeout(resolve, 10)); + }), + t.step("step 2", async () => { + await new Promise((resolve) => setTimeout(resolve, 10)); + }), + ]); + }, + sanitizeResources: false, + sanitizeOps: false, + sanitizeExit: false, +}); + +Deno.test({ + name: "steps with disabled sanitizers, then enabled, then parallel disabled", + fn: async (t) => { + await t.step("step 1", async (t) => { + await t.step({ + name: "step 1", + fn: async (t) => { + await Promise.all([ + t.step({ + name: "step 1", + fn: async (t) => { + await new Promise((resolve) => setTimeout(resolve, 10)); + await Promise.all([ + t.step("step 1", () => {}), + t.step("step 1", () => {}), + ]); + }, + sanitizeExit: false, + sanitizeResources: false, + sanitizeOps: false, + }), + t.step({ + name: "step 2", + fn: () => {}, + sanitizeResources: false, + sanitizeOps: false, + sanitizeExit: false, + }), + ]); + }, + sanitizeResources: true, + sanitizeOps: true, + sanitizeExit: true, + }); + }); + }, + sanitizeResources: false, + sanitizeOps: false, + sanitizeExit: false, +}); + +Deno.test("steps buffered then streaming reporting", async (t) => { + // no sanitizers so this will be buffered + await t.step({ + name: "step 1", + fn: async (t) => { + // also ensure the buffered tests display in order regardless of the second one finishing first + const step2Finished = Promise.withResolvers<void>(); + const step1 = t.step("step 1 - 1", async () => { + await step2Finished.promise; + }); + const step2 = t.step("step 1 - 2", async (t) => { + await t.step("step 1 - 2 - 1", () => {}); + }); + await step2; + step2Finished.resolve(); + await step1; + }, + sanitizeResources: false, + sanitizeOps: false, + sanitizeExit: false, + }); + + // now this will start streaming and we want to + // ensure it flushes the buffer of the last test + await t.step("step 2", async () => {}); +}); diff --git a/tests/specs/test/steps_tap_failing_steps/__test__.jsonc b/tests/specs/test/steps_tap_failing_steps/__test__.jsonc new file mode 100644 index 000000000..fc83a7cdf --- /dev/null +++ b/tests/specs/test/steps_tap_failing_steps/__test__.jsonc @@ -0,0 +1,8 @@ +{ + "args": "test --reporter=tap failing_steps.ts", + "exitCode": 1, + "envs": { + "NO_COLOR": "1" + }, + "output": "failing_steps.tap.out" +} diff --git a/tests/specs/test/steps_tap_failing_steps/failing_steps.tap.out b/tests/specs/test/steps_tap_failing_steps/failing_steps.tap.out new file mode 100644 index 000000000..b47b9fed3 --- /dev/null +++ b/tests/specs/test/steps_tap_failing_steps/failing_steps.tap.out @@ -0,0 +1,43 @@ +TAP version 14 +# [WILDCARD]failing_steps.ts +# Subtest: nested failure + not ok 1 - inner 1 + --- + {"message":"Error: Failed.\n throw new Error(\"Failed.\");\n ^\n at [WILDCARD]/failing_steps.ts:[WILDCARD]\n[WILDCARD]","severity":"fail","at":{"file":"[WILDCARD]failing_steps.ts","line":[WILDCARD]}} + ... + ok 2 - inner 2 + not ok 3 - step 1 + --- + {"message":"1 test step failed.","severity":"fail","at":{"file":"[WILDCARD]failing_steps.ts","line":[WILDCARD]}} + ... + 1..3 +not ok 1 - nested failure + --- + {"message":"1 test step failed.","severity":"fail","at":{"file":"[WILDCARD]failing_steps.ts","line":[WILDCARD]}} + ... +# Subtest: multiple test step failures + not ok 1 - step 1 + --- + {"message":"Error: Fail.\n throw new Error(\"Fail.\");\n ^\n at [WILDCARD]/failing_steps.ts:[WILDCARD]\n[WILDCARD]","severity":"fail","at":{"file":"[WILDCARD]failing_steps.ts","line":[WILDCARD]}} + ... + not ok 2 - step 2 + --- + {"message":"Error: Fail.\n await t.step(\"step 2\", () => Promise.reject(new Error(\"Fail.\")));\n ^\n at [WILDCARD]/failing_steps.ts:[WILDCARD]\n[WILDCARD]","severity":"fail","at":{"file":"[WILDCARD]failing_steps.ts","line":[WILDCARD]}} + ... + 1..2 +not ok 2 - multiple test step failures + --- + {"message":"2 test steps failed.","severity":"fail","at":{"file":"[WILDCARD]failing_steps.ts","line":[WILDCARD]}} + ... +# Subtest: failing step in failing test + not ok 1 - step 1 + --- + {"message":"Error: Fail.\n throw new Error(\"Fail.\");\n ^\n at [WILDCARD]/failing_steps.ts:[WILDCARD]\n[WILDCARD]","severity":"fail","at":{"file":"[WILDCARD]failing_steps.ts","line":[WILDCARD]}} + ... + 1..1 +not ok 3 - failing step in failing test + --- + {"message":"Error: Fail test.\n throw new Error(\"Fail test.\");\n ^\n at [WILDCARD]/failing_steps.ts:[WILDCARD]","severity":"fail","at":{"file":"[WILDCARD]failing_steps.ts","line":[WILDCARD]}} + ... +1..3 +error: Test failed diff --git a/tests/specs/test/steps_tap_failing_steps/failing_steps.ts b/tests/specs/test/steps_tap_failing_steps/failing_steps.ts new file mode 100644 index 000000000..efa18d54e --- /dev/null +++ b/tests/specs/test/steps_tap_failing_steps/failing_steps.ts @@ -0,0 +1,27 @@ +Deno.test("nested failure", async (t) => { + const success = await t.step("step 1", async (t) => { + let success = await t.step("inner 1", () => { + throw new Error("Failed."); + }); + if (success) throw new Error("Expected failure"); + + success = await t.step("inner 2", () => {}); + if (!success) throw new Error("Expected success"); + }); + + if (success) throw new Error("Expected failure"); +}); + +Deno.test("multiple test step failures", async (t) => { + await t.step("step 1", () => { + throw new Error("Fail."); + }); + await t.step("step 2", () => Promise.reject(new Error("Fail."))); +}); + +Deno.test("failing step in failing test", async (t) => { + await t.step("step 1", () => { + throw new Error("Fail."); + }); + throw new Error("Fail test."); +}); diff --git a/tests/specs/test/steps_tap_ignored_steps/__test__.jsonc b/tests/specs/test/steps_tap_ignored_steps/__test__.jsonc new file mode 100644 index 000000000..c28efe691 --- /dev/null +++ b/tests/specs/test/steps_tap_ignored_steps/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test --reporter=tap ignored_steps.ts", + "exitCode": 0, + "output": "ignored_steps.tap.out" +} diff --git a/tests/specs/test/steps_tap_ignored_steps/ignored_steps.tap.out b/tests/specs/test/steps_tap_ignored_steps/ignored_steps.tap.out new file mode 100644 index 000000000..638905772 --- /dev/null +++ b/tests/specs/test/steps_tap_ignored_steps/ignored_steps.tap.out @@ -0,0 +1,8 @@ +TAP version 14 +# [WILDCARD]ignored_steps.ts +# Subtest: ignored step + ok 1 - step 1 # SKIP + ok 2 - step 2 + 1..2 +ok 1 - ignored step +1..1 diff --git a/tests/specs/test/steps_tap_ignored_steps/ignored_steps.ts b/tests/specs/test/steps_tap_ignored_steps/ignored_steps.ts new file mode 100644 index 000000000..102b481fb --- /dev/null +++ b/tests/specs/test/steps_tap_ignored_steps/ignored_steps.ts @@ -0,0 +1,16 @@ +Deno.test("ignored step", async (t) => { + let result = await t.step({ + name: "step 1", + ignore: true, + fn: () => { + throw new Error("Fail."); + }, + }); + if (result !== false) throw new Error("Expected false."); + result = await t.step({ + name: "step 2", + ignore: false, + fn: () => {}, + }); + if (result !== true) throw new Error("Expected true."); +}); diff --git a/tests/specs/test/steps_tap_passing_steps/__test__.jsonc b/tests/specs/test/steps_tap_passing_steps/__test__.jsonc new file mode 100644 index 000000000..b30d20d6b --- /dev/null +++ b/tests/specs/test/steps_tap_passing_steps/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test --reporter=tap passing_steps.ts", + "exitCode": 0, + "output": "passing_steps.tap.out" +} diff --git a/tests/specs/test/steps_tap_passing_steps/passing_steps.tap.out b/tests/specs/test/steps_tap_passing_steps/passing_steps.tap.out new file mode 100644 index 000000000..0797fb7de --- /dev/null +++ b/tests/specs/test/steps_tap_passing_steps/passing_steps.tap.out @@ -0,0 +1,42 @@ +TAP version 14 +# [WILDCARD]passing_steps.ts +# Subtest: description + ok 1 - inner 1 + ok 2 - inner 2 + ok 3 - step 1 + 1..3 +ok 1 - description +# Subtest: description function as first arg + ok 1 - inner1 + ok 2 - inner1 + ok 3 - step1 + 1..3 +ok 2 - description function as first arg +# Subtest: parallel steps without sanitizers + ok 1 - step 1 + ok 2 - step 2 + 1..2 +ok 3 - parallel steps without sanitizers +# Subtest: parallel steps without sanitizers due to parent + ok 1 - step 1 + ok 2 - step 2 + 1..2 +ok 4 - parallel steps without sanitizers due to parent +# Subtest: steps with disabled sanitizers, then enabled, then parallel disabled + ok 1 - step 2 + ok 2 - step 1 + ok 3 - step 1 + ok 4 - step 1 + ok 5 - step 1 + ok 6 - step 1 + 1..6 +ok 5 - steps with disabled sanitizers, then enabled, then parallel disabled +# Subtest: steps buffered then streaming reporting + ok 1 - step 1 - 2 - 1 + ok 2 - step 1 - 2 + ok 3 - step 1 - 1 + ok 4 - step 1 + ok 5 - step 2 + 1..5 +ok 6 - steps buffered then streaming reporting +1..6 diff --git a/tests/specs/test/steps_tap_passing_steps/passing_steps.ts b/tests/specs/test/steps_tap_passing_steps/passing_steps.ts new file mode 100644 index 000000000..fd145954b --- /dev/null +++ b/tests/specs/test/steps_tap_passing_steps/passing_steps.ts @@ -0,0 +1,127 @@ +Deno.test("description", async (t) => { + const success = await t.step("step 1", async (t) => { + await t.step("inner 1", () => {}); + await t.step("inner 2", () => {}); + }); + + if (!success) throw new Error("Expected the step to return true."); +}); + +Deno.test("description function as first arg", async (t) => { + const success = await t.step(async function step1(t) { + await t.step(function inner1() {}); + await t.step(function inner1() {}); + }); + + if (!success) throw new Error("Expected the step to return true."); +}); + +Deno.test("parallel steps without sanitizers", async (t) => { + // allowed + await Promise.all([ + t.step({ + name: "step 1", + fn: async () => { + await new Promise((resolve) => setTimeout(resolve, 10)); + }, + sanitizeOps: false, + sanitizeResources: false, + sanitizeExit: false, + }), + t.step({ + name: "step 2", + fn: async () => { + await new Promise((resolve) => setTimeout(resolve, 10)); + }, + sanitizeOps: false, + sanitizeResources: false, + sanitizeExit: false, + }), + ]); +}); + +Deno.test({ + name: "parallel steps without sanitizers due to parent", + fn: async (t) => { + // allowed because parent disabled the sanitizers + await Promise.all([ + t.step("step 1", async () => { + await new Promise((resolve) => setTimeout(resolve, 10)); + }), + t.step("step 2", async () => { + await new Promise((resolve) => setTimeout(resolve, 10)); + }), + ]); + }, + sanitizeResources: false, + sanitizeOps: false, + sanitizeExit: false, +}); + +Deno.test({ + name: "steps with disabled sanitizers, then enabled, then parallel disabled", + fn: async (t) => { + await t.step("step 1", async (t) => { + await t.step({ + name: "step 1", + fn: async (t) => { + await Promise.all([ + t.step({ + name: "step 1", + fn: async (t) => { + await new Promise((resolve) => setTimeout(resolve, 10)); + await Promise.all([ + t.step("step 1", () => {}), + t.step("step 1", () => {}), + ]); + }, + sanitizeExit: false, + sanitizeResources: false, + sanitizeOps: false, + }), + t.step({ + name: "step 2", + fn: () => {}, + sanitizeResources: false, + sanitizeOps: false, + sanitizeExit: false, + }), + ]); + }, + sanitizeResources: true, + sanitizeOps: true, + sanitizeExit: true, + }); + }); + }, + sanitizeResources: false, + sanitizeOps: false, + sanitizeExit: false, +}); + +Deno.test("steps buffered then streaming reporting", async (t) => { + // no sanitizers so this will be buffered + await t.step({ + name: "step 1", + fn: async (t) => { + // also ensure the buffered tests display in order regardless of the second one finishing first + const step2Finished = Promise.withResolvers<void>(); + const step1 = t.step("step 1 - 1", async () => { + await step2Finished.promise; + }); + const step2 = t.step("step 1 - 2", async (t) => { + await t.step("step 1 - 2 - 1", () => {}); + }); + await step2; + step2Finished.resolve(); + await step1; + }, + sanitizeResources: false, + sanitizeOps: false, + sanitizeExit: false, + }); + + // now this will start streaming and we want to + // ensure it flushes the buffer of the last test + await t.step("step 2", async () => {}); +}); diff --git a/tests/specs/test/test_filtered_out_only/__test__.jsonc b/tests/specs/test/test_filtered_out_only/__test__.jsonc new file mode 100644 index 000000000..b190d0166 --- /dev/null +++ b/tests/specs/test/test_filtered_out_only/__test__.jsonc @@ -0,0 +1,4 @@ +{ + "args": "test --quiet --filter foo main.ts", + "output": "main.out" +} diff --git a/tests/specs/test/test_filtered_out_only/main.out b/tests/specs/test/test_filtered_out_only/main.out new file mode 100644 index 000000000..488643c80 --- /dev/null +++ b/tests/specs/test/test_filtered_out_only/main.out @@ -0,0 +1,5 @@ +running 1 test from ./main.ts +foo ... ok ([WILDCARD]) + +ok | 1 passed | 0 failed | 1 filtered out ([WILDCARD]) + diff --git a/tests/specs/test/test_filtered_out_only/main.ts b/tests/specs/test/test_filtered_out_only/main.ts new file mode 100644 index 000000000..bda301a43 --- /dev/null +++ b/tests/specs/test/test_filtered_out_only/main.ts @@ -0,0 +1,2 @@ +Deno.test("foo", () => {}); +Deno.test("bar", { only: true }, () => {}); diff --git a/tests/specs/test/test_replace_timers/__test__.jsonc b/tests/specs/test/test_replace_timers/__test__.jsonc new file mode 100644 index 000000000..bc9124318 --- /dev/null +++ b/tests/specs/test/test_replace_timers/__test__.jsonc @@ -0,0 +1,5 @@ +// Regression test for https://github.com/denoland/deno/issues/23041 +{ + "args": "test main.js", + "output": "main.out" +} diff --git a/tests/specs/test/test_replace_timers/main.js b/tests/specs/test/test_replace_timers/main.js new file mode 100644 index 000000000..692f1d671 --- /dev/null +++ b/tests/specs/test/test_replace_timers/main.js @@ -0,0 +1,7 @@ +Deno.test("foo", async (t) => { + globalThis.setTimeout = () => {}; + globalThis.clearTimeout = () => {}; + globalThis.setInterval = () => {}; + globalThis.clearInterval = () => {}; + await t.step("bar", () => {}); +}); diff --git a/tests/specs/test/test_replace_timers/main.out b/tests/specs/test/test_replace_timers/main.out new file mode 100644 index 000000000..cfac49943 --- /dev/null +++ b/tests/specs/test/test_replace_timers/main.out @@ -0,0 +1,7 @@ +running 1 test from [WILDCARD]/main.js +foo ... + bar ... ok ([WILDCARD]) +foo ... ok ([WILDCARD]) + +ok | 1 passed (1 step) | 0 failed ([WILDCARD]) + diff --git a/tests/specs/test/test_with_config/__test__.jsonc b/tests/specs/test/test_with_config/__test__.jsonc new file mode 100644 index 000000000..8bd1e2a9e --- /dev/null +++ b/tests/specs/test/test_with_config/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test --config collect/deno.jsonc collect", + "exitCode": 0, + "output": "main.out" +} diff --git a/tests/specs/test/test_with_config/collect/deno.jsonc b/tests/specs/test/test_with_config/collect/deno.jsonc new file mode 100644 index 000000000..e14ce86da --- /dev/null +++ b/tests/specs/test/test_with_config/collect/deno.jsonc @@ -0,0 +1,5 @@ +{ + "test": { + "exclude": ["./ignore"] + } +} diff --git a/tests/specs/test/test_with_config/collect/deno.malformed.jsonc b/tests/specs/test/test_with_config/collect/deno.malformed.jsonc new file mode 100644 index 000000000..f2d8cbc65 --- /dev/null +++ b/tests/specs/test/test_with_config/collect/deno.malformed.jsonc @@ -0,0 +1,5 @@ +{ + "test": { + "dont_know_this_field": {} + } +} diff --git a/tests/specs/test/test_with_config/collect/deno2.jsonc b/tests/specs/test/test_with_config/collect/deno2.jsonc new file mode 100644 index 000000000..b7af09d1c --- /dev/null +++ b/tests/specs/test/test_with_config/collect/deno2.jsonc @@ -0,0 +1,6 @@ +{ + "test": { + "include": ["./include/"], + "exclude": ["./ignore", "./include/2_test.ts"] + } +} diff --git a/tests/specs/test/test_with_config/collect/ignore/test.ts b/tests/specs/test/test_with_config/collect/ignore/test.ts new file mode 100644 index 000000000..16fb63ba7 --- /dev/null +++ b/tests/specs/test/test_with_config/collect/ignore/test.ts @@ -0,0 +1 @@ +throw new Error("this module should be ignored"); diff --git a/tests/specs/test/test_with_config/collect/include.ts b/tests/specs/test/test_with_config/collect/include.ts new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/specs/test/test_with_config/collect/include.ts diff --git a/tests/specs/test/test_with_config/collect/include/2_test.ts b/tests/specs/test/test_with_config/collect/include/2_test.ts new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/specs/test/test_with_config/collect/include/2_test.ts diff --git a/tests/specs/test/test_with_config/collect/include/test.ts b/tests/specs/test/test_with_config/collect/include/test.ts new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/specs/test/test_with_config/collect/include/test.ts diff --git a/tests/specs/test/test_with_config/collect/test.ts b/tests/specs/test/test_with_config/collect/test.ts new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/specs/test/test_with_config/collect/test.ts diff --git a/tests/specs/test/test_with_config/main.out b/tests/specs/test/test_with_config/main.out new file mode 100644 index 000000000..c140f2f7c --- /dev/null +++ b/tests/specs/test/test_with_config/main.out @@ -0,0 +1,9 @@ +Check [WILDCARD]collect/include/2_test.ts +Check [WILDCARD]collect/include/test.ts +Check [WILDCARD]collect/test.ts +running 0 tests from [WILDCARD]collect/include/2_test.ts +running 0 tests from [WILDCARD]collect/include/test.ts +running 0 tests from [WILDCARD]collect/test.ts + +ok | 0 passed | 0 failed ([WILDCARD]) + diff --git a/tests/specs/test/test_with_config2/__test__.jsonc b/tests/specs/test/test_with_config2/__test__.jsonc new file mode 100644 index 000000000..51d0a8c6b --- /dev/null +++ b/tests/specs/test/test_with_config2/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test --config collect/deno2.jsonc collect", + "exitCode": 0, + "output": "main.out" +} diff --git a/tests/specs/test/test_with_config2/collect/deno.jsonc b/tests/specs/test/test_with_config2/collect/deno.jsonc new file mode 100644 index 000000000..e14ce86da --- /dev/null +++ b/tests/specs/test/test_with_config2/collect/deno.jsonc @@ -0,0 +1,5 @@ +{ + "test": { + "exclude": ["./ignore"] + } +} diff --git a/tests/specs/test/test_with_config2/collect/deno.malformed.jsonc b/tests/specs/test/test_with_config2/collect/deno.malformed.jsonc new file mode 100644 index 000000000..f2d8cbc65 --- /dev/null +++ b/tests/specs/test/test_with_config2/collect/deno.malformed.jsonc @@ -0,0 +1,5 @@ +{ + "test": { + "dont_know_this_field": {} + } +} diff --git a/tests/specs/test/test_with_config2/collect/deno2.jsonc b/tests/specs/test/test_with_config2/collect/deno2.jsonc new file mode 100644 index 000000000..b7af09d1c --- /dev/null +++ b/tests/specs/test/test_with_config2/collect/deno2.jsonc @@ -0,0 +1,6 @@ +{ + "test": { + "include": ["./include/"], + "exclude": ["./ignore", "./include/2_test.ts"] + } +} diff --git a/tests/specs/test/test_with_config2/collect/ignore/test.ts b/tests/specs/test/test_with_config2/collect/ignore/test.ts new file mode 100644 index 000000000..16fb63ba7 --- /dev/null +++ b/tests/specs/test/test_with_config2/collect/ignore/test.ts @@ -0,0 +1 @@ +throw new Error("this module should be ignored"); diff --git a/tests/specs/test/test_with_config2/collect/include.ts b/tests/specs/test/test_with_config2/collect/include.ts new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/specs/test/test_with_config2/collect/include.ts diff --git a/tests/specs/test/test_with_config2/collect/include/2_test.ts b/tests/specs/test/test_with_config2/collect/include/2_test.ts new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/specs/test/test_with_config2/collect/include/2_test.ts diff --git a/tests/specs/test/test_with_config2/collect/include/test.ts b/tests/specs/test/test_with_config2/collect/include/test.ts new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/specs/test/test_with_config2/collect/include/test.ts diff --git a/tests/specs/test/test_with_config2/collect/test.ts b/tests/specs/test/test_with_config2/collect/test.ts new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/specs/test/test_with_config2/collect/test.ts diff --git a/tests/specs/test/test_with_config2/main.out b/tests/specs/test/test_with_config2/main.out new file mode 100644 index 000000000..3354c16cc --- /dev/null +++ b/tests/specs/test/test_with_config2/main.out @@ -0,0 +1,7 @@ +Check [WILDCARD]/collect/include/test.ts +Check [WILDCARD]/collect/test.ts +running 0 tests from [WILDCARD]/collect/include/test.ts +running 0 tests from [WILDCARD]/collect/test.ts + +ok | 0 passed | 0 failed ([WILDCARD]) + diff --git a/tests/specs/test/test_with_custom_jsx/__test__.jsonc b/tests/specs/test/test_with_custom_jsx/__test__.jsonc new file mode 100644 index 000000000..e516467ee --- /dev/null +++ b/tests/specs/test/test_with_custom_jsx/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test --quiet --allow-read main.ts --config=deno_custom_jsx.json", + "output": "main.out", + "exitCode": 0 +} diff --git a/tests/specs/test/test_with_custom_jsx/deno_custom_jsx.json b/tests/specs/test/test_with_custom_jsx/deno_custom_jsx.json new file mode 100644 index 000000000..7ef04d829 --- /dev/null +++ b/tests/specs/test/test_with_custom_jsx/deno_custom_jsx.json @@ -0,0 +1,6 @@ +{ + "compilerOptions": { + "jsx": "react-jsx", + "jsxImportSource": "https://esm.sh/react@18.1.0" + } +} diff --git a/tests/specs/test/test_with_custom_jsx/main.out b/tests/specs/test/test_with_custom_jsx/main.out new file mode 100644 index 000000000..cfeb14fd5 --- /dev/null +++ b/tests/specs/test/test_with_custom_jsx/main.out @@ -0,0 +1,5 @@ +running 1 test from ./main.ts +hello world test ... ok ([WILDCARD]) + +ok | 1 passed | 0 failed ([WILDCARD]) + diff --git a/tests/specs/test/test_with_custom_jsx/main.ts b/tests/specs/test/test_with_custom_jsx/main.ts new file mode 100644 index 000000000..4a1c3463f --- /dev/null +++ b/tests/specs/test/test_with_custom_jsx/main.ts @@ -0,0 +1,9 @@ +Deno.test({ + name: "hello world test", + fn(): void { + const world = "world"; + if ("world" !== world) { + throw new Error("world !== world"); + } + }, +}); diff --git a/tests/specs/test/test_with_glob_config/__test__.jsonc b/tests/specs/test/test_with_glob_config/__test__.jsonc new file mode 100644 index 000000000..9e2deabf9 --- /dev/null +++ b/tests/specs/test/test_with_glob_config/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test --config deno.glob.json", + "output": "main.out", + "exitCode": 0 +} diff --git a/tests/specs/test/test_with_glob_config/deno.glob.json b/tests/specs/test/test_with_glob_config/deno.glob.json new file mode 100644 index 000000000..9deb4d2f2 --- /dev/null +++ b/tests/specs/test/test_with_glob_config/deno.glob.json @@ -0,0 +1,11 @@ +{ + "test": { + "include": [ + "glob/data/test1.?s", + "glob/nested/foo/*.ts", + "glob/nested/fizz/*.ts", + "glob/pages/[id].ts" + ], + "exclude": ["glob/nested/**/*bazz.ts"] + } +} diff --git a/tests/specs/test/test_with_glob_config/glob/data/tes.ts b/tests/specs/test/test_with_glob_config/glob/data/tes.ts new file mode 100644 index 000000000..6940729e9 --- /dev/null +++ b/tests/specs/test/test_with_glob_config/glob/data/tes.ts @@ -0,0 +1,2 @@ +function foo() { +} diff --git a/tests/specs/test/test_with_glob_config/glob/data/test1.js b/tests/specs/test/test_with_glob_config/glob/data/test1.js new file mode 100644 index 000000000..6940729e9 --- /dev/null +++ b/tests/specs/test/test_with_glob_config/glob/data/test1.js @@ -0,0 +1,2 @@ +function foo() { +} diff --git a/tests/specs/test/test_with_glob_config/glob/data/test1.ts b/tests/specs/test/test_with_glob_config/glob/data/test1.ts new file mode 100644 index 000000000..6940729e9 --- /dev/null +++ b/tests/specs/test/test_with_glob_config/glob/data/test1.ts @@ -0,0 +1,2 @@ +function foo() { +} diff --git a/tests/specs/test/test_with_glob_config/glob/data/test12.ts b/tests/specs/test/test_with_glob_config/glob/data/test12.ts new file mode 100644 index 000000000..6940729e9 --- /dev/null +++ b/tests/specs/test/test_with_glob_config/glob/data/test12.ts @@ -0,0 +1,2 @@ +function foo() { +} diff --git a/tests/specs/test/test_with_glob_config/glob/nested/fizz/bar.ts b/tests/specs/test/test_with_glob_config/glob/nested/fizz/bar.ts new file mode 100644 index 000000000..6940729e9 --- /dev/null +++ b/tests/specs/test/test_with_glob_config/glob/nested/fizz/bar.ts @@ -0,0 +1,2 @@ +function foo() { +} diff --git a/tests/specs/test/test_with_glob_config/glob/nested/fizz/bazz.ts b/tests/specs/test/test_with_glob_config/glob/nested/fizz/bazz.ts new file mode 100644 index 000000000..6940729e9 --- /dev/null +++ b/tests/specs/test/test_with_glob_config/glob/nested/fizz/bazz.ts @@ -0,0 +1,2 @@ +function foo() { +} diff --git a/tests/specs/test/test_with_glob_config/glob/nested/fizz/fizz.ts b/tests/specs/test/test_with_glob_config/glob/nested/fizz/fizz.ts new file mode 100644 index 000000000..6940729e9 --- /dev/null +++ b/tests/specs/test/test_with_glob_config/glob/nested/fizz/fizz.ts @@ -0,0 +1,2 @@ +function foo() { +} diff --git a/tests/specs/test/test_with_glob_config/glob/nested/fizz/foo.ts b/tests/specs/test/test_with_glob_config/glob/nested/fizz/foo.ts new file mode 100644 index 000000000..6940729e9 --- /dev/null +++ b/tests/specs/test/test_with_glob_config/glob/nested/fizz/foo.ts @@ -0,0 +1,2 @@ +function foo() { +} diff --git a/tests/specs/test/test_with_glob_config/glob/nested/foo/bar.ts b/tests/specs/test/test_with_glob_config/glob/nested/foo/bar.ts new file mode 100644 index 000000000..6940729e9 --- /dev/null +++ b/tests/specs/test/test_with_glob_config/glob/nested/foo/bar.ts @@ -0,0 +1,2 @@ +function foo() { +} diff --git a/tests/specs/test/test_with_glob_config/glob/nested/foo/bazz.ts b/tests/specs/test/test_with_glob_config/glob/nested/foo/bazz.ts new file mode 100644 index 000000000..6940729e9 --- /dev/null +++ b/tests/specs/test/test_with_glob_config/glob/nested/foo/bazz.ts @@ -0,0 +1,2 @@ +function foo() { +} diff --git a/tests/specs/test/test_with_glob_config/glob/nested/foo/fizz.ts b/tests/specs/test/test_with_glob_config/glob/nested/foo/fizz.ts new file mode 100644 index 000000000..6940729e9 --- /dev/null +++ b/tests/specs/test/test_with_glob_config/glob/nested/foo/fizz.ts @@ -0,0 +1,2 @@ +function foo() { +} diff --git a/tests/specs/test/test_with_glob_config/glob/nested/foo/foo.ts b/tests/specs/test/test_with_glob_config/glob/nested/foo/foo.ts new file mode 100644 index 000000000..6940729e9 --- /dev/null +++ b/tests/specs/test/test_with_glob_config/glob/nested/foo/foo.ts @@ -0,0 +1,2 @@ +function foo() { +} diff --git a/tests/specs/test/test_with_glob_config/glob/pages/[id].ts b/tests/specs/test/test_with_glob_config/glob/pages/[id].ts new file mode 100644 index 000000000..6940729e9 --- /dev/null +++ b/tests/specs/test/test_with_glob_config/glob/pages/[id].ts @@ -0,0 +1,2 @@ +function foo() { +} diff --git a/tests/specs/test/test_with_glob_config/main.out b/tests/specs/test/test_with_glob_config/main.out new file mode 100644 index 000000000..fbff4d934 --- /dev/null +++ b/tests/specs/test/test_with_glob_config/main.out @@ -0,0 +1,21 @@ +Check [WILDCARD]/glob/pages/[id].ts +Check [WILDCARD]/glob/data/test1.js +Check [WILDCARD]/glob/data/test1.ts +Check [WILDCARD]/glob/nested/fizz/bar.ts +Check [WILDCARD]/glob/nested/fizz/fizz.ts +Check [WILDCARD]/glob/nested/fizz/foo.ts +Check [WILDCARD]/glob/nested/foo/bar.ts +Check [WILDCARD]/glob/nested/foo/fizz.ts +Check [WILDCARD]/glob/nested/foo/foo.ts +running 0 tests from ./glob/pages/[id].ts +running 0 tests from ./glob/data/test1.js +running 0 tests from ./glob/data/test1.ts +running 0 tests from ./glob/nested/fizz/bar.ts +running 0 tests from ./glob/nested/fizz/fizz.ts +running 0 tests from ./glob/nested/fizz/foo.ts +running 0 tests from ./glob/nested/foo/bar.ts +running 0 tests from ./glob/nested/foo/fizz.ts +running 0 tests from ./glob/nested/foo/foo.ts + +ok | 0 passed | 0 failed ([WILDCARD]) + diff --git a/tests/specs/test/test_with_malformed_config/__test__.jsonc b/tests/specs/test/test_with_malformed_config/__test__.jsonc new file mode 100644 index 000000000..56c30bce6 --- /dev/null +++ b/tests/specs/test/test_with_malformed_config/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test --config deno.malformed.jsonc", + "exitCode": 1, + "output": "main.out" +} diff --git a/tests/specs/test/test_with_malformed_config/deno.malformed.jsonc b/tests/specs/test/test_with_malformed_config/deno.malformed.jsonc new file mode 100644 index 000000000..f2d8cbc65 --- /dev/null +++ b/tests/specs/test/test_with_malformed_config/deno.malformed.jsonc @@ -0,0 +1,5 @@ +{ + "test": { + "dont_know_this_field": {} + } +} diff --git a/tests/specs/test/test_with_malformed_config/main.out b/tests/specs/test/test_with_malformed_config/main.out new file mode 100644 index 000000000..b31b18e6a --- /dev/null +++ b/tests/specs/test/test_with_malformed_config/main.out @@ -0,0 +1,4 @@ +error: Failed to parse "test" configuration + +Caused by: + unknown field `dont_know_this_field`, expected one of `include`, `exclude`, `files` diff --git a/tests/specs/test/text/__test__.jsonc b/tests/specs/test/text/__test__.jsonc new file mode 100644 index 000000000..35ec2225b --- /dev/null +++ b/tests/specs/test/text/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test --doc --allow-all main.md", + "exitCode": 0, + "output": "main.out" +} diff --git a/tests/specs/test/text/main.md b/tests/specs/test/text/main.md new file mode 100644 index 000000000..be89d24bf --- /dev/null +++ b/tests/specs/test/text/main.md @@ -0,0 +1 @@ +This fixture contains no actual tests. diff --git a/tests/specs/test/text/main.out b/tests/specs/test/text/main.out new file mode 100644 index 000000000..f1b7f7d01 --- /dev/null +++ b/tests/specs/test/text/main.out @@ -0,0 +1,3 @@ + +ok | 0 passed | 0 failed ([WILDCARD]) + diff --git a/tests/specs/test/uncaught_errors/__test__.jsonc b/tests/specs/test/uncaught_errors/__test__.jsonc new file mode 100644 index 000000000..746ddfc26 --- /dev/null +++ b/tests/specs/test/uncaught_errors/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test --quiet uncaught_errors_1.ts uncaught_errors_2.ts uncaught_errors_3.ts", + "output": "main.out", + "exitCode": 1 +} diff --git a/tests/specs/test/uncaught_errors/main.out b/tests/specs/test/uncaught_errors/main.out new file mode 100644 index 000000000..23d59e61c --- /dev/null +++ b/tests/specs/test/uncaught_errors/main.out @@ -0,0 +1,59 @@ +running 3 tests from [WILDCARD]/uncaught_errors_1.ts +foo 1 ... FAILED ([WILDCARD]) +foo 2 ... ok ([WILDCARD]) +foo 3 ... +Uncaught error from [WILDCARD]/uncaught_errors_1.ts FAILED +foo 3 ... cancelled (0ms) +running 3 tests from [WILDCARD]/uncaught_errors_2.ts +bar 1 ... ok ([WILDCARD]) +bar 2 ... FAILED ([WILDCARD]) +bar 3 ... FAILED ([WILDCARD]) +Uncaught error from [WILDCARD]/uncaught_errors_3.ts FAILED + + ERRORS + +foo 1 => [WILDCARD]/uncaught_errors_1.ts:1:6 +error: Error: foo 1 message + throw new Error("foo 1 message"); + ^ + at [WILDCARD]/uncaught_errors_1.ts:2:9 + +[WILDCARD]/uncaught_errors_1.ts (uncaught error) +error: (in promise) Error: foo 3 message + Promise.reject(new Error("foo 3 message")); + ^ + at [WILDCARD]/uncaught_errors_1.ts:8:18 +This error was not caught from a test and caused the test runner to fail on the referenced module. +It most likely originated from a dangling promise, event/timeout handler or top-level code. + +bar 2 => [WILDCARD]/uncaught_errors_2.ts:3:6 +error: Error: bar 2 + throw new Error("bar 2"); + ^ + at [WILDCARD]/uncaught_errors_2.ts:4:9 + +bar 3 => [WILDCARD]/uncaught_errors_2.ts:6:6 +error: Error: bar 3 message + throw new Error("bar 3 message"); + ^ + at [WILDCARD]/uncaught_errors_2.ts:7:9 + +[WILDCARD]/uncaught_errors_3.ts (uncaught error) +error: (in promise) Error: baz +throw new Error("baz"); + ^ + at [WILDCARD]/uncaught_errors_3.ts:1:7 +This error was not caught from a test and caused the test runner to fail on the referenced module. +It most likely originated from a dangling promise, event/timeout handler or top-level code. + + FAILURES + +foo 1 => [WILDCARD]/uncaught_errors_1.ts:1:6 +[WILDCARD]/uncaught_errors_1.ts (uncaught error) +bar 2 => [WILDCARD]/uncaught_errors_2.ts:3:6 +bar 3 => [WILDCARD]/uncaught_errors_2.ts:6:6 +[WILDCARD]/uncaught_errors_3.ts (uncaught error) + +FAILED | 2 passed | 6 failed ([WILDCARD]) + +error: Test failed diff --git a/tests/specs/test/uncaught_errors/uncaught_errors_1.ts b/tests/specs/test/uncaught_errors/uncaught_errors_1.ts new file mode 100644 index 000000000..166b23ac3 --- /dev/null +++ b/tests/specs/test/uncaught_errors/uncaught_errors_1.ts @@ -0,0 +1,9 @@ +Deno.test("foo 1", () => { + throw new Error("foo 1 message"); +}); + +Deno.test("foo 2", () => {}); + +Deno.test("foo 3", () => { + Promise.reject(new Error("foo 3 message")); +}); diff --git a/tests/specs/test/uncaught_errors/uncaught_errors_2.ts b/tests/specs/test/uncaught_errors/uncaught_errors_2.ts new file mode 100644 index 000000000..8cafbe291 --- /dev/null +++ b/tests/specs/test/uncaught_errors/uncaught_errors_2.ts @@ -0,0 +1,8 @@ +Deno.test("bar 1", () => {}); + +Deno.test("bar 2", () => { + throw new Error("bar 2"); +}); +Deno.test("bar 3", () => { + throw new Error("bar 3 message"); +}); diff --git a/tests/specs/test/uncaught_errors/uncaught_errors_3.ts b/tests/specs/test/uncaught_errors/uncaught_errors_3.ts new file mode 100644 index 000000000..cb2a55036 --- /dev/null +++ b/tests/specs/test/uncaught_errors/uncaught_errors_3.ts @@ -0,0 +1 @@ +throw new Error("baz"); diff --git a/tests/specs/test/unhandled_rejection/__test__.jsonc b/tests/specs/test/unhandled_rejection/__test__.jsonc new file mode 100644 index 000000000..d8887f753 --- /dev/null +++ b/tests/specs/test/unhandled_rejection/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test main.ts", + "output": "main.out", + "exitCode": 1 +} diff --git a/tests/specs/test/unhandled_rejection/main.out b/tests/specs/test/unhandled_rejection/main.out new file mode 100644 index 000000000..e708ae20c --- /dev/null +++ b/tests/specs/test/unhandled_rejection/main.out @@ -0,0 +1,22 @@ +Check [WILDCARD]/main.ts +Uncaught error from ./main.ts FAILED + + ERRORS + +./main.ts (uncaught error) +error: (in promise) Error: rejection + reject(new Error("rejection")); + ^ + at [WILDCARD]/main.ts:2:10 + at new Promise (<anonymous>) + at [WILDCARD]/main.ts:1:1 +This error was not caught from a test and caused the test runner to fail on the referenced module. +It most likely originated from a dangling promise, event/timeout handler or top-level code. + + FAILURES + +./main.ts (uncaught error) + +FAILED | 0 passed | 1 failed ([WILDCARD]) + +error: Test failed diff --git a/tests/specs/test/unhandled_rejection/main.ts b/tests/specs/test/unhandled_rejection/main.ts new file mode 100644 index 000000000..32f3111ea --- /dev/null +++ b/tests/specs/test/unhandled_rejection/main.ts @@ -0,0 +1,3 @@ +new Promise((_resolve, reject) => { + reject(new Error("rejection")); +}); diff --git a/tests/specs/test/unresolved_promise/__test__.jsonc b/tests/specs/test/unresolved_promise/__test__.jsonc new file mode 100644 index 000000000..d8887f753 --- /dev/null +++ b/tests/specs/test/unresolved_promise/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test main.ts", + "output": "main.out", + "exitCode": 1 +} diff --git a/tests/specs/test/unresolved_promise/main.out b/tests/specs/test/unresolved_promise/main.out new file mode 100644 index 000000000..0195400b6 --- /dev/null +++ b/tests/specs/test/unresolved_promise/main.out @@ -0,0 +1,10 @@ +[WILDCARD] +./main.ts (uncaught error) +error: Top-level await promise never resolved +await new Promise((_resolve, _reject) => {}); +^ + at <anonymous> ([WILDCARD]/main.ts:1:1) +This error was not caught from a test and caused the test runner to fail on the referenced module. +It most likely originated from a dangling promise, event/timeout handler or top-level code. +[WILDCARD] +error: Test failed diff --git a/tests/specs/test/unresolved_promise/main.ts b/tests/specs/test/unresolved_promise/main.ts new file mode 100644 index 000000000..25fe70762 --- /dev/null +++ b/tests/specs/test/unresolved_promise/main.ts @@ -0,0 +1 @@ +await new Promise((_resolve, _reject) => {}); |