Skip to content

Commit 7659905

Browse files
Merge pull request #1535 from NullVoxPopuli/update-test-name-on-tests-start
Update test name on tests-start, guard updateTestName against double-prefixing
2 parents 3d54093 + 46bc19a commit 7659905

3 files changed

Lines changed: 72 additions & 3 deletions

File tree

addon-test-support/-private/patch-testem-output.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
* @return {string} testName
1010
*/
1111
export function updateTestName(urlParams, testName) {
12+
if (testName.includes('Exam Partition') || testName.includes('Browser Id')) {
13+
// The test name was already updated, e.g. by the `tests-start` event
14+
return testName;
15+
}
16+
1217
const split = urlParams.get('split');
1318
const loadBalance = urlParams.get('loadBalance');
1419

@@ -31,12 +36,18 @@ export function updateTestName(urlParams, testName) {
3136
}
3237

3338
/**
34-
* Setup testem test-result event to update the test name when a test completes
39+
* Setup testem tests-start and test-result events to update the test name
40+
* when a test starts and when it completes
3541
*
3642
* @function patchTestemOutput
3743
* @param {Map} urlParams
3844
*/
3945
export function patchTestemOutput(urlParams) {
46+
Testem.on('tests-start', (test) => {
47+
if (test?.name) {
48+
test.name = updateTestName(urlParams, test.name);
49+
}
50+
});
4051
Testem.on('test-result', (test) => {
4152
test.name = updateTestName(urlParams, test.name);
4253
});

node-tests/acceptance/exam-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function assertExpectRejection() {
1212
assert.ok(false, 'Expected promise to reject, but it fullfilled');
1313
}
1414

15-
const TOTAL_NUM_TESTS = 67; // Total Number of tests without the global 'Ember.onerror validation tests'
15+
const TOTAL_NUM_TESTS = 71; // Total Number of tests without the global 'Ember.onerror validation tests'
1616

1717
function getTotalNumberOfTests(output) {
1818
// In ember-qunit 3.4.0, this new check was added: https://github.com/emberjs/ember-qunit/commit/a7e93c4b4b535dae62fed992b46c00b62bfc83f4
@@ -607,7 +607,7 @@ describe('Acceptance | Exam Command', function () {
607607
assertOutput(output, 'Browser Id', ['2']);
608608
assert.strictEqual(
609609
getNumberOfTests(output),
610-
44,
610+
48,
611611
'ran all of the tests for browser two',
612612
);
613613
});

tests/unit/testem-output-test.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,63 @@ module('Unit | patch-testem-output', function () {
9999
'Exam Partition 2 - Browser Id 1 - test_module | test_name',
100100
);
101101
});
102+
103+
test('does not add partition number again when the test name already contains it', function (assert) {
104+
assert.deepEqual(
105+
TestemOutput.updateTestName(
106+
new Map().set('split', 2).set('partition', 2),
107+
'Exam Partition 2 - test_module | test_name',
108+
),
109+
'Exam Partition 2 - test_module | test_name',
110+
);
111+
});
112+
113+
test('does not add browser number again when the test name already contains it', function (assert) {
114+
assert.deepEqual(
115+
TestemOutput.updateTestName(
116+
new Map().set('loadBalance', 2).set('browser', 1),
117+
'Browser Id 1 - test_module | test_name',
118+
),
119+
'Browser Id 1 - test_module | test_name',
120+
);
121+
});
122+
});
123+
124+
module('patchTestemOutput', function (hooks) {
125+
let originalTestem;
126+
let handlers;
127+
128+
hooks.beforeEach(function () {
129+
originalTestem = window.Testem;
130+
handlers = new Map();
131+
window.Testem = {
132+
on(event, callback) {
133+
handlers.set(event, callback);
134+
},
135+
};
136+
});
137+
138+
hooks.afterEach(function () {
139+
window.Testem = originalTestem;
140+
});
141+
142+
test('updates the test name when a test starts and when it completes', function (assert) {
143+
TestemOutput.patchTestemOutput(new Map().set('split', 2));
144+
145+
const test = { name: 'test_module | test_name' };
146+
handlers.get('tests-start')(test);
147+
assert.deepEqual(test.name, 'Exam Partition 1 - test_module | test_name');
148+
149+
handlers.get('test-result')(test);
150+
assert.deepEqual(test.name, 'Exam Partition 1 - test_module | test_name');
151+
});
152+
153+
test('handles tests-start events without a test name', function (assert) {
154+
TestemOutput.patchTestemOutput(new Map().set('split', 2));
155+
156+
const test = {};
157+
handlers.get('tests-start')(test);
158+
assert.deepEqual(test.name, undefined);
159+
});
102160
});
103161
});

0 commit comments

Comments
 (0)