Skip to content

Commit

Permalink
Ensure test debug client routes service extension events
Browse files Browse the repository at this point in the history
  • Loading branch information
DanTup committed Apr 8, 2019
1 parent aadc4ca commit e1d5245
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/commands/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class DebugCommands {
public readonly onReceiveCoverage: vs.Event<CoverageData[]> = this.onReceiveCoverageEmitter.event;
private onFirstFrameEmitter: vs.EventEmitter<CoverageData[]> = new vs.EventEmitter<CoverageData[]>();
public readonly onFirstFrame: vs.Event<CoverageData[]> = this.onFirstFrameEmitter.event;
private readonly flutterExtensions: FlutterVmServiceExtensions;
public readonly flutterExtensions: FlutterVmServiceExtensions;
private readonly devTools: DevTools;

constructor(private readonly context: Context, private readonly workspaceContext: WorkspaceContext, private readonly analytics: Analytics, pubGlobal: PubGlobal) {
Expand Down
6 changes: 4 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ export function activate(context: vs.ExtensionContext, isRestart: boolean = fals
const analyzerCommands = new AnalyzerCommands(context, analyzer);
const pubGlobal = new PubGlobal(extContext, sdks);
const sdkCommands = new SdkCommands(context, workspaceContext, pubGlobal, flutterCapabilities, flutterDaemon && flutterDaemon.deviceManager);
const debug = new DebugCommands(extContext, workspaceContext, analytics, pubGlobal);
const debugCommands = new DebugCommands(extContext, workspaceContext, analytics, pubGlobal);

// Register URI handler.
context.subscriptions.push(vs.window.registerUriHandler(new DartUriHandler(flutterCapabilities)));
Expand Down Expand Up @@ -382,7 +382,7 @@ export function activate(context: vs.ExtensionContext, isRestart: boolean = fals
);

if (workspaceContext.hasAnyFlutterProjects && config.previewHotReloadCoverageMarkers) {
context.subscriptions.push(new HotReloadCoverageDecorations(debug));
context.subscriptions.push(new HotReloadCoverageDecorations(debugCommands));
}

context.subscriptions.push(vs.commands.registerCommand("dart.package.openFile", (filePath) => {
Expand Down Expand Up @@ -457,6 +457,7 @@ export function activate(context: vs.ExtensionContext, isRestart: boolean = fals
currentAnalysis: () => analyzer.currentAnalysis,
daemonCapabilities: flutterDaemon ? flutterDaemon.capabilities : DaemonCapabilities.empty,
dartCapabilities,
debugCommands,
debugProvider,
flutterCapabilities,
initialAnalysis,
Expand Down Expand Up @@ -612,6 +613,7 @@ export interface InternalExtensionApi {
currentAnalysis: () => Promise<void>;
daemonCapabilities: DaemonCapabilities;
dartCapabilities: DartCapabilities;
debugCommands: DebugCommands;
debugProvider: DebugConfigProvider;
flutterCapabilities: FlutterCapabilities;
initialAnalysis: Promise<void>;
Expand Down
14 changes: 11 additions & 3 deletions test/dart_debug_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as assert from "assert";
import { SpawnOptions } from "child_process";
import { DebugSessionCustomEvent } from "vscode";
import { DebugProtocol } from "vscode-debugprotocol";
import { debugSessions } from "../src/commands/debug";
import { DebugCommands, debugSessions } from "../src/commands/debug";
import { not } from "../src/utils/array";
import { isKnownInfrastructureThread } from "../src/utils/debugger";
import { handleDebugLogEvent, log } from "../src/utils/log";
Expand All @@ -14,10 +14,18 @@ import { delay, watchPromise, withTimeout } from "./helpers";

export class DartDebugClient extends DebugClient {
private readonly id: string;
constructor(runtime: string, executable: string, debugType: string, spawnOptions?: SpawnOptions, testProvider?: TestResultsProvider) {
constructor(runtime: string, executable: string, debugType: string, spawnOptions: SpawnOptions, debugCommands: DebugCommands, testProvider: TestResultsProvider) {
super(runtime, executable, debugType, spawnOptions);
this.on("dart.log", (e: DebugSessionCustomEvent) => handleDebugLogEvent(e.event, e.body));
// TODO: Make it so we don't have to keep copying logic from debug.ts into here...
this.on("dart.serviceExtensionAdded", (e: DebugSessionCustomEvent) => {
const fakeEvent: DebugSessionCustomEvent = {
body: e.body,
event: e.event,
session: debugSessions[0].session,
};
debugCommands.flutterExtensions.handleDebugEvent(fakeEvent);
});
this.on("dart.debuggerUris", (e: DebugSessionCustomEvent) => {
debugSessions[0].observatoryUri = e.body.observatoryUri;
debugSessions[0].vmServiceUri = e.body.vmServiceUri;
Expand Down Expand Up @@ -56,7 +64,7 @@ export class DartDebugClient extends DebugClient {
request: "launch",
type: "dart",
},
customRequest: this.customRequest,
customRequest: (e) => this.customRequest(e),
id: "INTEGRATION-TEST",
name: "Dart & Flutter",
type: "dart",
Expand Down
2 changes: 1 addition & 1 deletion test/dart_only/debug/dart_cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe("dart cli debugger", () => {

let dc: DartDebugClient;
beforeEach("create debug client", () => {
dc = new DartDebugClient(process.execPath, path.join(ext.extensionPath, "out/src/debug/dart_debug_entry.js"), "dart");
dc = new DartDebugClient(process.execPath, path.join(ext.extensionPath, "out/src/debug/dart_debug_entry.js"), "dart", undefined, extApi.debugCommands, undefined);
dc.defaultTimeout = 60000;
const thisDc = dc;
defer(() => thisDc.stop());
Expand Down
1 change: 1 addition & 0 deletions test/dart_only/debug/dart_test.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe("dart test debugger", () => {
path.join(ext.extensionPath, "out/src/debug/dart_test_debug_entry.js"),
"dart",
undefined,
extApi.debugCommands,
extApi.testTreeProvider,
);
dc.defaultTimeout = 60000;
Expand Down
2 changes: 1 addition & 1 deletion test/flutter_only/debug/flutter_run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe("flutter run debugger (launch)", () => {

let dc: DartDebugClient;
beforeEach("create debug client", () => {
dc = new DartDebugClient(process.execPath, path.join(ext.extensionPath, "out/src/debug/flutter_debug_entry.js"), "dart");
dc = new DartDebugClient(process.execPath, path.join(ext.extensionPath, "out/src/debug/flutter_debug_entry.js"), "dart", undefined, extApi.debugCommands, undefined);
dc.defaultTimeout = 60000;
const thisDc = dc;
defer(() => thisDc.stop());
Expand Down
2 changes: 1 addition & 1 deletion test/flutter_only/debug/flutter_run_attach.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe("flutter run debugger (attach)", () => {

let dc: DartDebugClient;
beforeEach("create debug client", () => {
dc = new DartDebugClient(process.execPath, path.join(ext.extensionPath, "out/src/debug/flutter_debug_entry.js"), "dart");
dc = new DartDebugClient(process.execPath, path.join(ext.extensionPath, "out/src/debug/flutter_debug_entry.js"), "dart", undefined, extApi.debugCommands, undefined);
dc.defaultTimeout = 60000;
defer(() => dc.stop());
});
Expand Down
1 change: 1 addition & 0 deletions test/flutter_only/debug/flutter_test.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ describe("flutter test debugger", () => {
path.join(ext.extensionPath, "out/src/debug/flutter_test_debug_entry.js"),
"dart",
undefined,
extApi.debugCommands,
extApi.testTreeProvider,
);
dc.defaultTimeout = 60000;
Expand Down

0 comments on commit e1d5245

Please sign in to comment.