Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/tests-tree-builder/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,17 @@ export class BaseTestsTreeBuilder {
const suite: TreeSuite = {id, parentId, name, suitePath, root: isRoot};

this._addSuite(suite);
} else if (suitePath.length > suites.byId[id].suitePath.length) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can do it in function with a name that explains what's going on in it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A comment would be more clear

const newParentId = this._buildId(suitePath.slice(0, -1));

suites.byId[id].parentId = newParentId;
suites.byId[id].suitePath = suitePath;
suites.byId[id].name = suites.byId[id].id.slice(newParentId.length + 1);

if (suites.byId[id].root) {
suites.byId[id].root = false;
suites.allRootIds.splice(suites.allRootIds.indexOf(id), 1);
}
}

if (ind !== arr.length - 1) {
Expand Down
82 changes: 82 additions & 0 deletions test/unit/lib/tests-tree-builder/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,88 @@ describe('ResultsTreeBuilder', () => {
}
);
});

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

assert.deepEqual(
builder.tree.suites.byId['s1 s2'],
{
id: 's1 s2',
name: 's1 s2',
parentId: null,
root: true,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Root suite

suitePath: ['s1 s2'],
status: SUCCESS,
suiteIds: ['s1 s2 s3']
}
);

builder.addTestResult(mkFormattedResult_({testPath: ['s1', 's2', 's4']}));

assert.deepEqual(
builder.tree.suites.byId['s1 s2'],
{
id: 's1 s2',
name: 's2',
parentId: 's1',
root: false,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now its non-root suite with "s1" being parent suite

suitePath: ['s1', 's2'],
status: SUCCESS,
suiteIds: ['s1 s2 s3', 's1 s2 s4']
}
);
});

it('should transform suite into child suite', () => {
builder.addTestResult(mkFormattedResult_({testPath: ['s1', 's2 s3', 's4']}));

assert.deepEqual(
builder.tree.suites.byId['s1 s2 s3'],
{
id: 's1 s2 s3',
name: 's2 s3',
parentId: 's1',
root: false,
suitePath: ['s1', 's2 s3'],
status: SUCCESS,
suiteIds: ['s1 s2 s3 s4']
}
);

builder.addTestResult(mkFormattedResult_({testPath: ['s1', 's2', 's3', 's5']}));

assert.deepEqual(
builder.tree.suites.byId['s1 s2 s3'],
{
id: 's1 s2 s3',
name: 's3',
parentId: 's1 s2',
root: false,
suitePath: ['s1', 's2', 's3'],
status: SUCCESS,
suiteIds: ['s1 s2 s3 s4', 's1 s2 s3 s5']
}
);
});

it('should merge suite into existing one', () => {
builder.addTestResult(mkFormattedResult_({testPath: ['s1', 's2', 's3', 's4']}));
builder.addTestResult(mkFormattedResult_({testPath: ['s1', 's2 s3', 's5']}));

assert.deepEqual(
builder.tree.suites.byId['s1 s2 s3'],
{
id: 's1 s2 s3',
name: 's3',
parentId: 's1 s2',
root: false,
suitePath: ['s1', 's2', 's3'],
status: SUCCESS,
suiteIds: ['s1 s2 s3 s4', 's1 s2 s3 s5']
}
);
});
});

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