Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: only mark first project as default #413

Merged
merged 4 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 7 additions & 17 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,7 @@ 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>();

let isFirstProject = true;
const configErrors = new MultiMap<string, TestError>();
for (const configFileUri of configFiles) {
const configFilePath = configFileUri.fsPath;
Expand Down Expand Up @@ -281,16 +279,10 @@ export class Extension {
}

for (const project of model.projects.values()) {
await this._createRunProfile(project, usedProfiles);
await this._createRunProfile(project, isFirstProject);
mxschmitt marked this conversation as resolved.
Show resolved Hide resolved
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();
if (isFirstProject)
isFirstProject = false;
}
}

Expand Down Expand Up @@ -337,7 +329,7 @@ export class Extension {
})) as NodeJS.ProcessEnv;
}

private async _createRunProfile(project: TestProject, usedProfiles: Set<vscodeTypes.TestRunProfile>) {
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));
Expand All @@ -346,16 +338,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), 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);
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.
});
Loading