From 7afb00a89abbcf5f4c8dd7a0aa2035586a0720ba Mon Sep 17 00:00:00 2001 From: step2yeung Date: Wed, 20 Nov 2019 16:29:54 -0800 Subject: [PATCH] Core: keeping count of tests not ran to ensure moduleDone is called --- Gruntfile.js | 1 + src/core/config.js | 1 + src/module.js | 1 + src/test.js | 31 +++++-- test/callbacks-filters.html | 14 ++++ test/callbacks-filters.js | 157 ++++++++++++++++++++++++++++++++++++ 6 files changed, 197 insertions(+), 8 deletions(-) create mode 100644 test/callbacks-filters.html create mode 100644 test/callbacks-filters.js diff --git a/Gruntfile.js b/Gruntfile.js index d291ed890..92cb6007f 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -151,6 +151,7 @@ module.exports = function( grunt ) { "test/reorderError2.html", "test/callbacks.html", "test/callbacks-promises.html", + "test/callbacks-filters.html", "test/events.html", "test/events-in-test.html", "test/logs.html", diff --git a/src/core/config.js b/src/core/config.js index a45fc89dc..81cd64f81 100644 --- a/src/core/config.js +++ b/src/core/config.js @@ -47,6 +47,7 @@ const config = { childModules: [], testsRun: 0, unskippedTestsRun: 0, + testsNotRan: 0, hooks: { before: [], beforeEach: [], diff --git a/src/module.js b/src/module.js index 623761c97..1f4d0dd89 100644 --- a/src/module.js +++ b/src/module.js @@ -23,6 +23,7 @@ function createModule( name, testEnvironment, modifiers ) { tests: [], moduleId: generateHash( moduleName ), testsRun: 0, + testsNotRan: 0, unskippedTestsRun: 0, childModules: [], suiteReport: new SuiteReport( name, parentSuite ), diff --git a/src/test.js b/src/test.js index 119389bef..d3f00103e 100644 --- a/src/test.js +++ b/src/test.js @@ -309,7 +309,7 @@ Test.prototype = { } } - notifyTestsRan( module, skipped ); + updateTestsRan( module, skipped ); // Store result when possible if ( storage ) { @@ -344,13 +344,15 @@ Test.prototype = { // generating stack trace is expensive, so using a getter will help defer this until we need it get source() { return test.stack; } } ).then( function() { - if ( module.testsRun === numberOfTests( module ) ) { + if ( ( module.testsRun + module.testsNotRan ) === numberOfTests( module ) ) { const completedModules = [ module ]; // Check if the parent modules, iteratively, are done. If that the case, // we emit the `suiteEnd` event and trigger `moduleDone` callback. let parent = module.parentModule; - while ( parent && parent.testsRun === numberOfTests( parent ) ) { + while ( parent && + ( parent.testsRun + parent.testsNotRan ) === numberOfTests( parent ) + ) { completedModules.push( parent ); parent = parent.parentModule; } @@ -394,6 +396,7 @@ Test.prototype = { const test = this; if ( !this.valid() ) { + updateTestsNotRan( this.module ); return; } @@ -551,10 +554,7 @@ Test.prototype = { }, valid: function() { - var filter = config.filter, - regexFilter = /^(!?)\/([\w\W]*)\/(i?$)/.exec( filter ), - module = config.module && config.module.toLowerCase(), - fullName = ( this.module.name + ": " + this.testName ); + var module = config.module && config.module.toLowerCase(); function moduleChainNameMatch( testModule ) { var testModuleName = testModule.name ? testModule.name.toLowerCase() : null; @@ -593,6 +593,14 @@ Test.prototype = { return false; } + return this.filterMatch(); + }, + + filterMatch: function() { + var filter = config.filter, + regexFilter = /^(!?)\/([\w\W]*)\/(i?$)/.exec( filter ), + fullName = ( this.module.name + ": " + this.testName ); + if ( !filter ) { return true; } @@ -865,7 +873,7 @@ function numberOfUnskippedTests( module ) { return collectTests( module ).filter( test => !test.skip ).length; } -function notifyTestsRan( module, skipped ) { +function updateTestsRan( module, skipped ) { module.testsRun++; if ( !skipped ) { module.unskippedTestsRun++; @@ -877,3 +885,10 @@ function notifyTestsRan( module, skipped ) { } } } + +function updateTestsNotRan( module ) { + module.testsNotRan++; + while ( ( module = module.parentModule ) ) { + module.testsNotRan++; + } +} diff --git a/test/callbacks-filters.html b/test/callbacks-filters.html new file mode 100644 index 000000000..d12216ba8 --- /dev/null +++ b/test/callbacks-filters.html @@ -0,0 +1,14 @@ + + + + + QUnit Callbacks Filters Test Suite + + + + + +
+
+ + diff --git a/test/callbacks-filters.js b/test/callbacks-filters.js new file mode 100644 index 000000000..5788d2994 --- /dev/null +++ b/test/callbacks-filters.js @@ -0,0 +1,157 @@ +var invokedHooks = []; +var done = false; + +function callback( name ) { + return function() { + if ( done ) { + return; + } + + invokedHooks.push( name ); + }; +} + +QUnit.begin( callback( "begin" ) ); +QUnit.moduleStart( callback( "moduleStart" ) ); +QUnit.testStart( callback( "testStart" ) ); +QUnit.testDone( callback( "testDone" ) ); +QUnit.moduleDone( callback( "moduleDone" ) ); +QUnit.done( callback( "done" ) ); + +QUnit.done( function() { + if ( done ) { + return; + } + + done = true; + + QUnit.test( "verify callback order", function( assert ) { + assert.deepEqual( invokedHooks, [ + "begin", + "moduleStart", + "testStart", + "testDone", + "testStart", + "testDone", + "moduleDone", + "moduleStart", + "testStart", + "testDone", + "moduleDone", + "moduleStart", + "testStart", + "testDone", + "moduleDone", + "moduleStart", + "testStart", + "testDone", + "moduleStart", + "testStart", + "testDone", + "moduleDone", + "moduleDone", + "moduleStart", + "moduleStart", + "testStart", + "testDone", + "moduleDone", + "moduleDone", + "moduleStart", + "testStart", + "testDone", + "moduleDone", + "done" + ] ); + } ); +} ); + +QUnit.config.moduleId = [ "1cf055b9" ]; + +// match for module Id +QUnit.module( "module1", function() { + QUnit.test( "test should run 1.1", function( assert ) { + assert.ok( true ); + } ); + + QUnit.test( "test should run 1.2", function( assert ) { + assert.ok( true ); + } ); +} ); + +// no match module Id +QUnit.module( "module2", function() { + QUnit.test( "test should NOT run 2.1", function( assert ) { + assert.ok( false ); + } ); + + QUnit.test( "test should NOT run 2.2", function( assert ) { + assert.ok( false ); + } ); +} ); + +QUnit.config.moduleId = []; +QUnit.config.testId = [ "3b3c4e75" ]; + +QUnit.module( "module3", function() { + + // match test Id + QUnit.test( "ABCtest should run 3.1", function( assert ) { + assert.ok( true ); + } ); + + QUnit.test( "test should NOT run 3.2", function( assert ) { + assert.ok( false ); + } ); +} ); + +QUnit.config.testId = []; +QUnit.config.filter = "!.2"; + +QUnit.module( "module4", function() { + + // match string filter + QUnit.test( "test should run 4.1", function( assert ) { + assert.ok( true ); + } ); + + QUnit.test( "test should NOT run 4.2", function( assert ) { + assert.ok( false ); + } ); +} ); + +// Make sure nest module scenarios are correct +QUnit.module( "module5", function() { + QUnit.test( "test", function( assert ) { + assert.ok( true ); + } ); + + QUnit.module( "nestedModule5A", function() { + QUnit.test( "test should run 5.A.1", function( assert ) { + assert.ok( true ); + } ); + } ); +} ); + +QUnit.module( "module6", function() { + QUnit.test( "test should NOT run 6.2", function( assert ) { + assert.ok( true ); + } ); + + QUnit.module( "nestedModule6A", function() { + QUnit.test( "test should run 6.A.1", function( assert ) { + assert.ok( true ); + } ); + } ); +} ); + +QUnit.module( "module7", function() { + QUnit.test( "test should run 7.1", function( assert ) { + assert.ok( true ); + } ); + + QUnit.module( "nestedModule7A", function() { + QUnit.test( "test should NOT run 7.A.2", function( assert ) { + assert.ok( true ); + } ); + } ); +} );