Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ internal class CodeBridgeTestingUi(private val project: Project, private val sco
val testing = HostedTesting.getInstance(project)
testing.setRunOpener({ run -> CodeBridgeTestRuns.show(project, run) }, this)
testing.addChangeListener(::changed, this)
// Discovery may finish before this startup activity registers its listener.
changed(emptySet())
}

/**
Expand Down
17 changes: 16 additions & 1 deletion src/test-extensions/workbench-probe-extension/testing-probe.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,24 @@ exports.install = context => {
const controller = vscode.tests.createTestController('probeTests', 'Probe tests');
context.subscriptions.push(controller);
context.subscriptions.push(vscode.commands.registerCommand('probe.testState', () => state));
let childrenReady = false;
let pendingChildren = [];
const publishChildren = () => {
const children = pendingChildren;
pendingChildren = [];
children.forEach(([parent, item]) => parent.children.add(item));
};
context.subscriptions.push(vscode.commands.registerCommand('probe.discoverChildTests', () => {
childrenReady = true;
publishChildren();
return true;
}));

const discover = document => {
if (document.languageId !== 'codebridgeactions') return;
const file = controller.createTestItem(document.uri.toString(), document.uri.path.split('/').pop(), document.uri);
let suite;
const children = [];
for (let line = 0; line < document.lineCount; line++) {
const match = /^(suite|test) (\w+)/.exec(document.lineAt(line).text);
if (!match) continue;
Expand All @@ -24,9 +37,11 @@ exports.install = context => {
if (match[1] === 'suite') {
suite = item;
file.children.add(item);
} else (suite ?? file).children.add(item);
} else children.push([suite ?? file, item]);
}
controller.items.replace([file]);
pendingChildren = children;
if (childrenReady) publishChildren();
};
controller.resolveHandler = async item => {
if (!item) vscode.workspace.textDocuments.forEach(discover);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.intellij.ide.starter.junit5.RemoteDevRun
import me.helvert.codebridge.uitest.awaitProbeValue
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import kotlin.test.assertEquals

/**
* `vscode.tests` as the user meets it in a JetBrains Client: Run in the gutter of each test an
Expand Down Expand Up @@ -48,6 +49,12 @@ class SplitModeTestingTest {

fun requested() = command("probe.testState")

// Publish children only after the suite was drawn, so their markers require an update
// rather than sharing the editor's initial highlighting pass.
awaitProbeValue("the suite's marker before child discovery", ::markers) {
it == mapOf(0 to "Run probe")
}
assertEquals("true", command("probe.discoverChildTests"))
awaitProbeValue("a Run marker on the suite and on each test", ::markers) {
it == mapOf(0 to "Run probe", 1 to "Run passes", 2 to "Run fails")
}
Expand Down
Loading