From 98c08add7e9e400d6b0fb0b9ae56234e422ba316 Mon Sep 17 00:00:00 2001 From: Xiaoyi Chen Date: Fri, 21 Feb 2020 18:19:10 -0800 Subject: [PATCH 01/18] lwc test: basic support for internal dev workspace --- packages/salesforcedx-vscode-lwc/package.json | 4 +- packages/salesforcedx-vscode-lwc/src/index.ts | 11 ++- .../src/messages/i18n.ts | 2 + .../codeLens/lwcTestCodeLensProvider.ts | 6 +- .../commands/forceLwcTestDebugAction.ts | 5 +- .../src/testSupport/index.ts | 13 +++- .../src/testSupport/testRunner/testRunner.ts | 23 ++++-- .../src/testSupport/types/constants.ts | 3 +- .../workspace/getCliArgsFromJestArgs.ts | 43 +++++++++++ .../workspace/getLwcTestRunnerExecutable.ts | 56 ++++++++++++++ .../src/testSupport/workspace/index.ts | 5 ++ .../testSupport/workspace/workspaceService.ts | 76 +++++++++++++++++++ 12 files changed, 227 insertions(+), 20 deletions(-) create mode 100644 packages/salesforcedx-vscode-lwc/src/testSupport/workspace/getCliArgsFromJestArgs.ts create mode 100644 packages/salesforcedx-vscode-lwc/src/testSupport/workspace/getLwcTestRunnerExecutable.ts create mode 100644 packages/salesforcedx-vscode-lwc/src/testSupport/workspace/index.ts create mode 100644 packages/salesforcedx-vscode-lwc/src/testSupport/workspace/workspaceService.ts diff --git a/packages/salesforcedx-vscode-lwc/package.json b/packages/salesforcedx-vscode-lwc/package.json index cd0a8ef8db..ac4a6afd41 100644 --- a/packages/salesforcedx-vscode-lwc/package.json +++ b/packages/salesforcedx-vscode-lwc/package.json @@ -98,8 +98,8 @@ "test": [ { "id": "sfdx.force.lightning.lwc.test.view", - "name": "%force_lightning_lwc_test_view_name%", - "when": "sfdx:project_opened" + "when": "sfdx:project_opened || sfdx:internal_dev", + "name": "%force_lightning_lwc_test_view_name%" } ] }, diff --git a/packages/salesforcedx-vscode-lwc/src/index.ts b/packages/salesforcedx-vscode-lwc/src/index.ts index ab88c8cada..0c920a47a8 100644 --- a/packages/salesforcedx-vscode-lwc/src/index.ts +++ b/packages/salesforcedx-vscode-lwc/src/index.ts @@ -30,7 +30,10 @@ import { import { ESLINT_NODEPATH_CONFIG, LWC_EXTENSION_NAME } from './constants'; import { DevServerService } from './service/devServerService'; import { telemetryService } from './telemetry'; -import { activateLwcTestSupport } from './testSupport'; +import { + activateLwcTestSupport, + shouldActivateLwcTestSupport +} from './testSupport'; // See https://github.com/Microsoft/vscode-languageserver-node/issues/105 export function code2ProtocolConverter(value: Uri) { @@ -116,9 +119,11 @@ export async function activate(context: ExtensionContext) { ); } } + } - // Activate Test support only for SFDX workspace type for now - activateLwcTestSupport(context); + // Activate Test support + if (shouldActivateLwcTestSupport(workspaceType)) { + activateLwcTestSupport(context, workspaceType); } // Notify telemetry that our extension is now active diff --git a/packages/salesforcedx-vscode-lwc/src/messages/i18n.ts b/packages/salesforcedx-vscode-lwc/src/messages/i18n.ts index ffba73af9b..aa97492565 100644 --- a/packages/salesforcedx-vscode-lwc/src/messages/i18n.ts +++ b/packages/salesforcedx-vscode-lwc/src/messages/i18n.ts @@ -47,6 +47,8 @@ export const messages = { 'SFDX: Navigate to Lightning Web Component Test', no_lwc_jest_found_text: 'sfdx-lwc-jest is not installed. Install it from https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.unit_testing_using_jest_installation', + no_lwc_testrunner_found_text: + 'lwc-testrunner is not installed. Install it from https://sfdc.co/lwc-testrunner-installation', no_workspace_folder_found_for_test_text: 'Unable to determine workspace folder for this test', run_test_title: 'Run Test', diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/codeLens/lwcTestCodeLensProvider.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/codeLens/lwcTestCodeLensProvider.ts index 6b3a8ff86a..b78dbb5a9e 100644 --- a/packages/salesforcedx-vscode-lwc/src/testSupport/codeLens/lwcTestCodeLensProvider.ts +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/codeLens/lwcTestCodeLensProvider.ts @@ -14,6 +14,7 @@ import { TextDocument } from 'vscode'; +import { LWC_TEST_DOCUMENT_SELECTOR } from '../types/constants'; import { provideLwcTestCodeLens } from './provideLwcTestCodeLens'; /** @@ -52,10 +53,7 @@ export const lwcTestCodeLensProvider = new LwcTestCodeLensProvider(); export function registerLwcTestCodeLensProvider(context: ExtensionContext) { context.subscriptions.push( languages.registerCodeLensProvider( - { - language: 'javascript', - pattern: '**/lwc/**/*.test.js' - }, + LWC_TEST_DOCUMENT_SELECTOR, lwcTestCodeLensProvider ) ); diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/commands/forceLwcTestDebugAction.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/commands/forceLwcTestDebugAction.ts index 4e322c4273..c50ca87e03 100644 --- a/packages/salesforcedx-vscode-lwc/src/testSupport/commands/forceLwcTestDebugAction.ts +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/commands/forceLwcTestDebugAction.ts @@ -18,6 +18,7 @@ import { FORCE_LWC_TEST_DEBUG_LOG_NAME } from '../types/constants'; import { isLwcJestTest } from '../utils'; import { telemetryService } from '../../telemetry'; +import { workspaceService } from '../workspace/workspaceService'; const debugSessionStartTimes = new Map(); @@ -132,7 +133,9 @@ export function handleDidTerminateDebugSession(session: vscode.DebugSession) { ); if (Array.isArray(startTime)) { telemetryService - .sendCommandEvent(FORCE_LWC_TEST_DEBUG_LOG_NAME, startTime) + .sendCommandEvent(FORCE_LWC_TEST_DEBUG_LOG_NAME, startTime, { + workspaceType: workspaceService.getCurrentWorkspaceTypeForTelemetry() + }) .catch(); } } diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/index.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/index.ts index 639682248f..9e7e0947fd 100644 --- a/packages/salesforcedx-vscode-lwc/src/testSupport/index.ts +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/index.ts @@ -4,6 +4,7 @@ * Licensed under the BSD 3-Clause license. * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ +import { shared as lspCommon } from 'lightning-lsp-common'; import { ExtensionContext } from 'vscode'; import { registerLwcTestCodeLensProvider } from './codeLens/lwcTestCodeLensProvider'; import { registerCommands } from './commands'; @@ -12,8 +13,18 @@ import { lwcTestIndexer } from './testIndexer'; import { taskService } from './testRunner/taskService'; import { testResultsWatcher } from './testRunner/testResultsWatcher'; import { startWatchingEditorFocusChange } from './utils/context'; +import { + shouldActivateLwcTestSupport, + workspaceService +} from './workspace/workspaceService'; -export function activateLwcTestSupport(context: ExtensionContext) { +export { shouldActivateLwcTestSupport }; + +export function activateLwcTestSupport( + context: ExtensionContext, + workspaceType: lspCommon.WorkspaceType +) { + workspaceService.register(context, workspaceType); registerCommands(context); registerLwcTestCodeLensProvider(context); registerLwcTestExplorerTreeView(context); diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/testRunner/testRunner.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/testRunner/testRunner.ts index 19165114e4..5b13f403be 100644 --- a/packages/salesforcedx-vscode-lwc/src/testSupport/testRunner/testRunner.ts +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/testRunner/testRunner.ts @@ -11,7 +11,12 @@ import * as vscode from 'vscode'; import { nls } from '../../messages'; import { telemetryService } from '../../telemetry'; import { TestExecutionInfo, TestInfoKind } from '../types'; -import { getLwcTestRunnerExecutable, getTestWorkspaceFolder } from './index'; +import { + getCliArgsFromJestArgs, + getLwcTestRunnerExecutable, + workspaceService +} from '../workspace'; +import { getTestWorkspaceFolder } from './index'; import { SfdxTask, taskService } from './taskService'; import { testResultsWatcher } from './testResultsWatcher'; @@ -132,12 +137,10 @@ export class TestRunner { const { jestArgs, jestOutputFilePath } = jestExecutionInfo; const cwd = workspaceFolder.uri.fsPath; const lwcTestRunnerExecutable = getLwcTestRunnerExecutable(cwd); - let cliArgs: string[]; - if (this.testRunType === TestRunType.DEBUG) { - cliArgs = ['--debug', '--', ...jestArgs]; - } else { - cliArgs = ['--', ...jestArgs]; - } + const cliArgs: string[] = getCliArgsFromJestArgs( + jestArgs, + this.testRunType + ); if (lwcTestRunnerExecutable) { return { workspaceFolder, @@ -195,7 +198,11 @@ export class TestRunner { if (this.logName) { const startTime = process.hrtime(); sfdxTask.onDidEnd(() => { - telemetryService.sendCommandEvent(this.logName, startTime).catch(); + telemetryService + .sendCommandEvent(this.logName, startTime, { + workspaceType: workspaceService.getCurrentWorkspaceTypeForTelemetry() + }) + .catch(); }); } return sfdxTask.execute(); diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/types/constants.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/types/constants.ts index d925218f67..27bf942d75 100644 --- a/packages/salesforcedx-vscode-lwc/src/testSupport/types/constants.ts +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/types/constants.ts @@ -14,7 +14,8 @@ export const SFDX_PROJECT_JSON_GLOB_PATTERN: GlobPattern = /** * LWC Jest Test glob pattern */ -export const LWC_TEST_GLOB_PATTERN: GlobPattern = '**/lwc/**/*.test.js'; +export const LWC_TEST_GLOB_PATTERN: GlobPattern = + '**/{lwc,modules}/**/*.test.js'; /** * LWC Jest Test document selector */ diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/getCliArgsFromJestArgs.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/getCliArgsFromJestArgs.ts new file mode 100644 index 0000000000..87255a616a --- /dev/null +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/getCliArgsFromJestArgs.ts @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2020, salesforce.com, inc. + * All rights reserved. + * Licensed under the BSD 3-Clause license. + * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause + */ +import { TestRunType } from '../testRunner/testRunner'; +import { + isCoreWorkspace, + isSFDXWorkspace, + workspaceService +} from './workspaceService'; + +/** + * Returns workspace specific jest args from CLI arguments and test run type + * @param jestArgs jest args + * @param testRunType test run type + */ +export function getCliArgsFromJestArgs( + jestArgs: string[], + testRunType: TestRunType +) { + const workspaceType = workspaceService.getCurrentWorkspaceType(); + if (testRunType === TestRunType.DEBUG) { + if (isSFDXWorkspace(workspaceType) || isCoreWorkspace(workspaceType)) { + return ['--debug', '--', ...jestArgs]; + } + // TODO: For LWC OSS + // Debug args are ['test:unit', '--debug', '--passthrough', ...jestArgs] + + // Fallback + return ['--debug', '--', ...jestArgs]; + } else { + if (isSFDXWorkspace(workspaceType) || isCoreWorkspace(workspaceType)) { + return ['--', ...jestArgs]; + } + // TODO: For LWC OSS + // Run/Watch args are ['test:unit', '--passthrough', ...jestArgs] + + // Fallback + return ['--', ...jestArgs]; + } +} diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/getLwcTestRunnerExecutable.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/getLwcTestRunnerExecutable.ts new file mode 100644 index 0000000000..ac55042992 --- /dev/null +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/getLwcTestRunnerExecutable.ts @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2020, salesforce.com, inc. + * All rights reserved. + * Licensed under the BSD 3-Clause license. + * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause + */ +import * as fs from 'fs'; +import * as path from 'path'; +import * as vscode from 'vscode'; +import * as which from 'which'; +import { nls } from '../../messages'; +import { telemetryService } from '../../telemetry'; +import { + isCoreWorkspace, + isSFDXWorkspace, + workspaceService +} from './workspaceService'; + +/** + * Get the absolute path to LWC Test runner executable, installed in an SFDX project. + * @param cwd path to the workspace folder + * @returns path to LWC Test runner + */ +export function getLwcTestRunnerExecutable(cwd: string) { + const workspaceType = workspaceService.getCurrentWorkspaceType(); + if (isSFDXWorkspace(workspaceType)) { + const lwcTestRunnerExecutable = path.join( + cwd, + 'node_modules', + '.bin', + 'lwc-jest' + ); + if (fs.existsSync(lwcTestRunnerExecutable)) { + return lwcTestRunnerExecutable; + } else { + const errorMessage = nls.localize('no_lwc_jest_found_text'); + console.error(errorMessage); + vscode.window.showErrorMessage(errorMessage); + telemetryService + .sendException('lwc_test_no_lwc_jest_found', errorMessage) + .catch(); + } + } else if (isCoreWorkspace(workspaceType)) { + const lwcTestRunnerExecutable = which.sync('lwc-test', { nothrow: true }); + if (lwcTestRunnerExecutable && fs.existsSync(lwcTestRunnerExecutable)) { + return lwcTestRunnerExecutable; + } else { + const errorMessage = nls.localize('no_lwc_testrunner_found_text'); + console.error(errorMessage); + vscode.window.showErrorMessage(errorMessage); + telemetryService + .sendException('lwc_test_no_lwc_testrunner_found', errorMessage) + .catch(); + } + } +} diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/index.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/index.ts new file mode 100644 index 0000000000..84359da8a2 --- /dev/null +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/index.ts @@ -0,0 +1,5 @@ +import { getCliArgsFromJestArgs } from './getCliArgsFromJestArgs'; +import { getLwcTestRunnerExecutable } from './getLwcTestRunnerExecutable'; +import { workspaceService } from './workspaceService'; + +export { getCliArgsFromJestArgs, getLwcTestRunnerExecutable, workspaceService }; diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/workspaceService.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/workspaceService.ts new file mode 100644 index 0000000000..dda350032a --- /dev/null +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/workspaceService.ts @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2020, salesforce.com, inc. + * All rights reserved. + * Licensed under the BSD 3-Clause license. + * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause + */ +import { shared as lspCommon } from 'lightning-lsp-common'; +import { workspace } from 'vscode'; +import * as vscode from 'vscode'; + +class WorkspaceService { + private currentWorkspaceType: lspCommon.WorkspaceType = + lspCommon.WorkspaceType.UNKNOWN; + + public register( + context: vscode.ExtensionContext, + workspaceType: lspCommon.WorkspaceType + ) { + this.setCurrentWorkspaceType(workspaceType); + const handleDidChangeWorkspaceFolders = workspace.onDidChangeWorkspaceFolders( + event => { + if (!workspace.workspaceFolders) { + return; + } + const workspaceUris: string[] = []; + workspace.workspaceFolders.forEach(folder => { + workspaceUris.push(folder.uri.fsPath); + }); + const newWorkspaceType = lspCommon.detectWorkspaceType(workspaceUris); + + // TODO - set context? + if (shouldActivateLwcTestSupport(newWorkspaceType)) { + this.setCurrentWorkspaceType(newWorkspaceType); + } + } + ); + context.subscriptions.push(handleDidChangeWorkspaceFolders); + } + + public getCurrentWorkspaceType() { + return this.currentWorkspaceType; + } + + public setCurrentWorkspaceType(workspaceType: lspCommon.WorkspaceType) { + this.currentWorkspaceType = workspaceType; + } + + /** + * @returns {String} workspace type name for telemetry + */ + public getCurrentWorkspaceTypeForTelemetry(): string { + return ''; + } +} +export const workspaceService = new WorkspaceService(); + +export function isSFDXWorkspace(workspaceType: lspCommon.WorkspaceType) { + return workspaceType === lspCommon.WorkspaceType.SFDX; +} + +export function isCoreWorkspace(workspaceType: lspCommon.WorkspaceType) { + return ( + workspaceType === lspCommon.WorkspaceType.CORE_ALL || + workspaceType === lspCommon.WorkspaceType.CORE_PARTIAL + ); +} + +/** + * Activate LWC Test support for supported workspace types + * @param workspaceType workspace type + */ +export function shouldActivateLwcTestSupport( + workspaceType: lspCommon.WorkspaceType +) { + return isSFDXWorkspace(workspaceType) || isCoreWorkspace(workspaceType); +} From 6d86aa7251e7e58e45ba86ee3ded4aed10b68dfb Mon Sep 17 00:00:00 2001 From: Xiaoyi Chen Date: Fri, 21 Feb 2020 18:35:38 -0800 Subject: [PATCH 02/18] add workspace type name for telemetry --- .../src/testSupport/workspace/workspaceService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/workspaceService.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/workspaceService.ts index dda350032a..6c0822c344 100644 --- a/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/workspaceService.ts +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/workspaceService.ts @@ -49,7 +49,7 @@ class WorkspaceService { * @returns {String} workspace type name for telemetry */ public getCurrentWorkspaceTypeForTelemetry(): string { - return ''; + return lspCommon.WorkspaceType[this.getCurrentWorkspaceType()]; } } export const workspaceService = new WorkspaceService(); From 2cac16e799016fcc1ce10a7ef940affb3f9a2482 Mon Sep 17 00:00:00 2001 From: Xiaoyi Chen Date: Fri, 21 Feb 2020 18:53:37 -0800 Subject: [PATCH 03/18] Update lightning-lsp-common reference --- packages/salesforcedx-vscode-lwc/src/testSupport/index.ts | 2 +- .../src/testSupport/workspace/workspaceService.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/index.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/index.ts index 9e7e0947fd..3ea8176a10 100644 --- a/packages/salesforcedx-vscode-lwc/src/testSupport/index.ts +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/index.ts @@ -4,7 +4,7 @@ * Licensed under the BSD 3-Clause license. * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ -import { shared as lspCommon } from 'lightning-lsp-common'; +import { shared as lspCommon } from '@salesforce/lightning-lsp-common'; import { ExtensionContext } from 'vscode'; import { registerLwcTestCodeLensProvider } from './codeLens/lwcTestCodeLensProvider'; import { registerCommands } from './commands'; diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/workspaceService.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/workspaceService.ts index 6c0822c344..b7ce61b57b 100644 --- a/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/workspaceService.ts +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/workspaceService.ts @@ -4,7 +4,7 @@ * Licensed under the BSD 3-Clause license. * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ -import { shared as lspCommon } from 'lightning-lsp-common'; +import { shared as lspCommon } from '@salesforce/lightning-lsp-common'; import { workspace } from 'vscode'; import * as vscode from 'vscode'; From 9bfc054298f7e4aea5b312ac58a5d8b0e1eb246c Mon Sep 17 00:00:00 2001 From: Xiaoyi Chen Date: Fri, 21 Feb 2020 20:56:02 -0800 Subject: [PATCH 04/18] Fix tests for test runner executable --- .../src/testSupport/testRunner/index.ts | 26 ------- .../workspace/getLwcTestRunnerExecutable.ts | 2 + .../commands/forceLwcTestDebugAction.test.ts | 16 ++-- .../commands/forceLwcTestRunAction.test.ts | 2 +- .../testSupport/mocks/index.ts | 29 ++++++- .../testSupport/testRunner/index.test.ts | 56 ------------- .../getLwcTestRunnerExecutable.test.ts | 78 +++++++++++++++++++ 7 files changed, 116 insertions(+), 93 deletions(-) create mode 100644 packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/workspace/getLwcTestRunnerExecutable.test.ts diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/testRunner/index.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/testRunner/index.ts index dffe72e312..da5ca204cc 100644 --- a/packages/salesforcedx-vscode-lwc/src/testSupport/testRunner/index.ts +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/testRunner/index.ts @@ -4,37 +4,11 @@ * Licensed under the BSD 3-Clause license. * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ -import * as fs from 'fs'; -import * as path from 'path'; import * as vscode from 'vscode'; import { nls } from '../../messages'; import { telemetryService } from '../../telemetry'; import { TestRunner, TestRunType } from './testRunner'; -/** - * Get the absolute path to LWC Test runner executable, installed in an SFDX project. - * @param sfdxProjectPath path to the root directory of an SFDX Project - * @returns path to lwc test runner - */ -export function getLwcTestRunnerExecutable(sfdxProjectPath: string) { - const lwcTestRunnerExecutable = path.join( - sfdxProjectPath, - 'node_modules', - '.bin', - 'lwc-jest' - ); - if (fs.existsSync(lwcTestRunnerExecutable)) { - return lwcTestRunnerExecutable; - } else { - const errorMessage = nls.localize('no_lwc_jest_found_text'); - console.error(errorMessage); - vscode.window.showErrorMessage(errorMessage); - telemetryService - .sendException('lwc_test_no_lwc_jest_found', errorMessage) - .catch(); - } -} - /** * If testUri is specified, returns the workspace folder containing the test if it exists. * Otherwise, return the first workspace folder if it exists. diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/getLwcTestRunnerExecutable.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/getLwcTestRunnerExecutable.ts index ac55042992..3981f144dc 100644 --- a/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/getLwcTestRunnerExecutable.ts +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/getLwcTestRunnerExecutable.ts @@ -53,4 +53,6 @@ export function getLwcTestRunnerExecutable(cwd: string) { .catch(); } } + // TODO + // Test support should not be activated for other workspace types } diff --git a/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/commands/forceLwcTestDebugAction.test.ts b/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/commands/forceLwcTestDebugAction.test.ts index f42289394d..361a35773a 100644 --- a/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/commands/forceLwcTestDebugAction.test.ts +++ b/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/commands/forceLwcTestDebugAction.test.ts @@ -6,6 +6,7 @@ */ import { expect } from 'chai'; +import * as fs from 'fs'; import * as path from 'path'; import { assert, SinonStub, stub } from 'sinon'; import * as uuid from 'uuid'; @@ -20,7 +21,7 @@ import { handleDidStartDebugSession, handleDidTerminateDebugSession } from '../../../../src/testSupport/commands/forceLwcTestDebugAction'; -import * as lwcTestRunner from '../../../../src/testSupport/testRunner'; +import * as lwcTestWorkspace from '../../../../src/testSupport/workspace'; import { TestCaseInfo, TestInfoKind, @@ -49,7 +50,7 @@ describe('Force LWC Test Debug - Code Action', () => { ], Thenable >; - let lwcTestRunnerStub: SinonStub<[string], string | undefined>; + let getLwcTestRunnerExecutableStub: SinonStub<[string], fs.PathLike>; let processHrtimeStub: SinonStub< [([number, number] | undefined)?], [number, number] @@ -64,7 +65,10 @@ describe('Force LWC Test Debug - Code Action', () => { debugStub = stub(vscode.debug, 'startDebugging'); processHrtimeStub = stub(process, 'hrtime'); telemetryStub = stub(telemetryService, 'sendCommandEvent'); - lwcTestRunnerStub = stub(lwcTestRunner, 'getLwcTestRunnerExecutable'); + getLwcTestRunnerExecutableStub = stub( + lwcTestWorkspace, + 'getLwcTestRunnerExecutable' + ); uuidStub.returns(mockUuid); telemetryStub.returns(Promise.resolve()); debugStub.returns(Promise.resolve()); @@ -75,7 +79,7 @@ describe('Force LWC Test Debug - Code Action', () => { debugStub.restore(); processHrtimeStub.restore(); telemetryStub.restore(); - lwcTestRunnerStub.restore(); + getLwcTestRunnerExecutableStub.restore(); }); const root = /^win32/.test(process.platform) ? 'C:\\' : '/var'; @@ -136,7 +140,7 @@ describe('Force LWC Test Debug - Code Action', () => { describe('Debug Test Case', () => { it('Should send telemetry for debug test case', async () => { - lwcTestRunnerStub.returns(lwcTestExecutablePath); + getLwcTestRunnerExecutableStub.returns(lwcTestExecutablePath); const mockExecutionTime: [number, number] = [123, 456]; processHrtimeStub.returns(mockExecutionTime); const debugConfiguration = getDebugConfiguration(command, args, cwd); @@ -164,7 +168,7 @@ describe('Force LWC Test Debug - Code Action', () => { describe('Debug Test File', () => { beforeEach(() => { - lwcTestRunnerStub.returns(lwcTestExecutablePath); + getLwcTestRunnerExecutableStub.returns(lwcTestExecutablePath); mockTestResultWatcher(); }); afterEach(() => { diff --git a/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/commands/forceLwcTestRunAction.test.ts b/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/commands/forceLwcTestRunAction.test.ts index 35a5dc0340..5655edae01 100644 --- a/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/commands/forceLwcTestRunAction.test.ts +++ b/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/commands/forceLwcTestRunAction.test.ts @@ -13,7 +13,7 @@ import { forceLwcTestRun, forceLwcTestRunActiveTextEditorTest } from '../../../../src/testSupport/commands/forceLwcTestRunAction'; -import { getLwcTestRunnerExecutable } from '../../../../src/testSupport/testRunner'; +import { getLwcTestRunnerExecutable } from '../../../../src/testSupport/workspace'; import { FORCE_LWC_TEST_RUN_LOG_NAME } from '../../../../src/testSupport/types/constants'; import { createMockTestFileInfo, diff --git a/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/mocks/index.ts b/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/mocks/index.ts index f30bdd1e04..acdd9db2cf 100644 --- a/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/mocks/index.ts +++ b/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/mocks/index.ts @@ -4,9 +4,11 @@ * Licensed under the BSD 3-Clause license. * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ +import { shared as lspCommon } from '@salesforce/lightning-lsp-common'; import { TestRunner as UtilsTestRunner } from '@salesforce/salesforcedx-utils-vscode/out/src/cli/'; import * as fs from 'fs'; import * as path from 'path'; +import * as which from 'which'; import { SinonStub, stub } from 'sinon'; import * as vscode from 'vscode'; import URI from 'vscode-uri'; @@ -19,6 +21,7 @@ import { } from '../../../../src/testSupport/types'; let existsSyncStub: SinonStub<[fs.PathLike], boolean>; +let whichSyncStub: SinonStub<[string], fs.PathLike>; let sfdxTaskExecuteStub: SinonStub<[], Promise>; let activeTextEditorStub: SinonStub; let getTempFolderStub: SinonStub<[string, string], string>; @@ -43,13 +46,31 @@ export function createMockTestFileInfo() { return testExecutionInfo; } -export function mockGetLwcTestRunnerExecutable() { - existsSyncStub = stub(fs, 'existsSync'); - existsSyncStub.returns(true); +export function mockGetLwcTestRunnerExecutable( + mockWorkspaceType: lspCommon.WorkspaceType = lspCommon.WorkspaceType.SFDX +) { + if (mockWorkspaceType === lspCommon.WorkspaceType.SFDX) { + existsSyncStub = stub(fs, 'existsSync'); + existsSyncStub.returns(true); + } + if ( + mockWorkspaceType === lspCommon.WorkspaceType.CORE_ALL || + mockWorkspaceType === lspCommon.WorkspaceType.CORE_PARTIAL + ) { + whichSyncStub = stub(which, 'sync'); + whichSyncStub.returns(path.join('usr', 'local', 'bin', 'lwc-test')); + existsSyncStub = stub(fs, 'existsSync'); + existsSyncStub.returns(true); + } } export function unmockGetLwcTestRunnerExecutable() { - existsSyncStub.restore(); + if (existsSyncStub) { + existsSyncStub.restore(); + } + if (whichSyncStub) { + whichSyncStub.restore(); + } } export function mockSfdxTaskExecute(immediate?: boolean) { diff --git a/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/testRunner/index.test.ts b/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/testRunner/index.test.ts index e4d92ce57d..c7a48aa862 100644 --- a/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/testRunner/index.test.ts +++ b/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/testRunner/index.test.ts @@ -6,7 +6,6 @@ */ import { TestRunner as UtilsTestRunner } from '@salesforce/salesforcedx-utils-vscode/out/src/cli/'; import { expect } from 'chai'; -import * as fs from 'fs'; import * as path from 'path'; import { assert, SinonStub, stub, SinonSpy, spy } from 'sinon'; import * as uuid from 'uuid'; @@ -19,68 +18,13 @@ import { TestType } from '../../../../src/testSupport/types'; -import { nls } from '../../../../src/messages'; -import { telemetryService } from '../../../../src/telemetry'; import { - getLwcTestRunnerExecutable, TestRunner, TestRunType } from '../../../../src/testSupport/testRunner'; import { InputBuffer } from 'uuid/interfaces'; describe('LWC Test Runner', () => { - describe('getLwcTestRunnerExecutable Unit Tests', () => { - let existsSyncStub: SinonStub<[fs.PathLike], boolean>; - let notificationStub: SinonSpy< - [string, vscode.MessageOptions, ...vscode.MessageItem[]], - Thenable - >; - let telemetryStub: SinonStub<[string, string], Promise>; - beforeEach(() => { - existsSyncStub = stub(fs, 'existsSync'); - notificationStub = spy(vscode.window, 'showErrorMessage'); - telemetryStub = stub(telemetryService, 'sendException'); - telemetryStub.returns(Promise.resolve()); - }); - - afterEach(() => { - existsSyncStub.restore(); - notificationStub.restore(); - telemetryStub.restore(); - }); - const root = /^win32/.test(process.platform) ? 'C:\\' : '/var'; - const sfdxProjectPath = path.join(root, 'project', 'mockSfdxProject'); - - it('Should return LWC Test Runner Path when LWC Test Runner is installed and not display error message', () => { - existsSyncStub.returns(true); - const lwcTestRunnerExecutable = getLwcTestRunnerExecutable( - sfdxProjectPath - ); - expect(lwcTestRunnerExecutable).to.equal( - path.join(sfdxProjectPath, 'node_modules', '.bin', 'lwc-jest') - ); - assert.notCalled(notificationStub); - assert.notCalled(telemetryStub); - }); - - it('Should display error message when LWC Jest Test Runner is not installed', () => { - existsSyncStub.returns(false); - getLwcTestRunnerExecutable(sfdxProjectPath); - assert.calledOnce(notificationStub); - // @ts-ignore - assert.calledWith( - notificationStub, - nls.localize('no_lwc_jest_found_text') - ); - assert.calledOnce(telemetryStub); - assert.calledWith( - telemetryStub, - 'lwc_test_no_lwc_jest_found', - nls.localize('no_lwc_jest_found_text') - ); - }); - }); - describe('Jest Execution Info Unit Tests', () => { let uuidStub: SinonStub< [({ random: InputBuffer } | { rng(): InputBuffer } | undefined)?], diff --git a/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/workspace/getLwcTestRunnerExecutable.test.ts b/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/workspace/getLwcTestRunnerExecutable.test.ts new file mode 100644 index 0000000000..624822a0f0 --- /dev/null +++ b/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/workspace/getLwcTestRunnerExecutable.test.ts @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2020, salesforce.com, inc. + * All rights reserved. + * Licensed under the BSD 3-Clause license. + * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause + */ +import { shared as lspCommon } from '@salesforce/lightning-lsp-common'; +import { expect } from 'chai'; +import * as fs from 'fs'; +import * as path from 'path'; +import * as vscode from 'vscode'; +import { assert, SinonStub, stub } from 'sinon'; +import { nls } from '../../../../src/messages'; +import { telemetryService } from '../../../../src/telemetry'; +import { + getLwcTestRunnerExecutable, + workspaceService +} from '../../../../src/testSupport/workspace'; + +describe('getLwcTestRunnerExecutable Unit Tests', () => { + let existsSyncStub: SinonStub; + let notificationStub: SinonStub; + let telemetryStub: SinonStub; + let getCurrentWorkspaceTypeStub: SinonStub; + beforeEach(() => { + existsSyncStub = stub(fs, 'existsSync'); + notificationStub = stub(vscode.window, 'showErrorMessage'); + telemetryStub = stub(telemetryService, 'sendException'); + getCurrentWorkspaceTypeStub = stub( + workspaceService, + 'getCurrentWorkspaceType' + ); + telemetryStub.returns(Promise.resolve()); + }); + + afterEach(() => { + existsSyncStub.restore(); + notificationStub.restore(); + telemetryStub.restore(); + getCurrentWorkspaceTypeStub.restore(); + }); + const root = /^win32/.test(process.platform) ? 'C:\\' : '/var'; + const sfdxProjectPath = path.join(root, 'project', 'mockSfdxProject'); + + describe('SFDX workspace', () => { + beforeEach(() => { + getCurrentWorkspaceTypeStub.returns(lspCommon.WorkspaceType.SFDX); + }); + + it('Should return LWC Test Runner Path when LWC Test Runner is installed and not display error message', () => { + existsSyncStub.returns(true); + const lwcTestRunnerExecutable = getLwcTestRunnerExecutable( + sfdxProjectPath + ); + expect(lwcTestRunnerExecutable).to.equal( + path.join(sfdxProjectPath, 'node_modules', '.bin', 'lwc-jest') + ); + assert.notCalled(notificationStub); + assert.notCalled(telemetryStub); + }); + + it('Should display error message when LWC Jest Test Runner is not installed', () => { + existsSyncStub.returns(false); + getLwcTestRunnerExecutable(sfdxProjectPath); + assert.calledOnce(notificationStub); + assert.calledWith( + notificationStub, + nls.localize('no_lwc_jest_found_text') + ); + assert.calledOnce(telemetryStub); + assert.calledWith( + telemetryStub, + 'lwc_test_no_lwc_jest_found', + nls.localize('no_lwc_jest_found_text') + ); + }); + }); +}); From f645dd28294f48f404b0928d18b6483adddc1c1d Mon Sep 17 00:00:00 2001 From: Xiaoyi Chen Date: Mon, 24 Feb 2020 19:10:39 -0800 Subject: [PATCH 05/18] cli args and test runner executable tests --- .../testSupport/mocks/index.ts | 2 +- .../workspace/getCliArgsFromJestArgs.test.ts | 83 +++++++++++++++++++ .../getLwcTestRunnerExecutable.test.ts | 46 +++++++++- 3 files changed, 127 insertions(+), 4 deletions(-) create mode 100644 packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/workspace/getCliArgsFromJestArgs.test.ts diff --git a/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/mocks/index.ts b/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/mocks/index.ts index acdd9db2cf..dcd0f129f5 100644 --- a/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/mocks/index.ts +++ b/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/mocks/index.ts @@ -58,7 +58,7 @@ export function mockGetLwcTestRunnerExecutable( mockWorkspaceType === lspCommon.WorkspaceType.CORE_PARTIAL ) { whichSyncStub = stub(which, 'sync'); - whichSyncStub.returns(path.join('usr', 'local', 'bin', 'lwc-test')); + whichSyncStub.returns(path.join('/bin', 'lwc-test')); existsSyncStub = stub(fs, 'existsSync'); existsSyncStub.returns(true); } diff --git a/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/workspace/getCliArgsFromJestArgs.test.ts b/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/workspace/getCliArgsFromJestArgs.test.ts new file mode 100644 index 0000000000..9959a330e1 --- /dev/null +++ b/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/workspace/getCliArgsFromJestArgs.test.ts @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2020, salesforce.com, inc. + * All rights reserved. + * Licensed under the BSD 3-Clause license. + * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause + */ +import { expect } from 'chai'; +import { shared as lspCommon } from '@salesforce/lightning-lsp-common'; +import { assert, SinonStub, stub } from 'sinon'; +import { + getCliArgsFromJestArgs, + workspaceService +} from '../../../../src/testSupport/workspace'; +import { TestRunType } from '../../../../src/testSupport/testRunner/testRunner'; + +describe('getCliArgsFromJestArgs Unit Tests', () => { + const mockJestArgs = [ + '--json', + '--outputFile', + 'test-result.json', + '--testLocationInResults', + '--runTestsByPath', + 'mockTestPath' + ]; + let getCurrentWorkspaceTypeStub: SinonStub; + beforeEach(() => { + getCurrentWorkspaceTypeStub = stub( + workspaceService, + 'getCurrentWorkspaceType' + ); + }); + afterEach(() => { + getCurrentWorkspaceTypeStub.restore(); + }); + + describe('SFDX Workspace', () => { + beforeEach(() => { + getCurrentWorkspaceTypeStub.returns(lspCommon.WorkspaceType.SFDX); + }); + + it('Should return Cli args for run mode', () => { + const cliArgs = getCliArgsFromJestArgs(mockJestArgs, TestRunType.RUN); + const expectedCliArgs = ['--', ...mockJestArgs]; + expect(cliArgs).to.eql(expectedCliArgs); + }); + + it('Should return Cli args for watch mode', () => { + const cliArgs = getCliArgsFromJestArgs(mockJestArgs, TestRunType.WATCH); + const expectedCliArgs = ['--', ...mockJestArgs]; + expect(cliArgs).to.eql(expectedCliArgs); + }); + + it('Should return Cli args for debug mode', () => { + const cliArgs = getCliArgsFromJestArgs(mockJestArgs, TestRunType.DEBUG); + const expectedCliArgs = ['--debug', '--', ...mockJestArgs]; + expect(cliArgs).to.eql(expectedCliArgs); + }); + }); + + describe('Internal Dev Workspace', () => { + beforeEach(() => { + getCurrentWorkspaceTypeStub.returns(lspCommon.WorkspaceType.CORE_PARTIAL); + }); + + it('Should return Cli args for run mode', () => { + const cliArgs = getCliArgsFromJestArgs(mockJestArgs, TestRunType.RUN); + const expectedCliArgs = ['--', ...mockJestArgs]; + expect(cliArgs).to.eql(expectedCliArgs); + }); + + it('Should return Cli args for watch mode', () => { + const cliArgs = getCliArgsFromJestArgs(mockJestArgs, TestRunType.WATCH); + const expectedCliArgs = ['--', ...mockJestArgs]; + expect(cliArgs).to.eql(expectedCliArgs); + }); + + it('Should return Cli args for debug mode', () => { + const cliArgs = getCliArgsFromJestArgs(mockJestArgs, TestRunType.DEBUG); + const expectedCliArgs = ['--debug', '--', ...mockJestArgs]; + expect(cliArgs).to.eql(expectedCliArgs); + }); + }); +}); diff --git a/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/workspace/getLwcTestRunnerExecutable.test.ts b/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/workspace/getLwcTestRunnerExecutable.test.ts index 624822a0f0..1f3f765a1f 100644 --- a/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/workspace/getLwcTestRunnerExecutable.test.ts +++ b/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/workspace/getLwcTestRunnerExecutable.test.ts @@ -10,6 +10,7 @@ import * as fs from 'fs'; import * as path from 'path'; import * as vscode from 'vscode'; import { assert, SinonStub, stub } from 'sinon'; +import * as which from 'which'; import { nls } from '../../../../src/messages'; import { telemetryService } from '../../../../src/telemetry'; import { @@ -19,6 +20,7 @@ import { describe('getLwcTestRunnerExecutable Unit Tests', () => { let existsSyncStub: SinonStub; + let whichSyncStub: SinonStub; let notificationStub: SinonStub; let telemetryStub: SinonStub; let getCurrentWorkspaceTypeStub: SinonStub; @@ -39,10 +41,10 @@ describe('getLwcTestRunnerExecutable Unit Tests', () => { telemetryStub.restore(); getCurrentWorkspaceTypeStub.restore(); }); - const root = /^win32/.test(process.platform) ? 'C:\\' : '/var'; - const sfdxProjectPath = path.join(root, 'project', 'mockSfdxProject'); - describe('SFDX workspace', () => { + const root = /^win32/.test(process.platform) ? 'C:\\' : '/var'; + describe('SFDX Workspace', () => { + const sfdxProjectPath = path.join(root, 'project', 'mockSfdxProject'); beforeEach(() => { getCurrentWorkspaceTypeStub.returns(lspCommon.WorkspaceType.SFDX); }); @@ -75,4 +77,42 @@ describe('getLwcTestRunnerExecutable Unit Tests', () => { ); }); }); + + describe('Internal Dev Workspace', () => { + const projectPath = path.join(root, 'project', 'mockProject'); + const mockLwcTestRunnerPath = path.join('/bin', 'lwc-test'); + beforeEach(() => { + getCurrentWorkspaceTypeStub.returns(lspCommon.WorkspaceType.CORE_PARTIAL); + whichSyncStub = stub(which, 'sync'); + whichSyncStub.returns(mockLwcTestRunnerPath); + }); + + afterEach(() => { + whichSyncStub.restore(); + }); + + it('Should return LWC Test Runner Path when LWC Test Runner is installed and not display error message', () => { + existsSyncStub.returns(true); + const lwcTestRunnerExecutable = getLwcTestRunnerExecutable(projectPath); + expect(lwcTestRunnerExecutable).to.equal(mockLwcTestRunnerPath); + assert.notCalled(notificationStub); + assert.notCalled(telemetryStub); + }); + + it('Should display error message when LWC Jest Test Runner is not installed', () => { + existsSyncStub.returns(false); + getLwcTestRunnerExecutable(projectPath); + assert.calledOnce(notificationStub); + assert.calledWith( + notificationStub, + nls.localize('no_lwc_testrunner_found_text') + ); + assert.calledOnce(telemetryStub); + assert.calledWith( + telemetryStub, + 'lwc_test_no_lwc_testrunner_found', + nls.localize('no_lwc_testrunner_found_text') + ); + }); + }); }); From 59dba5a06bf63f9d29ed9505321cfcaf3722d61f Mon Sep 17 00:00:00 2001 From: Xiaoyi Chen Date: Fri, 28 Feb 2020 16:20:16 -0800 Subject: [PATCH 06/18] refactor workspace type services and add tests --- .../src/testSupport/index.ts | 18 ++- .../workspace/getCliArgsFromJestArgs.ts | 16 ++- .../workspace/getLwcTestRunnerExecutable.ts | 14 +- .../testSupport/workspace/workspaceService.ts | 58 ++++---- .../workspace/getCliArgsFromJestArgs.test.ts | 26 +++- .../workspace/workspaceService.test.ts | 130 ++++++++++++++++++ 6 files changed, 209 insertions(+), 53 deletions(-) create mode 100644 packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/workspace/workspaceService.test.ts diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/index.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/index.ts index 3ea8176a10..a4907003e3 100644 --- a/packages/salesforcedx-vscode-lwc/src/testSupport/index.ts +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/index.ts @@ -13,12 +13,20 @@ import { lwcTestIndexer } from './testIndexer'; import { taskService } from './testRunner/taskService'; import { testResultsWatcher } from './testRunner/testResultsWatcher'; import { startWatchingEditorFocusChange } from './utils/context'; -import { - shouldActivateLwcTestSupport, - workspaceService -} from './workspace/workspaceService'; +import { workspaceService } from './workspace/workspaceService'; -export { shouldActivateLwcTestSupport }; +/** + * Activate LWC Test support for supported workspace types + * @param workspaceType workspace type + */ +export function shouldActivateLwcTestSupport( + workspaceType: lspCommon.WorkspaceType +) { + return ( + workspaceService.isSFDXWorkspace(workspaceType) || + workspaceService.isCoreWorkspace(workspaceType) + ); +} export function activateLwcTestSupport( context: ExtensionContext, diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/getCliArgsFromJestArgs.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/getCliArgsFromJestArgs.ts index 87255a616a..004d9e21f2 100644 --- a/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/getCliArgsFromJestArgs.ts +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/getCliArgsFromJestArgs.ts @@ -5,11 +5,7 @@ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ import { TestRunType } from '../testRunner/testRunner'; -import { - isCoreWorkspace, - isSFDXWorkspace, - workspaceService -} from './workspaceService'; +import { workspaceService } from './workspaceService'; /** * Returns workspace specific jest args from CLI arguments and test run type @@ -22,7 +18,10 @@ export function getCliArgsFromJestArgs( ) { const workspaceType = workspaceService.getCurrentWorkspaceType(); if (testRunType === TestRunType.DEBUG) { - if (isSFDXWorkspace(workspaceType) || isCoreWorkspace(workspaceType)) { + if ( + workspaceService.isSFDXWorkspace(workspaceType) || + workspaceService.isCoreWorkspace(workspaceType) + ) { return ['--debug', '--', ...jestArgs]; } // TODO: For LWC OSS @@ -31,7 +30,10 @@ export function getCliArgsFromJestArgs( // Fallback return ['--debug', '--', ...jestArgs]; } else { - if (isSFDXWorkspace(workspaceType) || isCoreWorkspace(workspaceType)) { + if ( + workspaceService.isSFDXWorkspace(workspaceType) || + workspaceService.isCoreWorkspace(workspaceType) + ) { return ['--', ...jestArgs]; } // TODO: For LWC OSS diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/getLwcTestRunnerExecutable.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/getLwcTestRunnerExecutable.ts index 3981f144dc..12a7f5f0f7 100644 --- a/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/getLwcTestRunnerExecutable.ts +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/getLwcTestRunnerExecutable.ts @@ -10,11 +10,7 @@ import * as vscode from 'vscode'; import * as which from 'which'; import { nls } from '../../messages'; import { telemetryService } from '../../telemetry'; -import { - isCoreWorkspace, - isSFDXWorkspace, - workspaceService -} from './workspaceService'; +import { workspaceService } from './workspaceService'; /** * Get the absolute path to LWC Test runner executable, installed in an SFDX project. @@ -23,7 +19,7 @@ import { */ export function getLwcTestRunnerExecutable(cwd: string) { const workspaceType = workspaceService.getCurrentWorkspaceType(); - if (isSFDXWorkspace(workspaceType)) { + if (workspaceService.isSFDXWorkspace(workspaceType)) { const lwcTestRunnerExecutable = path.join( cwd, 'node_modules', @@ -40,8 +36,10 @@ export function getLwcTestRunnerExecutable(cwd: string) { .sendException('lwc_test_no_lwc_jest_found', errorMessage) .catch(); } - } else if (isCoreWorkspace(workspaceType)) { - const lwcTestRunnerExecutable = which.sync('lwc-test', { nothrow: true }); + } else if (workspaceService.isCoreWorkspace(workspaceType)) { + const lwcTestRunnerExecutable = which.sync('lwc-test', { + nothrow: true + }); if (lwcTestRunnerExecutable && fs.existsSync(lwcTestRunnerExecutable)) { return lwcTestRunnerExecutable; } else { diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/workspaceService.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/workspaceService.ts index b7ce61b57b..da97406ce9 100644 --- a/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/workspaceService.ts +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/workspaceService.ts @@ -12,6 +12,11 @@ class WorkspaceService { private currentWorkspaceType: lspCommon.WorkspaceType = lspCommon.WorkspaceType.UNKNOWN; + /** + * Setup current workspace type and listen to workspace type changes + * @param context extension context + * @param workspaceType + */ public register( context: vscode.ExtensionContext, workspaceType: lspCommon.WorkspaceType @@ -22,19 +27,18 @@ class WorkspaceService { if (!workspace.workspaceFolders) { return; } - const workspaceUris: string[] = []; - workspace.workspaceFolders.forEach(folder => { - workspaceUris.push(folder.uri.fsPath); - }); + const workspaceUris = workspace.workspaceFolders.map( + workspaceFolder => { + return workspaceFolder.uri.fsPath; + } + ); const newWorkspaceType = lspCommon.detectWorkspaceType(workspaceUris); - - // TODO - set context? - if (shouldActivateLwcTestSupport(newWorkspaceType)) { - this.setCurrentWorkspaceType(newWorkspaceType); - } - } + this.setCurrentWorkspaceType(newWorkspaceType); + }, + null, + context.subscriptions ); - context.subscriptions.push(handleDidChangeWorkspaceFolders); + return vscode.Disposable.from(handleDidChangeWorkspaceFolders); } public getCurrentWorkspaceType() { @@ -45,6 +49,17 @@ class WorkspaceService { this.currentWorkspaceType = workspaceType; } + public isSFDXWorkspace(workspaceType: lspCommon.WorkspaceType) { + return workspaceType === lspCommon.WorkspaceType.SFDX; + } + + public isCoreWorkspace(workspaceType: lspCommon.WorkspaceType) { + return ( + workspaceType === lspCommon.WorkspaceType.CORE_ALL || + workspaceType === lspCommon.WorkspaceType.CORE_PARTIAL + ); + } + /** * @returns {String} workspace type name for telemetry */ @@ -53,24 +68,3 @@ class WorkspaceService { } } export const workspaceService = new WorkspaceService(); - -export function isSFDXWorkspace(workspaceType: lspCommon.WorkspaceType) { - return workspaceType === lspCommon.WorkspaceType.SFDX; -} - -export function isCoreWorkspace(workspaceType: lspCommon.WorkspaceType) { - return ( - workspaceType === lspCommon.WorkspaceType.CORE_ALL || - workspaceType === lspCommon.WorkspaceType.CORE_PARTIAL - ); -} - -/** - * Activate LWC Test support for supported workspace types - * @param workspaceType workspace type - */ -export function shouldActivateLwcTestSupport( - workspaceType: lspCommon.WorkspaceType -) { - return isSFDXWorkspace(workspaceType) || isCoreWorkspace(workspaceType); -} diff --git a/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/workspace/getCliArgsFromJestArgs.test.ts b/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/workspace/getCliArgsFromJestArgs.test.ts index 9959a330e1..ccad8ed4e3 100644 --- a/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/workspace/getCliArgsFromJestArgs.test.ts +++ b/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/workspace/getCliArgsFromJestArgs.test.ts @@ -6,7 +6,7 @@ */ import { expect } from 'chai'; import { shared as lspCommon } from '@salesforce/lightning-lsp-common'; -import { assert, SinonStub, stub } from 'sinon'; +import { SinonStub, stub } from 'sinon'; import { getCliArgsFromJestArgs, workspaceService @@ -80,4 +80,28 @@ describe('getCliArgsFromJestArgs Unit Tests', () => { expect(cliArgs).to.eql(expectedCliArgs); }); }); + + describe('Unknown Workspace', () => { + beforeEach(() => { + getCurrentWorkspaceTypeStub.returns(lspCommon.WorkspaceType.UNKNOWN); + }); + + it('Should return Cli args for run mode', () => { + const cliArgs = getCliArgsFromJestArgs(mockJestArgs, TestRunType.RUN); + const expectedCliArgs = ['--', ...mockJestArgs]; + expect(cliArgs).to.eql(expectedCliArgs); + }); + + it('Should return Cli args for watch mode', () => { + const cliArgs = getCliArgsFromJestArgs(mockJestArgs, TestRunType.WATCH); + const expectedCliArgs = ['--', ...mockJestArgs]; + expect(cliArgs).to.eql(expectedCliArgs); + }); + + it('Should return Cli args for debug mode', () => { + const cliArgs = getCliArgsFromJestArgs(mockJestArgs, TestRunType.DEBUG); + const expectedCliArgs = ['--debug', '--', ...mockJestArgs]; + expect(cliArgs).to.eql(expectedCliArgs); + }); + }); }); diff --git a/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/workspace/workspaceService.test.ts b/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/workspace/workspaceService.test.ts new file mode 100644 index 0000000000..4cb5e377b1 --- /dev/null +++ b/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/workspace/workspaceService.test.ts @@ -0,0 +1,130 @@ +import { shared as lspCommon } from '@salesforce/lightning-lsp-common'; +import { expect } from 'chai'; +import * as vscode from 'vscode'; +import { workspaceService } from '../../../../src/testSupport/workspace/workspaceService'; + +describe('Workspace Service Unit Tests', () => { + let originalWorkspaceType: lspCommon.WorkspaceType; + let workspaceServiceRegistration: vscode.Disposable; + + beforeEach(() => { + originalWorkspaceType = workspaceService.getCurrentWorkspaceType(); + }); + + afterEach(() => { + workspaceService.setCurrentWorkspaceType(originalWorkspaceType); + }); + + describe('SFDX workspace', () => { + beforeEach(() => { + workspaceServiceRegistration = workspaceService.register( + {} as any, + lspCommon.WorkspaceType.SFDX + ); + }); + + afterEach(() => { + workspaceServiceRegistration.dispose(); + }); + + it('isSFDXWorkspace should return true', () => { + expect( + workspaceService.isSFDXWorkspace(lspCommon.WorkspaceType.SFDX) + ).to.equal(true); + }); + + it('isCoreWorkspace should return false', () => { + expect( + workspaceService.isCoreWorkspace(lspCommon.WorkspaceType.SFDX) + ).to.equal(false); + }); + + it('getCurrentWorkspaceType should return correctly', () => { + expect(workspaceService.getCurrentWorkspaceType()).to.equal( + lspCommon.WorkspaceType.SFDX + ); + }); + + it('getCurrentWorkspaceTypeForTelemetry should return correctly', () => { + expect(workspaceService.getCurrentWorkspaceTypeForTelemetry()).to.equal( + 'SFDX' + ); + }); + }); + + describe('Core all workspace', () => { + beforeEach(() => { + workspaceServiceRegistration = workspaceService.register( + {} as any, + lspCommon.WorkspaceType.CORE_ALL + ); + }); + + afterEach(() => { + workspaceServiceRegistration.dispose(); + }); + + it('isSFDXWorkspace should return false', () => { + expect( + workspaceService.isSFDXWorkspace(lspCommon.WorkspaceType.CORE_ALL) + ).to.equal(false); + }); + + it('isCoreWorkspace should return true', () => { + expect( + workspaceService.isCoreWorkspace(lspCommon.WorkspaceType.CORE_ALL) + ).to.equal(true); + }); + + it('getCurrentWorkspaceType should return correctly', () => { + expect(workspaceService.getCurrentWorkspaceType()).to.equal( + lspCommon.WorkspaceType.CORE_ALL + ); + }); + + it('getCurrentWorkspaceTypeForTelemetry should return correctly', () => { + expect(workspaceService.getCurrentWorkspaceTypeForTelemetry()).to.equal( + 'CORE_ALL' + ); + }); + }); + + describe('Core partial workspace', () => { + beforeEach(() => { + workspaceServiceRegistration = workspaceService.register( + {} as any, + lspCommon.WorkspaceType.CORE_PARTIAL + ); + }); + + afterEach(() => { + workspaceServiceRegistration.dispose(); + }); + + it('isSFDXWorkspace should return false', () => { + expect( + workspaceService.isSFDXWorkspace(lspCommon.WorkspaceType.CORE_PARTIAL) + ).to.equal(false); + }); + + it('isCoreWorkspace should return true', () => { + expect( + workspaceService.isCoreWorkspace(lspCommon.WorkspaceType.CORE_PARTIAL) + ).to.equal(true); + }); + + it('getCurrentWorkspaceType should return correctly', () => { + expect(workspaceService.getCurrentWorkspaceType()).to.equal( + lspCommon.WorkspaceType.CORE_PARTIAL + ); + }); + + it('getCurrentWorkspaceTypeForTelemetry should return correctly', () => { + expect(workspaceService.getCurrentWorkspaceTypeForTelemetry()).to.equal( + 'CORE_PARTIAL' + ); + }); + }); + + describe('getCurrentWorkspaceTypeForTelemetry', () => {}); +}); From 9e0d7a210c7cabe271588fb75edf9bae2a4ddc3f Mon Sep 17 00:00:00 2001 From: Xiaoyi Chen Date: Fri, 28 Feb 2020 16:59:23 -0800 Subject: [PATCH 07/18] tests for sending workspace type telemetry --- .../testSupport/commands/forceLwcTestDebugAction.test.ts | 5 ++++- .../testSupport/commands/forceLwcTestRunAction.test.ts | 5 ++++- .../testSupport/testRunner/testWatcher.test.ts | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/commands/forceLwcTestDebugAction.test.ts b/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/commands/forceLwcTestDebugAction.test.ts index 361a35773a..0cd469b9fb 100644 --- a/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/commands/forceLwcTestDebugAction.test.ts +++ b/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/commands/forceLwcTestDebugAction.test.ts @@ -161,7 +161,10 @@ describe('Force LWC Test Debug - Code Action', () => { assert.calledWith( telemetryStub, FORCE_LWC_TEST_DEBUG_LOG_NAME, - mockExecutionTime + mockExecutionTime, + { + workspaceType: 'SFDX' + } ); }); }); diff --git a/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/commands/forceLwcTestRunAction.test.ts b/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/commands/forceLwcTestRunAction.test.ts index 5655edae01..ff321e32be 100644 --- a/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/commands/forceLwcTestRunAction.test.ts +++ b/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/commands/forceLwcTestRunAction.test.ts @@ -62,7 +62,10 @@ describe('Force LWC Test Run - Code Action', () => { assert.calledWith( telemetryStub, FORCE_LWC_TEST_RUN_LOG_NAME, - mockExecutionTime + mockExecutionTime, + { + workspaceType: 'SFDX' + } ); processHrtimeStub.restore(); diff --git a/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/testRunner/testWatcher.test.ts b/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/testRunner/testWatcher.test.ts index 7f66cf122f..d8084e9806 100644 --- a/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/testRunner/testWatcher.test.ts +++ b/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/testRunner/testWatcher.test.ts @@ -49,7 +49,10 @@ describe('Test Watcher', () => { assert.calledWith( telemetryStub, FORCE_LWC_TEST_WATCH_LOG_NAME, - mockExecutionTime + mockExecutionTime, + { + workspaceType: 'SFDX' + } ); }); }); From e7cd96e76bcf1941d6d00bce64680243e402ffde Mon Sep 17 00:00:00 2001 From: Xiaoyi Chen Date: Thu, 19 Mar 2020 17:08:18 -0700 Subject: [PATCH 08/18] fix stub types --- packages/salesforcedx-vscode-lwc/package.json | 2 +- .../commands/forceLwcTestDebugAction.test.ts | 5 ++++- .../workspace/getCliArgsFromJestArgs.test.ts | 2 +- .../getLwcTestRunnerExecutable.test.ts | 19 ++++++++++++------- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/packages/salesforcedx-vscode-lwc/package.json b/packages/salesforcedx-vscode-lwc/package.json index ac4a6afd41..0decde3566 100644 --- a/packages/salesforcedx-vscode-lwc/package.json +++ b/packages/salesforcedx-vscode-lwc/package.json @@ -45,7 +45,7 @@ "@types/mocha": "^5", "@types/node": "8.9.3", "@types/sinon": "^7.5.1", - "@types/uuid": "^3.4.5", + "@types/uuid": "^3.4.8", "@types/which": "^1.3.1", "chai": "^4.0.2", "cross-env": "5.2.0", diff --git a/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/commands/forceLwcTestDebugAction.test.ts b/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/commands/forceLwcTestDebugAction.test.ts index 0cd469b9fb..b8c41158cf 100644 --- a/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/commands/forceLwcTestDebugAction.test.ts +++ b/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/commands/forceLwcTestDebugAction.test.ts @@ -50,7 +50,10 @@ describe('Force LWC Test Debug - Code Action', () => { ], Thenable >; - let getLwcTestRunnerExecutableStub: SinonStub<[string], fs.PathLike>; + let getLwcTestRunnerExecutableStub: SinonStub< + [string], + fs.PathLike | undefined + >; let processHrtimeStub: SinonStub< [([number, number] | undefined)?], [number, number] diff --git a/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/workspace/getCliArgsFromJestArgs.test.ts b/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/workspace/getCliArgsFromJestArgs.test.ts index ccad8ed4e3..cb8fc9af31 100644 --- a/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/workspace/getCliArgsFromJestArgs.test.ts +++ b/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/workspace/getCliArgsFromJestArgs.test.ts @@ -22,7 +22,7 @@ describe('getCliArgsFromJestArgs Unit Tests', () => { '--runTestsByPath', 'mockTestPath' ]; - let getCurrentWorkspaceTypeStub: SinonStub; + let getCurrentWorkspaceTypeStub: SinonStub<[], lspCommon.WorkspaceType>; beforeEach(() => { getCurrentWorkspaceTypeStub = stub( workspaceService, diff --git a/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/workspace/getLwcTestRunnerExecutable.test.ts b/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/workspace/getLwcTestRunnerExecutable.test.ts index 1f3f765a1f..fafb3f6829 100644 --- a/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/workspace/getLwcTestRunnerExecutable.test.ts +++ b/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/workspace/getLwcTestRunnerExecutable.test.ts @@ -9,7 +9,7 @@ import { expect } from 'chai'; import * as fs from 'fs'; import * as path from 'path'; import * as vscode from 'vscode'; -import { assert, SinonStub, stub } from 'sinon'; +import { assert, SinonSpy, SinonStub, spy, stub } from 'sinon'; import * as which from 'which'; import { nls } from '../../../../src/messages'; import { telemetryService } from '../../../../src/telemetry'; @@ -19,14 +19,17 @@ import { } from '../../../../src/testSupport/workspace'; describe('getLwcTestRunnerExecutable Unit Tests', () => { - let existsSyncStub: SinonStub; - let whichSyncStub: SinonStub; - let notificationStub: SinonStub; - let telemetryStub: SinonStub; - let getCurrentWorkspaceTypeStub: SinonStub; + let existsSyncStub: SinonStub<[fs.PathLike], boolean>; + let whichSyncStub: SinonStub<[string], fs.PathLike>; + let notificationStub: SinonSpy< + [string, vscode.MessageOptions, ...vscode.MessageItem[]], + Thenable + >; + let telemetryStub: SinonStub<[string, string], Promise>; + let getCurrentWorkspaceTypeStub: SinonStub<[], lspCommon.WorkspaceType>; beforeEach(() => { existsSyncStub = stub(fs, 'existsSync'); - notificationStub = stub(vscode.window, 'showErrorMessage'); + notificationStub = spy(vscode.window, 'showErrorMessage'); telemetryStub = stub(telemetryService, 'sendException'); getCurrentWorkspaceTypeStub = stub( workspaceService, @@ -65,6 +68,7 @@ describe('getLwcTestRunnerExecutable Unit Tests', () => { existsSyncStub.returns(false); getLwcTestRunnerExecutable(sfdxProjectPath); assert.calledOnce(notificationStub); + // @ts-ignore assert.calledWith( notificationStub, nls.localize('no_lwc_jest_found_text') @@ -103,6 +107,7 @@ describe('getLwcTestRunnerExecutable Unit Tests', () => { existsSyncStub.returns(false); getLwcTestRunnerExecutable(projectPath); assert.calledOnce(notificationStub); + // @ts-ignore assert.calledWith( notificationStub, nls.localize('no_lwc_testrunner_found_text') From 89ccec281b0ae56d1c9ed8fcf516f907ceb34eec Mon Sep 17 00:00:00 2001 From: Xiaoyi Chen Date: Fri, 20 Mar 2020 18:14:16 -0700 Subject: [PATCH 09/18] send exception for unsupported workspace --- .../workspace/getLwcTestRunnerExecutable.ts | 10 ++++++++-- .../workspace/getLwcTestRunnerExecutable.test.ts | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/getLwcTestRunnerExecutable.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/getLwcTestRunnerExecutable.ts index 12a7f5f0f7..e57d45955c 100644 --- a/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/getLwcTestRunnerExecutable.ts +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/getLwcTestRunnerExecutable.ts @@ -50,7 +50,13 @@ export function getLwcTestRunnerExecutable(cwd: string) { .sendException('lwc_test_no_lwc_testrunner_found', errorMessage) .catch(); } + } else { + // This is not expected since test support should not be activated for other workspace types + telemetryService + .sendException( + 'lwc_test_no_lwc_testrunner_found', + 'Unsupported workspace' + ) + .catch(); } - // TODO - // Test support should not be activated for other workspace types } diff --git a/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/workspace/getLwcTestRunnerExecutable.test.ts b/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/workspace/getLwcTestRunnerExecutable.test.ts index fafb3f6829..795cfaee90 100644 --- a/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/workspace/getLwcTestRunnerExecutable.test.ts +++ b/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/workspace/getLwcTestRunnerExecutable.test.ts @@ -120,4 +120,18 @@ describe('getLwcTestRunnerExecutable Unit Tests', () => { ); }); }); + + describe('Unsupported Workspace', () => { + const projectPath = path.join(root, 'project', 'mockProject'); + it('Should send exception in unsupported workspace', () => { + getCurrentWorkspaceTypeStub.returns(lspCommon.WorkspaceType.UNKNOWN); + getLwcTestRunnerExecutable(projectPath); + assert.calledOnce(telemetryStub); + assert.calledWith( + telemetryStub, + 'lwc_test_no_lwc_testrunner_found', + 'Unsupported workspace' + ); + }); + }); }); From ee65a0203ea7fc965c8a78f3307a61c9078d1b7b Mon Sep 17 00:00:00 2001 From: Xiaoyi Chen Date: Fri, 20 Mar 2020 18:20:54 -0700 Subject: [PATCH 10/18] update package.json --- packages/salesforcedx-vscode-lwc/package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/salesforcedx-vscode-lwc/package.json b/packages/salesforcedx-vscode-lwc/package.json index 0decde3566..9c6a4fc09a 100644 --- a/packages/salesforcedx-vscode-lwc/package.json +++ b/packages/salesforcedx-vscode-lwc/package.json @@ -81,6 +81,7 @@ "test:vscode-insiders-integration": "cross-env CODE_VERSION=insiders npm run test:vscode-integration" }, "activationEvents": [ + "workspaceContains:modules", "workspaceContains:sfdx-project.json", "workspaceContains:**/workspace-user.xml", "onView:salesforce-lightning-explorer", @@ -221,11 +222,11 @@ }, { "command": "sfdx.force.lightning.lwc.test.runAllTests", - "when": "sfdx:project_opened" + "when": "sfdx:project_opened || sfdx:internal_dev" }, { "command": "sfdx.force.lightning.lwc.test.refreshTestExplorer", - "when": "sfdx:project_opened" + "when": "sfdx:project_opened || sfdx:internal_dev" }, { "command": "sfdx.force.lightning.lwc.test.editorTitle.run", From fd1542df291a26f2642a4931ffe8fb45c9dcb256 Mon Sep 17 00:00:00 2001 From: Xiaoyi Chen Date: Wed, 29 Apr 2020 14:47:17 -0700 Subject: [PATCH 11/18] remove workspaceContains:modules activation event --- packages/salesforcedx-vscode-lwc/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/salesforcedx-vscode-lwc/package.json b/packages/salesforcedx-vscode-lwc/package.json index c3e295bfbf..6da2950498 100644 --- a/packages/salesforcedx-vscode-lwc/package.json +++ b/packages/salesforcedx-vscode-lwc/package.json @@ -81,7 +81,6 @@ "test:vscode-insiders-integration": "cross-env CODE_VERSION=insiders npm run test:vscode-integration" }, "activationEvents": [ - "workspaceContains:modules", "workspaceContains:sfdx-project.json", "workspaceContains:**/workspace-user.xml", "onView:salesforce-lightning-explorer", From 1809a3f5b673fe1cb66d7c3f320010cc05bd2cea Mon Sep 17 00:00:00 2001 From: Xiaoyi Chen Date: Mon, 15 Jun 2020 17:04:27 -0700 Subject: [PATCH 12/18] Activate for core partial workspace --- packages/salesforcedx-vscode-lwc/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/salesforcedx-vscode-lwc/package.json b/packages/salesforcedx-vscode-lwc/package.json index 549f4ba423..22702bc753 100644 --- a/packages/salesforcedx-vscode-lwc/package.json +++ b/packages/salesforcedx-vscode-lwc/package.json @@ -81,6 +81,7 @@ }, "activationEvents": [ "workspaceContains:sfdx-project.json", + "workspaceContains:../workspace-user.xml", "workspaceContains:**/workspace-user.xml", "onCommand:sfdx.force.lightning.lwc.start" ], From 7b7317eecc4f358e045f52a26e075964b3cddd0d Mon Sep 17 00:00:00 2001 From: Xiaoyi Chen Date: Wed, 17 Jun 2020 19:21:06 -0700 Subject: [PATCH 13/18] setting sfdx:internal_dev context eagerly on lwc test features activation; remove onDidChangeWorkspaceFolders since we do not support multiroot --- .../testSupport/workspace/workspaceService.ts | 28 +++------ .../workspace/workspaceService.test.ts | 62 +++++++++++-------- 2 files changed, 47 insertions(+), 43 deletions(-) diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/workspaceService.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/workspaceService.ts index da97406ce9..9a295a246d 100644 --- a/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/workspaceService.ts +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/workspaceService.ts @@ -5,15 +5,17 @@ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ import { shared as lspCommon } from '@salesforce/lightning-lsp-common'; -import { workspace } from 'vscode'; import * as vscode from 'vscode'; +/** + * Provide capabilities for VS Code regarding LWC workspace types defined in lightning-lsp-common + */ class WorkspaceService { private currentWorkspaceType: lspCommon.WorkspaceType = lspCommon.WorkspaceType.UNKNOWN; /** - * Setup current workspace type and listen to workspace type changes + * Setup current workspace type * @param context extension context * @param workspaceType */ @@ -22,23 +24,13 @@ class WorkspaceService { workspaceType: lspCommon.WorkspaceType ) { this.setCurrentWorkspaceType(workspaceType); - const handleDidChangeWorkspaceFolders = workspace.onDidChangeWorkspaceFolders( - event => { - if (!workspace.workspaceFolders) { - return; - } - const workspaceUris = workspace.workspaceFolders.map( - workspaceFolder => { - return workspaceFolder.uri.fsPath; - } - ); - const newWorkspaceType = lspCommon.detectWorkspaceType(workspaceUris); - this.setCurrentWorkspaceType(newWorkspaceType); - }, - null, - context.subscriptions + + const isInternalDev = this.isCoreWorkspace(workspaceType); + vscode.commands.executeCommand( + 'setContext', + 'sfdx:internal_dev', + isInternalDev ); - return vscode.Disposable.from(handleDidChangeWorkspaceFolders); } public getCurrentWorkspaceType() { diff --git a/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/workspace/workspaceService.test.ts b/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/workspace/workspaceService.test.ts index 4cb5e377b1..3ff179fd68 100644 --- a/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/workspace/workspaceService.test.ts +++ b/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/workspace/workspaceService.test.ts @@ -1,30 +1,25 @@ import { shared as lspCommon } from '@salesforce/lightning-lsp-common'; import { expect } from 'chai'; +import { assert, SinonStub, stub } from 'sinon'; import * as vscode from 'vscode'; import { workspaceService } from '../../../../src/testSupport/workspace/workspaceService'; describe('Workspace Service Unit Tests', () => { let originalWorkspaceType: lspCommon.WorkspaceType; - let workspaceServiceRegistration: vscode.Disposable; - + let executeCommandStub: SinonStub<[string, ...any[]], Thenable>; beforeEach(() => { originalWorkspaceType = workspaceService.getCurrentWorkspaceType(); + executeCommandStub = stub(vscode.commands, 'executeCommand'); }); afterEach(() => { workspaceService.setCurrentWorkspaceType(originalWorkspaceType); + executeCommandStub.restore(); }); describe('SFDX workspace', () => { beforeEach(() => { - workspaceServiceRegistration = workspaceService.register( - {} as any, - lspCommon.WorkspaceType.SFDX - ); - }); - - afterEach(() => { - workspaceServiceRegistration.dispose(); + workspaceService.register({} as any, lspCommon.WorkspaceType.SFDX); }); it('isSFDXWorkspace should return true', () => { @@ -50,18 +45,21 @@ describe('Workspace Service Unit Tests', () => { 'SFDX' ); }); - }); - describe('Core all workspace', () => { - beforeEach(() => { - workspaceServiceRegistration = workspaceService.register( - {} as any, - lspCommon.WorkspaceType.CORE_ALL + it('should set sfdx:internal_dev to false', () => { + assert.calledOnce(executeCommandStub); + assert.calledWith( + executeCommandStub, + 'setContext', + 'sfdx:internal_dev', + false ); }); + }); - afterEach(() => { - workspaceServiceRegistration.dispose(); + describe('Core all workspace', () => { + beforeEach(() => { + workspaceService.register({} as any, lspCommon.WorkspaceType.CORE_ALL); }); it('isSFDXWorkspace should return false', () => { @@ -87,20 +85,26 @@ describe('Workspace Service Unit Tests', () => { 'CORE_ALL' ); }); + + it('should set sfdx:internal_dev to true', () => { + assert.calledOnce(executeCommandStub); + assert.calledWith( + executeCommandStub, + 'setContext', + 'sfdx:internal_dev', + true + ); + }); }); describe('Core partial workspace', () => { beforeEach(() => { - workspaceServiceRegistration = workspaceService.register( + workspaceService.register( {} as any, lspCommon.WorkspaceType.CORE_PARTIAL ); }); - afterEach(() => { - workspaceServiceRegistration.dispose(); - }); - it('isSFDXWorkspace should return false', () => { expect( workspaceService.isSFDXWorkspace(lspCommon.WorkspaceType.CORE_PARTIAL) @@ -124,7 +128,15 @@ describe('Workspace Service Unit Tests', () => { 'CORE_PARTIAL' ); }); - }); - describe('getCurrentWorkspaceTypeForTelemetry', () => {}); + it('should set sfdx:internal_dev to true', () => { + assert.calledOnce(executeCommandStub); + assert.calledWith( + executeCommandStub, + 'setContext', + 'sfdx:internal_dev', + true + ); + }); + }); }); From 01968931778bbc5c1569a40d721a06f45566542a Mon Sep 17 00:00:00 2001 From: Xiaoyi Chen Date: Thu, 18 Jun 2020 13:37:07 -0700 Subject: [PATCH 14/18] add licensing --- .../src/testSupport/workspace/index.ts | 6 ++++++ .../testSupport/workspace/workspaceService.test.ts | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/index.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/index.ts index 84359da8a2..6cc242b4f4 100644 --- a/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/index.ts +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/index.ts @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2020, salesforce.com, inc. + * All rights reserved. + * Licensed under the BSD 3-Clause license. + * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause + */ import { getCliArgsFromJestArgs } from './getCliArgsFromJestArgs'; import { getLwcTestRunnerExecutable } from './getLwcTestRunnerExecutable'; import { workspaceService } from './workspaceService'; diff --git a/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/workspace/workspaceService.test.ts b/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/workspace/workspaceService.test.ts index 3ff179fd68..d0594f731d 100644 --- a/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/workspace/workspaceService.test.ts +++ b/packages/salesforcedx-vscode-lwc/test/vscode-integration/testSupport/workspace/workspaceService.test.ts @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2020, salesforce.com, inc. + * All rights reserved. + * Licensed under the BSD 3-Clause license. + * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause + */ import { shared as lspCommon } from '@salesforce/lightning-lsp-common'; import { expect } from 'chai'; import { assert, SinonStub, stub } from 'sinon'; From 3848d2e0394bd433fc4dcb96178828d5a0403027 Mon Sep 17 00:00:00 2001 From: Xiaoyi Chen Date: Mon, 22 Jun 2020 11:02:07 -0700 Subject: [PATCH 15/18] Update packages/salesforcedx-vscode-lwc/src/testSupport/index.ts Co-authored-by: lcampos --- packages/salesforcedx-vscode-lwc/src/testSupport/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/index.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/index.ts index a4907003e3..274dbc5d78 100644 --- a/packages/salesforcedx-vscode-lwc/src/testSupport/index.ts +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/index.ts @@ -13,7 +13,7 @@ import { lwcTestIndexer } from './testIndexer'; import { taskService } from './testRunner/taskService'; import { testResultsWatcher } from './testRunner/testResultsWatcher'; import { startWatchingEditorFocusChange } from './utils/context'; -import { workspaceService } from './workspace/workspaceService'; +import { workspaceService } from './workspace'; /** * Activate LWC Test support for supported workspace types From dcae08f7d096da27aaf5ce77df726bb798057db6 Mon Sep 17 00:00:00 2001 From: Xiaoyi Chen Date: Mon, 22 Jun 2020 11:33:05 -0700 Subject: [PATCH 16/18] move getTestWorkspaceFolder to workspace module --- .../commands/forceLwcTestRunAction.ts | 3 +- .../src/testSupport/testRunner/index.ts | 33 ---------------- .../src/testSupport/testRunner/testRunner.ts | 2 +- .../workspace/getTestWorkspaceFolder.ts | 38 +++++++++++++++++++ .../src/testSupport/workspace/index.ts | 8 +++- 5 files changed, 48 insertions(+), 36 deletions(-) create mode 100644 packages/salesforcedx-vscode-lwc/src/testSupport/workspace/getTestWorkspaceFolder.ts diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/commands/forceLwcTestRunAction.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/commands/forceLwcTestRunAction.ts index 38fd00f670..3ff42e55ca 100644 --- a/packages/salesforcedx-vscode-lwc/src/testSupport/commands/forceLwcTestRunAction.ts +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/commands/forceLwcTestRunAction.ts @@ -5,7 +5,7 @@ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ import * as vscode from 'vscode'; -import { getTestWorkspaceFolder, TestRunner, TestRunType } from '../testRunner'; +import { TestRunner, TestRunType } from '../testRunner'; import { TestDirectoryInfo, TestExecutionInfo, @@ -15,6 +15,7 @@ import { } from '../types'; import { FORCE_LWC_TEST_RUN_LOG_NAME } from '../types/constants'; import { isLwcJestTest } from '../utils'; +import { getTestWorkspaceFolder } from '../workspace'; /** * Run an LWC Jest test from provided test execution info diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/testRunner/index.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/testRunner/index.ts index da5ca204cc..bd55379da4 100644 --- a/packages/salesforcedx-vscode-lwc/src/testSupport/testRunner/index.ts +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/testRunner/index.ts @@ -4,38 +4,5 @@ * Licensed under the BSD 3-Clause license. * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ -import * as vscode from 'vscode'; -import { nls } from '../../messages'; -import { telemetryService } from '../../telemetry'; import { TestRunner, TestRunType } from './testRunner'; - -/** - * If testUri is specified, returns the workspace folder containing the test if it exists. - * Otherwise, return the first workspace folder if it exists. - * @param testUri optional testUri - */ -export function getTestWorkspaceFolder(testUri?: vscode.Uri) { - let workspaceFolder; - if (testUri) { - workspaceFolder = vscode.workspace.getWorkspaceFolder(testUri); - } else { - workspaceFolder = vscode.workspace.workspaceFolders![0]; - } - if (workspaceFolder) { - return workspaceFolder; - } else { - const errorMessage = nls.localize( - 'no_workspace_folder_found_for_test_text' - ); - console.error(errorMessage); - vscode.window.showErrorMessage(errorMessage); - telemetryService - .sendException( - 'lwc_test_no_workspace_folder_found_for_test', - errorMessage - ) - .catch(); - } -} - export { TestRunner, TestRunType }; diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/testRunner/testRunner.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/testRunner/testRunner.ts index 5b13f403be..685a784601 100644 --- a/packages/salesforcedx-vscode-lwc/src/testSupport/testRunner/testRunner.ts +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/testRunner/testRunner.ts @@ -14,9 +14,9 @@ import { TestExecutionInfo, TestInfoKind } from '../types'; import { getCliArgsFromJestArgs, getLwcTestRunnerExecutable, + getTestWorkspaceFolder, workspaceService } from '../workspace'; -import { getTestWorkspaceFolder } from './index'; import { SfdxTask, taskService } from './taskService'; import { testResultsWatcher } from './testResultsWatcher'; diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/getTestWorkspaceFolder.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/getTestWorkspaceFolder.ts new file mode 100644 index 0000000000..9e3342621c --- /dev/null +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/getTestWorkspaceFolder.ts @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2020, salesforce.com, inc. + * All rights reserved. + * Licensed under the BSD 3-Clause license. + * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause + */ +import * as vscode from 'vscode'; +import { nls } from '../../messages'; +import { telemetryService } from '../../telemetry'; + +/** + * If testUri is specified, returns the workspace folder containing the test if it exists. + * Otherwise, return the first workspace folder if it exists. + * @param testUri optional testUri + */ +export function getTestWorkspaceFolder(testUri?: vscode.Uri) { + let workspaceFolder; + if (testUri) { + workspaceFolder = vscode.workspace.getWorkspaceFolder(testUri); + } else { + workspaceFolder = vscode.workspace.workspaceFolders![0]; + } + if (workspaceFolder) { + return workspaceFolder; + } else { + const errorMessage = nls.localize( + 'no_workspace_folder_found_for_test_text' + ); + console.error(errorMessage); + vscode.window.showErrorMessage(errorMessage); + telemetryService + .sendException( + 'lwc_test_no_workspace_folder_found_for_test', + errorMessage + ) + .catch(); + } +} diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/index.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/index.ts index 6cc242b4f4..f6fc60e672 100644 --- a/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/index.ts +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/index.ts @@ -6,6 +6,12 @@ */ import { getCliArgsFromJestArgs } from './getCliArgsFromJestArgs'; import { getLwcTestRunnerExecutable } from './getLwcTestRunnerExecutable'; +import { getTestWorkspaceFolder } from './getTestWorkspaceFolder'; import { workspaceService } from './workspaceService'; -export { getCliArgsFromJestArgs, getLwcTestRunnerExecutable, workspaceService }; +export { + getCliArgsFromJestArgs, + getLwcTestRunnerExecutable, + getTestWorkspaceFolder, + workspaceService +}; From 64b0b0f1c2cea65173cd7827a79527ad94419b99 Mon Sep 17 00:00:00 2001 From: Xiaoyi Chen Date: Mon, 22 Jun 2020 12:17:21 -0700 Subject: [PATCH 17/18] remove url in helper text --- packages/salesforcedx-vscode-lwc/src/messages/i18n.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/salesforcedx-vscode-lwc/src/messages/i18n.ts b/packages/salesforcedx-vscode-lwc/src/messages/i18n.ts index 451f580fc3..fd298b3ac9 100644 --- a/packages/salesforcedx-vscode-lwc/src/messages/i18n.ts +++ b/packages/salesforcedx-vscode-lwc/src/messages/i18n.ts @@ -51,8 +51,7 @@ export const messages = { 'SFDX: Navigate to Lightning Web Component Test', no_lwc_jest_found_text: 'sfdx-lwc-jest is not installed. Install it from https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.unit_testing_using_jest_installation', - no_lwc_testrunner_found_text: - 'lwc-testrunner is not installed. Install it from https://sfdc.co/lwc-testrunner-installation', + no_lwc_testrunner_found_text: 'lwc-testrunner is not installed.', no_workspace_folder_found_for_test_text: 'Unable to determine workspace folder for this test', run_test_title: 'Run Test', From ec9fc882ddafd1bb5116bc8c6d85ee5d6ed79bcf Mon Sep 17 00:00:00 2001 From: Xiaoyi Chen Date: Mon, 22 Jun 2020 20:12:34 -0700 Subject: [PATCH 18/18] PR feedback: refactor getCliArgsFromJestArgs --- .../workspace/getCliArgsFromJestArgs.ts | 28 ++----------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/getCliArgsFromJestArgs.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/getCliArgsFromJestArgs.ts index 004d9e21f2..2810fc25ee 100644 --- a/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/getCliArgsFromJestArgs.ts +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/getCliArgsFromJestArgs.ts @@ -5,7 +5,6 @@ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ import { TestRunType } from '../testRunner/testRunner'; -import { workspaceService } from './workspaceService'; /** * Returns workspace specific jest args from CLI arguments and test run type @@ -16,30 +15,9 @@ export function getCliArgsFromJestArgs( jestArgs: string[], testRunType: TestRunType ) { - const workspaceType = workspaceService.getCurrentWorkspaceType(); + const cliArgs = ['--', ...jestArgs]; if (testRunType === TestRunType.DEBUG) { - if ( - workspaceService.isSFDXWorkspace(workspaceType) || - workspaceService.isCoreWorkspace(workspaceType) - ) { - return ['--debug', '--', ...jestArgs]; - } - // TODO: For LWC OSS - // Debug args are ['test:unit', '--debug', '--passthrough', ...jestArgs] - - // Fallback - return ['--debug', '--', ...jestArgs]; - } else { - if ( - workspaceService.isSFDXWorkspace(workspaceType) || - workspaceService.isCoreWorkspace(workspaceType) - ) { - return ['--', ...jestArgs]; - } - // TODO: For LWC OSS - // Run/Watch args are ['test:unit', '--passthrough', ...jestArgs] - - // Fallback - return ['--', ...jestArgs]; + cliArgs.unshift('--debug'); } + return cliArgs; }