Skip to content

Commit

Permalink
chore: filter test tree by selected project (#431)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman authored Mar 4, 2024
1 parent 1c2f766 commit 4ad3412
Show file tree
Hide file tree
Showing 15 changed files with 304 additions and 229 deletions.
34 changes: 17 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"url": "https://github.com/microsoft/playwright-vscode/issues"
},
"engines": {
"vscode": "^1.78.0"
"vscode": "^1.86.0"
},
"categories": [
"Testing"
Expand Down Expand Up @@ -128,13 +128,13 @@
"@types/glob": "^8.0.0",
"@types/node": "^18.11.9",
"@types/stack-utils": "^2.0.1",
"@types/vscode": "1.78.0",
"@types/vscode": "1.86.0",
"@types/which": "^2.0.1",
"@types/ws": "^8.5.3",
"@typescript-eslint/eslint-plugin": "^5.44.0",
"@typescript-eslint/parser": "^5.44.0",
"@vscode/l10n-dev": "^0.0.24",
"@vscode/vsce": "^2.20.1",
"@vscode/vsce": "^2.24.0",
"esbuild": "^0.15.15",
"eslint": "^8.28.0",
"eslint-plugin-notice": "^0.9.10",
Expand Down
53 changes: 35 additions & 18 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,17 +292,30 @@ export class Extension implements RunHooks {
}

const model = new TestModel(this._vscode, this._playwrightTest, workspaceFolderPath, configFileUri.fsPath, playwrightInfo, this._envProvider.bind(this));
this._models.push(model);
this._testTree.addModel(model);
const configError = await model.listFiles();
if (configError) {
configErrors.set(configError.location?.file ?? configFilePath, configError);
continue;
}

for (const project of model.projects.values()) {
await this._createRunProfile(project);
this._workspaceObserver.addWatchFolder(project.testDir);
this._models.push(model);
this._testTree.addModel(model);
}

// Update list of run profiles.
{
// rebuildModel can run concurrently, swapping run profiles needs to be sync.
const existingProfiles = this._runProfiles;
this._runProfiles = new Map();
for (const model of this._models) {
for (const project of model.allProjects().values()) {
this._createRunProfile(project, existingProfiles);
this._workspaceObserver.addWatchFolder(project.testDir);
}
}
for (const [id, profile] of existingProfiles) {
if (!this._runProfiles.has(id))
profile.dispose();
}
}

Expand Down Expand Up @@ -332,7 +345,7 @@ export class Extension implements RunHooks {
if (error?.location) {
const range = new this._vscode.Range(
new this._vscode.Position(Math.max(error.location.line - 4, 0), 0),
new this._vscode.Position(error.location.line - 1, error.location.column - 1),
new this._vscode.Position(Math.max(error.location.line - 1, 0), Math.max(error.location.column - 1, 0)),
);
this._vscode.window.activeTextEditor?.revealRange(range);
}
Expand All @@ -349,25 +362,26 @@ export class Extension implements RunHooks {
})) as NodeJS.ProcessEnv;
}

private async _createRunProfile(project: TestProject) {
private _createRunProfile(project: TestProject, existingProfiles: Map<string, vscodeTypes.TestRunProfile>) {
const configFile = project.model.config.configFile;
const configName = path.basename(configFile);
const folderName = path.basename(path.dirname(configFile));
const projectPrefix = project.name ? `${project.name} — ` : '';
const keyPrefix = configFile + ':' + project.name;
let runProfile = this._runProfiles.get(keyPrefix + ':run');
let runProfile = existingProfiles.get(keyPrefix + ':run');
const projectTag = this._testTree.projectTag(project);
const isDefault = false;
const supportsContinuousRun = this._settingsModel.allowWatchingFiles.get();
if (!runProfile) {
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, supportsContinuousRun);
this._runProfiles.set(keyPrefix + ':run', runProfile);
}
let debugProfile = this._runProfiles.get(keyPrefix + ':debug');
if (!debugProfile) {
this._runProfiles.set(keyPrefix + ':run', runProfile);
let debugProfile = existingProfiles.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, supportsContinuousRun);
this._runProfiles.set(keyPrefix + ':debug', debugProfile);
}
this._runProfiles.set(keyPrefix + ':debug', debugProfile);

runProfile.onDidChangeDefault(enabled => project.model.setProjectEnabled(project, enabled));
debugProfile.onDidChangeDefault(enabled => project.model.setProjectEnabled(project, enabled));
}

private _scheduleTestRunRequest(configFile: string, projectName: string, isDebug: boolean, request: vscodeTypes.TestRunRequest, cancellationToken?: vscodeTypes.CancellationToken) {
Expand All @@ -380,7 +394,7 @@ export class Extension implements RunHooks {
const model = this._models.find(m => m.config.configFile === configFile);
if (!model)
return;
const project = model.projects.get(projectName);
const project = model.allProjects().get(projectName);
if (!project)
return;

Expand Down Expand Up @@ -690,7 +704,10 @@ located next to Run / Debug Tests toolbar buttons.`);
const allErrors = new Set<string>();
const errorsByFile = new MultiMap<string, TestError>();
for (const model of this._models.slice()) {
const errors = await model.listTests([...files]).catch(e => console.log(e)) || [];
const filteredFiles = model.narrowDownFilesToEnabledProjects(files);
if (!filteredFiles.size)
continue;
const errors = await model.listTests([...filteredFiles]).catch(e => console.log(e)) || [];
for (const error of errors) {
if (!error.location || !error.message)
continue;
Expand Down Expand Up @@ -728,7 +745,7 @@ located next to Run / Debug Tests toolbar buttons.`);
diagnostics.push({
severity: this._vscode.DiagnosticSeverity.Error,
source: 'playwright',
range: new this._vscode.Range(error.location!.line - 1, error.location!.column - 1, error.location!.line, 0),
range: new this._vscode.Range(Math.max(error.location!.line - 1, 0), Math.max(error.location!.column - 1, 0), error.location!.line, 0),
message: error.message!,
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/reusedBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import { TestConfig } from './playwrightTest';
import { TestModel, TestProject } from './testModel';
import type { TestModel } from './testModel';
import { createGuid } from './utils';
import * as vscodeTypes from './vscodeTypes';
import path from 'path';
Expand Down Expand Up @@ -324,7 +324,7 @@ export class ReusedBrowser implements vscodeTypes.Disposable {
}

private async _createFileForNewTest(model: TestModel) {
const project = model.projects.values().next().value as TestProject;
const project = model.enabledProjects()[0];
if (!project)
return;
let file;
Expand Down
Loading

0 comments on commit 4ad3412

Please sign in to comment.