Skip to content

Commit

Permalink
Core: Connected to #1434: run all only tests (address feedback).
Browse files Browse the repository at this point in the history
  • Loading branch information
ventuno committed Apr 26, 2020
1 parent 8342c7b commit 152fd7c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/QUnit/module.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ The module's callback is invoked with the test environment as its `this` context

## Exclusive tests

When you are debugging your code, you will often need to _only_ run a subset of tests. You can append `only` to `QUnit.module` to specify which module you want to run.
When you are debugging your code, you will often need to _only_ run a subset of tests. You can append `only` to `QUnit.module` to specify which module(s) you want to run.

It works the same way `QUnit.only()` does for tests.

Expand Down
6 changes: 3 additions & 3 deletions docs/QUnit/only.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
layout: default
title: only
description: Adds a test to exclusively run, preventing all other tests from running.
description: Adds a test to exclusively run, preventing any other tests not defined with `QUnit.only()` from running.
categories:
- main
---

## `QUnit.only( name, callback )`

Add a set of tests to exclusively run, preventing other tests from running.
Adds a test to exclusively run, preventing any other tests not defined with `QUnit.only()` from running.

| parameter | description |
|-----------|-------------|
Expand All @@ -23,7 +23,7 @@ Add a set of tests to exclusively run, preventing other tests from running.

### Description

Use this method to focus your test suite on a specific set of tests. `QUnit.only` will cause any other tests in your suite to be ignored.
Use this method to focus your test suite on specific tests. `QUnit.only` will cause any other tests in your suite to be ignored.

This is an alternative to filtering tests to run in the HTML reporter. It is especially useful when you use a console reporter or in a codebase with a large set of long running tests.

Expand Down
7 changes: 6 additions & 1 deletion src/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ let focused = false;

const moduleStack = [];

function isParentModuleInQueue() {
const modulesInQueue = config.modules.map( module => module.moduleId );
return moduleStack.some( module => modulesInQueue.includes( module.moduleId ) );
}

function createModule( name, testEnvironment, modifiers ) {
const parentModule = moduleStack.length ? moduleStack.slice( -1 )[ 0 ] : null;
const moduleName = parentModule !== null ? [ parentModule.name, name ].join( " > " ) : name;
Expand Down Expand Up @@ -96,7 +101,7 @@ function processModule( name, options, executeNow, modifiers = {} ) {
}

export default function module( name, options, executeNow ) {
if ( focused ) {
if ( focused && !isParentModuleInQueue() ) {
return;
}

Expand Down
33 changes: 33 additions & 0 deletions test/module-only.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,16 @@ QUnit.done( function() {
"c7ae85c2": {
skipped: false,
todo: false
},
"74b800d1": {
skipped: false,
todo: false
},
"2f8fb2a2": {
skipped: false,
todo: false
}

} );
} );
} );
Expand Down Expand Up @@ -89,3 +98,27 @@ QUnit.module.only( "module D", function() {
assert.ok( true, "this test should run as well" );
} );
} );

QUnit.module.only( "module E", function() {
QUnit.module( "module F", function() {
QUnit.test( "test F", function( assert ) {
assert.ok( true, "this test should run as well" );
} );
} );

QUnit.test( "test E", function( assert ) {
assert.ok( true, "this test should run as well" );
} );
} );

QUnit.module.skip( "module G", function() {
QUnit.module.only( "module H", function() {
QUnit.test( "test H", function( assert ) {
assert.ok( false, "this test should not run" );
} );
} );

QUnit.test( "test G", function( assert ) {
assert.ok( false, "this test should not run" );
} );
} );

0 comments on commit 152fd7c

Please sign in to comment.