Skip to content

Commit

Permalink
Tests: Add "only/module-then-test.js" test fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
Krinkle committed Sep 18, 2021
1 parent e0aa69a commit 35219ef
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,14 @@ export default function module( name, options, executeNow ) {

module.only = function( ...args ) {
if ( !focused ) {

// Upon the first module.only() call,
// delete any and all previously registered modules and tests.
config.modules.length = 0;
config.queue.length = 0;

// aggressively ignore any direct tests in "outer" nested modules
// Ignore any tests declared after this block within the same
// module parent. https://github.com/qunitjs/qunit/issues/1645
config.currentModule.ignored = true;
}

Expand Down
10 changes: 10 additions & 0 deletions test/cli/cli-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,16 @@ CALLBACK: done`;
assert.equal( execution.stdout, expectedOutput[ command ] );
} );

QUnit.test( "module followed by test", async assert => {

const command = "qunit only/module-then-test.js";
const execution = await execute( command );

assert.equal( execution.code, 0 );
assert.equal( execution.stderr, "" );
assert.equal( execution.stdout, expectedOutput[ command ] );
} );

QUnit.test( "flat modules", async assert => {

const command = "qunit only/module-flat.js";
Expand Down
10 changes: 10 additions & 0 deletions test/cli/fixtures/expected/tap-outputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,16 @@ ok 6 module E > test E
# todo 1
# fail 0`,

"qunit only/module-then-test.js":
`TAP version 13
ok 1 module A > module B > test B
1..2
# pass 2
# skip 0
# todo 0
# fail 0`,


"qunit only/module-flat.js":
`TAP version 13
not ok 1 # TODO module B > test B
Expand Down
16 changes: 16 additions & 0 deletions test/cli/fixtures/only/module-then-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// https://github.com/qunitjs/qunit/issues/1645
QUnit.module( "module A", function() {
QUnit.test( "test A1", function( assert ) {
assert.true( false, "not run" );
} );

QUnit.module.only( "module B", function() {
QUnit.test( "test B", function( assert ) {
assert.true( true, "run" );
} );
} );

QUnit.test( "test A2", function( assert ) {
assert.true( false, "not run" );
} );
} );
4 changes: 0 additions & 4 deletions test/cli/fixtures/only/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ QUnit.module( "module B", function() {
} );
} );

QUnit.test( "test with the only-module as its peer", function( assert ) {
assert.true( false, "this test should not run" );
} );

QUnit.module( "This also should not run", function() {
QUnit.test( "normal test", function( assert ) {
assert.true( false, "this test should not run" );
Expand Down

0 comments on commit 35219ef

Please sign in to comment.