diff options
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/integration/repl_tests.rs | 42 | ||||
-rw-r--r-- | cli/tests/testdata/jupyter/integration_test.ipynb | 52 |
2 files changed, 94 insertions, 0 deletions
diff --git a/cli/tests/integration/repl_tests.rs b/cli/tests/integration/repl_tests.rs index 5335cf964..a6524f718 100644 --- a/cli/tests/integration/repl_tests.rs +++ b/cli/tests/integration/repl_tests.rs @@ -872,6 +872,48 @@ fn repl_with_quiet_flag() { } #[test] +fn repl_unit_tests() { + util::with_pty(&["repl"], |mut console| { + console.write_line( + "\ + console.log('Hello from outside of test!'); \ + Deno.test('test1', async (t) => { \ + console.log('Hello from inside of test!'); \ + await t.step('step1', () => {}); \ + }); \ + Deno.test('test2', () => { \ + throw new Error('some message'); \ + }); \ + console.log('Hello again from outside of test!'); \ + ", + ); + + console.expect("Hello from outside of test!"); + console.expect("Hello again from outside of test!"); + // FIXME(nayeemrmn): REPL unit tests don't support output capturing. + console.expect("Hello from inside of test!"); + console.expect("test1 ..."); + console.expect(" step1 ... ok ("); + console.expect("test1 ... ok ("); + console.expect("test2 ... FAILED ("); + console.expect(" ERRORS "); + console.expect("test2 => <anonymous>:7:6"); + console.expect("error: Error: some message"); + console.expect(" at <anonymous>:8:9"); + console.expect(" FAILURES "); + console.expect("test2 => <anonymous>:7:6"); + console.expect("FAILED | 1 passed (1 step) | 1 failed ("); + console.expect("undefined"); + + console.write_line("Deno.test('test2', () => {});"); + + console.expect("test2 ... ok ("); + console.expect("ok | 1 passed | 0 failed ("); + console.expect("undefined"); + }); +} + +#[test] fn npm_packages() { let mut env_vars = util::env_vars_for_npm_tests(); env_vars.push(("NO_COLOR".to_owned(), "1".to_owned())); diff --git a/cli/tests/testdata/jupyter/integration_test.ipynb b/cli/tests/testdata/jupyter/integration_test.ipynb index c1b31724c..25d55e88c 100644 --- a/cli/tests/testdata/jupyter/integration_test.ipynb +++ b/cli/tests/testdata/jupyter/integration_test.ipynb @@ -630,6 +630,58 @@ }, { "cell_type": "markdown", + "id": "9f38f1eb", + "metadata": {}, + "source": [ + "## Unit Tests With `Deno.test()`" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "b33808fd", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "passing test ... \u001b[0m\u001b[32mok\u001b[0m \u001b[0m\u001b[38;5;245m(1ms)\u001b[0m\n", + "passing test with steps ...\n", + " step 1 ... \u001b[0m\u001b[32mok\u001b[0m \u001b[0m\u001b[38;5;245m(0ms)\u001b[0m\n", + " step 2 ... \u001b[0m\u001b[32mok\u001b[0m \u001b[0m\u001b[38;5;245m(0ms)\u001b[0m\n", + "passing test with steps ... \u001b[0m\u001b[32mok\u001b[0m \u001b[0m\u001b[38;5;245m(1ms)\u001b[0m\n", + "failing test ... \u001b[0m\u001b[31mFAILED\u001b[0m \u001b[0m\u001b[38;5;245m(1ms)\u001b[0m\n", + "\n", + "\u001b[0m\u001b[1m\u001b[37m\u001b[41m ERRORS \u001b[0m\n", + "\n", + "failing test \u001b[0m\u001b[38;5;245m=> <anonymous>:7:6\u001b[0m\n", + "\u001b[0m\u001b[1m\u001b[31merror\u001b[0m: Error: some message\n", + " at \u001b[0m\u001b[36m<anonymous>\u001b[0m:\u001b[0m\u001b[33m8\u001b[0m:\u001b[0m\u001b[33m9\u001b[0m\n", + "\n", + "\u001b[0m\u001b[1m\u001b[37m\u001b[41m FAILURES \u001b[0m\n", + "\n", + "failing test \u001b[0m\u001b[38;5;245m=> <anonymous>:7:6\u001b[0m\n", + "\n", + "\u001b[0m\u001b[31mFAILED\u001b[0m | 2 passed (2 steps) | 1 failed \u001b[0m\u001b[38;5;245m(0ms)\u001b[0m\n" + ] + } + ], + "source": [ + "Deno.test(\"passing test\", () => {});\n", + "\n", + "Deno.test(\"passing test with steps\", async (t) => {\n", + " await t.step(\"step 1\", () => {});\n", + " await t.step(\"step 2\", () => {});\n", + "});\n", + "\n", + "Deno.test(\"failing test\", () => {\n", + " throw new Error(\"some message\");\n", + "});\n" + ] + }, + { + "cell_type": "markdown", "id": "8822eed9-a801-4c1b-81c0-00e4ff180f40", "metadata": {}, "source": [ |