Skip to content

Commit 5d10d7f

Browse files
committed
Flutter can run multiple suites just not with debugger
1 parent 0d3baee commit 5d10d7f

3 files changed

Lines changed: 18 additions & 42 deletions

File tree

‎src/commands/debug.ts‎

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import * as fs from "fs";
2-
import * as glob from "glob";
3-
import * as _ from "lodash";
42
import * as path from "path";
53
import * as vs from "vscode";
64
import { Analytics } from "../analytics";
75
import { PromiseCompleter } from "../debug/utils";
86
import { SERVICE_EXTENSION_CONTEXT_PREFIX } from "../extension";
9-
import { fsPath, getDartWorkspaceFolders, isFlutterProjectFolder, openInBrowser } from "../utils";
7+
import { fsPath, getDartWorkspaceFolders, openInBrowser } from "../utils";
108
import { handleDebugLogEvent } from "../utils/log";
119
import { TestResultsProvider } from "../views/test_view";
1210

@@ -184,30 +182,15 @@ export class DebugCommands {
184182
.map((project) => path.join(fsPath(project.uri), "test"))
185183
.filter((testFolder) => fs.existsSync(testFolder));
186184
for (const folder of testFolders) {
187-
// Flutter doesn't support running whole folder, so we
188-
// have to run each file individually.
189-
// TODO: Do we need to limit this? Spawning 1,000 debug sessions would
190-
// be crazy.
191-
const testSuites = isFlutterProjectFolder(folder)
192-
? _.flatMap(testFolders, (folder) => glob.sync("**/*_test.dart", {
193-
absolute: true, cwd: folder, nodir: true, nonull: false, nosort: true,
194-
}))
195-
: [undefined];
196-
testSuites.forEach((suite) => {
197-
const ws = vs.workspace.getWorkspaceFolder(vs.Uri.file(folder));
198-
const name = suite
199-
? path.relative(fsPath(ws.uri), suite)
200-
: path.basename(folder); // TODO: Should this be parent + " tests"?
201-
const runner = suite ? undefined : "pubTest";
202-
vs.debug.startDebugging(ws, {
203-
cwd: path.dirname(folder),
204-
name: `Dart ${path.basename(folder)}`,
205-
noDebug: true,
206-
program: suite,
207-
request: "launch",
208-
runner,
209-
type: "dart",
210-
});
185+
const ws = vs.workspace.getWorkspaceFolder(vs.Uri.file(folder));
186+
const name = path.basename(path.dirname(folder)); // TODO: Should this be parent + " tests"?
187+
vs.debug.startDebugging(ws, {
188+
cwd: path.dirname(folder),
189+
name: `Dart ${name}`,
190+
noDebug: true,
191+
request: "launch",
192+
runner: "tests",
193+
type: "dart",
211194
});
212195
}
213196
}));

‎src/debug/flutter_test_debug_impl.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ export class FlutterTestDebugSession extends DartTestDebugSession {
1717
}
1818

1919
// TODO: Validate that args.program is always absolute (we use it as a key for notifications).
20-
appArgs.push(this.sourceFileForArgs(args));
20+
if (args.program)
21+
appArgs.push(this.sourceFileForArgs(args));
2122

2223
const logger = (message: string) => this.sendEvent(new Event("dart.log.flutter.test", { message }));
2324
return this.createRunner(args.flutterPath, args.cwd, args.program, globalFlutterArgs.concat(["test", "--machine"]).concat(appArgs), args.flutterTestLogFile, logger);

‎src/providers/debug_config_provider.ts‎

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ export class DebugConfigProvider implements DebugConfigurationProvider {
4040

4141
public async resolveDebugConfiguration(folder: WorkspaceFolder | undefined, debugConfig: DebugConfiguration, token?: CancellationToken): Promise<DebugConfiguration> {
4242
const openFile = window.activeTextEditor && window.activeTextEditor.document ? fsPath(window.activeTextEditor.document.uri) : null;
43-
const allowProgramlessRun = debugConfig && debugConfig.runner === "pubTest";
43+
const isFullTestRun = debugConfig && debugConfig.runner === "tests"; // TODO: Allow pubTest and flutterTest explicitly.
44+
const allowProgramlessRun = isFullTestRun;
4445

4546
// VS Code often gives us a bogus folder, so only trust it if we got a real debugConfig (eg. with program or cwd).
4647
// Otherwise, take from open file if we have one, else blank it (unless we only have one open folder, then use that).
@@ -110,20 +111,11 @@ export class DebugConfigProvider implements DebugConfigurationProvider {
110111
// Disable Flutter mode for attach.
111112
// TODO: Update FlutterDebugSession to understand attach mode, and remove this limitation.
112113
const isFlutter = debugConfig.cwd && isFlutterProjectFolder(debugConfig.cwd as string) && !isAttachRequest;
113-
const isTest = debugConfig.program && isTestFile(debugConfig.program as string);
114+
const isTest = isFullTestRun || (debugConfig.program && isTestFile(debugConfig.program as string));
114115
const canPubRunTest = isTest && supportsPubRunTest(debugConfig.cwd as string, debugConfig.program as string);
115-
// TODO: Make this better (and official)..
116-
const debugRunners: { [key: string]: DebuggerType } = {
117-
dart: DebuggerType.Dart,
118-
flutter: DebuggerType.Flutter,
119-
flutterTest: DebuggerType.FlutterTest,
120-
pubTest: DebuggerType.PubTest,
121-
};
122-
const debugType = debugConfig.runner && debugRunners[debugConfig.runner]
123-
? debugRunners[debugConfig.runner]
124-
: isFlutter
125-
? (isTest ? DebuggerType.FlutterTest : DebuggerType.Flutter)
126-
: (isTest && canPubRunTest ? DebuggerType.PubTest : DebuggerType.Dart);
116+
const debugType = isFlutter
117+
? (isTest ? DebuggerType.FlutterTest : DebuggerType.Flutter)
118+
: (isTest && canPubRunTest ? DebuggerType.PubTest : DebuggerType.Dart);
127119

128120
// Ensure we have a device
129121
const deviceId = this.deviceManager && this.deviceManager.currentDevice ? this.deviceManager.currentDevice.id : null;

0 commit comments

Comments
 (0)