Conversation
aeisenberg
left a comment
There was a problem hiding this comment.
Thanks for taking this on.
| ctx.subscriptions.push(testRunner); | ||
|
|
||
| let testManager: TestManagerBase | undefined = undefined; | ||
| if (isCanary()) { |
There was a problem hiding this comment.
As much as possible, we try to dis/enable all canary features without a restart. It looks like this is not following the pattern. I don't know how easy it would be to do, though.
There was a problem hiding this comment.
Hmm. There's no way to "unregister" a TestController AFAICT, but maybe just deleting all of its TestItems would be equivalent. I'll have to see if there's a way to unregister the legacy test adapter, but it might not be worth the effort.
There was a problem hiding this comment.
OK, there is a way to unregister the legacy test stuff. However, handling of the commands we expose is trickier. We share the same command IDs between the two implementations, but they route to slightly different implementations depending on which test UI we're using.
Given how easy the transition to the new UI was, and how annoying our dependency on that third-party extension is, I suspect we'll move this out of canary pretty soon anyway.
There was a problem hiding this comment.
If it's going to take significant time and still be imperfect, I don't think it's worth taking on for a transitional feature.
|
|
||
| if (!(await pathExists(expectedPath))) { | ||
| void showAndLogWarningMessage( | ||
| `'${basename(expectedPath)}' does not exist. Creating an empty file.`, |
There was a problem hiding this comment.
I know you are just moving this around, but it seems odd that we are popping up a warning box here. Maybe a bit annoying. I think better to just log it in the outpuut view without a popup and create the file.
There was a problem hiding this comment.
I've just removed the error message altogether. I don't think it's interesting to log.
| */ | ||
| async function tryReadFileContents( | ||
| path: string, | ||
| testMessages: TestMessage[], |
There was a problem hiding this comment.
I'd slightly prefer changing this function so that it actually throws the error message and the call site is wrapped in a try-catch that would add to the testMessages array. This is more stylistic, so what you have now is also fine.
There was a problem hiding this comment.
I only did it this way to avoid duplicating the code that formats and adds the test message. For a non-exported function, I think it's OK as-is.
|
Would it be possible to extract upgrading |
|
In a separate PR, we should probably be moving all of the |
Co-authored-by: Andrew Eisenberg <aeisenberg@github.com>
|
| private readonly testController: TestController = tests.createTestController( | ||
| "codeql", | ||
| "Fancy CodeQL Tests", | ||
| "CodeQL Tests", |
|
Just deleted two comments that were meant for #2307 |
| try { | ||
| await childPromise; | ||
| } catch (_e) { | ||
| // We need to await this to avoid an unhandled rejection, but we want to propagate the | ||
| // original exception. | ||
| } |
There was a problem hiding this comment.
Would childPromise.catch(() => void 0); have the same effect? We wouldn't need to wait on the promise but still no unhandled rejection will be shown.
| ].join("\n") | ||
| : [ | ||
| "", | ||
| `${event.failureStage?.toLowerCase()} error: ${event.test}`, |
There was a problem hiding this comment.
This will print undefined error if the failureStage is empty. Should we printing an empty string or unknown instead?
| if (node.uri === undefined || node.uri.scheme !== "file") { | ||
| throw new Error("Selected test is not a CodeQL test."); | ||
| } | ||
| return node.uri!.fsPath; |
There was a problem hiding this comment.
TypeScript should recognize that node.uri is now not undefined:
| return node.uri!.fsPath; | |
| return node.uri.fsPath; |
| const tests: string[] = []; | ||
| testsToRun.forEach((t) => { | ||
| testRun.enqueued(t); | ||
| tests.push(t.uri!.fsPath); |
There was a problem hiding this comment.
Can we do something different here, like returning if t.uri === undefined?
There was a problem hiding this comment.
We actually already had the path we need in the key of the map entry, so I used that instead.
…e-codeql into dbartol/new-test-ui
|
Related: #1099 |
I decided to take a look at what it would take to move away from the third-party Test Explorer extension for CodeQL tests, and it turned out to be easier than I expected. This PR moves CodeQL testing to use the native VS Code test UI when the canary flag is set. If everything seems to work well after a bit of internal dogfooding, we can remove the old code entirely and enable this for everyone.
Code changes
To access the new VS Code testing API, I needed to update our
@types/vscodedependency. This exposed a name collision in some unrelated quick pick code, which I fixed in a separate commit.I was able to reuse much of the existing test-related code. In particular, the test discovery code is entirely unchanged.
TestRunnerservice, used by both the legacy and the new test managers.acceptOutputandshowOutputDiffs) has been moved into a newTestManagerBaseclass, from which both the old and new test manager classes inhierit.The CLI server has been updated to use
BaseLoggerinstead ofLogger, since it doesn't need theshow()function.I tweaked the code that runs an async CLI command to await the child process even on failure, to avoid a runtime error about the promise rejection being unhandled.
I added the
actualproperty toTestCompleted, since it was already being set by the CLI.I implemented the new support in the new
TestManagerservice. The model for interacting with the native VS Code test UI is quite a bit simpler than the third-party extension.TestControllerobject and update its list ofTestItems as we discover tests.TestRunRequestthat tells us what to run, and we call the sharedTestRunnerservice to handle the CLI invocation and communication.TestRunobject. Test results can includeTestMessageobjects, which can have file locations, and can contain diffs between actual and expected text. For compilation failures, we emit the compilation errors asTestMessages. For actual/expected mismatch failure, we create aTestMessagecontaining the result diff.TestRun.logOutput(), which sends it to the "Test Results" tab.Test changes
test-runner.test.ts, since they really only test the functionality that is now factored out into theTestRunnerclass.test-adapter.test.tsto test the new test controller similar to how we test the legacy one.test-runner-helpers.tsfile.