Skip to content

Commit

Permalink
Don't pass all test filenames when running the whole set
Browse files Browse the repository at this point in the history
  • Loading branch information
DanTup committed Mar 3, 2022
1 parent efa647e commit fac8c20
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
19 changes: 13 additions & 6 deletions src/extension/commands/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { noAction } from "../../shared/constants";
import { TestStatus } from "../../shared/enums";
import { Logger } from "../../shared/interfaces";
import { GroupNode, SuiteData, SuiteNode, TestModel, TestNode, TreeNode } from "../../shared/test/test_model";
import { disposeAll, escapeDartString, generateTestNameFromFileName } from "../../shared/utils";
import { disposeAll, escapeDartString, generateTestNameFromFileName, uniq } from "../../shared/utils";
import { sortBy } from "../../shared/utils/array";
import { fsPath, isWithinPath, mkDirRecursive } from "../../shared/utils/fs";
import { TestOutlineInfo } from "../../shared/utils/outline_das";
Expand Down Expand Up @@ -34,7 +34,7 @@ export class TestCommands implements vs.Disposable {
vs.commands.registerCommand("_dart.startWithoutDebuggingTestFromOutline", (test: TestOutlineInfo, launchTemplate: any | undefined) => this.startTestFromOutline(true, test, launchTemplate)),
vs.commands.registerCommand("_dart.startDebuggingTestsFromVsTestController", (suiteData: SuiteData, treeNodes: Array<SuiteNode | GroupNode | TestNode>, suppressPromptOnErrors: boolean, testRun: vs.TestRun | undefined) => this.runTestsForNode(suiteData, this.getTestNamesForNodes(treeNodes), true, suppressPromptOnErrors, treeNodes.length === 1 && treeNodes[0] instanceof TestNode, undefined, testRun)),
vs.commands.registerCommand("_dart.startWithoutDebuggingTestsFromVsTestController", (suiteData: SuiteData, treeNodes: Array<SuiteNode | GroupNode | TestNode>, suppressPromptOnErrors: boolean, testRun: vs.TestRun | undefined) => this.runTestsForNode(suiteData, this.getTestNamesForNodes(treeNodes), false, suppressPromptOnErrors, treeNodes.length === 1 && treeNodes[0] instanceof TestNode, undefined, testRun)),
vs.commands.registerCommand("_dart.runAllTestsWithoutDebugging", (suites?: SuiteNode[], testRun?: vs.TestRun) => this.runAllTestsWithoutDebugging(suites, testRun)),
vs.commands.registerCommand("_dart.runAllTestsWithoutDebugging", (suites: SuiteNode[] | undefined, testRun: vs.TestRun | undefined, isRunningAll: boolean) => this.runAllTestsWithoutDebugging(suites, testRun, isRunningAll)),
vs.commands.registerCommand("dart.goToTests", (resource: vs.Uri | undefined) => this.goToTestOrImplementationFile(resource), this),
vs.commands.registerCommand("dart.goToTestOrImplementationFile", () => this.goToTestOrImplementationFile(), this),
vs.window.onDidChangeActiveTextEditor((e) => this.updateEditorContexts(e)),
Expand All @@ -44,7 +44,7 @@ export class TestCommands implements vs.Disposable {
this.updateEditorContexts(vs.window.activeTextEditor);
}

private async runAllTestsWithoutDebugging(suites?: SuiteNode[], testRun?: vs.TestRun): Promise<void> {
private async runAllTestsWithoutDebugging(suites: SuiteNode[] | undefined, testRun: vs.TestRun | undefined, isRunningAll: boolean): Promise<void> {
// To run multiple folders/suites, we can pass the first as `program` and the rest as `args` which
// will be appended immediately after `program`. However, this only works for things in the same project
// as the first one that runs will be used for resolving package: URIs etc. We also can't mix and match
Expand All @@ -67,19 +67,26 @@ export class TestCommands implements vs.Disposable {
if (!suites)
return;

const tests = suites
let testPaths = suites
.map((suite) => suite.suiteData.path)
.filter((suitePath) => isWithinPath(suitePath, projectFolder))
.filter((suitePath) => isInsideFolderNamed(suitePath, "integration_test") === integrationTests)
.filter((suitePath) => closestProjectFolder(suitePath) === projectFolder);


if (tests.length) {
if (testPaths.length) {
const projectName = path.basename(projectFolder);
const testType = integrationTests ? "Integration Tests" : "Tests";
const name = `${projectName} ${testType}`;

projectsWithTests.push({ projectFolder, name, tests });
// To avoid making a huge list of suite names that may trigger
// "The command line is too long" on Windows, if we know we're running them
// _all_ we can simplify the list of test names to just the top-level folders
// that contain each.
if (isRunningAll)
testPaths = uniq(testPaths.map((suitePath) => path.relative(projectFolder, suitePath).split(path.sep)[0]));

projectsWithTests.push({ projectFolder, name, tests: testPaths });
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/extension/test/vs_test_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export class VsCodeTestController implements TestEventListener, IAmDisposable {
await this.discoverer?.ensureSuitesDiscovered();

const testsToRun = new Set<vs.TestItem>();
const isRunningAll = !request.include?.length && !request.exclude?.length;
(request.include ?? this.controller.items).forEach((item) => testsToRun.add(item));
request.exclude?.forEach((item) => testsToRun.delete(item));

Expand All @@ -82,7 +83,7 @@ export class VsCodeTestController implements TestEventListener, IAmDisposable {
// As an optimisation, if we're no-debug and running complete files (eg. all included or excluded items are
// suites), we can run the "fast path" in a single `dart test` invocation.
if (!debug && [...testsToRun].every((item) => this.nodeForItem.get(item) instanceof SuiteNode)) {
await vs.commands.executeCommand("_dart.runAllTestsWithoutDebugging", [...testsToRun].map((item) => this.nodeForItem.get(item)), run);
await vs.commands.executeCommand("_dart.runAllTestsWithoutDebugging", [...testsToRun].map((item) => this.nodeForItem.get(item)), run, isRunningAll);
return;
}

Expand Down

0 comments on commit fac8c20

Please sign in to comment.