diff --git a/src/extension.ts b/src/extension.ts index ea68a5068..6245145bc 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -408,6 +408,11 @@ export class Extension implements RunHooks { const result = model.narrowDownLocations(items); if (!result.testIds && !result.locations) continue; + if (items.length) { + const enabledFiles = model.enabledFiles(); + if (items.every(item => !enabledFiles.has(item.uri!.fsPath))) + continue; + } await this._runTest(this._testRun, items, testItemForGlobalErrors, new Set(), model, mode === 'debug', enqueuedTests.length === 1); } } finally { diff --git a/src/testModel.ts b/src/testModel.ts index b008f4c9b..3043adb2e 100644 --- a/src/testModel.ts +++ b/src/testModel.ts @@ -265,6 +265,7 @@ export class TestModel { if (!testFiles.length) return; + const enabledFiles = this.enabledFiles(); const files: string[] = []; const items: vscodeTypes.TestItem[] = []; for (const watch of this._watches || []) { @@ -278,7 +279,7 @@ export class TestModel { for (const include of watch.include) { if (!include.uri) continue; - if (!this.enabledFiles().has(include.uri.fsPath)) + if (!enabledFiles.has(include.uri.fsPath)) continue; // Folder is watched => add file. if (testFile.startsWith(include.uri.fsPath + path.sep)) { diff --git a/tests/watch.spec.ts b/tests/watch.spec.ts index 34ef998cf..6c749bc69 100644 --- a/tests/watch.spec.ts +++ b/tests/watch.spec.ts @@ -15,7 +15,7 @@ */ import { TestRun } from './mock/vscode'; -import { escapedPathSep, expect, test } from './utils'; +import { enableConfigs, enableProjects, escapedPathSep, expect, selectConfig, test } from './utils'; import path from 'path'; test.skip(({ overridePlaywrightVersion }) => !!overridePlaywrightVersion); @@ -408,3 +408,99 @@ test('should watch two tests in a file', async ({ activate }) => { }, ]); }); + +test('should watch one test in a file with two configs sharig the same testDir but only one project(config1) is enabled', async ({ activate }) => { + const { vscode, testController, workspaceFolder } = await activate({ + 'playwright-1.config.js': `module.exports = { testDir: 'tests', projects: [{ name: 'project-from-config1' }] }`, + 'playwright-2.config.js': `module.exports = { testDir: 'tests', projects: [{ name: 'project-from-config2' }] }`, + 'tests/test.spec.ts': ` + import { test } from '@playwright/test'; + test('pass 1', async () => {}); + test('pass 2', async () => {}); + `, + }); + + await enableConfigs(vscode, [`playwright-1.config.js`, `playwright-2.config.js`]); + + await selectConfig(vscode, `playwright-2.config.js`); + + const webView = vscode.webViews.get('pw.extension.settingsView')!; + // Wait for the projects to be loaded. + await expect(webView.getByTestId('projects').locator('div').locator('label')).toHaveCount(1); + // Disable the project from config 2. + await enableProjects(vscode, []); + await expect(vscode).toHaveProjectTree(` + config: playwright-2.config.js + [ ] project-from-config2 +`); + + await testController.expandTestItems(/test.spec/); + const testItems = testController.findTestItems(/pass 1/); + expect(testItems).toHaveLength(1); + await testController.watch(testItems); + const [testRun] = await Promise.all([ + new Promise(f => testController.onDidCreateTestRun(testRun => { + testRun.onDidEnd(() => f(testRun)); + })), + workspaceFolder.changeFile('tests/test.spec.ts', ` + import { test } from '@playwright/test'; + test('pass 1', async () => {}); + test('pass 2', async () => {}); + test('pass 3', async () => {}); + `), + ]); + + expect(testRun.renderLog()).toBe(` + tests > test.spec.ts > pass 1 [2:0] + enqueued + enqueued + started + passed + `); + + await expect(vscode).toHaveConnectionLog([ + { method: 'listFiles', params: {} }, + { method: 'listFiles', params: {} }, + { + method: 'listTests', + params: expect.objectContaining({ + locations: [expect.stringContaining(`tests${escapedPathSep}test\\.spec\\.ts`)], + }) + }, + { method: 'runGlobalSetup', params: {} }, + { + method: 'runTests', + params: expect.objectContaining({ + locations: undefined, + testIds: [ + expect.any(String) + ] + }) + }, + { + method: 'watch', + params: expect.objectContaining({ + fileNames: [expect.stringContaining(`tests${path.sep}test.spec.ts`)], + }) + }, + { + method: 'watch', + params: expect.objectContaining({ + fileNames: [expect.stringContaining(`tests${path.sep}test.spec.ts`)], + }) + }, + { + method: 'listTests', + params: expect.objectContaining({ + locations: [expect.stringContaining(`tests${escapedPathSep}test\\.spec\\.ts`)], + }) + }, + { + method: 'runTests', + params: expect.objectContaining({ + locations: undefined, + testIds: [expect.any(String)] + }) + }, + ]); +}); \ No newline at end of file