Skip to content

Commit 70b4aac

Browse files
author
Dave Bartolomeo
authored
Merge pull request #2306 from github/dbartol/new-test-ui
Use native VS Code test UI on canary
2 parents cc241d0 + a52391b commit 70b4aac

File tree

12 files changed

+1100
-395
lines changed

12 files changed

+1100
-395
lines changed

extensions/ql-vscode/package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,10 @@
682682
"command": "codeQLTests.acceptOutput",
683683
"title": "Accept Test Output"
684684
},
685+
{
686+
"command": "codeQLTests.acceptOutputContextTestItem",
687+
"title": "Accept Test Output"
688+
},
685689
{
686690
"command": "codeQLAstViewer.gotoCode",
687691
"title": "Go To Code"
@@ -977,6 +981,13 @@
977981
"when": "viewItem == testWithSource"
978982
}
979983
],
984+
"testing/item/context": [
985+
{
986+
"command": "codeQLTests.acceptOutputContextTestItem",
987+
"group": "qltest@1",
988+
"when": "controllerId == codeql && testId =~ /^test /"
989+
}
990+
],
980991
"explorer/context": [
981992
{
982993
"command": "codeQL.setCurrentDatabase",
@@ -1325,6 +1336,10 @@
13251336
{
13261337
"command": "codeQL.createQuery",
13271338
"when": "config.codeQL.canary"
1339+
},
1340+
{
1341+
"command": "codeQLTests.acceptOutputContextTestItem",
1342+
"when": "false"
13281343
}
13291344
],
13301345
"editor/context": [

extensions/ql-vscode/src/cli.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
getErrorStack,
2424
} from "./pure/helpers-pure";
2525
import { QueryMetadata, SortDirection } from "./pure/interface-types";
26-
import { Logger, ProgressReporter } from "./common";
26+
import { BaseLogger, Logger, ProgressReporter } from "./common";
2727
import { CompilationMessage } from "./pure/legacy-messages";
2828
import { sarifParser } from "./sarif-parser";
2929
import { walkDirectory } from "./helpers";
@@ -149,6 +149,7 @@ export interface TestCompleted {
149149
compilationMs: number;
150150
evaluationMs: number;
151151
expected: string;
152+
actual?: string;
152153
diff: string[] | undefined;
153154
failureDescription?: string;
154155
failureStage?: string;
@@ -439,14 +440,19 @@ export class CodeQLCliServer implements Disposable {
439440
command: string[],
440441
commandArgs: string[],
441442
cancellationToken?: CancellationToken,
442-
logger?: Logger,
443+
logger?: BaseLogger,
443444
): AsyncGenerator<string, void, unknown> {
444445
// Add format argument first, in case commandArgs contains positional parameters.
445446
const args = [...command, "--format", "jsonz", ...commandArgs];
446447

447448
// Spawn the CodeQL process
448449
const codeqlPath = await this.getCodeQlPath();
449450
const childPromise = spawn(codeqlPath, args);
451+
// Avoid a runtime message about unhandled rejection.
452+
childPromise.catch(() => {
453+
/**/
454+
});
455+
450456
const child = childPromise.childProcess;
451457

452458
let cancellationRegistration: Disposable | undefined = undefined;
@@ -497,7 +503,7 @@ export class CodeQLCliServer implements Disposable {
497503
logger,
498504
}: {
499505
cancellationToken?: CancellationToken;
500-
logger?: Logger;
506+
logger?: BaseLogger;
501507
} = {},
502508
): AsyncGenerator<EventType, void, unknown> {
503509
for await (const event of this.runAsyncCodeQlCliCommandInternal(
@@ -776,7 +782,7 @@ export class CodeQLCliServer implements Disposable {
776782
logger,
777783
}: {
778784
cancellationToken?: CancellationToken;
779-
logger?: Logger;
785+
logger?: BaseLogger;
780786
},
781787
): AsyncGenerator<TestCompleted, void, unknown> {
782788
const subcommandArgs = this.cliConfig.additionalTestArguments.concat([
@@ -1661,7 +1667,7 @@ const lineEndings = ["\r\n", "\r", "\n"];
16611667
* @param stream The stream to log.
16621668
* @param logger The logger that will consume the stream output.
16631669
*/
1664-
async function logStream(stream: Readable, logger: Logger): Promise<void> {
1670+
async function logStream(stream: Readable, logger: BaseLogger): Promise<void> {
16651671
for await (const line of splitStreamAtSeparators(stream, lineEndings)) {
16661672
// Await the result of log here in order to ensure the logs are written in the correct order.
16671673
await logger.log(line);

extensions/ql-vscode/src/common/commands.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,9 @@ export type SummaryLanguageSupportCommands = {
298298
export type TestUICommands = {
299299
"codeQLTests.showOutputDifferences": (node: TestTreeNode) => Promise<void>;
300300
"codeQLTests.acceptOutput": (node: TestTreeNode) => Promise<void>;
301+
"codeQLTests.acceptOutputContextTestItem": (
302+
node: TestTreeNode,
303+
) => Promise<void>;
301304
};
302305

303306
export type MockGitHubApiServerCommands = {

extensions/ql-vscode/src/extension.ts

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { CodeQLCliServer } from "./cli";
3131
import {
3232
CliConfigListener,
3333
DistributionConfigListener,
34+
isCanary,
3435
joinOrderWarningThreshold,
3536
QueryHistoryConfigListener,
3637
QueryServerConfigListener,
@@ -114,14 +115,16 @@ import {
114115
BaseCommands,
115116
PreActivationCommands,
116117
QueryServerCommands,
117-
TestUICommands,
118118
} from "./common/commands";
119119
import { LocalQueries } from "./local-queries";
120120
import { getAstCfgCommands } from "./ast-cfg-commands";
121121
import { getQueryEditorCommands } from "./query-editor";
122122
import { App } from "./common/app";
123123
import { registerCommandWithErrorHandling } from "./common/vscode/commands";
124124
import { DataExtensionsEditorModule } from "./data-extensions-editor/data-extensions-editor-module";
125+
import { TestManager } from "./test-manager";
126+
import { TestRunner } from "./test-runner";
127+
import { TestManagerBase } from "./test-manager-base";
125128

126129
/**
127130
* extension.ts
@@ -885,25 +888,34 @@ async function activateWithInstalledDistribution(
885888
);
886889

887890
void extLogger.log("Initializing QLTest interface.");
888-
const testExplorerExtension = extensions.getExtension<TestHub>(
889-
testExplorerExtensionId,
890-
);
891-
let testUiCommands: Partial<TestUICommands> = {};
892-
if (testExplorerExtension) {
893-
const testHub = testExplorerExtension.exports;
894-
const testAdapterFactory = new QLTestAdapterFactory(
895-
testHub,
896-
cliServer,
897-
dbm,
898-
);
899-
ctx.subscriptions.push(testAdapterFactory);
900891

901-
const testUIService = new TestUIService(app, testHub);
902-
ctx.subscriptions.push(testUIService);
892+
const testRunner = new TestRunner(dbm, cliServer);
893+
ctx.subscriptions.push(testRunner);
894+
895+
let testManager: TestManagerBase | undefined = undefined;
896+
if (isCanary()) {
897+
testManager = new TestManager(app, testRunner, cliServer);
898+
ctx.subscriptions.push(testManager);
899+
} else {
900+
const testExplorerExtension = extensions.getExtension<TestHub>(
901+
testExplorerExtensionId,
902+
);
903+
if (testExplorerExtension) {
904+
const testHub = testExplorerExtension.exports;
905+
const testAdapterFactory = new QLTestAdapterFactory(
906+
testHub,
907+
testRunner,
908+
cliServer,
909+
);
910+
ctx.subscriptions.push(testAdapterFactory);
903911

904-
testUiCommands = testUIService.getCommands();
912+
testManager = new TestUIService(app, testHub);
913+
ctx.subscriptions.push(testManager);
914+
}
905915
}
906916

917+
const testUiCommands = testManager?.getCommands() ?? {};
918+
907919
const astViewer = new AstViewer();
908920
const astTemplateProvider = new TemplatePrintAstProvider(
909921
cliServer,

0 commit comments

Comments
 (0)