From 0132edd195a04257d357fd9d081748cdbc8c0c34 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Tue, 3 Aug 2021 00:00:28 +0100 Subject: [PATCH] Tests: Add module-nested.js test case This asserts the undesirable status quo, where the stack is left in a bad state if the module closure encounters a global error while test suites are still being loaded. Ref https://github.com/qunitjs/qunit/issues/1478. --- test/cli/fixtures/expected/tap-outputs.js | 10 ++++++ test/cli/fixtures/module-nested.js | 37 +++++++++++++++++++++++ test/cli/main.js | 9 ++++++ 3 files changed, 56 insertions(+) create mode 100644 test/cli/fixtures/module-nested.js diff --git a/test/cli/fixtures/expected/tap-outputs.js b/test/cli/fixtures/expected/tap-outputs.js index 0f279c4d6..4811e1d2b 100644 --- a/test/cli/fixtures/expected/tap-outputs.js +++ b/test/cli/fixtures/expected/tap-outputs.js @@ -323,6 +323,16 @@ ok 3 module B > test D # pass 2 # skip 1 # todo 1 +# fail 0`, + + "qunit module-nested.js": +`TAP version 13 +ok 1 module 1 > test in module 1 +ok 2 module 2 > module 3 > test in module 3 +1..2 +# pass 2 +# skip 0 +# todo 0 # fail 0`, "qunit incorrect-hooks-warning/test.js": diff --git a/test/cli/fixtures/module-nested.js b/test/cli/fixtures/module-nested.js new file mode 100644 index 000000000..ec79cf7f4 --- /dev/null +++ b/test/cli/fixtures/module-nested.js @@ -0,0 +1,37 @@ +try { + QUnit.module( "module 1", () => { + QUnit.test( "test in module 1", assert => { + assert.true( true ); + } ); + } ); +} catch ( e ) { + + // Ignore +} + +try { + QUnit.module( "module 2", () => { + + // trigger an error in executeNow + undefined(); + + QUnit.test( "test in module 2", assert => { + assert.true( true ); + } ); + } ); +} catch ( e ) { + + // Ignore +} + + +try { + QUnit.module( "module 3", () => { + QUnit.test( "test in module 3", assert => { + assert.true( true ); + } ); + } ); +} catch ( e ) { + + // Ignore +} diff --git a/test/cli/main.js b/test/cli/main.js index 4c1c77f0e..267320f91 100644 --- a/test/cli/main.js +++ b/test/cli/main.js @@ -657,6 +657,15 @@ CALLBACK: done`; } ); } ); + // Regression test for https://github.com/qunitjs/qunit/issues/1478 + QUnit.test( "nested module scopes", async assert => { + const command = "qunit module-nested.js"; + const execution = await execute( command ); + + assert.equal( execution.code, 0 ); + assert.equal( execution.stdout, expectedOutput[ command ] ); + } ); + QUnit.test( "warns about incorrect hook usage", async assert => { const command = "qunit incorrect-hooks-warning/test.js"; const execution = await execute( command );