-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Align Test Explorer and Mocha Test Hierarchy Behavior (#21)
- Loading branch information
1 parent
171b515
commit 0630140
Showing
9 changed files
with
247 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
/** | ||
* Copyright (C) Daniel Kuschny (Danielku15) and contributors. | ||
* Copyright (C) Microsoft Corporation. All rights reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style | ||
* license that can be found in the LICENSE file or at | ||
* https://opensource.org/licenses/MIT. | ||
*/ | ||
|
||
import { expect } from 'chai'; | ||
import * as vscode from 'vscode'; | ||
import { TestState, captureTestRun, expectTestTree, findTestItem, getController } from '../util'; | ||
|
||
describe('overlapping tests', () => { | ||
it('discovers tests', async () => { | ||
const c = await getController(); | ||
|
||
await expectTestTree(c, [ | ||
[ | ||
'folder', | ||
[ | ||
['suite01-duplicate.test.js', [['suite01', [['test01']]]]], | ||
['suite03.test.js', [['suite03', [['test01']]]]], | ||
], | ||
], | ||
[ | ||
'suite01.test.js', | ||
[ | ||
['suite01', [['test01'], ['test02']]], | ||
['suite01.1', [['suite01.1']]], | ||
], | ||
], | ||
[ | ||
'suite02.test.js', | ||
[ | ||
['suite02', [['test01'], ['test02']]], | ||
['suite02.1', [['test01'], ['test02']]], | ||
], | ||
], | ||
]); | ||
}); | ||
|
||
it('runs all tests', async () => { | ||
const c = await getController(); | ||
const profiles = c.profiles; | ||
expect(profiles).to.have.lengthOf(2); | ||
|
||
const run = await captureTestRun( | ||
c, | ||
new vscode.TestRunRequest( | ||
undefined, | ||
undefined, | ||
profiles.find((p) => p.kind === vscode.TestRunProfileKind.Run), | ||
), | ||
); | ||
|
||
run.expectStates({ | ||
'suite01.test.js/suite01/test01': ['enqueued', 'started', 'passed'], | ||
'suite01.test.js/suite01/test02': ['enqueued', 'started', 'passed'], | ||
'suite01.test.js/suite01.1/suite01.1': ['enqueued', 'started', 'passed'], | ||
'suite02.test.js/suite02/test01': ['enqueued', 'started', 'passed'], | ||
'suite02.test.js/suite02/test02': ['enqueued', 'started', 'passed'], | ||
'suite02.test.js/suite02.1/test01': ['enqueued', 'started', 'passed'], | ||
'suite02.test.js/suite02.1/test02': ['enqueued', 'started', 'passed'], | ||
'folder/suite03.test.js/suite03/test01': ['enqueued', 'started', 'passed'], | ||
'folder/suite01-duplicate.test.js/suite01/test01': ['enqueued', 'started', 'passed'], | ||
}); | ||
}); | ||
|
||
const testCases: [string, string[], { [id: string]: TestState[] }][] = [ | ||
[ | ||
'runs only test of specific file', | ||
['suite01.test.js/suite01/test01'], | ||
{ | ||
'suite01.test.js/suite01/test01': ['enqueued', 'started', 'passed'], | ||
}, | ||
], | ||
[ | ||
'runs only suite of specific file', | ||
['suite01.test.js/suite01'], | ||
{ | ||
'suite01.test.js/suite01/test01': ['enqueued', 'started', 'passed'], | ||
'suite01.test.js/suite01/test02': ['enqueued', 'started', 'passed'], | ||
}, | ||
], | ||
[ | ||
'runs all suites in specific file', | ||
['suite01.test.js'], | ||
{ | ||
'suite01.test.js/suite01/test01': ['enqueued', 'started', 'passed'], | ||
'suite01.test.js/suite01/test02': ['enqueued', 'started', 'passed'], | ||
'suite01.test.js/suite01.1/suite01.1': ['enqueued', 'started', 'passed'], | ||
}, | ||
], | ||
[ | ||
'runs multiple files', | ||
['suite01.test.js', 'suite02.test.js'], | ||
{ | ||
'suite01.test.js/suite01/test01': ['enqueued', 'started', 'passed'], | ||
'suite01.test.js/suite01/test02': ['enqueued', 'started', 'passed'], | ||
'suite01.test.js/suite01.1/suite01.1': ['enqueued', 'started', 'passed'], | ||
'suite02.test.js/suite02/test01': ['enqueued', 'started', 'passed'], | ||
'suite02.test.js/suite02/test02': ['enqueued', 'started', 'passed'], | ||
'suite02.test.js/suite02.1/test01': ['enqueued', 'started', 'passed'], | ||
'suite02.test.js/suite02.1/test02': ['enqueued', 'started', 'passed'], | ||
}, | ||
], | ||
[ | ||
'runs mixed nodes', | ||
[ | ||
'suite01.test.js/suite01', | ||
'suite02.test.js/suite02/test01', | ||
'suite02.test.js/suite02.1/test02', | ||
], | ||
{ | ||
'suite01.test.js/suite01/test01': ['enqueued', 'started', 'passed'], | ||
'suite01.test.js/suite01/test02': ['enqueued', 'started', 'passed'], | ||
'suite02.test.js/suite02/test01': ['enqueued', 'started', 'passed'], | ||
'suite02.test.js/suite02.1/test02': ['enqueued', 'started', 'passed'], | ||
}, | ||
], | ||
[ | ||
'runs all in folder', | ||
['folder'], | ||
{ | ||
'folder/suite03.test.js/suite03/test01': ['enqueued', 'started', 'passed'], | ||
'folder/suite01-duplicate.test.js/suite01/test01': ['enqueued', 'started', 'passed'], | ||
}, | ||
], | ||
[ | ||
'cannot differenciate overlapping suites', | ||
['suite01.test.js/suite01/test02', 'folder/suite01-duplicate.test.js/suite01/test01'], | ||
{ | ||
// these tests are actually expected | ||
'suite01.test.js/suite01/test02': ['enqueued', 'started', 'passed'], | ||
'folder/suite01-duplicate.test.js/suite01/test01': ['enqueued', 'started', 'passed'], | ||
|
||
// this test we cannot avoid to be executed due to name overlap, it's not really queued but still running | ||
'suite01.test.js/suite01/test01': ['started', 'passed'], | ||
}, | ||
], | ||
]; | ||
|
||
for (const [name, include, expected] of testCases) { | ||
it(name, async () => { | ||
const c = await getController(); | ||
const profiles = c.profiles; | ||
expect(profiles).to.have.lengthOf(2); | ||
|
||
const testItems = include.map((i) => findTestItem(c.ctrl.items, i)!); | ||
|
||
const run = await captureTestRun( | ||
c, | ||
new vscode.TestRunRequest( | ||
testItems, | ||
undefined, | ||
profiles.find((p) => p.kind === vscode.TestRunProfileKind.Run), | ||
), | ||
); | ||
|
||
run.expectStates(expected); | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
spec: '**/*.test.js' | ||
}; |
6 changes: 6 additions & 0 deletions
6
test-workspaces/overlapping-tests/folder/suite01-duplicate.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
describe('suite01', () => { | ||
it('test01', () => { | ||
console.log('suite01-duplicate/test01'); | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
describe('suite03', () => { | ||
it('test01', () => { | ||
console.log('suite03/test01'); | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
describe('suite01', () => { | ||
it('test01', () => { | ||
console.log('suite01/test01'); | ||
}); | ||
it('test02', () => { | ||
console.log('suite01/test02'); | ||
}); | ||
}); | ||
|
||
describe('suite01.1', () => { | ||
it('suite01.1', () => { | ||
console.log('suite01/test01'); | ||
}); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
describe('suite02', () => { | ||
it('test01', () => { | ||
console.log('suite02/test01'); | ||
}); | ||
it('test02', () => { | ||
console.log('suite02/test02'); | ||
}); | ||
}); | ||
|
||
describe('suite02.1', () => { | ||
it('test01', () => { | ||
console.log('suite02.1/test01'); | ||
}); | ||
it('test02', () => { | ||
console.log('suite02.1/test02'); | ||
}); | ||
}); |