Showing with 112 additions and 5 deletions.
  1. +3 −1 Gruntfile.js
  2. +23 −4 src/core.js
  3. +6 −0 src/test.js
  4. +13 −0 test/module-todo.html
  5. +67 −0 test/module-todo.js
@@ -155,7 +155,8 @@ module.exports = function( grunt ) {
"test/regex-exclude-filter.html",
"test/string-filter.html",
"test/module-only.html",
"test/module-skip.html"
"test/module-skip.html",
"test/module-todo.html"
]
},
"test-on-node": {
@@ -181,6 +182,7 @@ module.exports = function( grunt ) {
"test/node/storage-2",
"test/module-only",
"test/module-skip",
"test/module-todo",
HAS_ASYNC_FUNCTIONS ? "test/es2017/async-functions" : null
].filter( Boolean )
},
@@ -41,6 +41,9 @@ function createModule( name, testEnvironment, modifiers ) {
const moduleName = parentModule !== null ? [ parentModule.name, name ].join( " > " ) : name;
const parentSuite = parentModule ? parentModule.suiteReport : globalSuite;

const skip = parentModule !== null && parentModule.skip || modifiers.skip;
const todo = parentModule !== null && parentModule.todo || modifiers.todo;

const module = {
name: moduleName,
parentModule: parentModule,
@@ -51,11 +54,12 @@ function createModule( name, testEnvironment, modifiers ) {
childModules: [],
suiteReport: new SuiteReport( name, parentSuite ),

// Pass along `skip` property from parent module, in case there is one,
// to childs. And use own otherwise.
// Pass along `skip` and `todo` properties 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
// as either `skipped` or `todo`.
skip: skip,
todo: skip ? false : todo
};

const env = {};
@@ -151,6 +155,21 @@ module.skip = function( name, options, executeNow ) {
processModule( name, options, executeNow, { skip: true } );
};

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

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

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

extend( QUnit, {
on,

@@ -38,12 +38,18 @@ export default function Test( settings ) {

// 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`.
// As for `todo` module, all its tests will be treated as `todo` except for
// tests defined as `skip` which will be left intact.
//
// 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;

// Skipped tests should be left intact
} else if ( this.module.todo && !settings.skip ) {
settings.todo = true;
}

extend( this, settings );
@@ -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-todo.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, {
"efa6d5f5": {
skipped: false,
todo: false
},
"d394a378": {
skipped: false,
todo: true
},
"ffd66a5e": {
skipped: true,
todo: false
},
"951df7ad": {
skipped: false,
todo: true
}
} );
} );
} );

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.todo( "a todo module", function() {
QUnit.todo( "a todo test", function( assert ) {
assert.ok( false, "not implemented yet" );
} );

QUnit.skip( "a skipped test that will be left intact", function( assert ) {
assert.ok( false, "not implemented yet" );
} );

QUnit.test( "a normal test that will be treated as a todo", function( assert ) {
assert.ok( false, "not implemented yet" );
} );
} );
} );