diff --git a/src/testTree.ts b/src/testTree.ts index c16ed4917..60969a398 100644 --- a/src/testTree.ts +++ b/src/testTree.ts @@ -81,6 +81,12 @@ export class TestTree extends DisposableBase { this._loadingItem.parent.children.delete(this._loadingItem.id); else if (this._testController.items.get(this._loadingItem.id)) this._testController.items.delete(this._loadingItem.id); + + // There might be scenarios where there are no test inside a Workspace folder. Clean them up after loading. + this._testController.items.forEach(item => { + if (item.children.size === 0) + this._testController.items.delete(item.id); + }); } collectTestsInside(rootItem: vscodeTypes.TestItem): vscodeTypes.TestItem[] { diff --git a/tests/list-tests.spec.ts b/tests/list-tests.spec.ts index cb3e685b6..48998a2ac 100644 --- a/tests/list-tests.spec.ts +++ b/tests/list-tests.spec.ts @@ -759,6 +759,35 @@ test('should list tests in multi-folder workspace', async ({ activate }, testInf `); }); +test('should not keep empty workspace-folders in a workspace', async ({ activate }, testInfo) => { + const { testController } = await activate({}, { + workspaceFolders: [ + [testInfo.outputPath('folder1'), {}], + [testInfo.outputPath('folder2'), { + 'playwright.config.js': `module.exports = { testDir: './' }`, + 'test.spec.ts': ` + import { test } from '@playwright/test'; + test('two', async () => {}); + `, + }] + ] + }); + + // Make sure folder1 is not listed. + await expect(testController).toHaveTestTree(` + - folder2 + - test.spec.ts + `); + + await testController.expandTestItems(/test.spec.ts/); + // Make sure folder1 is not listed. + await expect(testController).toHaveTestTree(` + - folder2 + - test.spec.ts + - two [2:0] + `); +}); + test('should merge items from different projects', async ({ activate }, testInfo) => { const { vscode, testController } = await activate({ 'playwright.config.ts': `module.exports = {