Skip to content

Commit 0d71e21

Browse files
fix: transform suite into child suite
1 parent 4841c60 commit 0d71e21

File tree

2 files changed

+58
-5
lines changed

2 files changed

+58
-5
lines changed

lib/tests-tree-builder/base.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,17 @@ export class BaseTestsTreeBuilder {
160160
const suite: TreeSuite = {id, parentId, name, suitePath, root: isRoot};
161161

162162
this._addSuite(suite);
163-
} else if (!isRoot && suites.byId[id].root) {
163+
} else if (suitePath.length > suites.byId[id].suitePath.length) {
164164
const newParentId = this._buildId(suitePath.slice(0, -1));
165165

166-
suites.byId[id].root = false;
167166
suites.byId[id].parentId = newParentId;
168167
suites.byId[id].suitePath = suitePath;
169-
suites.byId[id].name = suites.byId[id].name.slice(newParentId.length + 1);
170-
suites.allRootIds.splice(suites.allRootIds.indexOf(id), 1);
168+
suites.byId[id].name = suites.byId[id].id.slice(newParentId.length + 1);
169+
170+
if (suites.byId[id].root) {
171+
suites.byId[id].root = false;
172+
suites.allRootIds.splice(suites.allRootIds.indexOf(id), 1);
173+
}
171174
}
172175

173176
if (ind !== arr.length - 1) {

test/unit/lib/tests-tree-builder/base.js

+51-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ describe('ResultsTreeBuilder', () => {
109109
);
110110
});
111111

112-
it('should transform root suite into child suite', () => {
112+
it('should transform root suite into non-root suite', () => {
113113
builder.addTestResult(mkFormattedResult_({testPath: ['s1 s2', 's3']}));
114114

115115
assert.deepEqual(
@@ -140,6 +140,56 @@ describe('ResultsTreeBuilder', () => {
140140
}
141141
);
142142
});
143+
144+
it('should transform suite into child suite', () => {
145+
builder.addTestResult(mkFormattedResult_({testPath: ['s1', 's2 s3', 's4']}));
146+
147+
assert.deepEqual(
148+
builder.tree.suites.byId['s1 s2 s3'],
149+
{
150+
id: 's1 s2 s3',
151+
name: 's2 s3',
152+
parentId: 's1',
153+
root: false,
154+
suitePath: ['s1', 's2 s3'],
155+
status: SUCCESS,
156+
suiteIds: ['s1 s2 s3 s4']
157+
}
158+
);
159+
160+
builder.addTestResult(mkFormattedResult_({testPath: ['s1', 's2', 's3', 's5']}));
161+
162+
assert.deepEqual(
163+
builder.tree.suites.byId['s1 s2 s3'],
164+
{
165+
id: 's1 s2 s3',
166+
name: 's3',
167+
parentId: 's1 s2',
168+
root: false,
169+
suitePath: ['s1', 's2', 's3'],
170+
status: SUCCESS,
171+
suiteIds: ['s1 s2 s3 s4', 's1 s2 s3 s5']
172+
}
173+
);
174+
});
175+
176+
it('should merge suite into existing one', () => {
177+
builder.addTestResult(mkFormattedResult_({testPath: ['s1', 's2', 's3', 's4']}));
178+
builder.addTestResult(mkFormattedResult_({testPath: ['s1', 's2 s3', 's5']}));
179+
180+
assert.deepEqual(
181+
builder.tree.suites.byId['s1 s2 s3'],
182+
{
183+
id: 's1 s2 s3',
184+
name: 's3',
185+
parentId: 's1 s2',
186+
root: false,
187+
suitePath: ['s1', 's2', 's3'],
188+
status: SUCCESS,
189+
suiteIds: ['s1 s2 s3 s4', 's1 s2 s3 s5']
190+
}
191+
);
192+
});
143193
});
144194

145195
describe('"browsers" field in the tree', () => {

0 commit comments

Comments
 (0)