From ed2899ab2b2e6971e850b9bf8c58fb84d4d7ec07 Mon Sep 17 00:00:00 2001 From: David Barbet Date: Tue, 2 May 2023 18:44:35 -0700 Subject: [PATCH] Combine test compile step into normal compile --- package.json | 18 +++---- test/featureTests/assets.test.ts | 48 +++++++++---------- test/featureTests/processPicker.test.ts | 6 +-- .../advisor.integration.test.ts | 6 +-- .../codeActionRename.integration.test.ts | 4 +- .../codeLensProvider.integration.test.ts | 10 ++-- .../diagnostics.integration.test.ts | 6 +-- .../dotnetTest.integration.test.ts | 10 ++-- .../inlayHints.integration.test.ts | 4 +- test/integrationTests/integrationHelpers.ts | 20 +++++--- .../languageMiddleware.integration.test.ts | 4 +- .../launchConfiguration.integration.test.ts | 4 +- test/integrationTests/poll.ts | 6 +-- .../reAnalyze.integration.test.ts | 2 +- .../sourceGeneratorDefinitionProvider.test.ts | 2 +- .../testAssets/testAssetWorkspace.ts | 4 +- .../integrationTests/testAssets/testAssets.ts | 24 ++++++---- test/runIntegrationTests.ts | 4 ++ test/tsconfig.json | 13 ----- test/unitTests/Fakes/FakeDotnetResolver.ts | 4 +- test/unitTests/Fakes/FakeMonoResolver.ts | 4 +- test/unitTests/Fakes/FakeOptions.ts | 6 +-- .../InstallRuntimeDependencies.test.ts | 4 +- test/unitTests/OmnisharpManager.test.ts | 4 +- .../unitTests/OmnisharpPackageCreator.test.ts | 48 +++++++++---------- .../OptionChangeObserver.test.ts | 15 +++--- .../logging/CsharpChannelObserver.test.ts | 2 +- .../logging/DotnetTestChannelObserver.test.ts | 2 +- .../logging/DotnetTestLoggerObserver.test.ts | 6 +-- .../logging/ErrorMessageObserver.test.ts | 2 +- .../InformationMessageObserver.test.ts | 14 +++--- .../logging/OmnisharpChannelObserver.test.ts | 2 +- .../logging/OmnisharpLoggerObserver.test.ts | 2 +- .../unitTests/logging/OpenURLObserver.test.ts | 8 ++-- .../logging/TelemetryObserver.test.ts | 36 +++++++------- .../logging/WarningMessageObserver.test.ts | 8 ++-- test/unitTests/optionStream.test.ts | 7 +-- tsconfig.json | 8 +--- 38 files changed, 185 insertions(+), 192 deletions(-) delete mode 100644 test/tsconfig.json diff --git a/package.json b/package.json index 46a052880..46fcb97a6 100644 --- a/package.json +++ b/package.json @@ -45,15 +45,15 @@ "compileDev": "tsc -p ./ && tslint -p ./ && webpack --mode development", "watch": "tsc -watch -p ./", "tdd": "mocha --config ./.mocharc.jsonc --watch --watch-extensions ts test/unitTests/**/*.test.ts*", - "test": "tsc -p test && gulp test", - "test:unit": "tsc -p test && gulp test:unit", - "test:feature": "tsc -p test && gulp test:feature", - "test:integration": "tsc -p test && gulp test:integration", - "test:integration:singleCsproj": "tsc -p test && gulp test:integration:singleCsproj", - "test:integration:slnWithCsproj": "tsc -p test && gulp test:integration:slnWithCsproj", - "test:integration:slnFilterWithCsproj": "tsc -p test && gulp test:integration:slnFilterWithCsproj", - "test:release": "tsc -p test && mocha out/test/releaseTests/**/*.test.js", - "test:artifacts": "tsc -p test && mocha out/test/artifactTests/**/*.test.js", + "test": "tsc -p ./ && gulp test", + "test:unit": "tsc -p ./ && gulp test:unit", + "test:feature": "tsc -p ./ && gulp test:feature", + "test:integration": "tsc -p ./ && gulp test:integration", + "test:integration:singleCsproj": "tsc -p ./ && gulp test:integration:singleCsproj", + "test:integration:slnWithCsproj": "tsc -p ./ && gulp test:integration:slnWithCsproj", + "test:integration:slnFilterWithCsproj": "tsc -p ./ && gulp test:integration:slnFilterWithCsproj", + "test:release": "tsc -p ./ && mocha out/test/releaseTests/**/*.test.js", + "test:artifacts": "tsc -p ./ && mocha out/test/artifactTests/**/*.test.js", "unpackage:vsix": "gulp vsix:release:unpackage", "updatePackageDependencies": "gulp updatePackageDependencies" }, diff --git a/test/featureTests/assets.test.ts b/test/featureTests/assets.test.ts index 213fd383b..b17f56c81 100644 --- a/test/featureTests/assets.test.ts +++ b/test/featureTests/assets.test.ts @@ -24,7 +24,7 @@ suite("Asset generation: csproj", () => { let generator = new AssetGenerator(info, createMockWorkspaceFolder(rootPath)); generator.setStartupProject(0); let tasksJson = generator.createTasksConfiguration(); - let buildPath = tasksJson.tasks[0].args[1]; + let buildPath = tasksJson.tasks![0].args![1]; // ${workspaceFolder}/project.json let segments = buildPath.split(path.posix.sep); @@ -39,9 +39,9 @@ suite("Asset generation: csproj", () => { let tasksJson = generator.createTasksConfiguration(); // We do not check the watch task since this parameter can break hot reload scenarios. - tasksJson.tasks + tasksJson.tasks! .filter(task => task.label !== "watch") - .forEach(task => task.args.should.contain("/property:GenerateFullPaths=true")); + .forEach(task => task.args!.should.contain("/property:GenerateFullPaths=true")); }); test("Generated 'build' and 'publish' tasks have the consoleloggerparameters argument set to NoSummary", () => { @@ -52,9 +52,9 @@ suite("Asset generation: csproj", () => { let tasksJson = generator.createTasksConfiguration(); // We do not check the watch task since this parameter can break hot reload scenarios. - tasksJson.tasks + tasksJson.tasks! .filter(task => task.label !== "watch") - .forEach(task => task.args.should.contain("/consoleloggerparameters:NoSummary")); + .forEach(task => task.args!.should.contain("/consoleloggerparameters:NoSummary")); }); test("Generated 'watch' task does not have the property GenerateFullPaths set to true ", () => { @@ -64,8 +64,8 @@ suite("Asset generation: csproj", () => { generator.setStartupProject(0); let tasksJson = generator.createTasksConfiguration(); - const watchTask = tasksJson.tasks.find(task => task.label === "watch"); - watchTask.args.should.not.contain("/property:GenerateFullPaths=true"); + const watchTask = tasksJson.tasks!.find(task => task.label === "watch"); + watchTask!.args!.should.not.contain("/property:GenerateFullPaths=true"); }); test("Generated 'watch' task does not have the consoleloggerparameters argument set to NoSummary", () => { @@ -75,8 +75,8 @@ suite("Asset generation: csproj", () => { generator.setStartupProject(0); let tasksJson = generator.createTasksConfiguration(); - const watchTask = tasksJson.tasks.find(task => task.label === "watch"); - watchTask.args.should.not.contain("/consoleloggerparameters:NoSummary"); + const watchTask = tasksJson.tasks!.find(task => task.label === "watch"); + watchTask!.args!.should.not.contain("/consoleloggerparameters:NoSummary"); }); test("Create tasks.json for nested project opened in workspace", () => { @@ -85,7 +85,7 @@ suite("Asset generation: csproj", () => { let generator = new AssetGenerator(info, createMockWorkspaceFolder(rootPath)); generator.setStartupProject(0); let tasksJson = generator.createTasksConfiguration(); - let buildPath = tasksJson.tasks[0].args[1]; + let buildPath = tasksJson.tasks![0].args![1]; // ${workspaceFolder}/nested/project.json let segments = buildPath.split(path.posix.sep); @@ -100,7 +100,7 @@ suite("Asset generation: csproj", () => { let launchJson = parse(generator.createLaunchJsonConfigurations(ProgramLaunchType.Console), undefined, { disallowComments: true }); let programPath: string = launchJson[0].program; - checkProgramPath(rootPath, programPath, info.MsBuild.Projects[0].TargetPath); + checkProgramPath(rootPath, programPath, info.MsBuild!.Projects[0].TargetPath); }); [5, 6, 7, 8, 9].forEach(version => { @@ -114,7 +114,7 @@ suite("Asset generation: csproj", () => { let launchJson = parse(generator.createLaunchJsonConfigurations(ProgramLaunchType.Console), undefined, { disallowComments: true }); let programPath: string = launchJson[0].program; - checkProgramPath(rootPath, programPath, info.MsBuild.Projects[0].TargetPath); + checkProgramPath(rootPath, programPath, info.MsBuild!.Projects[0].TargetPath); }); }); @@ -126,7 +126,7 @@ suite("Asset generation: csproj", () => { let launchJson = parse(generator.createLaunchJsonConfigurations(ProgramLaunchType.Console), undefined, { disallowComments: true }); let programPath: string = launchJson[0].program; - checkProgramPath(rootPath, programPath, info.MsBuild.Projects[0].TargetPath); + checkProgramPath(rootPath, programPath, info.MsBuild!.Projects[0].TargetPath); }); test("Create launch.json for project opened in workspace with non-relative output path", function() { @@ -142,7 +142,7 @@ suite("Asset generation: csproj", () => { let launchJson = parse(generator.createLaunchJsonConfigurations(ProgramLaunchType.Console), undefined, { disallowComments: true }); let programPath: string = launchJson[0].program; - checkProgramPath(rootPath, programPath, info.MsBuild.Projects[0].TargetPath); + checkProgramPath(rootPath, programPath, info.MsBuild!.Projects[0].TargetPath); }); test("Create launch.json for Blazor web assembly standalone project opened in workspace", () => { @@ -180,7 +180,7 @@ suite("Asset generation: csproj", () => { const cwd = hostedBlazorLaunchConfig.cwd; const hosted = hostedBlazorLaunchConfig.hosted; - checkProgramPath(rootPath, programPath, info.MsBuild.Projects[0].TargetPath); + checkProgramPath(rootPath, programPath, info.MsBuild!.Projects[0].TargetPath); cwd.should.equal('${workspaceFolder}'); hosted.should.equal(true); @@ -197,7 +197,7 @@ suite("Asset generation: csproj", () => { const cwd = hostedBlazorLaunchConfig.cwd; const hosted = hostedBlazorLaunchConfig.hosted; - checkProgramPath(rootPath, programPath, info.MsBuild.Projects[0].TargetPath); + checkProgramPath(rootPath, programPath, info.MsBuild!.Projects[0].TargetPath); cwd.should.equal('${workspaceFolder}/nested'); hosted.should.equal(true); @@ -211,7 +211,7 @@ suite("Asset generation: csproj", () => { let launchJson = parse(generator.createLaunchJsonConfigurations(ProgramLaunchType.Web), undefined, { disallowComments: true }); let programPath: string = launchJson[0].program; - checkProgramPath(rootPath, programPath, info.MsBuild.Projects[0].TargetPath); + checkProgramPath(rootPath, programPath, info.MsBuild!.Projects[0].TargetPath); }); test("Create launch.json for nested web project opened in workspace", () => { @@ -222,7 +222,7 @@ suite("Asset generation: csproj", () => { let launchJson = parse(generator.createLaunchJsonConfigurations(ProgramLaunchType.Web), undefined, { disallowComments: true }); let programPath: string = launchJson[0].program; - checkProgramPath(rootPath, programPath, info.MsBuild.Projects[0].TargetPath); + checkProgramPath(rootPath, programPath, info.MsBuild!.Projects[0].TargetPath); }); test("Add a new item to JSON", () => { @@ -234,7 +234,7 @@ suite("Asset generation: csproj", () => { }; const newItem = { name: 'new-item' }; - const updated = updateJsonWithComments(JSON.stringify(original), [newItem], 'configurations', 'name', /*formattingOptions*/ null); + const updated = updateJsonWithComments(JSON.stringify(original), [newItem], 'configurations', 'name', /*formattingOptions*/ null!); const parsed = jsonc.parse(updated); const configurations = parsed.configurations; @@ -254,7 +254,7 @@ suite("Asset generation: csproj", () => { const updatedItem = { name: 'build', command: 'dotnet' }; - const updated = updateJsonWithComments(JSON.stringify(original), [updatedItem], 'configurations', 'name', /*formattingOptions*/ null); + const updated = updateJsonWithComments(JSON.stringify(original), [updatedItem], 'configurations', 'name', /*formattingOptions*/ null!); const parsed = jsonc.parse(updated); const configurations = parsed.configurations; @@ -278,7 +278,7 @@ suite("Asset generation: csproj", () => { const updatedItem = { name: 'build', command: 'dotnet' }; - const updated = updateJsonWithComments(original, [updatedItem], 'configurations', 'name', /*formattingOptions*/ null); + const updated = updateJsonWithComments(original, [updatedItem], 'configurations', 'name', /*formattingOptions*/ null!); const lines = updated.trim().split('\n'); lines[0].trim().should.equal('// user comment in file'); @@ -336,12 +336,12 @@ function checkProgramPath(rootPath: string, programPath: string, targetPath: str function createMockWorkspaceFolder(rootPath: string): vscode.WorkspaceFolder { return { uri: vscode.Uri.file(rootPath), - name: undefined, - index: undefined + name: '', + index: -1 }; } -function createMSBuildWorkspaceInformation(projectPath: string, assemblyName: string, targetFrameworkShortName: string, targetPath: string = undefined, isExe: boolean = true, isWebProject: boolean = false, isBlazorWebAssemblyStandalone: boolean = false, isBlazorWebAssemblyHosted: boolean = false): protocol.WorkspaceInformationResponse { +function createMSBuildWorkspaceInformation(projectPath: string, assemblyName: string, targetFrameworkShortName: string, targetPath: string | undefined = undefined, isExe: boolean = true, isWebProject: boolean = false, isBlazorWebAssemblyStandalone: boolean = false, isBlazorWebAssemblyHosted: boolean = false): protocol.WorkspaceInformationResponse { return { MsBuild: { SolutionPath: '', diff --git a/test/featureTests/processPicker.test.ts b/test/featureTests/processPicker.test.ts index 5d7aa96c1..555f50fe1 100644 --- a/test/featureTests/processPicker.test.ts +++ b/test/featureTests/processPicker.test.ts @@ -197,15 +197,15 @@ suite("Remote Process Picker: Validate quoting arguments.", () => { process1.name.should.equal('System Idle Process'); process1.pid.should.equal('0'); - process2.commandLine.should.equal('"C:\\Program Files\\WindowsApps\\Microsoft.WindowsTerminalPreview_1.12.2931.0_x64__8wekyb3d8bbwe\\WindowsTerminal.exe"'); + process2.commandLine!.should.equal('"C:\\Program Files\\WindowsApps\\Microsoft.WindowsTerminalPreview_1.12.2931.0_x64__8wekyb3d8bbwe\\WindowsTerminal.exe"'); process2.name.should.equal('WindowsTerminal.exe'); process2.pid.should.equal('5112'); - process3.commandLine.should.equal('C:\\WINDOWS\\system32\\conhost.exe --headless --width 80 --height 30 --signal 0x8e0 --server 0x824'); + process3.commandLine!.should.equal('C:\\WINDOWS\\system32\\conhost.exe --headless --width 80 --height 30 --signal 0x8e0 --server 0x824'); process3.name.should.equal('conhost.exe'); process3.pid.should.equal('34560'); - process4.commandLine.should.equal('C:\\WINDOWS\\system32\\conhost.exe 0x4'); + process4.commandLine!.should.equal('C:\\WINDOWS\\system32\\conhost.exe 0x4'); process4.name.should.equal('conhost.exe'); process4.pid.should.equal('33732'); }); diff --git a/test/integrationTests/advisor.integration.test.ts b/test/integrationTests/advisor.integration.test.ts index c9f2b3fdb..43f9bdd05 100644 --- a/test/integrationTests/advisor.integration.test.ts +++ b/test/integrationTests/advisor.integration.test.ts @@ -34,11 +34,7 @@ suite(`Advisor ${testAssetWorkspace.description}`, function () { const activation = await activateCSharpExtension(); await testAssetWorkspace.restore(); - if (!activation) { - throw new Error('Cannot activate extension.'); - } else { - advisor = activation.advisor; - } + advisor = activation.advisor; let fileName = 'completion.cs'; let dir = testAssetWorkspace.projects[0].projectDirectoryPath; diff --git a/test/integrationTests/codeActionRename.integration.test.ts b/test/integrationTests/codeActionRename.integration.test.ts index a797299c1..faf97d892 100644 --- a/test/integrationTests/codeActionRename.integration.test.ts +++ b/test/integrationTests/codeActionRename.integration.test.ts @@ -44,8 +44,8 @@ suite(`Code Action Rename ${testAssetWorkspace.description}`, function () { const codeAction = codeActions.find(codeAction => codeAction.title == "Rename file to C.cs"); expect(codeAction, "Didn't find rename class code action"); - await vscode.commands.executeCommand(codeAction.command.command, ...codeAction.command.arguments); + await vscode.commands.executeCommand(codeAction!.command!.command, ...codeAction!.command!.arguments!); - await assertWithPoll(() => { }, 15 * 1000, 500, _ => expect(vscode.window.activeTextEditor.document.fileName).contains("C.cs")); + await assertWithPoll(() => { }, 15 * 1000, 500, _ => expect(vscode.window.activeTextEditor!.document.fileName).contains("C.cs")); }); }); diff --git a/test/integrationTests/codeLensProvider.integration.test.ts b/test/integrationTests/codeLensProvider.integration.test.ts index bfda0f4c8..21e0a4276 100644 --- a/test/integrationTests/codeLensProvider.integration.test.ts +++ b/test/integrationTests/codeLensProvider.integration.test.ts @@ -61,7 +61,7 @@ suite(`CodeLensProvider: ${testAssetWorkspace.description}`, function () { for (let codeLens of codeLenses) { expect(codeLens.isResolved).to.be.true; expect(codeLens.command).not.to.be.undefined; - expect(codeLens.command.title).to.equal("0 references"); + expect(codeLens.command!.title).to.equal("0 references"); } }); }); @@ -105,8 +105,8 @@ suite(`CodeLensProvider options: ${testAssetWorkspace.description}`, function () for (let codeLens of codeLenses) { expect(codeLens.isResolved).to.be.true; expect(codeLens.command).not.to.be.undefined; - expect(codeLens.command.command).to.be.oneOf(['dotnet.test.run', 'dotnet.classTests.run', 'dotnet.test.debug', 'dotnet.classTests.debug']); - expect(codeLens.command.title).to.be.oneOf(['Run Test', 'Run All Tests', 'Debug Test', 'Debug All Tests']); + expect(codeLens.command!.command).to.be.oneOf(['dotnet.test.run', 'dotnet.classTests.run', 'dotnet.test.debug', 'dotnet.classTests.debug']); + expect(codeLens.command!.title).to.be.oneOf(['Run Test', 'Run All Tests', 'Debug Test', 'Debug All Tests']); } }); @@ -121,8 +121,8 @@ suite(`CodeLensProvider options: ${testAssetWorkspace.description}`, function () for (let codeLens of codeLenses) { expect(codeLens.isResolved).to.be.true; expect(codeLens.command).not.to.be.undefined; - expect(codeLens.command.command).to.be.equal('editor.action.showReferences'); - expect(codeLens.command.title).to.equal('0 references'); + expect(codeLens.command!.command).to.be.equal('editor.action.showReferences'); + expect(codeLens.command!.title).to.equal('0 references'); } }); diff --git a/test/integrationTests/diagnostics.integration.test.ts b/test/integrationTests/diagnostics.integration.test.ts index 04788254b..97aaac6a1 100644 --- a/test/integrationTests/diagnostics.integration.test.ts +++ b/test/integrationTests/diagnostics.integration.test.ts @@ -116,7 +116,7 @@ suite(`DiagnosticProvider: ${testAssetWorkspace.description}`, function () { let cs0219 = result.find(x => x.code === "CS0219"); expect(cs0219).to.not.be.undefined; - expect(cs0219.tags).to.include(vscode.DiagnosticTag.Unnecessary); + expect(cs0219!.tags).to.include(vscode.DiagnosticTag.Unnecessary); }); test("Return unnecessary tag in case of unnesessary using", async function () { @@ -128,7 +128,7 @@ suite(`DiagnosticProvider: ${testAssetWorkspace.description}`, function () { let cs8019 = result.find(x => x.code === "CS8019"); expect(cs8019).to.not.be.undefined; - expect(cs8019.tags).to.include(vscode.DiagnosticTag.Unnecessary); + expect(cs8019!.tags).to.include(vscode.DiagnosticTag.Unnecessary); }); test("Return fadeout diagnostics like unused variables based on roslyn analyzers", async function () { @@ -140,7 +140,7 @@ suite(`DiagnosticProvider: ${testAssetWorkspace.description}`, function () { let ide0059 = result.find(x => x.code === "IDE0059"); expect(ide0059).to.not.be.undefined; - expect(ide0059.tags).to.include(vscode.DiagnosticTag.Unnecessary); + expect(ide0059!.tags).to.include(vscode.DiagnosticTag.Unnecessary); }); test("On small workspaces also show/fetch closed document analysis results", async function () { diff --git a/test/integrationTests/dotnetTest.integration.test.ts b/test/integrationTests/dotnetTest.integration.test.ts index 9187e13f8..bcef544ef 100644 --- a/test/integrationTests/dotnetTest.integration.test.ts +++ b/test/integrationTests/dotnetTest.integration.test.ts @@ -59,7 +59,7 @@ suite(`DotnetTest: ${testAssetWorkspace.description}`, function () { await vscode.commands.executeCommand('dotnet.test.runTestsInContext'); const event = await eventWaiter; - const runTestsRequest = event.request.data; + const runTestsRequest = event!.request.data; expect(runTestsRequest.RunSettings).to.be.undefined; }); @@ -76,7 +76,7 @@ suite(`DotnetTest: ${testAssetWorkspace.description}`, function () { await vscode.commands.executeCommand('dotnet.test.runTestsInContext'); const event = await eventWaiter; - const runTestsRequest = event.request.data; + const runTestsRequest = event!.request.data; expect(runTestsRequest.RunSettings).to.be.equal(absoluteRunSettingsPath); }); @@ -93,11 +93,11 @@ suite(`DotnetTest: ${testAssetWorkspace.description}`, function () { await vscode.commands.executeCommand('dotnet.test.runTestsInContext'); const event = await eventWaiter; - const runTestsRequest = event.request.data; + const runTestsRequest = event!.request.data; expect(runTestsRequest.RunSettings).to.be.not.null; - expect(runTestsRequest.RunSettings.endsWith(endingPath), "Path includes relative path").to.be.true; - expect(path.isAbsolute(runTestsRequest.RunSettings), "Path is absolute").to.be.true; + expect(runTestsRequest.RunSettings!.endsWith(endingPath), "Path includes relative path").to.be.true; + expect(path.isAbsolute(runTestsRequest.RunSettings!), "Path is absolute").to.be.true; }); }); diff --git a/test/integrationTests/inlayHints.integration.test.ts b/test/integrationTests/inlayHints.integration.test.ts index 28557e613..a7c5b09f7 100644 --- a/test/integrationTests/inlayHints.integration.test.ts +++ b/test/integrationTests/inlayHints.integration.test.ts @@ -82,10 +82,10 @@ suite(`Inlay Hints ${testAssetWorkspace.description}`, function () { return; } - assert.equal(actual.textEdits.length, expected.TextEdits.length); + assert.equal(actual.textEdits.length, expected.TextEdits!.length); for (let i = 0; i < actual.textEdits.length; i++) { const actualTextEdit = actual.textEdits[i]; - const expectedTextEdit = expected.TextEdits[i]; + const expectedTextEdit = expected.TextEdits![i]; assertTextEditEqual(actualTextEdit, expectedTextEdit); } diff --git a/test/integrationTests/integrationHelpers.ts b/test/integrationTests/integrationHelpers.ts index 67acb2844..b43aa5a80 100644 --- a/test/integrationTests/integrationHelpers.ts +++ b/test/integrationTests/integrationHelpers.ts @@ -15,8 +15,11 @@ export interface ActivationResult { readonly eventStream: EventStream; } -export async function activateCSharpExtension(): Promise { +export async function activateCSharpExtension(): Promise { const csharpExtension = vscode.extensions.getExtension("ms-dotnettools.csharp"); + if (!csharpExtension) { + throw new Error("Failed to find installation of ms-dotnettools.csharp"); + } if (!csharpExtension.isActive) { await csharpExtension.activate(); @@ -24,20 +27,25 @@ export async function activateCSharpExtension(): Promise { const csharpExtension = vscode.extensions.getExtension("ms-dotnettools.csharp"); + if (!csharpExtension) { + throw new Error("Failed to find installation of ms-dotnettools.csharp"); + } if (!csharpExtension.isActive) { await activateCSharpExtension(); @@ -57,7 +65,7 @@ export async function restartOmniSharpServer(): Promise { } catch (err) { console.log(JSON.stringify(err)); - return; + throw err; } } @@ -74,7 +82,7 @@ export function isSlnWithGenerator(workspace: typeof vscode.workspace) { } function isGivenSln(workspace: typeof vscode.workspace, expectedProjectFileName: string) { - const primeWorkspace = workspace.workspaceFolders[0]; + const primeWorkspace = workspace.workspaceFolders![0]; const projectFileName = primeWorkspace.uri.fsPath.split(path.sep).pop(); return projectFileName === expectedProjectFileName; diff --git a/test/integrationTests/languageMiddleware.integration.test.ts b/test/integrationTests/languageMiddleware.integration.test.ts index c72301207..2f43dd240 100644 --- a/test/integrationTests/languageMiddleware.integration.test.ts +++ b/test/integrationTests/languageMiddleware.integration.test.ts @@ -101,7 +101,7 @@ class TestLanguageMiddleware implements LanguageMiddleware { this.fileToRemapUri = vscode.Uri.file(path.join(projectDirectory, fileToRemap)); } - remapWorkspaceEdit?(workspaceEdit: vscode.WorkspaceEdit, token: vscode.CancellationToken): vscode.ProviderResult { + remapWorkspaceEdit(workspaceEdit: vscode.WorkspaceEdit, token: vscode.CancellationToken): vscode.ProviderResult { const newEdit = new vscode.WorkspaceEdit(); for (const entry of workspaceEdit.entries()) { const uri = entry[0]; @@ -116,7 +116,7 @@ class TestLanguageMiddleware implements LanguageMiddleware { return newEdit; } - remapLocations?(locations: vscode.Location[], token: vscode.CancellationToken): vscode.ProviderResult { + remapLocations(locations: vscode.Location[], token: vscode.CancellationToken): vscode.ProviderResult { const remapped = new Array(); for (const location of locations) { if (location.uri.path === this.fileToRemapUri.path) { diff --git a/test/integrationTests/launchConfiguration.integration.test.ts b/test/integrationTests/launchConfiguration.integration.test.ts index 429d8c44e..add348504 100644 --- a/test/integrationTests/launchConfiguration.integration.test.ts +++ b/test/integrationTests/launchConfiguration.integration.test.ts @@ -41,10 +41,10 @@ suite(`Tasks generation: ${testAssetWorkspace.description}`, function () { const onChangeSubscription = vscode.debug.onDidChangeActiveDebugSession((e) => { onChangeSubscription.dispose(); expect(vscode.debug.activeDebugSession).not.to.be.undefined; - expect(vscode.debug.activeDebugSession.type).to.equal("coreclr"); + expect(vscode.debug.activeDebugSession!.type).to.equal("coreclr"); }); - let result = await vscode.debug.startDebugging(vscode.workspace.workspaceFolders[0], ".NET Core Launch (console)"); + let result = await vscode.debug.startDebugging(vscode.workspace.workspaceFolders![0], ".NET Core Launch (console)"); expect(result, "Debugger could not be started."); let debugSessionTerminated = new Promise(resolve => { diff --git a/test/integrationTests/poll.ts b/test/integrationTests/poll.ts index a0a5fb83e..c5a0b55d5 100644 --- a/test/integrationTests/poll.ts +++ b/test/integrationTests/poll.ts @@ -17,9 +17,9 @@ export async function assertWithPoll( getValue: () => T, duration: number, step: number, - assertForValue: (input: T) => void = defaultAssertion): Promise { + assertForValue: (input: T) => void = defaultAssertion): Promise { - let assertResult: Error = undefined; + let assertResult: Error | undefined = undefined; while (duration > 0) { let value = await getValue(); @@ -28,7 +28,7 @@ export async function assertWithPoll( assertResult = undefined; assertForValue(value); } catch (error) { - assertResult = error; + assertResult = error as Error; } if (assertResult === undefined) { diff --git a/test/integrationTests/reAnalyze.integration.test.ts b/test/integrationTests/reAnalyze.integration.test.ts index 324a689dc..4d336fa77 100644 --- a/test/integrationTests/reAnalyze.integration.test.ts +++ b/test/integrationTests/reAnalyze.integration.test.ts @@ -69,7 +69,7 @@ suite(`ReAnalyze: ${testAssetWorkspace.description}`, function () { let editor = vscode.window.activeTextEditor; - await editor.edit(editorBuilder => editorBuilder.replace(new vscode.Range(2, 0, 2, 50), 'public interface ISomeInterfaceRenamedNow')); + await editor!.edit(editorBuilder => editorBuilder.replace(new vscode.Range(2, 0, 2, 50), 'public interface ISomeInterfaceRenamedNow')); await vscode.commands.executeCommand('o.reanalyze.currentProject', interfaceImplUri); diff --git a/test/integrationTests/sourceGeneratorDefinitionProvider.test.ts b/test/integrationTests/sourceGeneratorDefinitionProvider.test.ts index bdfa96af3..b4a1781ad 100644 --- a/test/integrationTests/sourceGeneratorDefinitionProvider.test.ts +++ b/test/integrationTests/sourceGeneratorDefinitionProvider.test.ts @@ -62,7 +62,7 @@ suite(`${CSharpDefinitionProvider.name}: ${testAssetWorkspace.description}`, () await vscode.commands.executeCommand('vscode.open', generatedCodeUri); await assertWithPoll(() => { }, 15 * 1000, 500, _ => { - const documentText = vscode.window.activeTextEditor.document.getText(); + const documentText = vscode.window.activeTextEditor!.document.getText(); expect(documentText).does.not.contain("Hello world!"); expect(documentText).contains("Goodbye"); }); diff --git a/test/integrationTests/testAssets/testAssetWorkspace.ts b/test/integrationTests/testAssets/testAssetWorkspace.ts index 808bbd077..175cd2129 100644 --- a/test/integrationTests/testAssets/testAssetWorkspace.ts +++ b/test/integrationTests/testAssets/testAssetWorkspace.ts @@ -22,10 +22,10 @@ const testAssetWorkspaces: { [x: string]: ITestAssetWorkspace } = { slnWithGenerator }; -const workspaceName = vscode.workspace.workspaceFolders[0].uri.fsPath +const workspaceName = vscode.workspace.workspaceFolders![0].uri.fsPath .split(path.sep) .pop(); -const activeTestAssetWorkspace = new TestAssetWorkspace(testAssetWorkspaces[workspaceName]); +const activeTestAssetWorkspace = new TestAssetWorkspace(testAssetWorkspaces[workspaceName!]); export default activeTestAssetWorkspace; diff --git a/test/integrationTests/testAssets/testAssets.ts b/test/integrationTests/testAssets/testAssets.ts index 4bf472742..a97bbe7d3 100644 --- a/test/integrationTests/testAssets/testAssets.ts +++ b/test/integrationTests/testAssets/testAssets.ts @@ -21,7 +21,7 @@ export class TestAssetProject { relativeFilePath: string; get projectDirectoryPath(): string { - return path.join(vscode.workspace.workspaceFolders[0].uri.fsPath, + return path.join(vscode.workspace.workspaceFolders![0].uri.fsPath, path.dirname(this.relativeFilePath)); } @@ -53,8 +53,8 @@ export class TestAssetWorkspace { await this.waitForIdle(activation.eventStream); } - async waitForEvent(stream: EventStream, captureType: EventType, stopCondition: (e: T) => boolean = _ => true, timeout: number = 25 * 1000): Promise { - let event: T = null; + async waitForEvent(stream: EventStream, captureType: EventType, stopCondition: (e: T) => boolean = _ => true, timeout: number = 25 * 1000): Promise { + let event: T | undefined = undefined; const subscription = stream.subscribe((e: BaseEvent) => { if (e.type === captureType) { @@ -73,17 +73,25 @@ export class TestAssetWorkspace { } async waitForIdle(stream: EventStream, timeout: number = 25 * 1000): Promise { - let event: BaseEvent = { type: 0 }; + let event: BaseEvent | undefined = { type: 0 }; const subscription = stream.subscribe((e: BaseEvent) => e.type !== EventType.BackgroundDiagnosticStatus && (event = e)); - - await poll(() => event, timeout, 500, e => !e || (event = null)); + await poll(() => event, timeout, 500, e => { + if (e) { + // We're still getting real events, set the event to undefined so we can check if it changed in the next poll. + event = undefined; + return false; + } else { + // The event is still undefined (set by the last poll) which means we haven't recieved any new events - we can exit here. + return true; + } + }); subscription.unsubscribe(); } get vsCodeDirectoryPath(): string { - return path.join(vscode.workspace.workspaceFolders[0].uri.fsPath, ".vscode"); + return path.join(vscode.workspace.workspaceFolders![0].uri.fsPath, ".vscode"); } get launchJsonPath(): string { @@ -95,7 +103,7 @@ export class TestAssetWorkspace { } async cleanupWorkspace(): Promise { - let workspaceRootPath = vscode.workspace.workspaceFolders[0].uri.fsPath; + let workspaceRootPath = vscode.workspace.workspaceFolders![0].uri.fsPath; let cleanUpRoutine = async () => { await vscode.commands.executeCommand("workbench.action.closeAllEditors"); await spawnGit(["clean", "-xdf", "."], { cwd: workspaceRootPath }); diff --git a/test/runIntegrationTests.ts b/test/runIntegrationTests.ts index d28cd4e8c..aabcbcc3a 100644 --- a/test/runIntegrationTests.ts +++ b/test/runIntegrationTests.ts @@ -38,6 +38,10 @@ async function main() { const sln = getSln(workspacePath); if (sln) { // Run a build before the tests, to ensure that source generators are set up correctly + if (!process.env.DOTNET_ROOT) { + throw new Error("Environment variable DOTNET_ROOT is not set"); + } + const dotnetPath = path.join(process.env.DOTNET_ROOT, 'dotnet'); await execChildProcess(`${dotnetPath} build ${sln}`, workspacePath); } diff --git a/test/tsconfig.json b/test/tsconfig.json deleted file mode 100644 index a22bc481d..000000000 --- a/test/tsconfig.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - // This is a temporary tsconfig.json to disable strict mode for the test folder - // until all nullability issues are fixed. - "extends": "../tsconfig.json", - "include": [ - "../src", - "../test", - "../typings" - ], - "compilerOptions": { - "strict": false - } -} diff --git a/test/unitTests/Fakes/FakeDotnetResolver.ts b/test/unitTests/Fakes/FakeDotnetResolver.ts index 0b1b8dbff..defaccd68 100644 --- a/test/unitTests/Fakes/FakeDotnetResolver.ts +++ b/test/unitTests/Fakes/FakeDotnetResolver.ts @@ -9,7 +9,7 @@ import { HostExecutableInformation } from "../../../src/constants/HostExecutable export const fakeMonoInfo: HostExecutableInformation = { version: "someDotNetVersion", path: "someDotNetPath", - env: undefined + env: undefined! }; export class FakeDotnetResolver implements IHostExecutableResolver { @@ -25,6 +25,6 @@ export class FakeDotnetResolver implements IHostExecutableResolver { return Promise.resolve(fakeMonoInfo); } - return Promise.resolve(undefined); + return Promise.resolve(undefined!); } } diff --git a/test/unitTests/Fakes/FakeMonoResolver.ts b/test/unitTests/Fakes/FakeMonoResolver.ts index adb75f390..ed8e17344 100644 --- a/test/unitTests/Fakes/FakeMonoResolver.ts +++ b/test/unitTests/Fakes/FakeMonoResolver.ts @@ -9,7 +9,7 @@ import { HostExecutableInformation } from "../../../src/constants/HostExecutable export const fakeMonoInfo: HostExecutableInformation = { version: "someMonoVersion", path: "somePath", - env: undefined + env: undefined! }; export class FakeMonoResolver implements IHostExecutableResolver { @@ -25,6 +25,6 @@ export class FakeMonoResolver implements IHostExecutableResolver { return Promise.resolve(fakeMonoInfo); } - return Promise.resolve(undefined); + return Promise.resolve(undefined!); } } diff --git a/test/unitTests/Fakes/FakeOptions.ts b/test/unitTests/Fakes/FakeOptions.ts index c0e1b1928..e68baf185 100644 --- a/test/unitTests/Fakes/FakeOptions.ts +++ b/test/unitTests/Fakes/FakeOptions.ts @@ -20,7 +20,7 @@ export function getEmptyOptions(): Options { /* organizeImportsOnFormat */false, /* showReferencesCodeLens */false, /* showTestsCodeLens */false, - /* filteredSymbolsCodeLens */undefined, + /* filteredSymbolsCodeLens */undefined!, /* disableCodeActions */false, /* disableMSBuildDiagnosticWarning */false, /* showOmnisharpLogOnError */false, @@ -55,8 +55,8 @@ export function getEmptyOptions(): Options { /* defaultLaunchSolution */"", /* monoPath */"", /* dotnetPath */"", - /* excludePaths */null, - /* maxProjectFileCountForDiagnosticAnalysis */null, + /* excludePaths */[], + /* maxProjectFileCountForDiagnosticAnalysis */1000, /* testRunSettings */"", /* dotNetCliPaths */[]); } diff --git a/test/unitTests/InstallRuntimeDependencies.test.ts b/test/unitTests/InstallRuntimeDependencies.test.ts index edf3b4bc2..53448c8d1 100644 --- a/test/unitTests/InstallRuntimeDependencies.test.ts +++ b/test/unitTests/InstallRuntimeDependencies.test.ts @@ -80,8 +80,8 @@ suite(`${installRuntimeDependencies.name}`, () => { let installed = await installRuntimeDependencies(packageJSON, extensionPath, installDependencies, eventStream, platformInfo, useFramework); expect(installed).to.be.true; - expect(inputPackage).to.have.length(1); - expect(inputPackage[0]).to.be.deep.equal(AbsolutePathPackage.getAbsolutePathPackage(packageToInstall, extensionPath)); + expect(inputPackage!).to.have.length(1); + expect(inputPackage![0]).to.be.deep.equal(AbsolutePathPackage.getAbsolutePathPackage(packageToInstall, extensionPath)); }); test("Returns false when installDependencies returns false", async () => { diff --git a/test/unitTests/OmnisharpManager.test.ts b/test/unitTests/OmnisharpManager.test.ts index 868fe831d..a1bf09305 100644 --- a/test/unitTests/OmnisharpManager.test.ts +++ b/test/unitTests/OmnisharpManager.test.ts @@ -28,7 +28,7 @@ suite(OmnisharpManager.name, () => { const installPath = ".omnisharp"; let tmpInstallDir: TmpAsset; let extensionPath: string; - let tmpFile: TmpAsset; + let tmpFile: TmpAsset | undefined; let testZip: TestZip; let useFramework: boolean; let suffix: string; @@ -186,7 +186,7 @@ suite(OmnisharpManager.name, () => { tmpFile = undefined; } tmpInstallDir.dispose(); - extensionPath = undefined; + extensionPath = ''; }); }); diff --git a/test/unitTests/OmnisharpPackageCreator.test.ts b/test/unitTests/OmnisharpPackageCreator.test.ts index efeb22a8a..2a6de9316 100644 --- a/test/unitTests/OmnisharpPackageCreator.test.ts +++ b/test/unitTests/OmnisharpPackageCreator.test.ts @@ -31,66 +31,66 @@ suite("GetOmnisharpPackage : Output package depends on the input package and oth test(`Architectures, binaries and platforms do not change useFramework: ${useFramework}`, () => { let testPackage = inputPackages.find(element => (element.platformId && element.platformId == "os-architecture")); - let resultPackage = SetBinaryAndGetPackage(testPackage, useFramework, serverUrl, version, installPath); + let resultPackage = SetBinaryAndGetPackage(testPackage!, useFramework, serverUrl, version, installPath); - resultPackage.architectures.should.equal(testPackage.architectures); - assert.equal(resultPackage.binaries, testPackage.binaries); - resultPackage.platforms.should.equal(testPackage.platforms); + resultPackage.architectures.should.equal(testPackage!.architectures); + assert.equal(resultPackage.binaries, testPackage!.binaries); + resultPackage.platforms.should.equal(testPackage!.platforms); }); test(`Version information is appended to the description useFramework: ${useFramework}`, () => { let testPackage = inputPackages.find(element => (element.platformId && element.platformId == "os-architecture")); - let resultPackage = SetBinaryAndGetPackage(testPackage, useFramework, serverUrl, "1.2.3", installPath); + let resultPackage = SetBinaryAndGetPackage(testPackage!, useFramework, serverUrl, "1.2.3", installPath); - resultPackage.description.should.equal(`${testPackage.description}, Version = 1.2.3`); + resultPackage.description.should.equal(`${testPackage!.description}, Version = 1.2.3`); }); test(`Install path is calculated using the specified path and version useFramework: ${useFramework}`, () => { let testPackage = inputPackages.find(element => (element.platformId && element.platformId == "os-architecture")); - let resultPackage = SetBinaryAndGetPackage(testPackage, useFramework, serverUrl, "1.2.3", "experimentPath"); - resultPackage.installPath.should.equal(`experimentPath/1.2.3${pathSuffix}`); + let resultPackage = SetBinaryAndGetPackage(testPackage!, useFramework, serverUrl, "1.2.3", "experimentPath"); + resultPackage.installPath!.should.equal(`experimentPath/1.2.3${pathSuffix}`); }); test(`Install test path is calculated using specified path, version and ends with OmniSharp.exe or OmniSharp.dll - Windows(x86) useFramework: ${useFramework}`, () => { let testPackage = inputPackages.find(element => (element.platformId && element.platformId == "win-x86")); - let resultPackage = SetBinaryAndGetPackage(testPackage, useFramework, serverUrl, "1.2.3", "experimentPath"); - resultPackage.installTestPath.should.equal(`./experimentPath/1.2.3${pathSuffix}/OmniSharp.${useFramework ? 'exe' : 'dll'}`); + let resultPackage = SetBinaryAndGetPackage(testPackage!, useFramework, serverUrl, "1.2.3", "experimentPath"); + resultPackage.installTestPath!.should.equal(`./experimentPath/1.2.3${pathSuffix}/OmniSharp.${useFramework ? 'exe' : 'dll'}`); }); test(`Install test path is calculated using specified path, version and ends with OmniSharp.exe or OmniSharp.dll - Windows(x64) useFramework: ${useFramework}`, () => { let testPackage = inputPackages.find(element => (element.platformId && element.platformId == "win-x64")); - let resultPackage = SetBinaryAndGetPackage(testPackage, useFramework, serverUrl, "1.2.3", "experimentPath"); - resultPackage.installTestPath.should.equal(`./experimentPath/1.2.3${pathSuffix}/OmniSharp.${useFramework ? 'exe' : 'dll'}`); + let resultPackage = SetBinaryAndGetPackage(testPackage!, useFramework, serverUrl, "1.2.3", "experimentPath"); + resultPackage.installTestPath!.should.equal(`./experimentPath/1.2.3${pathSuffix}/OmniSharp.${useFramework ? 'exe' : 'dll'}`); }); test(`Install test path is calculated using specified path, version and ends with correct binary - OSX useFramework: ${useFramework}`, () => { let testPackage = inputPackages.find(element => (element.platformId && element.platformId == "osx")); - let resultPackage = SetBinaryAndGetPackage(testPackage, useFramework, serverUrl, "1.2.3", "experimentPath"); - resultPackage.installTestPath.should.equal(`./experimentPath/1.2.3${pathSuffix}/${useFramework ? 'run' : 'OmniSharp.dll'}`); + let resultPackage = SetBinaryAndGetPackage(testPackage!, useFramework, serverUrl, "1.2.3", "experimentPath"); + resultPackage.installTestPath!.should.equal(`./experimentPath/1.2.3${pathSuffix}/${useFramework ? 'run' : 'OmniSharp.dll'}`); }); test(`Install test path is calculated using specified path, version and ends with correct binary - Linux(x86) useFramework: ${useFramework}`, () => { let testPackage = inputPackages.find(element => (element.platformId && element.platformId == "linux-x86")); - let resultPackage = SetBinaryAndGetPackage(testPackage, useFramework, serverUrl, "1.2.3", "experimentPath"); - resultPackage.installTestPath.should.equal(`./experimentPath/1.2.3${pathSuffix}/${useFramework ? 'run' : 'OmniSharp.dll'}`); + let resultPackage = SetBinaryAndGetPackage(testPackage!, useFramework, serverUrl, "1.2.3", "experimentPath"); + resultPackage.installTestPath!.should.equal(`./experimentPath/1.2.3${pathSuffix}/${useFramework ? 'run' : 'OmniSharp.dll'}`); }); test(`Install test path is calculated using specified path, version and ends with correct binary - Linux(x64) useFramework: ${useFramework}`, () => { let testPackage = inputPackages.find(element => (element.platformId && element.platformId == "linux-x64")); - let resultPackage = SetBinaryAndGetPackage(testPackage, useFramework, serverUrl, "1.2.3", "experimentPath"); - resultPackage.installTestPath.should.equal(`./experimentPath/1.2.3${pathSuffix}/${useFramework ? 'run' : 'OmniSharp.dll'}`); + let resultPackage = SetBinaryAndGetPackage(testPackage!, useFramework, serverUrl, "1.2.3", "experimentPath"); + resultPackage.installTestPath!.should.equal(`./experimentPath/1.2.3${pathSuffix}/${useFramework ? 'run' : 'OmniSharp.dll'}`); }); }); test('Download url is calculated using server url and version (useFramework: true)', () => { let testPackage = inputPackages.find(element => (element.platformId && element.platformId == "os-architecture")); - let resultPackage = SetBinaryAndGetPackage(testPackage, /* useFramework: */ true, "http://someurl", "1.1.1", installPath); + let resultPackage = SetBinaryAndGetPackage(testPackage!, /* useFramework: */ true, "http://someurl", "1.1.1", installPath); resultPackage.url.should.equal("http://someurl/releases/1.1.1/omnisharp-os-architecture.zip"); }); test('Download url is calculated using server url and version (useFramework: false)', () => { let testPackage = inputPackages.find(element => (element.platformId && element.platformId == "os-architecture")); - let resultPackage = SetBinaryAndGetPackage(testPackage, /* useFramework: */ false, "http://someurl", "1.1.1", installPath); + let resultPackage = SetBinaryAndGetPackage(testPackage!, /* useFramework: */ false, "http://someurl", "1.1.1", installPath); resultPackage.url.should.equal(`http://someurl/releases/1.1.1/omnisharp-os-architecture-net${modernNetVersion}.zip`); }); }); @@ -160,8 +160,8 @@ suite('GetPackagesFromVersion : Gets the experimental omnisharp packages from a let outPackages = GetPackagesFromVersion("1.1.1", useFramework, inputPackages, serverUrl, "experimentPath"); const suffix = useFramework ? '' : `-net${modernNetVersion}`; outPackages.length.should.equal(2); - outPackages[0].installTestPath.should.equal(`./experimentPath/1.1.1${suffix}/OmniSharp.${useFramework ? 'exe' : 'dll'}`); - outPackages[1].installTestPath.should.equal(`./experimentPath/1.1.1${suffix}/${useFramework ? 'run' : 'OmniSharp.dll'}`); + outPackages[0].installTestPath!.should.equal(`./experimentPath/1.1.1${suffix}/OmniSharp.${useFramework ? 'exe' : 'dll'}`); + outPackages[1].installTestPath!.should.equal(`./experimentPath/1.1.1${suffix}/${useFramework ? 'run' : 'OmniSharp.dll'}`); }); test('Returns only omnisharp packages with experimentalIds', () => { @@ -221,8 +221,8 @@ suite('GetPackagesFromVersion : Gets the experimental omnisharp packages from a let outPackages = GetPackagesFromVersion(version, useFramework, inputPackages, serverUrl, installPath); outPackages.length.should.equal(1); - outPackages[0].platformId.should.equal("win-x64"); - outPackages[0].isFramework.should.equal(useFramework); + outPackages[0].platformId!.should.equal("win-x64"); + outPackages[0].isFramework!.should.equal(useFramework); }); }); }); diff --git a/test/unitTests/OptionObserver/OptionChangeObserver.test.ts b/test/unitTests/OptionObserver/OptionChangeObserver.test.ts index b7e9ea9e7..7fbc7d0d3 100644 --- a/test/unitTests/OptionObserver/OptionChangeObserver.test.ts +++ b/test/unitTests/OptionObserver/OptionChangeObserver.test.ts @@ -20,10 +20,10 @@ suite("OmniSharpConfigChangeObserver", () => { let doClickOk: () => void; let doClickCancel: () => void; let signalCommandDone: () => void; - let commandDone: Promise; + let commandDone: Promise | undefined; let vscode: vscode; - let infoMessage: string; - let invokedCommand: string; + let infoMessage: string | undefined; + let invokedCommand: string | undefined; let optionObservable: Subject; setup(() => { @@ -56,7 +56,7 @@ suite("OmniSharpConfigChangeObserver", () => { test('Given an information message if the user clicks cancel, the command is not executed', async () => { doClickCancel(); - await expect(observableFrom(commandDone).pipe(timeout(1)).toPromise()).to.be.rejected; + await expect(observableFrom(commandDone!).pipe(timeout(1)).toPromise()).to.be.rejected; expect(invokedCommand).to.be.undefined; }); @@ -92,9 +92,6 @@ suite("OmniSharpConfigChangeObserver", () => { teardown(() => { infoMessage = undefined; invokedCommand = undefined; - doClickCancel = undefined; - doClickOk = undefined; - signalCommandDone = undefined; commandDone = undefined; }); @@ -102,7 +99,7 @@ suite("OmniSharpConfigChangeObserver", () => { let vscode = getVSCodeWithConfig(); vscode.window.showInformationMessage = async (message: string, ...items: T[]) => { infoMessage = message; - return new Promise(resolve => { + return new Promise(resolve => { doClickCancel = () => { resolve(undefined); }; @@ -113,7 +110,7 @@ suite("OmniSharpConfigChangeObserver", () => { }); }; - vscode.commands.executeCommand = (command: string, ...rest: any[]) => { + vscode.commands.executeCommand = async (command: string, ...rest: any[]) => { invokedCommand = command; signalCommandDone(); return undefined; diff --git a/test/unitTests/logging/CsharpChannelObserver.test.ts b/test/unitTests/logging/CsharpChannelObserver.test.ts index c6f8229cb..2a9fd9242 100644 --- a/test/unitTests/logging/CsharpChannelObserver.test.ts +++ b/test/unitTests/logging/CsharpChannelObserver.test.ts @@ -20,7 +20,7 @@ suite("CsharpChannelObserver", () => { ].forEach((event: BaseEvent) => { test(`${event.constructor.name}: Channel is shown and preserve focus is set to true`, () => { let hasShown = false; - let preserveFocus = false; + let preserveFocus: boolean | undefined = false; let observer = new CsharpChannelObserver({ ...getNullChannel(), show: (preserve) => { diff --git a/test/unitTests/logging/DotnetTestChannelObserver.test.ts b/test/unitTests/logging/DotnetTestChannelObserver.test.ts index a34fede2c..314d9abc0 100644 --- a/test/unitTests/logging/DotnetTestChannelObserver.test.ts +++ b/test/unitTests/logging/DotnetTestChannelObserver.test.ts @@ -10,7 +10,7 @@ import DotnetTestChannelObserver from '../../../src/observers/DotnetTestChannelO suite("DotnetTestChannelObserver", () => { let hasShown: boolean; - let preserveFocus: boolean; + let preserveFocus: boolean | undefined; let observer = new DotnetTestChannelObserver({ ...getNullChannel(), diff --git a/test/unitTests/logging/DotnetTestLoggerObserver.test.ts b/test/unitTests/logging/DotnetTestLoggerObserver.test.ts index c62945d6b..a9b86c45c 100644 --- a/test/unitTests/logging/DotnetTestLoggerObserver.test.ts +++ b/test/unitTests/logging/DotnetTestLoggerObserver.test.ts @@ -89,7 +89,7 @@ suite(`${DotNetTestLoggerObserver.name}`, () => { test(`Displays the outcome of each test`, () => { observer.post(event); - event.results.forEach(result => { + event.results!.forEach(result => { expect(appendedMessage).to.containIgnoreCase(`${result.MethodName}:\n Outcome: ${result.Outcome}`); }); }); @@ -107,14 +107,14 @@ suite(`${DotNetTestLoggerObserver.name}`, () => { test(`Displays the standard output messages if any`, () => { observer.post(event); - event.results.forEach(result => { + event.results!.forEach(result => { result.StandardOutput.forEach(message => expect(appendedMessage).to.contain(message)); }); }); test(`Displays the standard error messages if any`, () => { observer.post(event); - event.results.forEach(result => { + event.results!.forEach(result => { result.StandardError.forEach(message => expect(appendedMessage).to.contain(message)); }); }); diff --git a/test/unitTests/logging/ErrorMessageObserver.test.ts b/test/unitTests/logging/ErrorMessageObserver.test.ts index 6b96ee0c0..4fbef6dcc 100644 --- a/test/unitTests/logging/ErrorMessageObserver.test.ts +++ b/test/unitTests/logging/ErrorMessageObserver.test.ts @@ -18,7 +18,7 @@ suite("ErrorMessageObserver", () => { suiteSetup(() => should()); let vscode: vscode = getFakeVsCode(); - let errorMessage: string; + let errorMessage: string | undefined; let observer = new ErrorMessageObserver(vscode); vscode.window.showErrorMessage = async (message: string, ...items: string[]) => { diff --git a/test/unitTests/logging/InformationMessageObserver.test.ts b/test/unitTests/logging/InformationMessageObserver.test.ts index a3858f7b2..3f10e0d67 100644 --- a/test/unitTests/logging/InformationMessageObserver.test.ts +++ b/test/unitTests/logging/InformationMessageObserver.test.ts @@ -18,17 +18,15 @@ suite("InformationMessageObserver", () => { let doClickOk: () => void; let doClickCancel: () => void; let signalCommandDone: () => void; - let commandDone: Promise; + let commandDone: Promise | undefined; let vscode = getVsCode(); - let infoMessage: string; - let invokedCommand: string; + let infoMessage: string | undefined; + let invokedCommand: string | undefined; let observer: InformationMessageObserver = new InformationMessageObserver(vscode); setup(() => { infoMessage = undefined; invokedCommand = undefined; - doClickCancel = undefined; - doClickOk = undefined; commandDone = new Promise(resolve => { signalCommandDone = () => { resolve(); }; }); @@ -71,7 +69,7 @@ suite("InformationMessageObserver", () => { test('Given an information message if the user clicks cancel, the command is not executed', async () => { observer.post(elem.event); doClickCancel(); - await expect(observableFrom(commandDone).pipe(timeout(1)).toPromise()).to.be.rejected; + await expect(observableFrom(commandDone!).pipe(timeout(1)).toPromise()).to.be.rejected; expect(invokedCommand).to.be.undefined; }); }); @@ -86,7 +84,7 @@ suite("InformationMessageObserver", () => { let vscode = getVSCodeWithConfig(); vscode.window.showInformationMessage = async (message: string, ...items: T[]) => { infoMessage = message; - return new Promise(resolve => { + return new Promise(resolve => { doClickCancel = () => { resolve(undefined); }; @@ -97,7 +95,7 @@ suite("InformationMessageObserver", () => { }); }; - vscode.commands.executeCommand = (command: string, ...rest: any[]) => { + vscode.commands.executeCommand = async (command: string, ...rest: any[]) => { invokedCommand = command; signalCommandDone(); return undefined; diff --git a/test/unitTests/logging/OmnisharpChannelObserver.test.ts b/test/unitTests/logging/OmnisharpChannelObserver.test.ts index 61a8473e4..99f7a647f 100644 --- a/test/unitTests/logging/OmnisharpChannelObserver.test.ts +++ b/test/unitTests/logging/OmnisharpChannelObserver.test.ts @@ -12,7 +12,7 @@ suite("OmnisharpChannelObserver", () => { let hasShown: boolean; let hasCleared: boolean; - let preserveFocus: boolean; + let preserveFocus: boolean | undefined; let vscode: vscode; let observer: OmnisharpChannelObserver; diff --git a/test/unitTests/logging/OmnisharpLoggerObserver.test.ts b/test/unitTests/logging/OmnisharpLoggerObserver.test.ts index 94c566bff..35af054c1 100644 --- a/test/unitTests/logging/OmnisharpLoggerObserver.test.ts +++ b/test/unitTests/logging/OmnisharpLoggerObserver.test.ts @@ -167,7 +167,7 @@ suite("OmnisharpLoggerObserver", () => { suite('OmnisharpServerOnError', () => { test(`Doesnot throw error if FileName is null`, () => { - let event = new OmnisharpServerOnError({ Text: "someText", FileName: null, Line: 1, Column: 2 }); + let event = new OmnisharpServerOnError({ Text: "someText", FileName: null!, Line: 1, Column: 2 }); let fn = function () { observer.post(event); }; expect(fn).to.not.throw(Error); }); diff --git a/test/unitTests/logging/OpenURLObserver.test.ts b/test/unitTests/logging/OpenURLObserver.test.ts index a11148eca..45f6ca33c 100644 --- a/test/unitTests/logging/OpenURLObserver.test.ts +++ b/test/unitTests/logging/OpenURLObserver.test.ts @@ -12,7 +12,7 @@ import { expect } from "chai"; suite(`${OpenURLObserver.name}`, () => { let observer: OpenURLObserver; let vscode: vscode; - let valueToBeParsed: string; + let valueToBeParsed: string | undefined; const url = "someUrl"; let openExternalCalled: boolean; @@ -20,14 +20,14 @@ suite(`${OpenURLObserver.name}`, () => { vscode = getFakeVsCode(); openExternalCalled = false; valueToBeParsed = undefined; - vscode.env.openExternal = (target: Uri) => { + vscode.env.openExternal = async (target: Uri) => { openExternalCalled = true; - return undefined; + return true; }; vscode.Uri.parse = (value: string) => { valueToBeParsed = value; - return undefined; + return undefined!; }; observer = new OpenURLObserver(vscode); diff --git a/test/unitTests/logging/TelemetryObserver.test.ts b/test/unitTests/logging/TelemetryObserver.test.ts index 2c8c7472e..b071e9429 100644 --- a/test/unitTests/logging/TelemetryObserver.test.ts +++ b/test/unitTests/logging/TelemetryObserver.test.ts @@ -17,7 +17,7 @@ suite('TelemetryReporterObserver', () => { suiteSetup(() => should()); let platformInfo = new PlatformInformation("linux", "architecture"); let name = ""; - let property: { [key: string]: string } = null; + let property: { [key: string]: string } | undefined = undefined; let measure: { [key: string]: number }[] = []; let errorProp: string[][] = []; let useModernNet = true; @@ -27,20 +27,20 @@ suite('TelemetryReporterObserver', () => { sendTelemetryEvent: (eventName: string, properties?: { [key: string]: string }, measures?: { [key: string]: number }) => { name += eventName; property = properties; - measure.push(measures); + measure.push(measures!); }, sendTelemetryErrorEvent: (eventName: string, properties?: { [key: string]: string; }, measures?: { [key: string]: number; }, errorProps?: string[]) => { name += eventName; property = properties; - measure.push(measures); - errorProp.push(errorProps); + measure.push(measures!); + errorProp.push(errorProps!); }, }; }, useModernNet); setup(() => { name = ""; - property = null; + property = undefined; measure = []; errorProp = []; }); @@ -81,16 +81,16 @@ suite('TelemetryReporterObserver', () => { }); observer.post(event); - expect(property["ProjectCapabilities"]).to.be.equal("cap1 cap2"); - expect(property["TargetFrameworks"]).to.be.equal("tfm1|tfm2"); - expect(property["ProjectId"]).to.be.equal(projectId); - expect(property["SessionId"]).to.be.equal(sessionId); - expect(property["OutputType"]).to.be.equal(outputKind.toString()); - expect(property["References"]).to.be.equal("ref1|ref2"); - expect(property["FileExtensions"]).to.be.equal(".cs|.cshtml"); - expect(property["FileCounts"]).to.be.equal("7|3"); - expect(property["useModernNet"]).to.be.equal("true"); - expect(property["sdkStyleProject"]).to.be.equal("true"); + expect(property!["ProjectCapabilities"]).to.be.equal("cap1 cap2"); + expect(property!["TargetFrameworks"]).to.be.equal("tfm1|tfm2"); + expect(property!["ProjectId"]).to.be.equal(projectId); + expect(property!["SessionId"]).to.be.equal(sessionId); + expect(property!["OutputType"]).to.be.equal(outputKind.toString()); + expect(property!["References"]).to.be.equal("ref1|ref2"); + expect(property!["FileExtensions"]).to.be.equal(".cs|.cshtml"); + expect(property!["FileCounts"]).to.be.equal("7|3"); + expect(property!["useModernNet"]).to.be.equal("true"); + expect(property!["sdkStyleProject"]).to.be.equal("true"); }); [ @@ -151,7 +151,7 @@ suite('TelemetryReporterObserver', () => { }); test('SendTelemetryEvent is not called for empty run count', () => { - let event = new TestExecutionCountReport({ "framework1": 20 }, null); + let event = new TestExecutionCountReport({ "framework1": 20 }, undefined!); observer.post(event); expect(name).to.not.contain("RunTest"); expect(name).to.contain("DebugTest"); @@ -159,7 +159,7 @@ suite('TelemetryReporterObserver', () => { }); test('SendTelemetryEvent is not called for empty debug count', () => { - let event = new TestExecutionCountReport(null, { "framework1": 20 }); + let event = new TestExecutionCountReport(undefined!, { "framework1": 20 }); observer.post(event); expect(name).to.contain("RunTest"); expect(name).to.not.contain("DebugTest"); @@ -167,7 +167,7 @@ suite('TelemetryReporterObserver', () => { }); test('SendTelemetryEvent is not called for empty debug and run counts', () => { - let event = new TestExecutionCountReport(null, null); + let event = new TestExecutionCountReport(undefined!, undefined!); observer.post(event); expect(name).to.be.empty; expect(measure).to.be.empty; diff --git a/test/unitTests/logging/WarningMessageObserver.test.ts b/test/unitTests/logging/WarningMessageObserver.test.ts index e9a8b2cae..acfd4303e 100644 --- a/test/unitTests/logging/WarningMessageObserver.test.ts +++ b/test/unitTests/logging/WarningMessageObserver.test.ts @@ -25,7 +25,7 @@ suite('WarningMessageObserver', () => { }); let warningMessages: string[]; - let invokedCommand: string; + let invokedCommand: string | undefined; let scheduler: TestScheduler; let assertionObservable: Subject; let observer: WarningMessageObserver; @@ -34,7 +34,7 @@ suite('WarningMessageObserver', () => { vscode.window.showWarningMessage = async (message: string, ...items: T[]) => { warningMessages.push(message); assertionObservable.next(`[${warningMessages.length}] ${message}`); - return new Promise(resolve => { + return new Promise(resolve => { doClickCancel = () => { resolve(undefined); }; @@ -45,10 +45,10 @@ suite('WarningMessageObserver', () => { }); }; - vscode.commands.executeCommand = (command: string, ...rest: any[]) => { + vscode.commands.executeCommand = async (command: string, ...rest: any[]) => { invokedCommand = command; signalCommandDone(); - return undefined; + return undefined; }; setup(() => { diff --git a/test/unitTests/optionStream.test.ts b/test/unitTests/optionStream.test.ts index 9b91b8d24..c3bb67c2d 100644 --- a/test/unitTests/optionStream.test.ts +++ b/test/unitTests/optionStream.test.ts @@ -75,10 +75,10 @@ suite('OptionStream', () => { }); teardown(() => { - options = undefined; - listenerFunction = undefined; + options = undefined!; + listenerFunction = undefined!; subscription.unsubscribe(); - subscription = undefined; + subscription = undefined!; }); }); @@ -97,6 +97,7 @@ suite('OptionStream', () => { function getVSCode(listenerFunction: Array<(e: ConfigurationChangeEvent) => any>): vscode { let vscode = getVSCodeWithConfig(); + // @ts-ignore vscode.workspace.onDidChangeConfiguration = (listener: (e: ConfigurationChangeEvent) => any, thisArgs?: any, disposables?: Disposable[]) => { listenerFunction.push(listener); return new Disposable(() => disposeCalled = true); diff --git a/tsconfig.json b/tsconfig.json index bd1f6e947..2524e0784 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -18,13 +18,7 @@ "gulpfile.ts", // tslint gets quite angry if we don't do this "src", "tasks", - // "test", // Uses its own tsconfig.json until all nullability issues are fixed. + "test", "typings" ] - // "exclude": [ - // "syntaxes", - // "test", // Uses its own tsconfig.json until all nullability issues are fixed. - // ".vscode-test", - // "vsix" - // ] }