Skip to content

Commit bf39c18

Browse files
kltanKean Tan
authored and
Kean Tan
committed
Core: Create config.testIds to expose all available test ids
What this does Currently each testId is calculated as each test is executed. Config.testIds pre-hashes all the loaded tests on demand and returns all testIds. How is this helpful Currently test runners can get access to test modules via config.modules and partition the modules based on some distribution strategy for running the tests in parallel. This is fine but it can lead to unbalanced distribution as some modules have a lot of tests and some modules are testing integration (longer running) test instead of unit test. Partitioning the tests by modules caused some instance of test runners to run way longer than others as some heavier running modules might be clumped together in the same instance. To mitigate and minimize the unbalanced test runs, the proposed solution is to partition based on each individual test with testId. The test runners can now access testIds beforehand and can distribute those ids with the testId url param. This will minimize the test execution time descrepencies between each individual instance of the test runners.
1 parent e678729 commit bf39c18

File tree

6 files changed

+41
-3
lines changed

6 files changed

+41
-3
lines changed

Gruntfile.js

+1
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ module.exports = function( grunt ) {
165165
"test/reporter-html/xhtml-single-testid.xhtml",
166166
"test/reporter-urlparams.html",
167167
"test/moduleId.html",
168+
"test/testIds.html",
168169
"test/onerror/inside-test.html",
169170
"test/onerror/outside-test.html",
170171
"test/only.html",

docs/config/QUnit.config.md

+4
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ Enabling this option will cause tests to fail, if they don't call `expect()` at
101101

102102
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.
103103

104+
### `QUnit.config.testIds` (array) | default: `array`
105+
106+
This property allows QUnit to return all hashed testIds of all loaded tests.
107+
104108
### `QUnit.config.testTimeout` (number) | default: `undefined`
105109

106110
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.

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/config.js

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { window, localSessionStorage } from "../globals";
2-
import { extend } from "./utilities";
2+
import { extend, generateHash } from "./utilities";
33

44
/**
55
* Config object: Maintain internal state
@@ -58,7 +58,22 @@ const config = {
5858
callbacks: {},
5959

6060
// The storage module to use for reordering tests
61-
storage: localSessionStorage
61+
storage: localSessionStorage,
62+
63+
// Get the testIds for all tests, value is read only
64+
get testIds() {
65+
var i, j, ml, tl, testIds = [];
66+
67+
// Loop through all modules and tests and generate testIds
68+
for ( i = 0, ml = config.modules.length; i < ml; i++ ) {
69+
for ( j = 0, tl = config.modules[ i ].tests.length; j < tl; j++ ) {
70+
testIds.push( generateHash( config.modules[ i ].name,
71+
config.modules[ i ].tests[ j ].name ) );
72+
}
73+
}
74+
return testIds;
75+
}
76+
6277
};
6378

6479
// take a predefined QUnit.config and extend the defaults

test/testIds.html

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>QUnit ModuleId Test Suite</title>
6+
<link rel="stylesheet" href="../dist/qunit.css">
7+
<script src="../dist/qunit.js"></script>
8+
<script src="testIds.js"></script>
9+
</head>
10+
<body>
11+
<div id="qunit"></div>
12+
</body>
13+
</html>

test/testIds.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
QUnit.module( "QUnit.config.testIds" );
2+
3+
QUnit.test( "testIds should return all testIds", function( assert ) {
4+
assert.deepEqual( QUnit.config.testIds, [ "01e80961" ] );
5+
} );

0 commit comments

Comments
 (0)