Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start discovering all available tests lazily #3120

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,10 @@
"description": "Opt-in/out of the Tapioca add-on",
"type": "boolean"
},
"fullTestDiscovery": {
"description": "UNDER DEVEOPMENT. Opt-in/out of the full test discovery experience",
"type": "boolean"
vinistock marked this conversation as resolved.
Show resolved Hide resolved
},
"launcher": {
"description": "Opt-in/out of the new launcher mode",
"type": "boolean"
Expand Down
1 change: 1 addition & 0 deletions vscode/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export const SUPPORTED_LANGUAGE_IDS = ["ruby", "erb"];
export const FEATURE_FLAGS = {
tapiocaAddon: 1.0,
launcher: 0.1,
fullTestDiscovery: -1,
};

type FeatureFlagConfigurationKey = keyof typeof FEATURE_FLAGS | "all";
Expand Down
151 changes: 149 additions & 2 deletions vscode/src/test/suite/testController.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
import * as assert from "assert";
import path from "path";
import fs from "fs";
import os from "os";

import * as vscode from "vscode";
import { CodeLens } from "vscode-languageclient/node";
import { afterEach } from "mocha";
import sinon from "sinon";

import { TestController } from "../../testController";
import { Command } from "../../common";
import * as common from "../../common";

import { FAKE_TELEMETRY } from "./fakeTelemetry";

suite("TestController", () => {
const workspacePath = path.dirname(
path.dirname(path.dirname(path.dirname(__dirname))),
);
const workspaceUri = vscode.Uri.file(workspacePath);
const workspaceFolder: vscode.WorkspaceFolder = {
uri: workspaceUri,
name: path.basename(workspaceUri.fsPath),
index: 0,
};
const context = {
extensionMode: vscode.ExtensionMode.Test,
subscriptions: [],
Expand All @@ -18,6 +32,10 @@ suite("TestController", () => {
},
} as unknown as vscode.ExtensionContext;

afterEach(() => {
context.subscriptions.forEach((subscription) => subscription.dispose());
});

test("createTestItems doesn't break when there's a missing group", () => {
const controller = new TestController(
context,
Expand All @@ -30,7 +48,7 @@ suite("TestController", () => {
range: new vscode.Range(0, 0, 10, 10),
command: {
title: "Run",
command: Command.RunTest,
command: common.Command.RunTest,
arguments: [
"test/fake_test.rb",
"test_do_something",
Expand Down Expand Up @@ -58,4 +76,133 @@ suite("TestController", () => {
controller.createTestItems(codeLensItems);
});
});

test("populates test structure directly if there's only one workspace", async () => {
const stub = sinon.stub(common, "featureEnabled").returns(true);
const controller = new TestController(
context,
FAKE_TELEMETRY,
() => undefined,
);
stub.restore();

const workspacesStub = sinon
.stub(vscode.workspace, "workspaceFolders")
.get(() => [workspaceFolder]);

const relativePathStub = sinon
.stub(vscode.workspace, "asRelativePath")
.callsFake((uri) =>
path.relative(workspacePath, (uri as vscode.Uri).fsPath),
);

await controller.testController.resolveHandler!(undefined);
workspacesStub.restore();
relativePathStub.restore();

const collection = controller.testController.items;

const testDir = collection.get(
vscode.Uri.joinPath(workspaceUri, "test").toString(),
);
assert.ok(testDir);

const serverTest = testDir!.children.get(
vscode.Uri.joinPath(workspaceUri, "test", "server_test.rb").toString(),
);
assert.ok(serverTest);
});

test("makes the workspaces the top level when there's more than one", async () => {
const stub = sinon.stub(common, "featureEnabled").returns(true);
const controller = new TestController(
context,
FAKE_TELEMETRY,
() => undefined,
);
stub.restore();

const secondWorkspacePath = fs.mkdtempSync(
path.join(os.tmpdir(), "ruby-lsp-test-controller-"),
);
const secondWorkspaceUri = vscode.Uri.file(secondWorkspacePath);

fs.mkdirSync(path.join(secondWorkspaceUri.fsPath, "test"));
fs.writeFileSync(
path.join(secondWorkspaceUri.fsPath, "test", "other_test.rb"),
"require 'test_helper'\n\nclass OtherTest < Minitest::Test; end",
);

const secondWorkspaceFolder: vscode.WorkspaceFolder = {
uri: secondWorkspaceUri,
name: "second_workspace",
index: 1,
};
const workspacesStub = sinon
.stub(vscode.workspace, "workspaceFolders")
.get(() => [workspaceFolder, secondWorkspaceFolder]);

const relativePathStub = sinon
.stub(vscode.workspace, "asRelativePath")
.callsFake((uri) => {
const filePath = (uri as vscode.Uri).fsPath;

if (path.basename(filePath) === "other_test.rb") {
return path.relative(secondWorkspacePath, filePath);
} else {
return path.relative(workspacePath, filePath);
}
});

const getWorkspaceStub = sinon
.stub(vscode.workspace, "getWorkspaceFolder")
.callsFake((uri) => {
if (uri === secondWorkspaceUri) {
return secondWorkspaceFolder;
} else {
return workspaceFolder;
}
});

await controller.testController.resolveHandler!(undefined);

const collection = controller.testController.items;

// First workspace
const workspaceItem = collection.get(workspaceUri.toString());
assert.ok(workspaceItem);
await controller.testController.resolveHandler!(workspaceItem);

const testDir = workspaceItem!.children.get(
vscode.Uri.joinPath(workspaceUri, "test").toString(),
);
assert.ok(testDir);

const serverTest = testDir!.children.get(
vscode.Uri.joinPath(workspaceUri, "test", "server_test.rb").toString(),
);
assert.ok(serverTest);

// Second workspace
const secondWorkspaceItem = collection.get(secondWorkspaceUri.toString());
assert.ok(secondWorkspaceItem);
await controller.testController.resolveHandler!(secondWorkspaceItem);

const secondTestDir = secondWorkspaceItem!.children.get(
vscode.Uri.joinPath(secondWorkspaceUri, "test").toString(),
);
assert.ok(secondTestDir);

const otherTest = secondTestDir!.children.get(
vscode.Uri.joinPath(
secondWorkspaceUri,
"test",
"other_test.rb",
).toString(),
);
assert.ok(otherTest);
workspacesStub.restore();
relativePathStub.restore();
getWorkspaceStub.restore();
});
});
Loading