From d25810ad3bcda56da1d9ec4f53dd5f7461750c58 Mon Sep 17 00:00:00 2001 From: peternhale Date: Thu, 21 Dec 2023 10:25:24 -0700 Subject: [PATCH] chore: vscode lwc to arrow functions (#5283) @W-14564471@ Refactor vscode lwc to use arrow functions --- .../fix-these-rules.json | 1 + .../src/commands/commandUtils.ts | 8 +-- .../src/commands/forceLightningLwcOpen.ts | 4 +- .../src/commands/forceLightningLwcPreview.ts | 58 +++++++++---------- .../src/commands/forceLightningLwcStart.ts | 4 +- .../src/commands/forceLightningLwcStop.ts | 4 +- packages/salesforcedx-vscode-lwc/src/index.ts | 16 ++--- .../src/languageClient/index.ts | 12 ++-- .../src/messages/index.ts | 4 +- .../codeLens/lwcTestCodeLensProvider.ts | 4 +- .../codeLens/provideLwcTestCodeLens.ts | 6 +- .../commands/forceLwcTestDebugAction.ts | 34 +++++------ .../commands/forceLwcTestNavigateToTest.ts | 8 +-- .../forceLwcTestRefreshTestExplorer.ts | 4 +- .../commands/forceLwcTestRunAction.ts | 24 ++++---- .../commands/forceLwcTestWatchAction.ts | 24 ++++---- .../src/testSupport/commands/index.ts | 6 +- .../src/testSupport/index.ts | 12 ++-- .../src/testSupport/testExplorer/iconPaths.ts | 4 +- .../src/testSupport/testExplorer/testNode.ts | 4 +- .../testExplorer/testOutlineProvider.ts | 22 +++---- .../src/testSupport/testIndexer/jestUtils.ts | 20 +++---- .../src/testSupport/testRunner/testRunner.ts | 8 +-- .../src/testSupport/types/index.ts | 6 +- .../src/testSupport/utils/context.ts | 10 ++-- .../src/testSupport/utils/isLwcJestTest.ts | 4 +- .../workspace/getCliArgsFromJestArgs.ts | 6 +- .../workspace/getLwcTestRunnerExecutable.ts | 4 +- .../workspace/getTestWorkspaceFolder.ts | 4 +- 29 files changed, 163 insertions(+), 162 deletions(-) diff --git a/packages/salesforcedx-vscode-lwc/fix-these-rules.json b/packages/salesforcedx-vscode-lwc/fix-these-rules.json index 305658fb08..621f248e00 100644 --- a/packages/salesforcedx-vscode-lwc/fix-these-rules.json +++ b/packages/salesforcedx-vscode-lwc/fix-these-rules.json @@ -1,5 +1,6 @@ { "rules": { + "prefer-arrow/prefer-arrow-functions": ["error", {}], "@typescript-eslint/no-floating-promises": "warn", "@typescript-eslint/no-misused-promises": "warn", "@typescript-eslint/no-unsafe-argument": "warn", diff --git a/packages/salesforcedx-vscode-lwc/src/commands/commandUtils.ts b/packages/salesforcedx-vscode-lwc/src/commands/commandUtils.ts index 3c281ff4f8..1b749c8707 100644 --- a/packages/salesforcedx-vscode-lwc/src/commands/commandUtils.ts +++ b/packages/salesforcedx-vscode-lwc/src/commands/commandUtils.ts @@ -11,7 +11,7 @@ import { channelService } from '../channel'; import { nls } from '../messages'; import { telemetryService } from '../telemetry'; -export function showError(e: Error, logName: string, commandName: string) { +export const showError = (e: Error, logName: string, commandName: string) => { telemetryService.sendException(`${logName}_error`, e.message); notificationService.showErrorMessage(e.message); notificationService.showErrorMessage( @@ -19,8 +19,8 @@ export function showError(e: Error, logName: string, commandName: string) { ); channelService.appendLine(`Error: ${e.message}`); channelService.showChannelOutput(); -} +}; -export function openBrowser(url: string) { +export const openBrowser = (url: string) => { return env.openExternal(Uri.parse(url)); -} +}; diff --git a/packages/salesforcedx-vscode-lwc/src/commands/forceLightningLwcOpen.ts b/packages/salesforcedx-vscode-lwc/src/commands/forceLightningLwcOpen.ts index 6b983797a9..eb152e3132 100644 --- a/packages/salesforcedx-vscode-lwc/src/commands/forceLightningLwcOpen.ts +++ b/packages/salesforcedx-vscode-lwc/src/commands/forceLightningLwcOpen.ts @@ -14,7 +14,7 @@ import { openBrowser, showError } from './commandUtils'; const logName = 'force_lightning_lwc_open'; const commandName = nls.localize('force_lightning_lwc_open_text'); -export async function forceLightningLwcOpen() { +export const forceLightningLwcOpen = async () => { const startTime = process.hrtime(); if (DevServerService.instance.isServerHandlerRegistered()) { @@ -29,4 +29,4 @@ export async function forceLightningLwcOpen() { await vscode.commands.executeCommand('sfdx.force.lightning.lwc.start'); telemetryService.sendCommandEvent(logName, startTime); } -} +}; diff --git a/packages/salesforcedx-vscode-lwc/src/commands/forceLightningLwcPreview.ts b/packages/salesforcedx-vscode-lwc/src/commands/forceLightningLwcPreview.ts index 29f6a36de7..7a3c3b997a 100644 --- a/packages/salesforcedx-vscode-lwc/src/commands/forceLightningLwcPreview.ts +++ b/packages/salesforcedx-vscode-lwc/src/commands/forceLightningLwcPreview.ts @@ -108,26 +108,26 @@ const sfdxDeviceListCommand = 'force:lightning:local:device:list'; const sfdxMobilePreviewCommand = 'force:lightning:lwc:preview'; const androidSuccessString = 'Launching... Opening Browser'; -export async function forceLightningLwcPreview(sourceUri: vscode.Uri) { +export const forceLightningLwcPreview = async (sourceUri: vscode.Uri) => { const preview = getPreview(); preview(sourceUri); -} +}; -export function getPreview() { +export const getPreview = () => { if (isSFContainerMode()) { return lwcPreviewContainerMode; } else { return lwcPreview; } -} +}; -function lwcPreviewContainerMode() { +const lwcPreviewContainerMode = () => { const message = nls.localize('force_lightning_lwc_preview_container_mode'); vscode.window.showErrorMessage(message); return; -} +}; -export async function lwcPreview(sourceUri: vscode.Uri) { +export const lwcPreview = async (sourceUri: vscode.Uri) => { const startTime = process.hrtime(); if (!sourceUri) { @@ -177,7 +177,7 @@ export async function lwcPreview(sourceUri: vscode.Uri) { } await executePreview(startTime, componentName, resourcePath); -} +}; /** * Performs the action of previewing the LWC. It takes care of prompting the user @@ -189,11 +189,11 @@ export async function lwcPreview(sourceUri: vscode.Uri) { * @param componentName name of the lwc * @param resourcePath path to the lwc */ -async function executePreview( +const executePreview = async ( startTime: [number, number], componentName: string, resourcePath: string -) { +) => { const commandCancelledMessage = nls.localize( 'force_lightning_lwc_operation_cancelled' ); @@ -249,7 +249,7 @@ async function executePreview( componentName, startTime ); -} +}; /** * Starts the lwc server if it is not already running. @@ -258,11 +258,11 @@ async function executePreview( * @param componentName name of the component to preview * @param startTime start time of the preview command */ -async function startServer( +const startServer = async ( isDesktop: boolean, componentName: string, startTime: [number, number] -) { +) => { if (!DevServerService.instance.isServerHandlerRegistered()) { console.log(`${logName}: server was not running, starting...`); const preconditionChecker = new SfdxWorkspaceChecker(); @@ -291,19 +291,19 @@ async function startServer( showError(e, logName, commandName); } } -} +}; /** * Prompts the user to select a platform to preview the LWC on. * @returns the selected platform or undefined if no selection was made. */ -async function selectPlatform(): Promise { +const selectPlatform = async (): Promise => { const platformSelection = await vscode.window.showQuickPick(platformOptions, { placeHolder: nls.localize('force_lightning_lwc_platform_selection') }); return platformSelection; -} +}; /** * Prompts the user to select a device to preview the LWC on. @@ -311,9 +311,9 @@ async function selectPlatform(): Promise { * @param platformSelection the selected platform * @returns the name of the selected device or undefined if no selection was made. */ -async function selectTargetDevice( +const selectTargetDevice = async ( platformSelection: PreviewQuickPickItem -): Promise { +): Promise => { const isAndroid = platformSelection.id === PreviewPlatformType.Android; const lastTarget = PreviewService.instance.getRememberedDevice( platformSelection.platformName @@ -453,7 +453,7 @@ async function selectTargetDevice( } return target; -} +}; /** * Prompts the user to select an app to preview the LWC on. Defaults to browser. @@ -462,10 +462,10 @@ async function selectTargetDevice( * @param configFile path to a config file * @returns the name of the selected device or undefined if user cancels selection. */ -async function selectTargetApp( +const selectTargetApp = async ( platformSelection: PreviewQuickPickItem, configFile: string | undefined -): Promise { +): Promise => { let targetApp: string | undefined = 'browser'; const items: vscode.QuickPickItem[] = []; const browserItem: vscode.QuickPickItem = { @@ -517,7 +517,7 @@ async function selectTargetApp( } return targetApp; -} +}; /** * Prompts the user to select a device to preview the LWC on. @@ -530,7 +530,7 @@ async function selectTargetApp( * @param componentName name of the component to preview * @param startTime start time of the preview command */ -async function executeMobilePreview( +const executeMobilePreview = async ( platformSelection: PreviewQuickPickItem, targetDevice: string, targetApp: string, @@ -538,7 +538,7 @@ async function executeMobilePreview( configFile: string | undefined, componentName: string, startTime: [number, number] -) { +) => { const isAndroid = platformSelection.id === PreviewPlatformType.Android; let commandBuilder = new SfdxCommandBuilder() @@ -607,7 +607,7 @@ async function executeMobilePreview( } }); } -} +}; /** * Given a path, it recursively goes through that directory and upwards, until it finds @@ -616,7 +616,7 @@ async function executeMobilePreview( * @param startPath starting path to search for the config file. * @returns the path to the folder containing the config file, or undefined if config file not found */ -export function getProjectRootDirectory(startPath: string): string | undefined { +export const getProjectRootDirectory = (startPath: string): string | undefined => { if (!fs.existsSync(startPath)) { return undefined; } @@ -636,7 +636,7 @@ export function getProjectRootDirectory(startPath: string): string | undefined { // couldn't determine the root dir return undefined; -} +}; /** * Given a path to a directory, returns a path that is one level up. @@ -644,7 +644,7 @@ export function getProjectRootDirectory(startPath: string): string | undefined { * @param directory path to a directory * @returns path to a directory that is one level up, or undefined if cannot go one level up. */ -export function directoryLevelUp(directory: string): string | undefined { +export const directoryLevelUp = (directory: string): string | undefined => { const levelUp = path.dirname(directory); if (levelUp === directory) { @@ -653,4 +653,4 @@ export function directoryLevelUp(directory: string): string | undefined { } return levelUp; -} +}; diff --git a/packages/salesforcedx-vscode-lwc/src/commands/forceLightningLwcStart.ts b/packages/salesforcedx-vscode-lwc/src/commands/forceLightningLwcStart.ts index 53596927f3..ddea0a0a94 100644 --- a/packages/salesforcedx-vscode-lwc/src/commands/forceLightningLwcStart.ts +++ b/packages/salesforcedx-vscode-lwc/src/commands/forceLightningLwcStart.ts @@ -211,7 +211,7 @@ export class ForceLightningLwcStartExecutor extends SfdxCommandletExecutor<{}> { } } -export async function forceLightningLwcStart() { +export const forceLightningLwcStart = async () => { if (DevServerService.instance.isServerHandlerRegistered()) { const warningMessage = nls.localize( 'force_lightning_lwc_start_already_running' @@ -248,4 +248,4 @@ export async function forceLightningLwcStart() { ); await commandlet.run(); -} +}; diff --git a/packages/salesforcedx-vscode-lwc/src/commands/forceLightningLwcStop.ts b/packages/salesforcedx-vscode-lwc/src/commands/forceLightningLwcStop.ts index 1eb0bf5fa7..09dc942aba 100644 --- a/packages/salesforcedx-vscode-lwc/src/commands/forceLightningLwcStop.ts +++ b/packages/salesforcedx-vscode-lwc/src/commands/forceLightningLwcStop.ts @@ -15,7 +15,7 @@ import { showError } from './commandUtils'; const logName = 'force_lightning_lwc_stop'; const commandName = nls.localize('force_lightning_lwc_stop_text'); -export async function forceLightningLwcStop() { +export const forceLightningLwcStop = async () => { const startTime = process.hrtime(); try { @@ -39,4 +39,4 @@ export async function forceLightningLwcStop() { } catch (e) { showError(e, logName, commandName); } -} +}; diff --git a/packages/salesforcedx-vscode-lwc/src/index.ts b/packages/salesforcedx-vscode-lwc/src/index.ts index 40856155e2..d9ded850e5 100644 --- a/packages/salesforcedx-vscode-lwc/src/index.ts +++ b/packages/salesforcedx-vscode-lwc/src/index.ts @@ -32,7 +32,7 @@ import { } from './testSupport'; import { WorkspaceUtils } from './util/workspaceUtils'; -export async function activate(extensionContext: ExtensionContext) { +export const activate = async (extensionContext: ExtensionContext) => { const extensionHRStart = process.hrtime(); log('Activation Mode: ' + getActivationMode()); // Run our auto detection routine before we activate @@ -125,23 +125,23 @@ export async function activate(extensionContext: ExtensionContext) { // Notify telemetry that our extension is now active telemetryService.sendExtensionActivationEvent(extensionHRStart); -} +}; -export async function deactivate() { +export const deactivate = async () => { if (DevServerService.instance.isServerHandlerRegistered()) { await DevServerService.instance.stopServer(); } log('Lightning Web Components Extension Deactivated'); telemetryService.sendExtensionDeactivationEvent(); -} +}; -function getActivationMode(): string { +const getActivationMode = (): string => { const config = workspace.getConfiguration('salesforcedx-vscode-lightning'); return config.get('activationMode') || 'autodetect'; // default to autodetect -} +}; // eslint-disable-next-line @typescript-eslint/no-unused-vars -function registerCommands(_extensionContext: ExtensionContext): Disposable { +const registerCommands = (_extensionContext: ExtensionContext): Disposable => { return Disposable.from( commands.registerCommand( 'sfdx.force.lightning.lwc.start', @@ -160,4 +160,4 @@ function registerCommands(_extensionContext: ExtensionContext): Disposable { forceLightningLwcPreview ) ); -} +}; diff --git a/packages/salesforcedx-vscode-lwc/src/languageClient/index.ts b/packages/salesforcedx-vscode-lwc/src/languageClient/index.ts index 6acdefaca5..0239bfc776 100644 --- a/packages/salesforcedx-vscode-lwc/src/languageClient/index.ts +++ b/packages/salesforcedx-vscode-lwc/src/languageClient/index.ts @@ -14,7 +14,7 @@ import { } from 'vscode-languageclient'; // See https://github.com/Microsoft/vscode-languageserver-node/issues/105 -export function code2ProtocolConverter(value: Uri) { +export const code2ProtocolConverter = (value: Uri) => { if (/^win32/.test(process.platform)) { // The *first* : is also being encoded which is not the standard for URI on Windows // Here we transform it back to the standard way @@ -22,13 +22,13 @@ export function code2ProtocolConverter(value: Uri) { } else { return value.toString(); } -} +}; -function protocol2CodeConverter(value: string) { +const protocol2CodeConverter = (value: string) => { return Uri.parse(value); -} +}; -export function createLanguageClient(serverPath: string): LanguageClient { +export const createLanguageClient = (serverPath: string): LanguageClient => { // Setup the language server const debugOptions = { execArgv: ['--nolazy', '--inspect=6030'] }; // If the extension is launched in debug mode then the debug server options are used @@ -75,4 +75,4 @@ export function createLanguageClient(serverPath: string): LanguageClient { serverOptions, clientOptions ); -} +}; diff --git a/packages/salesforcedx-vscode-lwc/src/messages/index.ts b/packages/salesforcedx-vscode-lwc/src/messages/index.ts index 14a30e8b33..18ce7b604d 100644 --- a/packages/salesforcedx-vscode-lwc/src/messages/index.ts +++ b/packages/salesforcedx-vscode-lwc/src/messages/index.ts @@ -17,7 +17,7 @@ import { messages as enMessages } from './i18n'; import { messages as jaMessages } from './i18n.ja'; const supportedLocales = [DEFAULT_LOCALE, LOCALE_JA]; -function loadMessageBundle(config?: Config): Message { +const loadMessageBundle = (config?: Config): Message => { const base = new Message(enMessages); const localeConfig = config ? config.locale : DEFAULT_LOCALE; @@ -31,7 +31,7 @@ function loadMessageBundle(config?: Config): Message { } return base; -} +}; export const nls = new Localization( loadMessageBundle( diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/codeLens/lwcTestCodeLensProvider.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/codeLens/lwcTestCodeLensProvider.ts index f6794577d4..a59708f9be 100644 --- a/packages/salesforcedx-vscode-lwc/src/testSupport/codeLens/lwcTestCodeLensProvider.ts +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/codeLens/lwcTestCodeLensProvider.ts @@ -50,11 +50,11 @@ export const lwcTestCodeLensProvider = new LwcTestCodeLensProvider(); * Register Code Lens Provider with the extension context * @param extensionContext Extension context */ -export function registerLwcTestCodeLensProvider(extensionContext: ExtensionContext) { +export const registerLwcTestCodeLensProvider = (extensionContext: ExtensionContext) => { extensionContext.subscriptions.push( languages.registerCodeLensProvider( LWC_TEST_DOCUMENT_SELECTOR, lwcTestCodeLensProvider ) ); -} +}; diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/codeLens/provideLwcTestCodeLens.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/codeLens/provideLwcTestCodeLens.ts index c261a65626..2deeeb512f 100644 --- a/packages/salesforcedx-vscode-lwc/src/testSupport/codeLens/provideLwcTestCodeLens.ts +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/codeLens/provideLwcTestCodeLens.ts @@ -23,11 +23,11 @@ import { TestExecutionInfo, TestInfoKind, TestType } from '../types'; * @param document text document * @param token cancellation token */ -export async function provideLwcTestCodeLens( +export const provideLwcTestCodeLens = async ( document: TextDocument, // eslint-disable-next-line @typescript-eslint/no-unused-vars token: CancellationToken -): Promise { +): Promise => { const fsPath = document.uri.fsPath; const parseResults = parse(fsPath, document.getText()); const { itBlocks } = parseResults; @@ -66,4 +66,4 @@ export async function provideLwcTestCodeLens( return [runTestCaseCodeLens, debugTestCaseCodeLens]; }) .reduce((xs, x) => xs.concat(x), []); -} +}; diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/commands/forceLwcTestDebugAction.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/commands/forceLwcTestDebugAction.ts index c12d500196..c26aa27c49 100644 --- a/packages/salesforcedx-vscode-lwc/src/testSupport/commands/forceLwcTestDebugAction.ts +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/commands/forceLwcTestDebugAction.ts @@ -28,11 +28,11 @@ const debugSessionStartTimes = new Map(); * @param args CLI arguments * @param cwd current working directory */ -export function getDebugConfiguration( +export const getDebugConfiguration = ( command: string, args: string[], cwd: string -): vscode.DebugConfiguration { +): vscode.DebugConfiguration => { const sfdxDebugSessionId = uuid.v4(); const debugConfiguration: vscode.DebugConfiguration = { sfdxDebugSessionId, @@ -49,13 +49,13 @@ export function getDebugConfiguration( disableOptimisticBPs: true }; return debugConfiguration; -} +}; /** * Start a debug session with provided test execution information * @param testExecutionInfo test execution information */ -export async function forceLwcTestDebug(testExecutionInfo: TestExecutionInfo) { +export const forceLwcTestDebug = async (testExecutionInfo: TestExecutionInfo) => { const testRunner = new TestRunner(testExecutionInfo, TestRunType.DEBUG); const shellExecutionInfo = testRunner.getShellExecutionInfo(); if (shellExecutionInfo) { @@ -73,34 +73,34 @@ export async function forceLwcTestDebug(testExecutionInfo: TestExecutionInfo) { ); await vscode.debug.startDebugging(workspaceFolder, debugConfiguration); } -} +}; /** * Debug an individual test case * @param data a test explorer node or information provided by code lens */ -export async function forceLwcTestCaseDebug(data: { +export const forceLwcTestCaseDebug = async (data: { testExecutionInfo: TestCaseInfo; -}) { +}) => { const { testExecutionInfo } = data; await forceLwcTestDebug(testExecutionInfo); -} +}; /** * Debug a test file * @param data a test explorer node */ -export async function forceLwcTestFileDebug(data: { +export const forceLwcTestFileDebug = async (data: { testExecutionInfo: TestExecutionInfo; -}) { +}) => { const { testExecutionInfo } = data; await forceLwcTestDebug(testExecutionInfo); -} +}; /** * Debug the test of currently focused editor */ -export async function forceLwcTestDebugActiveTextEditorTest() { +export const forceLwcTestDebugActiveTextEditorTest = async () => { const { activeTextEditor } = vscode.window; if (activeTextEditor && isLwcJestTest(activeTextEditor.document)) { const testExecutionInfo: TestFileInfo = { @@ -110,24 +110,24 @@ export async function forceLwcTestDebugActiveTextEditorTest() { }; await forceLwcTestFileDebug({ testExecutionInfo }); } -} +}; /** * Log the start time of debug session * @param session debug session */ -export function handleDidStartDebugSession(session: vscode.DebugSession) { +export const handleDidStartDebugSession = (session: vscode.DebugSession) => { const { configuration } = session; const { sfdxDebugSessionId } = configuration; const startTime = process.hrtime(); debugSessionStartTimes.set(sfdxDebugSessionId, startTime); -} +}; /** * Send telemetry event if applicable when debug session ends * @param session debug session */ -export function handleDidTerminateDebugSession(session: vscode.DebugSession) { +export const handleDidTerminateDebugSession = (session: vscode.DebugSession) => { const { configuration } = session; const startTime = debugSessionStartTimes.get( configuration.sfdxDebugSessionId @@ -141,4 +141,4 @@ export function handleDidTerminateDebugSession(session: vscode.DebugSession) { } ); } -} +}; diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/commands/forceLwcTestNavigateToTest.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/commands/forceLwcTestNavigateToTest.ts index b40e6a9052..28bb1fa5d6 100644 --- a/packages/salesforcedx-vscode-lwc/src/testSupport/commands/forceLwcTestNavigateToTest.ts +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/commands/forceLwcTestNavigateToTest.ts @@ -11,7 +11,7 @@ import { TestNode } from '../testExplorer/testNode'; * Select specific range in the text editor * @param index VS Code range */ -function updateSelection(index: vscode.Range | number) { +const updateSelection = (index: vscode.Range | number) => { const editor = vscode.window.activeTextEditor; if (editor) { if (index instanceof vscode.Range) { @@ -27,16 +27,16 @@ function updateSelection(index: vscode.Range | number) { editor.revealRange(line.range); // Show selection } } -} +}; /** * Navigate to the test position * @param node test explorer node */ -export function forceLwcTestNavigateToTest(node: TestNode) { +export const forceLwcTestNavigateToTest = (node: TestNode) => { if (node.location) { vscode.window.showTextDocument(node.location.uri); } const position: vscode.Range | number = node.location!.range; updateSelection(position); -} +}; diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/commands/forceLwcTestRefreshTestExplorer.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/commands/forceLwcTestRefreshTestExplorer.ts index 0364d24074..132713a260 100644 --- a/packages/salesforcedx-vscode-lwc/src/testSupport/commands/forceLwcTestRefreshTestExplorer.ts +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/commands/forceLwcTestRefreshTestExplorer.ts @@ -10,6 +10,6 @@ import { lwcTestIndexer } from '../testIndexer'; * Refresh the test explorer. This will clear the test results and clear the test index. * It will retrigger indexing from test indexer if test explorer view is open. */ -export function forceLwcTestRefreshTestExplorer() { +export const forceLwcTestRefreshTestExplorer = () => { lwcTestIndexer.resetIndex(); -} +}; diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/commands/forceLwcTestRunAction.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/commands/forceLwcTestRunAction.ts index 3b99f803c4..3502d7f30d 100644 --- a/packages/salesforcedx-vscode-lwc/src/testSupport/commands/forceLwcTestRunAction.ts +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/commands/forceLwcTestRunAction.ts @@ -21,7 +21,7 @@ import { workspace } from '../workspace'; * Run an LWC Jest test from provided test execution info * @param testExecutionInfo test execution info */ -export async function forceLwcTestRun(testExecutionInfo: TestExecutionInfo) { +export const forceLwcTestRun = async (testExecutionInfo: TestExecutionInfo) => { const testRunner = new TestRunner( testExecutionInfo, TestRunType.RUN, @@ -32,34 +32,34 @@ export async function forceLwcTestRun(testExecutionInfo: TestExecutionInfo) { } catch (error) { console.error(error); } -} +}; /** * Run an individual test case * @param data a test explorer node or information provided by code lens */ -export function forceLwcTestCaseRun(data: { +export const forceLwcTestCaseRun = (data: { testExecutionInfo: TestExecutionInfo; -}) { +}) => { const { testExecutionInfo } = data; return forceLwcTestRun(testExecutionInfo); -} +}; /** * Run a test file * @param data a test explorer node */ -export function forceLwcTestFileRun(data: { +export const forceLwcTestFileRun = (data: { testExecutionInfo: TestExecutionInfo; -}) { +}) => { const { testExecutionInfo } = data; return forceLwcTestRun(testExecutionInfo); -} +}; /** * Run all tests in the workspace folder */ -export function forceLwcTestRunAllTests() { +export const forceLwcTestRunAllTests = () => { const workspaceFolder = workspace.getTestWorkspaceFolder(); if (workspaceFolder) { const testExecutionInfo: TestDirectoryInfo = { @@ -69,12 +69,12 @@ export function forceLwcTestRunAllTests() { }; return forceLwcTestRun(testExecutionInfo); } -} +}; /** * Run the test of currently focused editor */ -export function forceLwcTestRunActiveTextEditorTest() { +export const forceLwcTestRunActiveTextEditorTest = () => { const { activeTextEditor } = vscode.window; if (activeTextEditor && isLwcJestTest(activeTextEditor.document)) { const testExecutionInfo: TestFileInfo = { @@ -86,4 +86,4 @@ export function forceLwcTestRunActiveTextEditorTest() { testExecutionInfo }); } -} +}; diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/commands/forceLwcTestWatchAction.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/commands/forceLwcTestWatchAction.ts index fed099b188..4ca92dfcc3 100644 --- a/packages/salesforcedx-vscode-lwc/src/testSupport/commands/forceLwcTestWatchAction.ts +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/commands/forceLwcTestWatchAction.ts @@ -22,37 +22,37 @@ import { isLwcJestTest } from '../utils'; * it will re-run the tests. * @param data provided by test watch commands (or test explorer potentially in the future) */ -export async function forceLwcTestStartWatching(data: { +export const forceLwcTestStartWatching = async (data: { testExecutionInfo: TestExecutionInfo; -}) { +}) => { const { testExecutionInfo } = data; await testWatcher.watchTest(testExecutionInfo); -} +}; /** * Stop watching tests using the provided test execution info. * It will terminate the test watch task matched by the test URI. * @param data provided by test watch commands */ -export async function forceLwcTestStopWatching(data: { +export const forceLwcTestStopWatching = async (data: { testExecutionInfo: TestExecutionInfo; -}) { +}) => { const { testExecutionInfo } = data; testWatcher.stopWatchingTest(testExecutionInfo); -} +}; /** * Stop watching all tests. * It will terminate all test watch tasks. */ -export function forceLwcTestStopWatchingAllTests() { +export const forceLwcTestStopWatchingAllTests = () => { testWatcher.stopWatchingAllTests(); -} +}; /** * Start watching the test of currently focused editor */ -export async function forceLwcTestStartWatchingCurrentFile() { +export const forceLwcTestStartWatchingCurrentFile = () => { const { activeTextEditor } = vscode.window; if (activeTextEditor && isLwcJestTest(activeTextEditor.document)) { const testExecutionInfo: TestFileInfo = { @@ -64,12 +64,12 @@ export async function forceLwcTestStartWatchingCurrentFile() { testExecutionInfo }); } -} +}; /** * Stop watching the test of currently focused editor */ -export function forceLwcTestStopWatchingCurrentFile() { +export const forceLwcTestStopWatchingCurrentFile = () => { const { activeTextEditor } = vscode.window; if (activeTextEditor && isLwcJestTest(activeTextEditor.document)) { const testExecutionInfo: TestFileInfo = { @@ -81,4 +81,4 @@ export function forceLwcTestStopWatchingCurrentFile() { testExecutionInfo }); } -} +}; diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/commands/index.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/commands/index.ts index aa891a90f0..38a7c26540 100644 --- a/packages/salesforcedx-vscode-lwc/src/testSupport/commands/index.ts +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/commands/index.ts @@ -31,9 +31,9 @@ import { * Register all commands with the extension context * @param extensionContext extension context */ -export function registerCommands( +export const registerCommands = ( extensionContext: ExtensionContext -): Disposable { +): Disposable => { const forceLwcTestRunAllTestsCmd = commands.registerCommand( 'sfdx.force.lightning.lwc.test.runAllTests', forceLwcTestRunAllTests @@ -106,4 +106,4 @@ export function registerCommands( ); extensionContext.subscriptions.push(disposables); return disposables; -} +}; diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/index.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/index.ts index 37bbcc3f4a..c33e8b9678 100644 --- a/packages/salesforcedx-vscode-lwc/src/testSupport/index.ts +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/index.ts @@ -19,19 +19,19 @@ import { workspaceService } from './workspace'; * Activate LWC Test support for supported workspace types * @param workspaceType workspace type */ -export function shouldActivateLwcTestSupport( +export const shouldActivateLwcTestSupport = ( workspaceType: lspCommon.WorkspaceType -) { +) => { return ( workspaceService.isSFDXWorkspace(workspaceType) || workspaceService.isCoreWorkspace(workspaceType) ); -} +}; -export function activateLwcTestSupport( +export const activateLwcTestSupport = ( extensionContext: ExtensionContext, workspaceType: lspCommon.WorkspaceType -) { +) => { workspaceService.register(extensionContext, workspaceType); registerCommands(extensionContext); registerLwcTestCodeLensProvider(extensionContext); @@ -40,4 +40,4 @@ export function activateLwcTestSupport( taskService.registerTaskService(extensionContext); testResultsWatcher.register(extensionContext); lwcTestIndexer.register(extensionContext); -} +}; diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/testExplorer/iconPaths.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/testExplorer/iconPaths.ts index c062640356..129d101d19 100644 --- a/packages/salesforcedx-vscode-lwc/src/testSupport/testExplorer/iconPaths.ts +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/testExplorer/iconPaths.ts @@ -54,7 +54,7 @@ type IconPath = { light: vscode.Uri; dark: vscode.Uri }; * Get icon path in the test explorer for test result * @param testResult test result */ -export function getIconPath(testResult?: TestResult): IconPath { +export const getIconPath = (testResult?: TestResult): IconPath => { if (testResult) { if (testResult.status === TestResultStatus.PASSED) { return { @@ -83,4 +83,4 @@ export function getIconPath(testResult?: TestResult): IconPath { dark: DARK_BLUE_BUTTON }; } -} +}; diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/testExplorer/testNode.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/testExplorer/testNode.ts index e2b98ce90d..59bd150fe5 100644 --- a/packages/salesforcedx-vscode-lwc/src/testSupport/testExplorer/testNode.ts +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/testExplorer/testNode.ts @@ -87,7 +87,7 @@ export class SfdxTestGroupNode extends TestNode { * @param node1 first test node * @param node2 second test node */ -export function sortTestNodeByLabel(node1: TestNode, node2: TestNode) { +export const sortTestNodeByLabel = (node1: TestNode, node2: TestNode) => { const label1 = node1.label; const label2 = node2.label; if (!label1) { @@ -99,4 +99,4 @@ export function sortTestNodeByLabel(node1: TestNode, node2: TestNode) { const label1String = String(label1); const label2String = String(label2); return label1String.localeCompare(label2String); -} +}; diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/testExplorer/testOutlineProvider.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/testExplorer/testOutlineProvider.ts index 884c6114a4..101a8545b5 100644 --- a/packages/salesforcedx-vscode-lwc/src/testSupport/testExplorer/testOutlineProvider.ts +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/testExplorer/testOutlineProvider.ts @@ -16,27 +16,27 @@ import { TestNode } from './testNode'; -function getLabelFromTestCaseInfo(testCaseInfo: TestCaseInfo) { +const getLabelFromTestCaseInfo = (testCaseInfo: TestCaseInfo) => { const { testName } = testCaseInfo; return testName; -} +}; -function getLabelFromTestFileInfo(testFileInfo: TestFileInfo) { +const getLabelFromTestFileInfo = (testFileInfo: TestFileInfo) => { const { testUri } = testFileInfo; const { fsPath } = testUri; const ext = '.test.js'; const testGroupLabel = path.basename(fsPath, ext); return testGroupLabel; -} +}; /** * Test Explorer Tree Data Provider implementation */ export class SfdxTestOutlineProvider - implements vscode.TreeDataProvider, vscode.Disposable { - private onDidChangeTestData: vscode.EventEmitter< - TestNode | undefined - > = new vscode.EventEmitter(); + implements vscode.TreeDataProvider, vscode.Disposable +{ + private onDidChangeTestData: vscode.EventEmitter = + new vscode.EventEmitter(); public onDidChangeTreeData = this.onDidChangeTestData.event; private disposables: vscode.Disposable[]; @@ -127,9 +127,9 @@ export class SfdxTestOutlineProvider * Register test explorer with extension context * @param extensionContext extension context */ -export function registerLwcTestExplorerTreeView( +export const registerLwcTestExplorerTreeView = ( extensionContext: vscode.ExtensionContext -) { +) => { const testOutlineProvider = new SfdxTestOutlineProvider(); const testProvider = vscode.window.registerTreeDataProvider( 'sfdx.force.lightning.lwc.test.view', @@ -137,4 +137,4 @@ export function registerLwcTestExplorerTreeView( ); extensionContext.subscriptions.push(testOutlineProvider); extensionContext.subscriptions.push(testProvider); -} +}; diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/testIndexer/jestUtils.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/testIndexer/jestUtils.ts index 6d077fef07..dc92d10513 100644 --- a/packages/salesforcedx-vscode-lwc/src/testSupport/testIndexer/jestUtils.ts +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/testIndexer/jestUtils.ts @@ -37,11 +37,11 @@ export type IExtendedParseResults = Pick< itBlocksWithAncestorTitles?: ItBlockWithAncestorTitles[]; }; -function populateAncestorTitlesRecursive( +const populateAncestorTitlesRecursive = ( node: ParsedNodeWithAncestorTitles, ancestorTitles: string[], itBlocksWithAncestorTitles: ItBlockWithAncestorTitles[] -) { +) => { node.ancestorTitles = ancestorTitles; if (node.type === ParsedNodeTypes.it) { itBlocksWithAncestorTitles.push(node as ItBlockWithAncestorTitles); @@ -61,13 +61,13 @@ function populateAncestorTitlesRecursive( ); }); } -} +}; /** * Populate ancestor titles for itBlocks * @param parsedResult original parse results */ -export function populateAncestorTitles(parsedResult: IExtendedParseResults) { +export const populateAncestorTitles = (parsedResult: IExtendedParseResults) => { try { const itBlocksWithAncestorTitles: ItBlockWithAncestorTitles[] = []; populateAncestorTitlesRecursive( @@ -80,17 +80,17 @@ export function populateAncestorTitles(parsedResult: IExtendedParseResults) { } catch (error) { console.error(error); } -} +}; /** * Extract the VS Code position from failure message stacktrace in Jest output. * @param testFsPath test file path * @param failureMessage failure message from Jest output */ -export function extractPositionFromFailureMessage( +export const extractPositionFromFailureMessage = ( testFsPath: string, failureMessage: string -) { +) => { try { const locationMatcher = new RegExp( escapeStrForRegex(testFsPath) + '\\:(\\d+)\\:(\\d+)', @@ -111,12 +111,12 @@ export function extractPositionFromFailureMessage( } catch (error) { return undefined; } -} +}; /** * Strip the ANSI color codes from failure message * @param failureMessage failure message from Jest output */ -export function sanitizeFailureMessage(failureMessage: string) { +export const sanitizeFailureMessage = (failureMessage: string) => { return stripAnsi(failureMessage); -} +}; diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/testRunner/testRunner.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/testRunner/testRunner.ts index 473ba24762..da5425cdb1 100644 --- a/packages/salesforcedx-vscode-lwc/src/testSupport/testRunner/testRunner.ts +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/testRunner/testRunner.ts @@ -27,20 +27,20 @@ export const enum TestRunType { * @param cwd * @param testFsPath */ -export function normalizeRunTestsByPath(cwd: string, testFsPath: string) { +export const normalizeRunTestsByPath = (cwd: string, testFsPath: string) => { if (/^win32/.test(process.platform)) { return path.relative(cwd, testFsPath); } return testFsPath; -} +}; /** * Returns testNamePattern flag and escaped test name * @param TestExecutionInfo */ -export function getTestNamePatternArgs(testName: string) { +export const getTestNamePatternArgs = (testName: string) => { return ['--testNamePattern', `${escapeStrForRegex(testName)}`]; -} +}; type JestExecutionInfo = { jestArgs: string[]; diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/types/index.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/types/index.ts index 88e453d729..ae5c342aa9 100644 --- a/packages/salesforcedx-vscode-lwc/src/testSupport/types/index.ts +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/types/index.ts @@ -45,11 +45,11 @@ export const enum TestInfoKind { /** * Confirms if the TestExecutionInfo kind is TestCaseInfo */ -export function isTestCaseInfo( +export const isTestCaseInfo = ( testExecutionInfo: TestExecutionInfo -): testExecutionInfo is TestCaseInfo { +): testExecutionInfo is TestCaseInfo => { return testExecutionInfo.kind === TestInfoKind.TEST_CASE; -} +}; /** * Raw Test Results generated from Jest output. diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/utils/context.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/utils/context.ts index 46d14d8a17..cf5e1aefba 100644 --- a/packages/salesforcedx-vscode-lwc/src/testSupport/utils/context.ts +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/utils/context.ts @@ -14,7 +14,7 @@ import { isLwcJestTest } from './isLwcJestTest'; * Set context for currently focused file initially or on active text editor change * @param textEditor text editor */ -function setLwcJestFileFocusedContext(textEditor?: vscode.TextEditor) { +const setLwcJestFileFocusedContext = (textEditor?: vscode.TextEditor) => { if (textEditor) { vscode.commands.executeCommand( 'setContext', @@ -30,16 +30,16 @@ function setLwcJestFileFocusedContext(textEditor?: vscode.TextEditor) { false ); } -} +}; /** * Sets up handlers for active text editor change * and make sure the correct context is set. * @param extensionContext extension context */ -export function startWatchingEditorFocusChange( +export const startWatchingEditorFocusChange = ( extensionContext: vscode.ExtensionContext -) { +) => { setLwcJestFileFocusedContext(vscode.window.activeTextEditor); const handleDidChangeActiveTextEditor = vscode.window.onDidChangeActiveTextEditor( textEditor => { @@ -47,4 +47,4 @@ export function startWatchingEditorFocusChange( } ); extensionContext.subscriptions.push(handleDidChangeActiveTextEditor); -} +}; diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/utils/isLwcJestTest.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/utils/isLwcJestTest.ts index 7dd6eb15fc..06e499cec5 100644 --- a/packages/salesforcedx-vscode-lwc/src/testSupport/utils/isLwcJestTest.ts +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/utils/isLwcJestTest.ts @@ -11,6 +11,6 @@ import { LWC_TEST_DOCUMENT_SELECTOR } from '../types/constants'; * Determine if the text document is an LWC Jest test * @param textDocument vscode text document */ -export function isLwcJestTest(textDocument: vscode.TextDocument) { +export const isLwcJestTest = (textDocument: vscode.TextDocument) => { return vscode.languages.match(LWC_TEST_DOCUMENT_SELECTOR, textDocument); -} +}; diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/getCliArgsFromJestArgs.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/getCliArgsFromJestArgs.ts index 2972c95f22..7cd6c432ba 100644 --- a/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/getCliArgsFromJestArgs.ts +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/getCliArgsFromJestArgs.ts @@ -12,10 +12,10 @@ import { TestRunType } from '../testRunner/testRunner'; * @param jestArgs jest args * @param testRunType test run type */ -export function getCliArgsFromJestArgs( +export const getCliArgsFromJestArgs = ( jestArgs: string[], testRunType: TestRunType -) { +) => { const cliArgs = ['--', ...jestArgs]; const usePreviewJavaScriptDebugger = workspace @@ -31,4 +31,4 @@ export function getCliArgsFromJestArgs( cliArgs.unshift('--debug'); } return cliArgs; -} +}; diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/getLwcTestRunnerExecutable.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/getLwcTestRunnerExecutable.ts index 6688ab5ab3..a46fcb3617 100644 --- a/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/getLwcTestRunnerExecutable.ts +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/getLwcTestRunnerExecutable.ts @@ -17,7 +17,7 @@ import { workspaceService } from './workspaceService'; * @param cwd path to the workspace folder * @returns path to LWC Test runner */ -export function getLwcTestRunnerExecutable(cwd: string) { +export const getLwcTestRunnerExecutable = (cwd: string) => { const workspaceType = workspaceService.getCurrentWorkspaceType(); if (workspaceService.isSFDXWorkspace(workspaceType)) { const lwcTestRunnerExecutable = path.join( @@ -59,4 +59,4 @@ export function getLwcTestRunnerExecutable(cwd: string) { 'Unsupported workspace' ); } -} +}; diff --git a/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/getTestWorkspaceFolder.ts b/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/getTestWorkspaceFolder.ts index ca36a7e47f..b0dae4dd38 100644 --- a/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/getTestWorkspaceFolder.ts +++ b/packages/salesforcedx-vscode-lwc/src/testSupport/workspace/getTestWorkspaceFolder.ts @@ -13,7 +13,7 @@ import { telemetryService } from '../../telemetry'; * Otherwise, return the first workspace folder if it exists. * @param testUri optional testUri */ -export function getTestWorkspaceFolder(testUri?: vscode.Uri) { +export const getTestWorkspaceFolder = (testUri?: vscode.Uri) => { let workspaceFolder; if (testUri) { workspaceFolder = vscode.workspace.getWorkspaceFolder(testUri); @@ -33,4 +33,4 @@ export function getTestWorkspaceFolder(testUri?: vscode.Uri) { errorMessage ); } -} +};