Skip to content

Commit

Permalink
fix: only mark first project as default (#413)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt authored Feb 8, 2024
1 parent f1e0a58 commit 970c501
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 42 deletions.
21 changes: 4 additions & 17 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<vscodeTypes.TestRunProfile>();

const configErrors = new MultiMap<string, TestError>();
for (const configFileUri of configFiles) {
const configFilePath = configFileUri.fsPath;
Expand Down Expand Up @@ -281,19 +278,11 @@ export class Extension {
}

for (const project of model.projects.values()) {
await this._createRunProfile(project, usedProfiles);
await this._createRunProfile(project);
this._workspaceObserver.addWatchFolder(project.testDir);
}
}

// 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();
Expand Down Expand Up @@ -337,7 +326,7 @@ export class Extension {
})) as NodeJS.ProcessEnv;
}

private async _createRunProfile(project: TestProject, usedProfiles: Set<vscodeTypes.TestRunProfile>) {
private async _createRunProfile(project: TestProject) {
const configFile = project.model.config.configFile;
const configName = path.basename(configFile);
const folderName = path.basename(path.dirname(configFile));
Expand All @@ -346,16 +335,14 @@ 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), 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), true, 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);
}
usedProfiles.add(runProfile);
usedProfiles.add(debugProfile);
}

private _scheduleTestRunRequest(configFile: string, projectName: string, isDebug: boolean, request: vscodeTypes.TestRunRequest) {
Expand Down
25 changes: 0 additions & 25 deletions tests/profile-discovery.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
});

0 comments on commit 970c501

Please sign in to comment.