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(win): normalize fs paths using vscode.Uri #386

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/debugHighlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import { locatorForSourcePosition, pruneAstCaches } from './babelHighlightUtil';
import { debugSessionName } from './debugSessionName';
import { replaceActionWithLocator, locatorMethodRegex } from './methodNames';
import type { Location } from './reporter';
import type { Location } from './oopReporter';
import { ReusedBrowser } from './reusedBrowser';
import * as vscodeTypes from './vscodeTypes';

Expand Down
3 changes: 1 addition & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ import StackUtils from 'stack-utils';
import { DebugHighlight } from './debugHighlight';
import { installBrowsers, installPlaywright } from './installer';
import { MultiMap } from './multimap';
import { Entry } from './oopReporter';
import { PlaywrightTest, TestListener } from './playwrightTest';
import type { Location, TestError } from './reporter';
import type { Location, TestError, Entry } from './oopReporter';
import { ReusedBrowser } from './reusedBrowser';
import { SettingsModel } from './settingsModel';
import { SettingsView } from './settingsView';
Expand Down
4 changes: 2 additions & 2 deletions src/oopReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import type { FullConfig, FullProject, FullResult, Location, Reporter, Suite, TestCase, TestError, TestResult, TestStatus, TestStep } from './reporter';
import { ConnectionTransport, WebSocketTransport } from './transport';

export type { TestError, Location } from './reporter';
export type EntryType = 'project' | 'file' | 'suite' | 'test';

export type Entry = {
type: EntryType;
title: string;
Expand Down Expand Up @@ -60,8 +62,6 @@ export type StepEndParams = {
};

class OopReporter implements Reporter {
config!: FullConfig;
suite!: Suite;
private _transport: Promise<ConnectionTransport>;

constructor() {
Expand Down
7 changes: 3 additions & 4 deletions src/playwrightTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import { spawn } from 'child_process';
import path from 'path';
import { debugSessionName } from './debugSessionName';
import { ConfigListFilesReport } from './listTests';
import { Entry, StepBeginParams, StepEndParams, TestBeginParams, TestEndParams } from './oopReporter';
import type { TestError } from './reporter';
import type { TestError, Entry, StepBeginParams, StepEndParams, TestBeginParams, TestEndParams } from './oopReporter';
import { ReporterServer } from './reporterServer';
import { ReusedBrowser } from './reusedBrowser';
import { findNode, spawnAsync } from './utils';
Expand Down Expand Up @@ -152,7 +151,7 @@ export class PlaywrightTest {
private async _test(config: TestConfig, locations: string[], args: string[], listener: TestListener, mode: 'list' | 'run', token: vscodeTypes.CancellationToken): Promise<void> {
// Playwright will restart itself as child process in the ESM mode and won't inherit the 3/4 pipes.
// Always use ws transport to mitigate it.
const reporterServer = new ReporterServer();
const reporterServer = new ReporterServer(this._vscode);
const node = await findNode();
if (token?.isCancellationRequested)
return;
Expand Down Expand Up @@ -230,7 +229,7 @@ export class PlaywrightTest {
this._log(`${escapeRegex(path.relative(config.workspaceFolder, configFolder))}> debug -c ${configFile}${relativeLocations.length ? ' ' + relativeLocations.join(' ') : ''}`);
}

const reporterServer = new ReporterServer();
const reporterServer = new ReporterServer(this._vscode);
await this._reusedBrowser.willRunTests(config, true);
try {
await vscode.debug.startDebugging(undefined, {
Expand Down
36 changes: 29 additions & 7 deletions src/reporterServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ import { TestListener } from './playwrightTest';
import { ConnectionTransport } from './transport';
import { createGuid } from './utils';
import * as vscodeTypes from './vscodeTypes';
import type { Location, TestError, Entry, StepBeginParams, StepEndParams, TestBeginParams, TestEndParams } from './oopReporter';

export class ReporterServer {
private _clientSocketPromise: Promise<WebSocket>;
private _clientSocketCallback!: (socket: WebSocket) => void;
private _wsServer: WebSocketServer | undefined;
private _vscode: vscodeTypes.VSCode;

constructor() {
constructor(vscode: vscodeTypes.VSCode) {
this._vscode = vscode;
this._clientSocketPromise = new Promise(f => this._clientSocketCallback = f);
}

Expand Down Expand Up @@ -86,12 +89,16 @@ export class ReporterServer {
if (token.isCancellationRequested && message.method !== 'onEnd')
return;
switch (message.method) {
case 'onBegin': listener.onBegin?.(message.params); break;
case 'onTestBegin': listener.onTestBegin?.(message.params); break;
case 'onTestEnd': listener.onTestEnd?.(message.params); break;
case 'onStepBegin': listener.onStepBegin?.(message.params); break;
case 'onStepEnd': listener.onStepEnd?.(message.params); break;
case 'onError': listener.onError?.(message.params); break;
case 'onBegin': {
(message.params as { projects: Entry[] }).projects.forEach((e: Entry) => patchLocation(this._vscode, e));
listener.onBegin?.(message.params);
break;
}
case 'onTestBegin': listener.onTestBegin?.(patchLocation(this._vscode, message.params as TestBeginParams)); break;
case 'onTestEnd': listener.onTestEnd?.(patchLocation(this._vscode, message.params as TestEndParams)); break;
case 'onStepBegin': listener.onStepBegin?.(patchLocation(this._vscode, message.params as StepBeginParams)); break;
case 'onStepEnd': listener.onStepEnd?.(patchLocation(this._vscode, message.params as StepEndParams)); break;
case 'onError': listener.onError?.(patchLocation(this._vscode, message.params as { error: TestError })); break;
case 'onEnd': {
listener.onEnd?.();
transport.close();
Expand Down Expand Up @@ -136,5 +143,20 @@ export class ReporterServer {
});
return transport;
}
}

function patchLocation<T extends { location?: Location, error?: TestError, errors?: TestError[] }>(vscode: vscodeTypes.VSCode, object: T): T {
// Normalize all the location.file values using the Uri.file().fsPath normalization.
// vscode will normalize Windows drive letter, etc.
if (object.location)
object.location.file = vscode.Uri.file(object.location.file).fsPath;
if (object.error?.location)
object.error.location.file = vscode.Uri.file(object.error.location.file).fsPath;
if (object.errors) {
object.errors.forEach(e => {
if (e.location)
e.location.file = vscode.Uri.file(e.location.file).fsPath;
});
}
return object;
}
3 changes: 1 addition & 2 deletions src/testModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
* limitations under the License.
*/

import { Entry } from './oopReporter';
import { Entry, TestError } from './oopReporter';
import { PlaywrightTest, TestConfig, TestListener } from './playwrightTest';
import { WorkspaceChange } from './workspaceObserver';
import * as vscodeTypes from './vscodeTypes';
import { resolveSourceMap } from './utils';
import { ProjectConfigWithFiles } from './listTests';
import { TestError } from './reporter';

/**
* This class builds the Playwright Test model in Playwright terms.
Expand Down
3 changes: 1 addition & 2 deletions src/testTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

import path from 'path';
import { MultiMap } from './multimap';
import { Entry, EntryType } from './oopReporter';
import { Location } from './reporter';
import type { Location, Entry, EntryType } from './oopReporter';
import { TestModel, TestProject } from './testModel';
import { createGuid } from './utils';
import * as vscodeTypes from './vscodeTypes';
Expand Down