Skip to content

Commit 17b9217

Browse files
authored
fix(win): normalize fs paths using vscode.Uri (#386)
1 parent 87ca2c6 commit 17b9217

File tree

7 files changed

+38
-20
lines changed

7 files changed

+38
-20
lines changed

src/debugHighlight.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import { locatorForSourcePosition, pruneAstCaches } from './babelHighlightUtil';
1818
import { debugSessionName } from './debugSessionName';
1919
import { replaceActionWithLocator, locatorMethodRegex } from './methodNames';
20-
import type { Location } from './reporter';
20+
import type { Location } from './oopReporter';
2121
import { ReusedBrowser } from './reusedBrowser';
2222
import * as vscodeTypes from './vscodeTypes';
2323

src/extension.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ import StackUtils from 'stack-utils';
1919
import { DebugHighlight } from './debugHighlight';
2020
import { installBrowsers, installPlaywright } from './installer';
2121
import { MultiMap } from './multimap';
22-
import { Entry } from './oopReporter';
2322
import { PlaywrightTest, TestListener } from './playwrightTest';
24-
import type { Location, TestError } from './reporter';
23+
import type { Location, TestError, Entry } from './oopReporter';
2524
import { ReusedBrowser } from './reusedBrowser';
2625
import { SettingsModel } from './settingsModel';
2726
import { SettingsView } from './settingsView';

src/oopReporter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
import type { FullConfig, FullProject, FullResult, Location, Reporter, Suite, TestCase, TestError, TestResult, TestStatus, TestStep } from './reporter';
1818
import { ConnectionTransport, WebSocketTransport } from './transport';
1919

20+
export type { TestError, Location } from './reporter';
2021
export type EntryType = 'project' | 'file' | 'suite' | 'test';
22+
2123
export type Entry = {
2224
type: EntryType;
2325
title: string;
@@ -60,8 +62,6 @@ export type StepEndParams = {
6062
};
6163

6264
class OopReporter implements Reporter {
63-
config!: FullConfig;
64-
suite!: Suite;
6565
private _transport: Promise<ConnectionTransport>;
6666

6767
constructor() {

src/playwrightTest.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ import { spawn } from 'child_process';
1818
import path from 'path';
1919
import { debugSessionName } from './debugSessionName';
2020
import { ConfigListFilesReport } from './listTests';
21-
import { Entry, StepBeginParams, StepEndParams, TestBeginParams, TestEndParams } from './oopReporter';
22-
import type { TestError } from './reporter';
21+
import type { TestError, Entry, StepBeginParams, StepEndParams, TestBeginParams, TestEndParams } from './oopReporter';
2322
import { ReporterServer } from './reporterServer';
2423
import { ReusedBrowser } from './reusedBrowser';
2524
import { findNode, spawnAsync } from './utils';
@@ -152,7 +151,7 @@ export class PlaywrightTest {
152151
private async _test(config: TestConfig, locations: string[], args: string[], listener: TestListener, mode: 'list' | 'run', token: vscodeTypes.CancellationToken): Promise<void> {
153152
// Playwright will restart itself as child process in the ESM mode and won't inherit the 3/4 pipes.
154153
// Always use ws transport to mitigate it.
155-
const reporterServer = new ReporterServer();
154+
const reporterServer = new ReporterServer(this._vscode);
156155
const node = await findNode();
157156
if (token?.isCancellationRequested)
158157
return;
@@ -230,7 +229,7 @@ export class PlaywrightTest {
230229
this._log(`${escapeRegex(path.relative(config.workspaceFolder, configFolder))}> debug -c ${configFile}${relativeLocations.length ? ' ' + relativeLocations.join(' ') : ''}`);
231230
}
232231

233-
const reporterServer = new ReporterServer();
232+
const reporterServer = new ReporterServer(this._vscode);
234233
await this._reusedBrowser.willRunTests(config, true);
235234
try {
236235
await vscode.debug.startDebugging(undefined, {

src/reporterServer.ts

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@ import { TestListener } from './playwrightTest';
2020
import { ConnectionTransport } from './transport';
2121
import { createGuid } from './utils';
2222
import * as vscodeTypes from './vscodeTypes';
23+
import type { Location, TestError, Entry, StepBeginParams, StepEndParams, TestBeginParams, TestEndParams } from './oopReporter';
2324

2425
export class ReporterServer {
2526
private _clientSocketPromise: Promise<WebSocket>;
2627
private _clientSocketCallback!: (socket: WebSocket) => void;
2728
private _wsServer: WebSocketServer | undefined;
29+
private _vscode: vscodeTypes.VSCode;
2830

29-
constructor() {
31+
constructor(vscode: vscodeTypes.VSCode) {
32+
this._vscode = vscode;
3033
this._clientSocketPromise = new Promise(f => this._clientSocketCallback = f);
3134
}
3235

@@ -86,12 +89,16 @@ export class ReporterServer {
8689
if (token.isCancellationRequested && message.method !== 'onEnd')
8790
return;
8891
switch (message.method) {
89-
case 'onBegin': listener.onBegin?.(message.params); break;
90-
case 'onTestBegin': listener.onTestBegin?.(message.params); break;
91-
case 'onTestEnd': listener.onTestEnd?.(message.params); break;
92-
case 'onStepBegin': listener.onStepBegin?.(message.params); break;
93-
case 'onStepEnd': listener.onStepEnd?.(message.params); break;
94-
case 'onError': listener.onError?.(message.params); break;
92+
case 'onBegin': {
93+
(message.params as { projects: Entry[] }).projects.forEach((e: Entry) => patchLocation(this._vscode, e));
94+
listener.onBegin?.(message.params);
95+
break;
96+
}
97+
case 'onTestBegin': listener.onTestBegin?.(patchLocation(this._vscode, message.params as TestBeginParams)); break;
98+
case 'onTestEnd': listener.onTestEnd?.(patchLocation(this._vscode, message.params as TestEndParams)); break;
99+
case 'onStepBegin': listener.onStepBegin?.(patchLocation(this._vscode, message.params as StepBeginParams)); break;
100+
case 'onStepEnd': listener.onStepEnd?.(patchLocation(this._vscode, message.params as StepEndParams)); break;
101+
case 'onError': listener.onError?.(patchLocation(this._vscode, message.params as { error: TestError })); break;
95102
case 'onEnd': {
96103
listener.onEnd?.();
97104
transport.close();
@@ -136,5 +143,20 @@ export class ReporterServer {
136143
});
137144
return transport;
138145
}
146+
}
139147

148+
function patchLocation<T extends { location?: Location, error?: TestError, errors?: TestError[] }>(vscode: vscodeTypes.VSCode, object: T): T {
149+
// Normalize all the location.file values using the Uri.file().fsPath normalization.
150+
// vscode will normalize Windows drive letter, etc.
151+
if (object.location)
152+
object.location.file = vscode.Uri.file(object.location.file).fsPath;
153+
if (object.error?.location)
154+
object.error.location.file = vscode.Uri.file(object.error.location.file).fsPath;
155+
if (object.errors) {
156+
object.errors.forEach(e => {
157+
if (e.location)
158+
e.location.file = vscode.Uri.file(e.location.file).fsPath;
159+
});
160+
}
161+
return object;
140162
}

src/testModel.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { Entry } from './oopReporter';
17+
import { Entry, TestError } from './oopReporter';
1818
import { PlaywrightTest, TestConfig, TestListener } from './playwrightTest';
1919
import { WorkspaceChange } from './workspaceObserver';
2020
import * as vscodeTypes from './vscodeTypes';
2121
import { resolveSourceMap } from './utils';
2222
import { ProjectConfigWithFiles } from './listTests';
23-
import { TestError } from './reporter';
2423

2524
/**
2625
* This class builds the Playwright Test model in Playwright terms.

src/testTree.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717
import path from 'path';
1818
import { MultiMap } from './multimap';
19-
import { Entry, EntryType } from './oopReporter';
20-
import { Location } from './reporter';
19+
import type { Location, Entry, EntryType } from './oopReporter';
2120
import { TestModel, TestProject } from './testModel';
2221
import { createGuid } from './utils';
2322
import * as vscodeTypes from './vscodeTypes';

0 commit comments

Comments
 (0)