Skip to content

Commit

Permalink
fix: should not list empty workspace folders
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt committed May 22, 2024
1 parent b54b662 commit 981a224
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/testTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] {
Expand Down
29 changes: 29 additions & 0 deletions tests/list-tests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit 981a224

Please sign in to comment.