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

Show setup message when no targets returned from sync #15

Merged
merged 2 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
36 changes: 36 additions & 0 deletions src/test-explorer/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export class TestResolver implements OnModuleInit, vscode.Disposable {
parentTest,
'Loading: waiting for build server connection'
)
parentTest.error = undefined
const conn = await this.buildServer.getConnection()

updateDescription(parentTest, 'Loading: fetching available targets')
Expand Down Expand Up @@ -202,6 +203,25 @@ export class TestResolver implements OnModuleInit, vscode.Disposable {
relevantParent.children.add(newTest)
})

// If no test items were added, show the getting started message as a test message overlaid on the .bazelproject file.
// This provides an opportunity for the user to make adjustments and re-sync.
if (parentTest.children.size === 0) {
// Dummy test run that overlays the getting started message on the .bazelproject file.
const run = this.store.testController.createTestRun(
new vscode.TestRunRequest()
)
run.errored(parentTest, new vscode.TestMessage(gettingStartedMessage))
run.end()

// Link in the test explorer tree to set up the project.
const encodedFileUri = encodeURIComponent(JSON.stringify(parentTest.uri))
const syncFailMessage = new vscode.MarkdownString(
`No test targets found. [Setup your project](command:vscode.open?${encodedFileUri})`
)
syncFailMessage.isTrusted = true
parentTest.error = syncFailMessage
}

// Replace all children with the newly returned test cases.
this.condenseTestItems(parentTest)
updateDescription(parentTest)
Expand Down Expand Up @@ -403,3 +423,19 @@ function combineCancelTokens(
token2?.onCancellationRequested(() => combinedSource.cancel())
return combinedSource.token
}

const gettingStartedMessage = new vscode.MarkdownString(
`To use the Test Explorer, please configure your project.

Getting started tips:
- Update this file with some paths that include test targets.
- Use the directories key to specify by directory
- Use the targets key to specify by Bazel target pattern
- Ensure that the bazel_binary field in this file matches the path to your Bazel binary.
- Re-sync at any time by clicking the $(extensions-refresh) refresh icon at the very top of the testing panel.

Does it seem like something else went wrong? Check for output [here](command:bazelbsp.showServerOutput).
mnoah1 marked this conversation as resolved.
Show resolved Hide resolved
`,
true
)
gettingStartedMessage.isTrusted = true
1 change: 1 addition & 0 deletions src/test-info/test-item-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class TestItemFactory {
'Bazel Test Targets',
uri
)
newTest.range = new vscode.Range(0, 0, 0, 0)
newTest.canResolveChildren = true
this.store.testCaseMetadata.set(
newTest,
Expand Down
24 changes: 24 additions & 0 deletions src/test/suite/resolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,30 @@ suite('Test Resolver', () => {
}
})

test('no targets returned', async () => {
const root = testCaseStore.testController.createTestItem(
'root',
'Bazel Test Targets'
)
testCaseStore.testController.items.add(root)
testCaseStore.testCaseMetadata.set(
root,
new TestCaseInfo(root, undefined, TestItemType.Root)
)
assert.ok(testCaseStore.testController.resolveHandler)

// Simulate an empty result from requesting targets.
const emptyResult: bsp.WorkspaceBuildTargetsResult = {
targets: [],
}
const sendRequestStub = sandbox
.stub(sampleConn, 'sendRequest')
.resolves(emptyResult)
await testCaseStore.testController.resolveHandler(root)
const message = root.error as vscode.MarkdownString
assert.ok(message.value.includes('No test targets found'))
})

test('source files within a target', async () => {
const buildTarget = sampleBuildTargetsResult.targets[0]
const sendRequestStub = sandbox
Expand Down
Loading