Showing with 120 additions and 6 deletions.
  1. +3 −1 Gruntfile.js
  2. +25 −4 src/core.js
  3. +12 −1 src/test.js
  4. +13 −0 test/module-skip.html
  5. +67 −0 test/module-skip.js
@@ -154,7 +154,8 @@ module.exports = function( grunt ) {
"test/regex-filter.html",
"test/regex-exclude-filter.html",
"test/string-filter.html",
"test/module-only.html"
"test/module-only.html",
"test/module-skip.html"
]
},
"test-on-node": {
@@ -179,6 +180,7 @@ module.exports = function( grunt ) {
"test/node/storage-1",
"test/node/storage-2",
"test/module-only",
"test/module-skip",
HAS_ASYNC_FUNCTIONS ? "test/es2017/async-functions" : null
].filter( Boolean )
},
@@ -36,7 +36,7 @@ QUnit.isLocal = !( defined.document && window.location.protocol !== "file:" );
// Expose the current QUnit version
QUnit.version = "@VERSION";

function createModule( name, testEnvironment ) {
function createModule( name, testEnvironment, modifiers ) {
const parentModule = moduleStack.length ? moduleStack.slice( -1 )[ 0 ] : null;
const moduleName = parentModule !== null ? [ parentModule.name, name ].join( " > " ) : name;
const parentSuite = parentModule ? parentModule.suiteReport : globalSuite;
@@ -49,7 +49,13 @@ function createModule( name, testEnvironment ) {
testsRun: 0,
unskippedTestsRun: 0,
childModules: [],
suiteReport: new SuiteReport( name, parentSuite )
suiteReport: new SuiteReport( name, parentSuite ),

// Pass along `skip` property from parent module, in case there is one,
// to childs. And use own otherwise.
// This property will be used to mark own tests and tests of child suites
// as `skipped`.
skip: parentModule !== null && parentModule.skip || modifiers.skip
};

const env = {};
@@ -64,8 +70,8 @@ function createModule( name, testEnvironment ) {
return module;
}

function processModule( name, options, executeNow ) {
let module = createModule( name, options );
function processModule( name, options, executeNow, modifiers = {} ) {
let module = createModule( name, options, modifiers );

// Move any hooks to a 'hooks' object
const testEnvironment = module.testEnvironment;
@@ -130,6 +136,21 @@ module.only = function() {
focused = true;
};

module.skip = function( name, options, executeNow ) {
if ( focused ) {
return;
}

if ( arguments.length === 2 ) {
if ( objectType( options ) === "function" ) {
executeNow = options;
options = undefined;
}
}

processModule( name, options, executeNow, { skip: true } );
};

extend( QUnit, {
on,

@@ -30,13 +30,24 @@ export default function Test( settings ) {
++Test.count;

this.expected = null;
extend( this, settings );
this.assertions = [];
this.semaphore = 0;
this.module = config.currentModule;
this.stack = sourceFromStacktrace( 3 );
this.steps = [];

// If a module is skipped, all its tests and the tests of the child suites
// should be treated as skipped even if they are defined as `only` or `todo`.
//
// So, if a test is defined as `todo` and is inside a skipped module, we should
// then treat that test as if was defined as `skip`.
if ( this.module.skip ) {
settings.skip = true;
settings.todo = false;
}

extend( this, settings );

this.testReport = new TestReport( settings.testName, this.module.suiteReport, {
todo: settings.todo,
skip: settings.skip,
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>QUnit module Test Suite</title>
<link rel="stylesheet" href="../dist/qunit.css">
<script src="../dist/qunit.js"></script>
<script src="module-skip.js"></script>
</head>
<body>
<div id="qunit"></div>
</body>
</html>
@@ -0,0 +1,67 @@
var tests = {};

var done = false;

QUnit.testDone( function( details ) {
if ( done ) {
return;
}

tests[ details.testId ] = {
skipped: details.skipped,
todo: details.todo
};
} );

QUnit.done( function() {
if ( done ) {
return;
}

done = true;

QUnit.test( "Compare stats", function( assert ) {
assert.expect( 1 );

assert.deepEqual( tests, {
"1d56e5b5": {
skipped: false,
todo: false
},
"d40f1738": {
skipped: true,
todo: false
},
"acdd0267": {
skipped: true,
todo: false
},
"8b1c454f": {
skipped: true,
todo: false
}
} );
} );
} );

QUnit.module( "Parent module", function() {
QUnit.module( "A normal module", function() {
QUnit.test( "normal test", function( assert ) {
assert.ok( true, "this test should run" );
} );
} );

QUnit.module.skip( "This module will be skipped", function() {
QUnit.test( "test will be treated as a skipped test", function( assert ) {
assert.ok( false, "this test should not run" );
} );

QUnit.todo( "a todo test that should be skipped", function( assert ) {
assert.ok( false, "this test should not run" );
} );

QUnit.skip( "a normal skipped test", function( assert ) {
assert.ok( false, "this test should not run" );
} );
} );
} );