Skip to content

Commit

Permalink
fix(watch): two configs with same testDir
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt committed May 23, 2024
1 parent 67353d7 commit c7925e2
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,9 @@ export class Extension implements RunHooks {
const result = model.narrowDownLocations(items);
if (!result.testIds && !result.locations)
continue;
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 {
Expand Down
3 changes: 2 additions & 1 deletion src/testModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 || []) {
Expand All @@ -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)) {
Expand Down
98 changes: 97 additions & 1 deletion tests/watch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<TestRun>(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)]
})
},
]);
});

0 comments on commit c7925e2

Please sign in to comment.