Skip to content

Commit 1416b2a

Browse files
authored
chore: revert "feat: pause at test end or error when debugging" (#719) (#770)
1 parent 157a57a commit 1416b2a

4 files changed

Lines changed: 25 additions & 336 deletions

File tree

src/extension.ts

Lines changed: 7 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import { ansi2html } from './ansi2html';
3333
import { LocatorsView } from './locatorsView';
3434
import { pathToFileURL } from 'url';
3535
import { TestConfig } from './playwrightTestServer';
36-
import { findTestEndPosition } from './babelHighlightUtil';
3736

3837
const stackUtils = new StackUtils({
3938
cwd: '/ensure_absolute_paths'
@@ -60,20 +59,14 @@ export class Extension implements RunHooks {
6059

6160
private _testController: vscodeTypes.TestController;
6261
private _workspaceObserver: WorkspaceObserver;
63-
private _testUnderDebug: {
64-
testItem: vscodeTypes.TestItem | undefined;
65-
testCase: reporterTypes.TestCase;
66-
disposables: vscodeTypes.Disposable[];
67-
} | undefined;
62+
private _testItemUnderDebug: vscodeTypes.TestItem | undefined;
6863
private _lastBeganTest?: reporterTypes.TestCase;
6964
private _activeSteps = new Map<reporterTypes.TestStep, StepInfo>();
7065
private _completedSteps = new Map<reporterTypes.TestStep, StepInfo>();
7166
private _testRun: vscodeTypes.TestRun | undefined;
7267
private _models: TestModelCollection;
7368
private _activeStepDecorationType: vscodeTypes.TextEditorDecorationType;
7469
private _completedStepDecorationType: vscodeTypes.TextEditorDecorationType;
75-
private _pausedOnErrorDecorationType: vscodeTypes.TextEditorDecorationType;
76-
private _pausedAtEndDecorationType: vscodeTypes.TextEditorDecorationType;
7770
private _debugHighlight: DebugHighlight;
7871
private _isUnderTest: boolean;
7972
private _reusedBrowser: ReusedBrowser;
@@ -115,21 +108,6 @@ export class Extension implements RunHooks {
115108
},
116109
});
117110

118-
this._pausedAtEndDecorationType = this._vscode.window.createTextEditorDecorationType({
119-
isWholeLine: true,
120-
backgroundColor: { id: 'editor.wordHighlightStrongBackground' },
121-
borderColor: { id: 'editor.wordHighlightStrongBorder' },
122-
after: {
123-
color: { id: 'editorCodeLens.foreground' },
124-
contentText: ' \u2014 paused\u2026',
125-
},
126-
});
127-
this._pausedOnErrorDecorationType = this._vscode.window.createTextEditorDecorationType({
128-
isWholeLine: true,
129-
backgroundColor: { id: 'editor.wordHighlightStrongBackground' },
130-
borderColor: { id: 'editor.wordHighlightStrongBorder' },
131-
});
132-
133111
this._logger = this._vscode.window.createOutputChannel('Playwright', { log: true });
134112
this._settingsModel = new SettingsModel(vscode, context);
135113
this._reusedBrowser = new ReusedBrowser(this._vscode, this._logger, this._settingsModel, this._envProvider.bind(this));
@@ -142,7 +120,6 @@ export class Extension implements RunHooks {
142120
envProvider: this._envProvider.bind(this),
143121
onStdOut: this._debugHighlight.onStdOut.bind(this._debugHighlight),
144122
requestWatchRun: this._runWatchedTests.bind(this),
145-
testPausedHandler: this._onTestPaused.bind(this),
146123
logger: this._logger,
147124
});
148125
this._testController = vscode.tests.createTestController('playwright', 'Playwright');
@@ -240,7 +217,7 @@ export class Extension implements RunHooks {
240217
const model = this._models.selectedModel();
241218
if (!model)
242219
return vscode.window.showWarningMessage(messageNoPlaywrightTestsFound);
243-
const openTestCase = this._testUnderDebug?.testCase ?? (this._settingsModel.showBrowser.get() ? this._lastBeganTest : undefined);
220+
const openTestCase = this._settingsModel.showBrowser.get() ? this._lastBeganTest : undefined;
244221
const project = openTestCase ? ancestorProject(openTestCase) : model.enabledProjects()[0]?.project;
245222
await this._reusedBrowser.record(model, project);
246223
}),
@@ -649,20 +626,15 @@ export class Extension implements RunHooks {
649626
this._showTraceOnTestProgress(testItem);
650627
if (mode === 'debug') {
651628
// Debugging is always single-workers.
652-
this._cleanupItemUnderDebug();
653-
this._testUnderDebug = {
654-
testItem,
655-
testCase: test,
656-
disposables: [],
657-
};
629+
this._testItemUnderDebug = testItem;
658630
}
659631
},
660632

661633
onTestEnd: (test: reporterTypes.TestCase, result: reporterTypes.TestResult) => {
662634
if (result.errors.find(e => e.message?.includes(`Error: browserType.launch: Executable doesn't exist`)))
663635
browserDoesNotExist = true;
664636

665-
this._cleanupItemUnderDebug();
637+
this._testItemUnderDebug = undefined;
666638
this._activeSteps.clear();
667639
this._executionLinesChanged();
668640

@@ -725,7 +697,6 @@ export class Extension implements RunHooks {
725697

726698
if (mode === 'debug') {
727699
await model.debugTests(request, testListener, testRun.token);
728-
this._cleanupItemUnderDebug();
729700
} else {
730701
// Force trace viewer update to surface check version errors.
731702
await this._models.selectedModel()?.updateTraceViewer(mode === 'run')?.willRunTests();
@@ -890,44 +861,12 @@ test('test', async ({ page }) => {
890861
}
891862

892863
private _errorInDebugger(errorStack: string, location: reporterTypes.Location) {
893-
if (!this._testRun || !this._testUnderDebug?.testItem)
864+
if (!this._testRun || !this._testItemUnderDebug)
894865
return;
895866
const testMessage = this._testMessageFromText(errorStack);
896867
testMessage.location = this._asLocation(location);
897-
this._testRun.failed(this._testUnderDebug.testItem, testMessage);
898-
this._cleanupItemUnderDebug();
899-
}
900-
901-
private _cleanupItemUnderDebug() {
902-
for (const disposable of this._testUnderDebug?.disposables || [])
903-
disposable.dispose();
904-
this._testUnderDebug = undefined;
905-
}
906-
907-
private async _onTestPaused(params: { errors: reporterTypes.TestError[] }) {
908-
if (!this._testUnderDebug)
909-
return;
910-
const errors = params.errors.filter(e => !!e.message);
911-
if (!errors.length) {
912-
const location = this._testUnderDebug.testCase.location;
913-
const document = await this._vscode.workspace.openTextDocument(location.file);
914-
const testEndPosition = findTestEndPosition(document.getText(), uriToPath(document.uri), location) ?? location;
915-
const range = this._asRange(testEndPosition);
916-
const editor = await this._vscode.window.showTextDocument(document, { selection: range });
917-
editor.setDecorations(this._pausedAtEndDecorationType, [{ range }]);
918-
this._testUnderDebug.disposables.push({ dispose: () => editor.setDecorations(this._pausedAtEndDecorationType, []) });
919-
} else {
920-
if (this._testRun && this._testUnderDebug.testItem)
921-
this._testRun.failed(this._testUnderDebug.testItem, errors.map(error => this._testMessageForTestError(error)));
922-
const error = errors.find(e => e.location);
923-
if (error?.location) {
924-
const range = this._asRange(error.location);
925-
const document = await this._vscode.workspace.openTextDocument(error.location.file);
926-
const editor = await this._vscode.window.showTextDocument(document, { selection: range });
927-
editor.setDecorations(this._pausedOnErrorDecorationType, [{ range }]);
928-
this._testUnderDebug.disposables.push({ dispose: () => editor.setDecorations(this._pausedOnErrorDecorationType, []) });
929-
}
930-
}
868+
this._testRun.failed(this._testItemUnderDebug, testMessage);
869+
this._testItemUnderDebug = undefined;
931870
}
932871

933872
private _executionLinesChanged() {

src/playwrightTestServer.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ export type PlaywrightTestOptions = {
5151
isUnderTest: boolean;
5252
envProvider: (configFile: string) => NodeJS.ProcessEnv;
5353
onStdOut: vscodeTypes.Event<string>;
54-
testPausedHandler: (params: { errors: reporterTypes.TestError[] }) => void;
5554
logger: vscodeTypes.LogOutputChannel;
5655
};
5756

@@ -298,7 +297,6 @@ export class PlaywrightTestServer {
298297
token = debugEnd.token;
299298

300299
const paths = this._normalizePaths();
301-
const kMinTestPausedVersion = 1.58;
302300

303301
await this._vscode.debug.startDebugging(undefined, {
304302
type: 'pwa-node',
@@ -314,8 +312,8 @@ export class PlaywrightTestServer {
314312
// Reset VSCode's options that affect nested Electron.
315313
ELECTRON_RUN_AS_NODE: undefined,
316314
FORCE_COLOR: '1',
317-
PW_TEST_SOURCE_TRANSFORM: this._model.config.version < kMinTestPausedVersion ? require.resolve('./debugTransform') : undefined,
318-
PW_TEST_SOURCE_TRANSFORM_SCOPE: this._model.config.version < kMinTestPausedVersion ? testDirs.join(pathSeparator) : undefined,
315+
PW_TEST_SOURCE_TRANSFORM: require.resolve('./debugTransform'),
316+
PW_TEST_SOURCE_TRANSFORM_SCOPE: testDirs.join(pathSeparator),
319317
PWDEBUG: 'console',
320318
},
321319
program: paths.cli,
@@ -333,7 +331,7 @@ export class PlaywrightTestServer {
333331
if (token?.isCancellationRequested)
334332
return;
335333

336-
const { locations, testIds, isSingleTest } = this._model.narrowDownLocations(request);
334+
const { locations, testIds } = this._model.narrowDownLocations(request);
337335
if (!locations && !testIds)
338336
return;
339337

@@ -350,15 +348,12 @@ export class PlaywrightTestServer {
350348
locations: locationPatterns,
351349
testIds,
352350
timeout: 0,
353-
pauseAtEnd: isSingleTest,
354-
pauseOnError: true,
355351
...runOptions,
356352
};
357353

358354
disposables.push(token.onCancellationRequested(() => {
359355
debugTestServer!.stopTestsNoReply({});
360356
}));
361-
disposables.push(debugTestServer.onTestPaused(params => this._options.testPausedHandler(params)));
362357
this._wireTestServer(debugTestServer, reporter, token, disposables);
363358
try {
364359
await debugTestServer.runTests(options);

src/testModel.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ export type TestModelEmbedder = {
5555
envProvider: (configFile: string) => NodeJS.ProcessEnv;
5656
onStdOut: vscodeTypes.Event<string>;
5757
requestWatchRun: (files: string[], testItems: vscodeTypes.TestItem[]) => void;
58-
testPausedHandler: (params: { errors: reporterTypes.TestError[] }) => any;
5958
logger: vscodeTypes.LogOutputChannel;
6059
};
6160

0 commit comments

Comments
 (0)