Skip to content

Commit 3470dcc

Browse files
committed
Improve Test CodeLens tests to ensure debug session runs
See #3108.
1 parent 0d30b1a commit 3470dcc

2 files changed

Lines changed: 36 additions & 4 deletions

File tree

‎src/test/dart_debug/debug/dart_test.test.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { LspTestOutlineInfo, LspTestOutlineVisitor } from "../../../shared/utils
88
import * as testUtils from "../../../shared/utils/test";
99
import { DartDebugClient } from "../../dart_debug_client";
1010
import { createDebugClient, waitAllThrowIfTerminates } from "../../debug_helpers";
11-
import { activate, delay, extApi, getCodeLens, getExpectedResults, getLaunchConfiguration, getPackages, getResolvedDebugConfiguration, helloWorldTestBrokenFile, helloWorldTestDupeNameFile, helloWorldTestMainFile, helloWorldTestShortFile, helloWorldTestSkipFile, helloWorldTestTreeFile, logger, makeTextTree, openFile, positionOf, setConfigForTest, waitForResult } from "../../helpers";
11+
import { activate, captureDebugSessionCustomEvents, delay, extApi, getCodeLens, getExpectedResults, getLaunchConfiguration, getPackages, getResolvedDebugConfiguration, helloWorldTestBrokenFile, helloWorldTestDupeNameFile, helloWorldTestMainFile, helloWorldTestShortFile, helloWorldTestSkipFile, helloWorldTestTreeFile, logger, makeTextTree, openFile, positionOf, setConfigForTest, waitForResult } from "../../helpers";
1212

1313
describe("dart test debugger", () => {
1414
// We have tests that require external packages.
@@ -69,8 +69,13 @@ describe("dart test debugger", () => {
6969
assert.equal(runAction.command!.arguments![0].fullName, "String .split() splits the string on the delimiter");
7070
assert.equal(runAction.command!.arguments![0].isGroup, false);
7171

72-
const didStart = await vs.commands.executeCommand(runAction.command!.command, ...(runAction.command!.arguments ?? []));
73-
assert.ok(didStart);
72+
const customEvents = await captureDebugSessionCustomEvents(async () => {
73+
const didStart = await vs.commands.executeCommand(runAction.command!.command, ...(runAction.command!.arguments ?? []));
74+
assert.ok(didStart);
75+
});
76+
// Ensure we got at least a "testDone" notification so we know the test run started correctly.
77+
const testDoneNotification = customEvents.find((e) => e.event === "dart.testRunNotification" && e.body.notification.type === "testDone");
78+
assert.ok(testDoneNotification, JSON.stringify(customEvents.map((e) => e.body), undefined, 4));
7479
});
7580

7681
it("receives the expected events from a Dart test script", async () => {

‎src/test/helpers.ts‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as sinon from "sinon";
66
import * as vs from "vscode";
77
import { dartCodeExtensionIdentifier, DART_TEST_SUITE_NODE_CONTEXT } from "../shared/constants";
88
import { LogCategory } from "../shared/enums";
9-
import { Logger } from "../shared/interfaces";
9+
import { IAmDisposable, Logger } from "../shared/interfaces";
1010
import { captureLogs } from "../shared/logging";
1111
import { internalApiSymbol } from "../shared/symbols";
1212
import { TreeNode } from "../shared/test/test_model";
@@ -909,6 +909,33 @@ export function deleteFileIfExists(filePath: string) {
909909
}
910910
}
911911

912+
export async function captureDebugSessionCustomEvents(startDebug: () => void): Promise<vs.DebugSessionCustomEvent[]> {
913+
let session: vs.DebugSession;
914+
let startSub: IAmDisposable;
915+
let endSub: IAmDisposable;
916+
const events: vs.DebugSessionCustomEvent[] = [];
917+
918+
const startPromise = new Promise<void>((resolve) => {
919+
startSub = vs.debug.onDidStartDebugSession((s) => {
920+
session = s;
921+
resolve();
922+
});
923+
}).finally(() => startSub.dispose());
924+
const eventSub = vs.debug.onDidReceiveDebugSessionCustomEvent((e) => events.push(e));
925+
const endPromise = new Promise<void>((resolve) => {
926+
endSub = vs.debug.onDidTerminateDebugSession((s) => {
927+
if (s === session)
928+
resolve();
929+
});
930+
}).finally(() => endSub.dispose());
931+
932+
startDebug();
933+
await Promise.all([startPromise, endPromise]);
934+
eventSub.dispose();
935+
936+
return events;
937+
}
938+
912939
export function prepareHasRunFile(name: string) {
913940
const hasRunFile = path.join(fsPath(flutterBazelRoot), `scripts/has_run/${name}`);
914941
deleteFileIfExists(hasRunFile);

0 commit comments

Comments
 (0)