From ea6b8d032daee02a2fc1bcfc24a4095a21e475ff Mon Sep 17 00:00:00 2001 From: Sheng Chen Date: Fri, 20 Nov 2020 13:05:58 +0800 Subject: [PATCH] refactor: Wrap open test document code as a command (#1103) --- src/commands/testReportCommands.ts | 33 ++++++- src/constants/commands.ts | 1 + src/extension.ts | 3 +- src/testReportProvider.ts | 29 +----- test/gradle-junit5-suite/codelens.test.ts | 44 ++++----- test/gradle-junit5-suite/testReport.test.ts | 53 ++++++++++ .../modular.gradle.test.ts | 2 +- test/maven-junit4-suite/codelens.test.ts | 96 +++++++++---------- 8 files changed, 160 insertions(+), 101 deletions(-) create mode 100644 test/gradle-junit5-suite/testReport.test.ts diff --git a/src/commands/testReportCommands.ts b/src/commands/testReportCommands.ts index d973c65..bf38bae 100644 --- a/src/commands/testReportCommands.ts +++ b/src/commands/testReportCommands.ts @@ -1,8 +1,11 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. -import { commands, Position, Range, Uri, ViewColumn, window } from 'vscode'; -import { resolveStackTraceLocation } from '../utils/commandUtils'; +import { commands, Position, QuickPickItem, Range, Uri, ViewColumn, window } from 'vscode'; +import { ILocation } from '../../extension.bundle'; +import { logger } from '../logger/logger'; +import { resolveStackTraceLocation, searchTestLocation } from '../utils/commandUtils'; +import { openTextDocument } from './explorerCommands'; export async function openStackTrace(trace: string, fullName: string): Promise { if (!trace || !fullName) { @@ -32,3 +35,29 @@ export async function openStackTrace(trace: string, fullName: string): Promise { + if (uri && range) { + return openTextDocument(Uri.parse(uri), JSON.parse(range) as Range); + } else if (fullName) { + const items: ILocation[] = await searchTestLocation(fullName.slice(fullName.indexOf('@') + 1)); + if (items.length === 1) { + return openTextDocument(Uri.parse(items[0].uri), items[0].range); + } else if (items.length > 1) { + const pick: ILocationQuickPick | undefined = await window.showQuickPick(items.map((item: ILocation) => { + return { label: fullName, detail: Uri.parse(item.uri).fsPath, location: item }; + }), { placeHolder: 'Select the file you want to navigate to' }); + if (pick) { + return openTextDocument(Uri.parse(pick.location.uri), pick.location.range); + } + } else { + logger.error('No test item could be found from Language Server.'); + } + } else { + logger.error('Could not open the document, Neither the Uri nor full name is null.'); + } +} + +interface ILocationQuickPick extends QuickPickItem { + location: ILocation; +} diff --git a/src/constants/commands.ts b/src/constants/commands.ts index fa2c35b..7a3122a 100644 --- a/src/constants/commands.ts +++ b/src/constants/commands.ts @@ -33,4 +33,5 @@ export namespace JavaTestRunnerCommands { export const JAVA_TEST_CANCEL: string = 'java.test.cancel'; export const JAVA_CONFIG_MIGRATE: string = 'java.test.config.migrate'; export const JAVA_TEST_REPORT_OPEN_STACKTRACE: string = 'java.test.report.openStackTrace'; + export const JAVA_TEST_REPORT_OPEN_TEST_SOURCE_LOCATION: string = 'java.test.report.openTestSourceLocation'; } diff --git a/src/extension.ts b/src/extension.ts index eab466d..472072c 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -12,7 +12,7 @@ import { debugTestsFromExplorer, openTextDocument, runTestsFromExplorer } from ' import { openLogFile, showOutputChannel } from './commands/logCommands'; import { runFromCodeLens } from './commands/runFromCodeLens'; import { executeTestsFromUri } from './commands/runFromUri'; -import { openStackTrace } from './commands/testReportCommands'; +import { openStackTrace, openTestSourceLocation } from './commands/testReportCommands'; import { JavaTestRunnerCommands } from './constants/commands'; import { testExplorer } from './explorer/testExplorer'; import { logger } from './logger/logger'; @@ -109,6 +109,7 @@ async function doActivate(_operationId: string, context: ExtensionContext): Prom instrumentOperationAsVsCodeCommand(JavaTestRunnerCommands.RUN_TEST_FROM_EDITOR, async (uri?: Uri) => await executeTestsFromUri(uri, false /* isDebug */)), instrumentOperationAsVsCodeCommand(JavaTestRunnerCommands.DEBUG_TEST_FROM_EDITOR, async (uri?: Uri) => await executeTestsFromUri(uri, true /* isDebug */)), instrumentOperationAsVsCodeCommand(JavaTestRunnerCommands.JAVA_TEST_REPORT_OPEN_STACKTRACE, async (trace: string, fullName: string) => await openStackTrace(trace, fullName)), + instrumentOperationAsVsCodeCommand(JavaTestRunnerCommands.JAVA_TEST_REPORT_OPEN_TEST_SOURCE_LOCATION, async (uri: string, range: string, fullName: string) => await openTestSourceLocation(uri, range, fullName)), ); setContextKeyForDeprecatedConfig(); diff --git a/src/testReportProvider.ts b/src/testReportProvider.ts index 1cbf59e..0e23558 100644 --- a/src/testReportProvider.ts +++ b/src/testReportProvider.ts @@ -4,15 +4,12 @@ import * as compareVersions from 'compare-versions'; import * as path from 'path'; import * as pug from 'pug'; -import { commands, Disposable, ExtensionContext, QuickPickItem, Range, Uri, ViewColumn, Webview, WebviewPanel, window } from 'vscode'; -import { openTextDocument } from './commands/explorerCommands'; +import { commands, Disposable, ExtensionContext, Uri, ViewColumn, Webview, WebviewPanel, window } from 'vscode'; import { JavaTestRunnerCommands } from './constants/commands'; -import { logger } from './logger/logger'; import { ILocation, ITestItem } from './protocols'; import { ITestResult, TestStatus } from './runners/models'; import { IExecutionCache, runnerScheduler } from './runners/runnerScheduler'; import { testItemModel } from './testItemModel'; -import { searchTestLocation } from './utils/commandUtils'; import { getReportPosition } from './utils/settingUtils'; class TestReportProvider implements Disposable { @@ -62,25 +59,7 @@ class TestReportProvider implements Disposable { } switch (message.command) { case JavaTestRunnerCommands.OPEN_DOCUMENT: - if (message.uri && message.range) { - return openTextDocument(Uri.parse(message.uri), JSON.parse(message.range) as Range); - } else if (message.fullName) { - const items: ILocation[] = await searchTestLocation(message.fullName.slice(message.fullName.indexOf('@') + 1)); - if (items.length === 1) { - return openTextDocument(Uri.parse(items[0].uri), items[0].range); - } else if (items.length > 1) { - const pick: ILocationQuickPick | undefined = await window.showQuickPick(items.map((item: ILocation) => { - return { label: message.fullName, detail: Uri.parse(item.uri).fsPath, location: item }; - }), { placeHolder: 'Select the file you want to navigate to' }); - if (pick) { - return openTextDocument(Uri.parse(pick.location.uri), pick.location.range); - } - } else { - logger.error('No test item could be found from Language Server.'); - } - } else { - logger.error('Could not open the document, Neither the Uri nor full name is null.'); - } + commands.executeCommand(JavaTestRunnerCommands.JAVA_TEST_REPORT_OPEN_TEST_SOURCE_LOCATION, message.uri, message.range, message.fullName); break; case JavaTestRunnerCommands.RELAUNCH_TESTS: commands.executeCommand(JavaTestRunnerCommands.RELAUNCH_TESTS); @@ -184,10 +163,6 @@ class TestReportProvider implements Disposable { } } -interface ILocationQuickPick extends QuickPickItem { - location: ILocation; -} - interface ITestReportItem extends ITestResult { fullName: string; location: ILocation | undefined; diff --git a/test/gradle-junit5-suite/codelens.test.ts b/test/gradle-junit5-suite/codelens.test.ts index 59a67e7..bf75754 100644 --- a/test/gradle-junit5-suite/codelens.test.ts +++ b/test/gradle-junit5-suite/codelens.test.ts @@ -19,21 +19,21 @@ suite('Code Lens Tests', function() { const codeLensProvider: TestCodeLensProvider = new TestCodeLensProvider(); const codeLens: CodeLens[] = await codeLensProvider.provideCodeLenses(document, Token.cancellationToken); - assert.equal(codeLens.length, 8, 'Code Lens should appear for @ParameterizedTest annotation'); + assert.strictEqual(codeLens.length, 8, 'Code Lens should appear for @ParameterizedTest annotation'); const command: Command | undefined = codeLens[0].command; - assert.notEqual(command, undefined, 'Command inside Code Lens should not be undefined'); - assert.notEqual(command, null, 'Command inside Code Lens should not be null'); + assert.notStrictEqual(command, undefined, 'Command inside Code Lens should not be undefined'); + assert.notStrictEqual(command, null, 'Command inside Code Lens should not be null'); const testItem: ITestItem[] = command!.arguments as ITestItem[]; - assert.equal(testItem.length, 1); + assert.strictEqual(testItem.length, 1); await commands.executeCommand(command!.command, testItem[0]); const projectName: string = testItem[0].project; const passedDetail: ITestResult| undefined = testResultManager.getResultById(`${projectName}@junit5.ParameterizedAnnotationTest#canRunWithComment`); - assert.equal(passedDetail!.status, TestStatus.Pass, 'Should have passed case'); + assert.strictEqual(passedDetail!.status, TestStatus.Pass, 'Should have passed case'); assert.ok(passedDetail!.duration !== undefined, 'Should have execution time'); }); @@ -53,7 +53,7 @@ suite('Code Lens Tests', function() { const projectName: string = testItem[0].project; const failedDetail: ITestResult| undefined = testResultManager.getResultById(`${projectName}@junit5.ParameterizedAnnotationTest#equal`); - assert.equal(failedDetail!.status, TestStatus.Fail); + assert.strictEqual(failedDetail!.status, TestStatus.Fail); assert.ok(failedDetail!.trace !== undefined, 'Should have error trace'); }); @@ -73,7 +73,7 @@ suite('Code Lens Tests', function() { const projectName: string = testItem[0].project; const detail: ITestResult| undefined = testResultManager.getResultById(`${projectName}@junit5.ParameterizedAnnotationTest#canRunWithGenericTypedParameter`); - assert.equal(detail!.status, TestStatus.Pass); + assert.strictEqual(detail!.status, TestStatus.Pass); }); test("Can run test method annotated with @Testable", async function() { @@ -82,21 +82,21 @@ suite('Code Lens Tests', function() { const codeLensProvider: TestCodeLensProvider = new TestCodeLensProvider(); const codeLens: CodeLens[] = await codeLensProvider.provideCodeLenses(document, Token.cancellationToken); - assert.equal(codeLens.length, 4, 'Code Lens should appear for @Property annotation'); + assert.strictEqual(codeLens.length, 4, 'Code Lens should appear for @Property annotation'); const command: Command | undefined = codeLens[0].command; - assert.notEqual(command, undefined, 'Command inside Code Lens should not be undefined'); - assert.notEqual(command, null, 'Command inside Code Lens should not be null'); + assert.notStrictEqual(command, undefined, 'Command inside Code Lens should not be undefined'); + assert.notStrictEqual(command, null, 'Command inside Code Lens should not be null'); const testItem: ITestItem[] = command!.arguments as ITestItem[]; - assert.equal(testItem.length, 1); + assert.strictEqual(testItem.length, 1); await commands.executeCommand(command!.command, testItem[0]); const projectName: string = testItem[0].project; const failedDetail: ITestResult| undefined = testResultManager.getResultById(`${projectName}@junit5.PropertyTest#absoluteValueOfIntegerAlwaysPositive`); - assert.equal(failedDetail!.status, TestStatus.Fail); + assert.strictEqual(failedDetail!.status, TestStatus.Fail); assert.ok(failedDetail!.duration !== undefined, 'Should have execution time'); }); @@ -106,7 +106,7 @@ suite('Code Lens Tests', function() { const codeLensProvider: TestCodeLensProvider = new TestCodeLensProvider(); let codeLens: CodeLens[] = await codeLensProvider.provideCodeLenses(document, Token.cancellationToken); - assert.equal(codeLens.length, 4); + assert.strictEqual(codeLens.length, 4); }); test("Can run test method annotated with @Nested", async function() { @@ -115,23 +115,23 @@ suite('Code Lens Tests', function() { const codeLensProvider: TestCodeLensProvider = new TestCodeLensProvider(); let codeLens: CodeLens[] = await codeLensProvider.provideCodeLenses(document, Token.cancellationToken); - assert.equal(codeLens.length, 14, 'Code Lens should appear for @Nested annotation'); + assert.strictEqual(codeLens.length, 14, 'Code Lens should appear for @Nested annotation'); const command: Command | undefined = codeLens[0].command; - assert.notEqual(command, undefined, 'Command inside Code Lens should not be undefined'); - assert.notEqual(command, null, 'Command inside Code Lens should not be null'); + assert.notStrictEqual(command, undefined, 'Command inside Code Lens should not be undefined'); + assert.notStrictEqual(command, null, 'Command inside Code Lens should not be null'); const testItem: ITestItem[] = command!.arguments as ITestItem[]; - assert.equal(testItem.length, 1); + assert.strictEqual(testItem.length, 1); await commands.executeCommand(command!.command, testItem[0]); codeLens = await codeLensProvider.provideCodeLenses(document, Token.cancellationToken); - assert.equal(codeLens.length, 21); + assert.strictEqual(codeLens.length, 21); - assert.equal(codeLens[2].command!.title, '$(x)'); - assert.equal(codeLens[5].command!.title, '$(check)'); + assert.strictEqual(codeLens[2].command!.title, '$(x)'); + assert.strictEqual(codeLens[5].command!.title, '$(check)'); }); test("Can correctly update the test results for cucumber tests", async function() { @@ -149,7 +149,7 @@ suite('Code Lens Tests', function() { const projectName: string = testItem[0].project; let result: ITestResult| undefined = testResultManager.getResultById(`${projectName}@The calculator application#client wants to add 2 numbers`); - assert.equal(result!.status, TestStatus.Fail); + assert.strictEqual(result!.status, TestStatus.Fail); // Correct the test case const fileContent: string = await fse.readFile(Uris.GRADLE_CUCUMBER_STEP.fsPath, 'utf-8'); @@ -160,7 +160,7 @@ suite('Code Lens Tests', function() { await commands.executeCommand('java.test.relaunch'); result = testResultManager.getResultById(`${projectName}@The calculator application#client wants to add 2 numbers`); - assert.equal(result!.status, TestStatus.Pass); + assert.strictEqual(result!.status, TestStatus.Pass); // revert the file change await fse.writeFile(Uris.GRADLE_CUCUMBER_STEP.fsPath, fileContent, {encoding: 'utf-8'}); diff --git a/test/gradle-junit5-suite/testReport.test.ts b/test/gradle-junit5-suite/testReport.test.ts new file mode 100644 index 0000000..34ddf15 --- /dev/null +++ b/test/gradle-junit5-suite/testReport.test.ts @@ -0,0 +1,53 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. + +import * as assert from 'assert'; +import { commands, window, extensions } from 'vscode'; +import { Uris } from '../shared'; + +suite('Test Report Tests', function() { + + suiteSetup(async function() { + await extensions.getExtension('vscjava.vscode-java-test')!.activate(); + await commands.executeCommand('workbench.action.closeActiveEditor'); + }); + + test("Can open test source location from uri and range", async function() { + await commands.executeCommand( + 'java.test.report.openTestSourceLocation', + Uris.GRADLE_JUNIT5_PARAMETERIZED_TEST.toString(), + '{"start":{"line":30,"character":16},"end":{"line":30,"character":21}}', + undefined, + ); + + assert.strictEqual(window.activeTextEditor?.document.uri.fsPath, Uris.GRADLE_JUNIT5_PARAMETERIZED_TEST.fsPath); + assert.strictEqual(window.activeTextEditor?.selection.start.line, 30); + }); + + test("Can open test source location from fullName", async function() { + await commands.executeCommand( + 'java.test.report.openTestSourceLocation', + undefined, + undefined, + 'junit5@junit5.ParameterizedAnnotationTest#equal', + ); + + assert.strictEqual(window.activeTextEditor?.document.uri.fsPath, Uris.GRADLE_JUNIT5_PARAMETERIZED_TEST.fsPath); + assert.strictEqual(window.activeTextEditor?.selection.start.line, 30); + }); + + test("Can open test source location from stack trace", async function() { + await commands.executeCommand( + 'java.test.report.openStackTrace', + 'at org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:55)', + 'junit5@junit5.ParameterizedAnnotationTest#equal', + ); + + assert.ok(window.activeTextEditor?.document.uri.fsPath.endsWith('AssertionUtils.class')); + assert.strictEqual(window.activeTextEditor?.selection.start.line, 54); + }); + + teardown(async function() { + await commands.executeCommand('workbench.action.closeActiveEditor'); + }); +}); diff --git a/test/gradle-modular-suite/modular.gradle.test.ts b/test/gradle-modular-suite/modular.gradle.test.ts index 1e76a40..6b56270 100644 --- a/test/gradle-modular-suite/modular.gradle.test.ts +++ b/test/gradle-modular-suite/modular.gradle.test.ts @@ -29,7 +29,7 @@ suite('Modular Porject Tests', function() { await commands.executeCommand(command!.command, testItem![0]); const result: ITestResult | undefined = testResultManager.getResultById(testItem![0].id); - assert.notEqual(result, undefined, 'Test Result for @Test should not be undefined'); + assert.notStrictEqual(result, undefined, 'Test Result for @Test should not be undefined'); }); teardown(async function() { diff --git a/test/maven-junit4-suite/codelens.test.ts b/test/maven-junit4-suite/codelens.test.ts index 23ac18e..4f9eec5 100644 --- a/test/maven-junit4-suite/codelens.test.ts +++ b/test/maven-junit4-suite/codelens.test.ts @@ -18,32 +18,32 @@ suite('Code Lens Tests', function() { const codeLensProvider: TestCodeLensProvider = new TestCodeLensProvider(); const codeLens: CodeLens[] = await codeLensProvider.provideCodeLenses(document, Token.cancellationToken); - assert.equal(codeLens.length, 6, 'Code Lens should appear for @Test annotation'); + assert.strictEqual(codeLens.length, 6, 'Code Lens should appear for @Test annotation'); const command: Command | undefined = codeLens[4].command; - assert.notEqual(command, undefined, 'Command inside Code Lens should not be undefined'); - assert.notEqual(command, null, 'Command inside Code Lens should not be null'); + assert.notStrictEqual(command, undefined, 'Command inside Code Lens should not be undefined'); + assert.notStrictEqual(command, null, 'Command inside Code Lens should not be null'); // TODO: compare test item in cache and run from it. const testItem: ITestItem[] = command!.arguments as ITestItem[]; - assert.notEqual(testItem, undefined, 'Test Item inside Code Lens Command should not be undefined'); - assert.notEqual(testItem, null, 'Test Item inside Code Lens Command should not be null'); - assert.equal(testItem.length, 1, 'Test Item inside Code Lens Command should has one element'); + assert.notStrictEqual(testItem, undefined, 'Test Item inside Code Lens Command should not be undefined'); + assert.notStrictEqual(testItem, null, 'Test Item inside Code Lens Command should not be null'); + assert.strictEqual(testItem.length, 1, 'Test Item inside Code Lens Command should has one element'); await commands.executeCommand(command!.command, testItem[0]); const projectName: string = testItem[0].project; const failedDetail: ITestResult| undefined = testResultManager.getResultById(`${projectName}@junit4.TestAnnotation#shouldFail`); - assert.equal(failedDetail!.status, TestStatus.Fail, 'Should have failed case'); + assert.strictEqual(failedDetail!.status, TestStatus.Fail, 'Should have failed case'); assert.ok(failedDetail!.duration !== undefined, 'Should have execution time'); const passedDetail: ITestResult | undefined = testResultManager.getResultById(`${projectName}@junit4.TestAnnotation#shouldPass`); - assert.equal(passedDetail!.status, TestStatus.Pass, 'Should have passed case'); + assert.strictEqual(passedDetail!.status, TestStatus.Pass, 'Should have passed case'); assert.ok(passedDetail!.duration !== undefined, 'Should have execution time'); const executionCache: IExecutionCache | undefined = runnerScheduler.getExecutionCache(); assert.ok(executionCache!.context != undefined); - assert.equal(executionCache!.results!.length, 2); + assert.strictEqual(executionCache!.results!.length, 2); }); test("Code Lens should be present for JUnit 4's @Theory annotation", async function() { @@ -52,26 +52,26 @@ suite('Code Lens Tests', function() { const codeLensProvider: TestCodeLensProvider = new TestCodeLensProvider(); const codeLens: CodeLens[] = await codeLensProvider.provideCodeLenses(document, Token.cancellationToken); - assert.equal(codeLens.length, 6, 'Code Lens should appear for @Theory annotation'); + assert.strictEqual(codeLens.length, 6, 'Code Lens should appear for @Theory annotation'); const command: Command | undefined = codeLens[4].command; - assert.notEqual(command, undefined, 'Command inside Code Lens should not be undefined'); - assert.notEqual(command, null, 'Command inside Code Lens should not be null'); + assert.notStrictEqual(command, undefined, 'Command inside Code Lens should not be undefined'); + assert.notStrictEqual(command, null, 'Command inside Code Lens should not be null'); const testItem: ITestItem[] = command!.arguments as ITestItem[]; - assert.notEqual(testItem, undefined, 'Test Item inside Code Lens Command should not be undefined'); - assert.notEqual(testItem, null, 'Test Item inside Code Lens Command should not be null'); - assert.equal(testItem.length, 1, 'Test Item inside Code Lens Command should has one element'); + assert.notStrictEqual(testItem, undefined, 'Test Item inside Code Lens Command should not be undefined'); + assert.notStrictEqual(testItem, null, 'Test Item inside Code Lens Command should not be null'); + assert.strictEqual(testItem.length, 1, 'Test Item inside Code Lens Command should has one element'); await await commands.executeCommand(command!.command, testItem[0]); const projectName: string = testItem[0].project; const failedDetail: ITestResult| undefined = testResultManager.getResultById(`${projectName}@junit4.TheoryAnnotation#shouldFail`); - assert.equal(failedDetail!.status, TestStatus.Fail, 'Should have failed case'); + assert.strictEqual(failedDetail!.status, TestStatus.Fail, 'Should have failed case'); assert.ok(failedDetail!.duration !== undefined, 'Should have execution time'); const passedDetail: ITestResult| undefined = testResultManager.getResultById(`${projectName}@junit4.TheoryAnnotation#shouldPass`); - assert.equal(passedDetail!.status, TestStatus.Pass, 'Should have passed case'); + assert.strictEqual(passedDetail!.status, TestStatus.Pass, 'Should have passed case'); assert.ok(passedDetail!.duration !== undefined, 'Should have execution time'); }); @@ -81,26 +81,26 @@ suite('Code Lens Tests', function() { const codeLensProvider: TestCodeLensProvider = new TestCodeLensProvider(); const codeLens: CodeLens[] = await codeLensProvider.provideCodeLenses(document, Token.cancellationToken); - assert.equal(codeLens.length, 2, 'Code Lens should appear for @RunWith annotation'); + assert.strictEqual(codeLens.length, 2, 'Code Lens should appear for @RunWith annotation'); const command: Command | undefined = codeLens[0].command; - assert.notEqual(command, undefined, 'Command inside Code Lens should not be undefined'); - assert.notEqual(command, null, 'Command inside Code Lens should not be null'); + assert.notStrictEqual(command, undefined, 'Command inside Code Lens should not be undefined'); + assert.notStrictEqual(command, null, 'Command inside Code Lens should not be null'); const testItem: any = command!.arguments; - assert.notEqual(testItem, undefined, 'Test Item inside Code Lens Command should not be undefined'); - assert.notEqual(testItem, null, 'Test Item inside Code Lens Command should not be null'); - assert.equal(testItem.length, 1, 'Test Item inside Code Lens Command should has one element'); + assert.notStrictEqual(testItem, undefined, 'Test Item inside Code Lens Command should not be undefined'); + assert.notStrictEqual(testItem, null, 'Test Item inside Code Lens Command should not be null'); + assert.strictEqual(testItem.length, 1, 'Test Item inside Code Lens Command should has one element'); await await commands.executeCommand(command!.command, testItem[0]); const projectName: string = testItem[0].project; const failedDetail: ITestResult| undefined = testResultManager.getResultById(`${projectName}@junit4.TestAnnotation#shouldFail`); - assert.equal(failedDetail!.status, TestStatus.Fail, 'Should have failed case'); + assert.strictEqual(failedDetail!.status, TestStatus.Fail, 'Should have failed case'); assert.ok(failedDetail!.duration !== undefined, 'Should have execution time'); const passedDetail: ITestResult| undefined = testResultManager.getResultById(`${projectName}@junit4.TestAnnotation#shouldPass`); - assert.equal(passedDetail!.status, TestStatus.Pass, 'Should have passed case'); + assert.strictEqual(passedDetail!.status, TestStatus.Pass, 'Should have passed case'); assert.ok(passedDetail!.duration !== undefined, 'Should have execution time'); }); @@ -110,22 +110,22 @@ suite('Code Lens Tests', function() { const codeLensProvider: TestCodeLensProvider = new TestCodeLensProvider(); const codeLens: CodeLens[] = await codeLensProvider.provideCodeLenses(document, Token.cancellationToken); - assert.equal(codeLens.length, 4, 'Code Lens should appear.'); + assert.strictEqual(codeLens.length, 4, 'Code Lens should appear.'); const command: Command | undefined = codeLens[0].command; - assert.notEqual(command, undefined, 'Command inside Code Lens should not be undefined'); - assert.notEqual(command, null, 'Command inside Code Lens should not be null'); + assert.notStrictEqual(command, undefined, 'Command inside Code Lens should not be undefined'); + assert.notStrictEqual(command, null, 'Command inside Code Lens should not be null'); const testItem: any = command!.arguments; - assert.notEqual(testItem, undefined, 'Test Item inside Code Lens Command should not be undefined'); - assert.notEqual(testItem, null, 'Test Item inside Code Lens Command should not be null'); - assert.equal(testItem.length, 1, 'Test Item inside Code Lens Command should has one element'); + assert.notStrictEqual(testItem, undefined, 'Test Item inside Code Lens Command should not be undefined'); + assert.notStrictEqual(testItem, null, 'Test Item inside Code Lens Command should not be null'); + assert.strictEqual(testItem.length, 1, 'Test Item inside Code Lens Command should has one element'); await await commands.executeCommand(command!.command, testItem[0]); const projectName: string = testItem[0].project; const failedDetail: ITestResult| undefined = testResultManager.getResultById(`${projectName}@junit4.ExceptionInBefore#`); - assert.equal(failedDetail!.status, TestStatus.Fail, 'Should have failed case'); + assert.strictEqual(failedDetail!.status, TestStatus.Fail, 'Should have failed case'); assert.ok(failedDetail!.trace !== undefined, 'Should have error trace'); }); @@ -135,22 +135,22 @@ suite('Code Lens Tests', function() { const codeLensProvider: TestCodeLensProvider = new TestCodeLensProvider(); const codeLens: CodeLens[] = await codeLensProvider.provideCodeLenses(document, Token.cancellationToken); - assert.equal(codeLens.length, 4, 'Code Lens should appear for @Test annotation'); + assert.strictEqual(codeLens.length, 4, 'Code Lens should appear for @Test annotation'); const command: Command | undefined = codeLens[0].command; - assert.notEqual(command, undefined, 'Command inside Code Lens should not be undefined'); - assert.notEqual(command, null, 'Command inside Code Lens should not be null'); + assert.notStrictEqual(command, undefined, 'Command inside Code Lens should not be undefined'); + assert.notStrictEqual(command, null, 'Command inside Code Lens should not be null'); const testItem: ITestItem[] = command!.arguments as ITestItem[]; - assert.notEqual(testItem, undefined, 'Test Item inside Code Lens Command should not be undefined'); - assert.notEqual(testItem, null, 'Test Item inside Code Lens Command should not be null'); - assert.equal(testItem.length, 1, 'Test Item inside Code Lens Command should has one element'); + assert.notStrictEqual(testItem, undefined, 'Test Item inside Code Lens Command should not be undefined'); + assert.notStrictEqual(testItem, null, 'Test Item inside Code Lens Command should not be null'); + assert.strictEqual(testItem.length, 1, 'Test Item inside Code Lens Command should has one element'); await commands.executeCommand(command!.command, testItem[0]); const projectName: string = testItem[0].project; const failedDetail: ITestResult| undefined = testResultManager.getResultById(`${projectName}@junit4.ParameterizedTest#test`); - assert.equal(failedDetail!.status, TestStatus.Fail, 'Should have failed case'); + assert.strictEqual(failedDetail!.status, TestStatus.Fail, 'Should have failed case'); assert.ok(failedDetail!.duration !== undefined, 'Should have execution time'); }); @@ -160,26 +160,26 @@ suite('Code Lens Tests', function() { const codeLensProvider: TestCodeLensProvider = new TestCodeLensProvider(); const codeLens: CodeLens[] = await codeLensProvider.provideCodeLenses(document, Token.cancellationToken); - assert.equal(codeLens.length, 4, 'Code Lens should appear for @Test annotation'); + assert.strictEqual(codeLens.length, 4, 'Code Lens should appear for @Test annotation'); const command: Command | undefined = codeLens[0].command; - assert.notEqual(command, undefined, 'Command inside Code Lens should not be undefined'); - assert.notEqual(command, null, 'Command inside Code Lens should not be null'); + assert.notStrictEqual(command, undefined, 'Command inside Code Lens should not be undefined'); + assert.notStrictEqual(command, null, 'Command inside Code Lens should not be null'); const testItem: ITestItem[] = command!.arguments as ITestItem[]; - assert.notEqual(testItem, undefined, 'Test Item inside Code Lens Command should not be undefined'); - assert.notEqual(testItem, null, 'Test Item inside Code Lens Command should not be null'); - assert.equal(testItem.length, 1, 'Test Item inside Code Lens Command should has one element'); + assert.notStrictEqual(testItem, undefined, 'Test Item inside Code Lens Command should not be undefined'); + assert.notStrictEqual(testItem, null, 'Test Item inside Code Lens Command should not be null'); + assert.strictEqual(testItem.length, 1, 'Test Item inside Code Lens Command should has one element'); await commands.executeCommand(command!.command, testItem[0]); const projectName: string = testItem[0].project; const passedDetail: ITestResult| undefined = testResultManager.getResultById(`${projectName}@junit4.ParameterizedWithNameTest#test[0: expect=1]`); - assert.equal(passedDetail!.status, TestStatus.Pass, 'Should have passed case'); + assert.strictEqual(passedDetail!.status, TestStatus.Pass, 'Should have passed case'); assert.ok(passedDetail!.duration !== undefined, 'Should have execution time'); const failedDetail: ITestResult| undefined = testResultManager.getResultById(`${projectName}@junit4.ParameterizedWithNameTest#test[3: expect=()]`); - assert.equal(failedDetail!.status, TestStatus.Fail, 'Should have failed case'); + assert.strictEqual(failedDetail!.status, TestStatus.Fail, 'Should have failed case'); assert.ok(failedDetail!.duration !== undefined, 'Should have execution time'); }); @@ -196,7 +196,7 @@ suite('Code Lens Tests', function() { const projectName: string = testItem[0].project; const skippedDetail: ITestResult| undefined = testResultManager.getResultById(`${projectName}@junit4.AssumeTest#shouldSkip`); - assert.equal(skippedDetail!.status, TestStatus.Skip, 'Should have skipped case'); + assert.strictEqual(skippedDetail!.status, TestStatus.Skip, 'Should have skipped case'); assert.ok(skippedDetail!.duration !== undefined, 'Should have execution time'); });