Skip to content

Commit

Permalink
Handle fast running of tests when noDebug and whole folder
Browse files Browse the repository at this point in the history
Fixes #3595.
  • Loading branch information
DanTup committed Oct 6, 2021
1 parent ae973ee commit 6055d8d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
19 changes: 14 additions & 5 deletions src/extension/test/vs_test_controller.ts
Expand Up @@ -16,15 +16,13 @@ export class VsCodeTestController implements TestEventListener, IAmDisposable {
private nodeForItem = new WeakMap<vs.TestItem, TreeNode>();
private testRuns: { [key: string]: vs.TestRun | undefined } = {};

public registerTestRun(dartCodeDebugSessionId: string, run: vs.TestRun): void {
this.testRuns[dartCodeDebugSessionId] = run;
}

constructor(private readonly logger: Logger, private readonly model: TestModel) {
const controller = vs.tests.createTestController("dart", "Dart & Flutter");
this.controller = controller;
this.disposables.push(controller);
this.disposables.push(model.onDidChangeTreeData.listen((node) => this.onDidChangeTreeData(node)));
this.disposables.push(vs.debug.onDidTerminateDebugSession((e) => this.handleDebugSessionEnd(e)));
model.addTestEventListener(this);

controller.createRunProfile("Run", vs.TestRunProfileKind.Run, (request, token) => {
Expand All @@ -36,11 +34,24 @@ export class VsCodeTestController implements TestEventListener, IAmDisposable {
});
}

public registerTestRun(dartCodeDebugSessionID: string, run: vs.TestRun): void {
this.testRuns[dartCodeDebugSessionID] = run;
}

private handleDebugSessionEnd(e: vs.DebugSession): any {
this.testRuns[e.configuration.dartCodeDebugSessionID]?.end();
}

public getLatestData(test: vs.TestItem): TreeNode | undefined {
return this.nodeForItem.get(test);
}

private async runTests(debug: boolean, request: vs.TestRunRequest, token: vs.CancellationToken): Promise<void> {
// As an optimiations, if we're no-debug and running all tests, we can use our command that will run
// the test folders directly.
if (!debug && !request.include?.length && !request.exclude?.length)
return vs.commands.executeCommand("dart.runAllTestsWithoutDebugging");

const run = this.controller.createTestRun(request);
const testsToRun = new Set<vs.TestItem>();
(request.include ?? this.controller.items).forEach((item) => testsToRun.add(item));
Expand Down Expand Up @@ -289,8 +300,6 @@ export class VsCodeTestController implements TestEventListener, IAmDisposable {
}

public suiteDone(sessionID: string, node: SuiteNode): void {
const run = this.getOrCreateTestRun(sessionID);
run.end();
}

public dispose(): any {
Expand Down
2 changes: 1 addition & 1 deletion src/extension/utils.ts
Expand Up @@ -187,7 +187,7 @@ export function hasTestNameFilter(...argss: Array<string[] | undefined>) {
export function ensureDebugLaunchUniqueId(config: BasicDebugConfiguration): string {
const conf = config as any;
if (!conf.dartCodeDebugSessionID) {
const dartCodeDebugSessionID = `session-${getRandomInt(0x1000, 0x10000).toString(16)}`;
const dartCodeDebugSessionID = `session-${getRandomInt(0x10000, 0x100000).toString(16)}`;
conf.dartCodeDebugSessionID = dartCodeDebugSessionID;
}
return conf.dartCodeDebugSessionID;
Expand Down

0 comments on commit 6055d8d

Please sign in to comment.