diff --git a/Gruntfile.js b/Gruntfile.js index d291ed890..a423f363d 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -165,6 +165,7 @@ module.exports = function( grunt ) { "test/reporter-html/xhtml-single-testid.xhtml", "test/reporter-urlparams.html", "test/moduleId.html", + "test/testIds.html", "test/onerror/inside-test.html", "test/onerror/outside-test.html", "test/only.html", diff --git a/docs/config/QUnit.config.md b/docs/config/QUnit.config.md index ed378ce64..505f7575e 100644 --- a/docs/config/QUnit.config.md +++ b/docs/config/QUnit.config.md @@ -101,6 +101,10 @@ Enabling this option will cause tests to fail, if they don't call `expect()` at This property allows QUnit to run specific tests identified by the hashed version of their module name and test name. You can specify one or multiple tests to run. +### `QUnit.config.testIds` (array) | default: `array` + +This property allows QUnit to return all hashed testIds of all loaded tests. + ### `QUnit.config.testTimeout` (number) | default: `undefined` Specify a global timeout in milliseconds after which all tests will fail with an appropriate message. Useful when async tests aren't finishing, to prevent the testrunner getting stuck. Set to something high, e.g. 30000 (30 seconds) to avoid slow tests to time out by accident. diff --git a/package-lock.json b/package-lock.json index 831a8ce56..e8e6767db 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "qunit", - "version": "2.9.3-pre", + "version": "2.9.4-pre", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/core/config.js b/src/core/config.js index a45fc89dc..6d132b338 100644 --- a/src/core/config.js +++ b/src/core/config.js @@ -1,5 +1,5 @@ import { window, localSessionStorage } from "../globals"; -import { extend } from "./utilities"; +import { extend, generateHash } from "./utilities"; /** * Config object: Maintain internal state @@ -58,7 +58,22 @@ const config = { callbacks: {}, // The storage module to use for reordering tests - storage: localSessionStorage + storage: localSessionStorage, + + // Get the testIds for all tests, value is read only + get testIds() { + var i, j, ml, tl, testIds = []; + + // Loop through all modules and tests and generate testIds + for ( i = 0, ml = config.modules.length; i < ml; i++ ) { + for ( j = 0, tl = config.modules[ i ].tests.length; j < tl; j++ ) { + testIds.push( generateHash( config.modules[ i ].name, + config.modules[ i ].tests[ j ].name ) ); + } + } + return testIds; + } + }; // take a predefined QUnit.config and extend the defaults diff --git a/test/testIds.html b/test/testIds.html new file mode 100644 index 000000000..60e2b0f8a --- /dev/null +++ b/test/testIds.html @@ -0,0 +1,13 @@ + + + + + QUnit ModuleId Test Suite + + + + + +
+ + diff --git a/test/testIds.js b/test/testIds.js new file mode 100644 index 000000000..603f1e460 --- /dev/null +++ b/test/testIds.js @@ -0,0 +1,5 @@ +QUnit.module( "QUnit.config.testIds" ); + +QUnit.test( "testIds should return all testIds", function( assert ) { + assert.deepEqual( QUnit.config.testIds, [ "01e80961" ] ); +} );