Skip to content

Commit c48bc2f

Browse files
authored
Merge pull request #963 from tasha-urbancic/feature/preserve-test-name
Add preserveTestName CLI flag to remove partition and browser
2 parents d1b2521 + 79de2c6 commit c48bc2f

9 files changed

Lines changed: 256 additions & 70 deletions

File tree

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ The [documentation website](https://ember-cli.github.io/ember-exam/) contains ex
2424
+ [Split Test Parallelization](#split-test-parallelization)
2525
* [Test Load Balancing](#test-load-balancing)
2626
- [Test Failure Reproduction](#test-failure-reproduction)
27+
* [Preserve Test Name](#preserve-test-name)
2728
- [Advanced Configuration](#advanced-configuration)
2829
* [Ember Try & CI Integration](#ember-try--ci-integration)
2930
* [Test Suite Segmentation](#test-suite-segmentation)
@@ -375,6 +376,33 @@ $ ember exam --replay-execution=test-execution-000000.json
375376
3. You must be using `qunit` version 2.8.0 or greater for this feature to work properly.
376377
4. This feature is not currently supported by Mocha.
377378

379+
#### Preserve Test Name
380+
381+
When using `--split` and/or `--load-balance` the output will look something like:
382+
383+
```bash
384+
# ember exam --split=2 --partition=1 --parallel=3 --load-balance
385+
ok 1 Chrome 66.0 - Exam Partition 1 - browser Id 1 - some test
386+
ok 2 Chrome 66.0 - Exam Partition 1 - browser Id 2 - another test
387+
ok 3 Chrome 66.0 - Exam Partition 1 - browser Id 3 - some the other test
388+
```
389+
However, if you change the amount of parallelization, or randomize across partitions, the output will change for the same test, which may be an issue if you are tracking test insights over time.
390+
391+
```bash
392+
# ember exam --split=2 --partition=1 --parallel=2 --load-balance
393+
ok 1 Chrome 66.0 - Exam Partition 1 - browser Id 2 - some test
394+
ok 2 Chrome 66.0 - Exam Partition 1 - browser Id 1 - another test
395+
ok 3 Chrome 66.0 - Exam Partition 1 - browser Id 2 - some the other test
396+
```
397+
You can add `--preserve-test-name` to remove the dynamic segments of the output (partition and browser) to ensure the output test names are always the same.
398+
399+
```bash
400+
# ember exam --split=2 --partition=1 --parallel=3 --load-balance --preserve-test-name
401+
ok 1 Chrome 66.0 - some test
402+
ok 2 Chrome 66.0 - another test
403+
ok 3 Chrome 66.0 - some the other test
404+
```
405+
378406
## Advanced Configuration
379407

380408
Ember Exam does its best to allow you to run your test suite in a way that is effective for your individual needs. To that end, there are lots of advanced ways to configure your setup by integrating with other aspects of the Ember testing environment. The following sections will cover a few of the more common scenarios.

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ export function updateTestName(urlParams, testName) {
1515
const partition = urlParams.get('partition') || 1;
1616
const browser = urlParams.get('browser') || 1;
1717

18-
if (split && loadBalance) {
18+
const preserveTestName = !!urlParams.get('preserveTestName');
19+
20+
if (preserveTestName) {
21+
return testName;
22+
} else if (split && loadBalance) {
1923
testName = `Exam Partition ${partition} - Browser Id ${browser} - ${testName}`;
2024
} else if (split) {
2125
testName = `Exam Partition ${partition} - ${testName}`;

lib/commands/exam.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ module.exports = TestCommand.extend({
4343
description:
4444
'Load balance test modules. Test modules will be sorted by weight from slowest (acceptance) to fastest (eslint).',
4545
},
46+
{
47+
name: 'preserve-test-name',
48+
type: Boolean,
49+
default: false,
50+
aliases: ['ptn'],
51+
description:
52+
'Preserve the test name when using load balance or split by omitting the partition and browser numbers.',
53+
},
4654
{
4755
name: 'random',
4856
type: String,
@@ -183,6 +191,14 @@ module.exports = TestCommand.extend({
183191
);
184192
}
185193

194+
if (commandOptions.preserveTestName) {
195+
commandOptions.query = addToQuery(
196+
commandOptions.query,
197+
'preserveTestName',
198+
commandOptions.preserveTestName
199+
);
200+
}
201+
186202
if (commandOptions.filePath) {
187203
commandOptions.query = addToQuery(
188204
commandOptions.query,

node-tests/unit/commands/exam-test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ describe('ExamCommand', function () {
8181
});
8282
});
8383

84+
it('should set `preserve-test-name` in the query option', function () {
85+
return command.run({ preserveTestName: true }).then(function () {
86+
assert.strictEqual(called.testRunOptions.query, 'preserveTestName');
87+
});
88+
});
89+
8490
it('should set `partition` in the query option with multiple partitions', function () {
8591
return command.run({ split: 2, partition: [1, 2] }).then(function () {
8692
assert.strictEqual(

tests/dummy/app/router.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Router.map(function () {
1515
this.route('split-parallel');
1616
this.route('filtering');
1717
this.route('load-balancing');
18+
this.route('preserve-test-name');
1819

1920
this.route('ember-try-and-ci');
2021
this.route('test-suite-segmentation');

tests/dummy/app/templates/docs.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
{{nav.item "Split Test Parallelization" "docs.split-parallel"}}
1414
{{nav.item "Filtering" "docs.filtering"}}
1515
{{nav.item "Test Load Balancing" "docs.load-balancing"}}
16+
{{nav.item "Preserve Test Name" "docs.preserve-test-name"}}
1617

1718
{{nav.section "Advanced Configuration"}}
1819
{{nav.item "Ember Try & CI Integration" "docs.ember-try-and-ci"}}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Preserve Test Name
2+
3+
When using `--split` and/or `--load-balance` the output will look something like:
4+
5+
```bash
6+
# ember exam --split=2 --partition=1 --parallel=3 --load-balance
7+
ok 1 Chrome 66.0 - Exam Partition 1 - browser Id 1 - some test
8+
ok 2 Chrome 66.0 - Exam Partition 1 - browser Id 2 - another test
9+
ok 3 Chrome 66.0 - Exam Partition 1 - browser Id 3 - some the other test
10+
```
11+
However, if you change the amount of parallelization, or randomize accross partitions, the output will change for the same test, which may be an issue if you are tracking test insights over time.
12+
13+
```bash
14+
# ember exam --split=2 --partition=1 --parallel=2 --load-balance
15+
ok 1 Chrome 66.0 - Exam Partition 1 - browser Id 2 - some test
16+
ok 2 Chrome 66.0 - Exam Partition 1 - browser Id 1 - another test
17+
ok 3 Chrome 66.0 - Exam Partition 1 - browser Id 2 - some the other test
18+
```
19+
You can add `--preserve-test-name` to remove the dynamic segments of the output (partition and browser) to ensure the output test names are always the same.
20+
21+
```bash
22+
# ember exam --split=2 --partition=1 --parallel=3 --load-balance --preserve-test-name
23+
ok 1 Chrome 66.0 - some test
24+
ok 2 Chrome 66.0 - another test
25+
ok 3 Chrome 66.0 - some the other test
26+
```

tests/unit/mocha/testem-output-test.js

Lines changed: 84 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,44 +10,94 @@ if (macroCondition(dependencySatisfies('ember-mocha', '*'))) {
1010
let { expect } = importSync('chai');
1111

1212
describe('Unit | Mocha | patch-testem-output', () => {
13-
it('add partition number to test name when `split` is passed', function () {
14-
expect(
15-
TestemOutput.updateTestName(
16-
new Map().set('split', 2),
17-
'test_module | test_name'
18-
)
19-
).to.equal('Exam Partition 1 - test_module | test_name');
20-
});
13+
describe('`preserveTestName` is passed', () => {
14+
it('does not add partition number to test name when `split` is passed', function () {
15+
expect(
16+
TestemOutput.updateTestName(
17+
new Map().set('split', 2).set('preserveTestName', true),
18+
'test_module | test_name'
19+
)
20+
).to.equal('test_module | test_name');
21+
});
2122

22-
it('add partition number to test name when `split` and `partition` are passed', function () {
23-
expect(
24-
TestemOutput.updateTestName(
25-
new Map().set('split', 2).set('partition', 2),
26-
'test_module | test_name'
27-
)
28-
).to.equal('Exam Partition 2 - test_module | test_name');
29-
});
23+
it('does not add partition number to test name when `split` and `partition` are passed', function () {
24+
expect(
25+
TestemOutput.updateTestName(
26+
new Map()
27+
.set('split', 2)
28+
.set('partition', 2)
29+
.set('preserveTestName', true),
30+
'test_module | test_name'
31+
)
32+
).to.equal('test_module | test_name');
33+
});
34+
35+
it('does not add browser number to test name when `loadBalance` and `browser` are passed', function () {
36+
expect(
37+
TestemOutput.updateTestName(
38+
new Map()
39+
.set('loadBalance', 2)
40+
.set('browser', 1)
41+
.set('preserveTestName', true),
42+
'test_module | test_name'
43+
)
44+
).to.equal('test_module | test_name');
45+
});
3046

31-
it('add browser number to test name when `loadBalance` and `browser` are passed', function () {
32-
expect(
33-
TestemOutput.updateTestName(
34-
new Map().set('loadBalance', 2).set('browser', 1),
35-
'test_module | test_name'
36-
)
37-
).to.equal('Browser Id 1 - test_module | test_name');
47+
it('does not add partition number, browser number to test name when `split`, `partition`, `browser`, and `loadBalance` are passed', function () {
48+
expect(
49+
TestemOutput.updateTestName(
50+
new Map()
51+
.set('split', 2)
52+
.set('partition', 2)
53+
.set('browser', 1)
54+
.set('loadBalance', 2)
55+
.set('preserveTestName', true),
56+
'test_module | test_name'
57+
)
58+
).to.equal('test_module | test_name');
59+
});
3860
});
61+
describe('`preserveTestName` is not passed', () => {
62+
it('adds partition number to test name when `split` is passed', function () {
63+
expect(
64+
TestemOutput.updateTestName(
65+
new Map().set('split', 2),
66+
'test_module | test_name'
67+
)
68+
).to.equal('Exam Partition 1 - test_module | test_name');
69+
});
70+
71+
it('adds partition number to test name when `split` and `partition` are passed', function () {
72+
expect(
73+
TestemOutput.updateTestName(
74+
new Map().set('split', 2).set('partition', 2),
75+
'test_module | test_name'
76+
)
77+
).to.equal('Exam Partition 2 - test_module | test_name');
78+
});
79+
80+
it('adds browser number to test name when `loadBalance` and `browser` are passed', function () {
81+
expect(
82+
TestemOutput.updateTestName(
83+
new Map().set('loadBalance', 2).set('browser', 1),
84+
'test_module | test_name'
85+
)
86+
).to.equal('Browser Id 1 - test_module | test_name');
87+
});
3988

40-
it('add partition number, browser number to test name when `split`, `partition`, `browser`, and `loadBalance` are passed', function () {
41-
expect(
42-
TestemOutput.updateTestName(
43-
new Map()
44-
.set('split', 2)
45-
.set('partition', 2)
46-
.set('browser', 1)
47-
.set('loadBalance', 2),
48-
'test_module | test_name'
49-
)
50-
).to.equal('Exam Partition 2 - Browser Id 1 - test_module | test_name');
89+
it('adds partition number, browser number to test name when `split`, `partition`, `browser`, and `loadBalance` are passed', function () {
90+
expect(
91+
TestemOutput.updateTestName(
92+
new Map()
93+
.set('split', 2)
94+
.set('partition', 2)
95+
.set('browser', 1)
96+
.set('loadBalance', 2),
97+
'test_module | test_name'
98+
)
99+
).to.equal('Exam Partition 2 - Browser Id 1 - test_module | test_name');
100+
});
51101
});
52102
});
53103
}

0 commit comments

Comments
 (0)