From 1ea95d529256bee146be4887daf8cef5dee139c1 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Mon, 5 Feb 2024 18:04:58 +0100 Subject: [PATCH 1/4] fix: only mark first project as default --- src/extension.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 7148403e3..759de262c 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -237,6 +237,7 @@ export class Extension { // Reuse already created run profiles in order to retain their 'selected' status. const usedProfiles = new Set(); + let isFirstProject = true; const configErrors = new MultiMap(); for (const configFileUri of configFiles) { const configFilePath = configFileUri.fsPath; @@ -281,8 +282,10 @@ export class Extension { } for (const project of model.projects.values()) { - await this._createRunProfile(project, usedProfiles); + await this._createRunProfile(project, usedProfiles, isFirstProject); this._workspaceObserver.addWatchFolder(project.testDir); + if (isFirstProject) + isFirstProject = false; } } @@ -337,7 +340,7 @@ export class Extension { })) as NodeJS.ProcessEnv; } - private async _createRunProfile(project: TestProject, usedProfiles: Set) { + private async _createRunProfile(project: TestProject, usedProfiles: Set, isDefault: boolean) { const configFile = project.model.config.configFile; const configName = path.basename(configFile); const folderName = path.basename(path.dirname(configFile)); @@ -346,12 +349,12 @@ export class Extension { let runProfile = this._runProfiles.get(keyPrefix + ':run'); const projectTag = this._testTree.projectTag(project); if (!runProfile) { - runProfile = this._testController.createRunProfile(`${projectPrefix}${folderName}${path.sep}${configName}`, this._vscode.TestRunProfileKind.Run, this._scheduleTestRunRequest.bind(this, configFile, project.name, false), true, projectTag); + runProfile = this._testController.createRunProfile(`${projectPrefix}${folderName}${path.sep}${configName}`, this._vscode.TestRunProfileKind.Run, this._scheduleTestRunRequest.bind(this, configFile, project.name, false), isDefault, projectTag); this._runProfiles.set(keyPrefix + ':run', runProfile); } let debugProfile = this._runProfiles.get(keyPrefix + ':debug'); if (!debugProfile) { - debugProfile = this._testController.createRunProfile(`${projectPrefix}${folderName}${path.sep}${configName}`, this._vscode.TestRunProfileKind.Debug, this._scheduleTestRunRequest.bind(this, configFile, project.name, true), true, projectTag); + debugProfile = this._testController.createRunProfile(`${projectPrefix}${folderName}${path.sep}${configName}`, this._vscode.TestRunProfileKind.Debug, this._scheduleTestRunRequest.bind(this, configFile, project.name, true), isDefault, projectTag); this._runProfiles.set(keyPrefix + ':debug', debugProfile); } usedProfiles.add(runProfile); From c12de6bf2670ab6b98d3cfd0432ef07d742d5536 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Mon, 5 Feb 2024 18:22:04 +0100 Subject: [PATCH 2/4] chore: get rid of usedProfiles --- src/extension.ts | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 759de262c..29df17b9a 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -234,9 +234,6 @@ export class Extension { const configFiles = await this._vscode.workspace.findFiles('**/*playwright*.config.{ts,js,mjs}', '**/node_modules/**'); - // Reuse already created run profiles in order to retain their 'selected' status. - const usedProfiles = new Set(); - let isFirstProject = true; const configErrors = new MultiMap(); for (const configFileUri of configFiles) { @@ -282,21 +279,13 @@ export class Extension { } for (const project of model.projects.values()) { - await this._createRunProfile(project, usedProfiles, isFirstProject); + await this._createRunProfile(project, isFirstProject); this._workspaceObserver.addWatchFolder(project.testDir); if (isFirstProject) isFirstProject = false; } } - // Clean up unused run profiles. - for (const [key, profile] of this._runProfiles) { - if (!usedProfiles.has(profile)) { - this._runProfiles.delete(key); - profile.dispose(); - } - } - this._settingsView.updateActions(); this._testTree.finishedLoading(); @@ -340,7 +329,7 @@ export class Extension { })) as NodeJS.ProcessEnv; } - private async _createRunProfile(project: TestProject, usedProfiles: Set, isDefault: boolean) { + private async _createRunProfile(project: TestProject, isDefault: boolean) { const configFile = project.model.config.configFile; const configName = path.basename(configFile); const folderName = path.basename(path.dirname(configFile)); @@ -357,8 +346,6 @@ export class Extension { debugProfile = this._testController.createRunProfile(`${projectPrefix}${folderName}${path.sep}${configName}`, this._vscode.TestRunProfileKind.Debug, this._scheduleTestRunRequest.bind(this, configFile, project.name, true), isDefault, projectTag); this._runProfiles.set(keyPrefix + ':debug', debugProfile); } - usedProfiles.add(runProfile); - usedProfiles.add(debugProfile); } private _scheduleTestRunRequest(configFile: string, projectName: string, isDebug: boolean, request: vscodeTypes.TestRunRequest) { From c33b032148af1ab3db792e4329a13f1e1857111e Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Mon, 5 Feb 2024 21:24:30 +0100 Subject: [PATCH 3/4] nit --- tests/profile-discovery.spec.ts | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/tests/profile-discovery.spec.ts b/tests/profile-discovery.spec.ts index fc66a5748..f6201de22 100644 --- a/tests/profile-discovery.spec.ts +++ b/tests/profile-discovery.spec.ts @@ -75,28 +75,3 @@ test('should create run & debug profile per project', async ({ activate }, testI > playwright list-files -c playwright.config.js `); }); - -test('retain run profile instances of reload', async ({ activate }, testInfo) => { - const { testController, workspaceFolder } = await activate({ - 'playwright.config.js': `module.exports = { - projects: [{ name: 'projectA' }, { name: 'projectB' }] - }` - }, { rootDir: testInfo.outputPath('workspace') }); - - const runProfiles = new Set(testController.runProfiles); - - await workspaceFolder.changeFile('playwright.config.js', `module.exports = { - projects: [{ name: 'projectA' }, { name: 'projectC' }, { name: 'projectD' }] - }`); - - while (testController.runProfiles.length !== 6) - await new Promise(f => setTimeout(f, 100)); - - let retained = 0; - for (const profile of testController.runProfiles) { - if (runProfiles.has(profile)) - ++retained; - } - - expect(retained).toBe(2); // Run & Debug projects from project A. -}); From d37d121071ba61e0003c658e3ed3c16a169bc3ce Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Thu, 8 Feb 2024 19:17:01 +0100 Subject: [PATCH 4/4] fixes --- src/extension.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 29df17b9a..bb1cd8d39 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -234,7 +234,6 @@ export class Extension { const configFiles = await this._vscode.workspace.findFiles('**/*playwright*.config.{ts,js,mjs}', '**/node_modules/**'); - let isFirstProject = true; const configErrors = new MultiMap(); for (const configFileUri of configFiles) { const configFilePath = configFileUri.fsPath; @@ -279,10 +278,8 @@ export class Extension { } for (const project of model.projects.values()) { - await this._createRunProfile(project, isFirstProject); + await this._createRunProfile(project); this._workspaceObserver.addWatchFolder(project.testDir); - if (isFirstProject) - isFirstProject = false; } } @@ -329,7 +326,7 @@ export class Extension { })) as NodeJS.ProcessEnv; } - private async _createRunProfile(project: TestProject, isDefault: boolean) { + private async _createRunProfile(project: TestProject) { const configFile = project.model.config.configFile; const configName = path.basename(configFile); const folderName = path.basename(path.dirname(configFile)); @@ -338,12 +335,12 @@ export class Extension { let runProfile = this._runProfiles.get(keyPrefix + ':run'); const projectTag = this._testTree.projectTag(project); if (!runProfile) { - runProfile = this._testController.createRunProfile(`${projectPrefix}${folderName}${path.sep}${configName}`, this._vscode.TestRunProfileKind.Run, this._scheduleTestRunRequest.bind(this, configFile, project.name, false), isDefault, projectTag); + runProfile = this._testController.createRunProfile(`${projectPrefix}${folderName}${path.sep}${configName}`, this._vscode.TestRunProfileKind.Run, this._scheduleTestRunRequest.bind(this, configFile, project.name, false), false, projectTag); this._runProfiles.set(keyPrefix + ':run', runProfile); } let debugProfile = this._runProfiles.get(keyPrefix + ':debug'); if (!debugProfile) { - debugProfile = this._testController.createRunProfile(`${projectPrefix}${folderName}${path.sep}${configName}`, this._vscode.TestRunProfileKind.Debug, this._scheduleTestRunRequest.bind(this, configFile, project.name, true), isDefault, projectTag); + debugProfile = this._testController.createRunProfile(`${projectPrefix}${folderName}${path.sep}${configName}`, this._vscode.TestRunProfileKind.Debug, this._scheduleTestRunRequest.bind(this, configFile, project.name, true), false, projectTag); this._runProfiles.set(keyPrefix + ':debug', debugProfile); } }