From f8f390949ebaa6fd85ba5d977e2e2af29bef43ab Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Thu, 23 May 2024 17:07:20 +0200 Subject: [PATCH] fix(watch): two configs with same testDir --- src/extension.ts | 2 + src/testModel.ts | 3 +- tests/watch.spec.ts | 98 ++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 101 insertions(+), 2 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index a36a5f9e4..b0b2560a2 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -406,6 +406,8 @@ export class Extension implements RunHooks { const result = model.narrowDownLocations(items); if (!result.testIds && !result.locations) continue; + if (!model.enabledProjects().length) + 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 71ec65f4a..80595250d 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