From d8cb4ff910b6d7c8625f9f885559edbfd49dc3bf Mon Sep 17 00:00:00 2001 From: Ritam Agrawal Date: Fri, 28 Oct 2022 22:10:06 +0530 Subject: [PATCH 1/7] chore: add relativeToolsFolder --- .../salesforcedx-utils-vscode/src/helpers/paths.ts | 8 +++++++- .../test/jest/helpers/paths.test.ts | 12 ++++++++++++ .../src/commands/isvdebugging/bootstrapCmd.ts | 7 +++---- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/packages/salesforcedx-utils-vscode/src/helpers/paths.ts b/packages/salesforcedx-utils-vscode/src/helpers/paths.ts index 04f1d2cece..2dcf5ab2df 100644 --- a/packages/salesforcedx-utils-vscode/src/helpers/paths.ts +++ b/packages/salesforcedx-utils-vscode/src/helpers/paths.ts @@ -146,6 +146,11 @@ function relativeStateFolder(): string { return Global.STATE_FOLDER; } +function relativeToolsFolder(): string { + const relativePathToToolsFolder = path.join(projectPaths.relativeStateFolder(), TOOLS); + return relativePathToToolsFolder; +} + export const projectPaths = { stateFolder, metadataFolder, @@ -156,5 +161,6 @@ export const projectPaths = { sfdxProjectConfig, toolsFolder, lwcTestResultsFolder, - relativeStateFolder + relativeStateFolder, + relativeToolsFolder }; diff --git a/packages/salesforcedx-utils-vscode/test/jest/helpers/paths.test.ts b/packages/salesforcedx-utils-vscode/test/jest/helpers/paths.test.ts index cf6734bb69..c874fe9b0c 100644 --- a/packages/salesforcedx-utils-vscode/test/jest/helpers/paths.test.ts +++ b/packages/salesforcedx-utils-vscode/test/jest/helpers/paths.test.ts @@ -13,6 +13,7 @@ jest.mock('@salesforce/core', () => { describe('test project paths', () => { const FAKE_WORKSPACE = '/here/is/a/fake/path/to/'; const FAKE_STATE_FOLDER = '.sfdx'; + const FAKE_TOOLS_FOLDER = '.sfdx/tools'; describe('test stateFolder', () => { let getRootWorkspacePathStub: jest.SpyInstance; @@ -70,4 +71,15 @@ describe('test project paths', () => { expect(relativeStateFolder).toEqual(FAKE_STATE_FOLDER); }); }); + + describe('test relativeToolsFolder', () => { + it('should be defined', () => { + expect(projectPaths.relativeToolsFolder).toBeDefined(); + }); + + it('should return a path to the relative tools folder', () => { + const relativeToolsFolder = projectPaths.relativeToolsFolder(); + expect(relativeToolsFolder).toEqual(FAKE_TOOLS_FOLDER); + }); + }); }); diff --git a/packages/salesforcedx-vscode-core/src/commands/isvdebugging/bootstrapCmd.ts b/packages/salesforcedx-vscode-core/src/commands/isvdebugging/bootstrapCmd.ts index 1b4256f8b7..dbf96322b9 100644 --- a/packages/salesforcedx-vscode-core/src/commands/isvdebugging/bootstrapCmd.ts +++ b/packages/salesforcedx-vscode-core/src/commands/isvdebugging/bootstrapCmd.ts @@ -13,6 +13,7 @@ import { CommandOutput, ContinueResponse, ParametersGatherer, + projectPaths, SfdxCommandBuilder } from '@salesforce/salesforcedx-utils-vscode'; import { SpawnOptions } from 'child_process'; @@ -55,8 +56,7 @@ export interface InstalledPackageInfo { export class IsvDebugBootstrapExecutor extends SfdxCommandletExecutor<{}> { public readonly relativeMetdataTempPath = path.join( - '.sfdx', - 'tools', + projectPaths.relativeToolsFolder(), 'isvdebuggermdapitmp' ); public readonly relativeApexPackageXmlPath = path.join( @@ -64,8 +64,7 @@ export class IsvDebugBootstrapExecutor extends SfdxCommandletExecutor<{}> { 'package.xml' ); public readonly relativeInstalledPackagesPath = path.join( - '.sfdx', - 'tools', + projectPaths.relativeToolsFolder(), 'installed-packages' ); From 6d0d7f8a737e439fbe0094f92c27e100a43dd211 Mon Sep 17 00:00:00 2001 From: Ritam Agrawal Date: Sat, 29 Oct 2022 04:33:38 +0530 Subject: [PATCH 2/7] refactor: updated paths.test.ts --- .../salesforcedx-utils-vscode/test/jest/helpers/paths.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/salesforcedx-utils-vscode/test/jest/helpers/paths.test.ts b/packages/salesforcedx-utils-vscode/test/jest/helpers/paths.test.ts index c874fe9b0c..26dd75b61b 100644 --- a/packages/salesforcedx-utils-vscode/test/jest/helpers/paths.test.ts +++ b/packages/salesforcedx-utils-vscode/test/jest/helpers/paths.test.ts @@ -13,7 +13,7 @@ jest.mock('@salesforce/core', () => { describe('test project paths', () => { const FAKE_WORKSPACE = '/here/is/a/fake/path/to/'; const FAKE_STATE_FOLDER = '.sfdx'; - const FAKE_TOOLS_FOLDER = '.sfdx/tools'; + const FAKE_TOOLS_FOLDER = 'tools'; describe('test stateFolder', () => { let getRootWorkspacePathStub: jest.SpyInstance; @@ -79,7 +79,7 @@ describe('test project paths', () => { it('should return a path to the relative tools folder', () => { const relativeToolsFolder = projectPaths.relativeToolsFolder(); - expect(relativeToolsFolder).toEqual(FAKE_TOOLS_FOLDER); + expect(relativeToolsFolder).toEqual(path.join(FAKE_STATE_FOLDER, FAKE_TOOLS_FOLDER)); }); }); }); From ca2558041c6aa156fb41f59bfee60961b0002f2c Mon Sep 17 00:00:00 2001 From: Ritam Agrawal Date: Tue, 1 Nov 2022 00:09:25 +0530 Subject: [PATCH 3/7] refactor: paths.test file --- packages/salesforcedx-utils-vscode/src/helpers/paths.ts | 3 ++- .../salesforcedx-utils-vscode/test/jest/helpers/paths.test.ts | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/salesforcedx-utils-vscode/src/helpers/paths.ts b/packages/salesforcedx-utils-vscode/src/helpers/paths.ts index 2dcf5ab2df..b3356e471d 100644 --- a/packages/salesforcedx-utils-vscode/src/helpers/paths.ts +++ b/packages/salesforcedx-utils-vscode/src/helpers/paths.ts @@ -162,5 +162,6 @@ export const projectPaths = { toolsFolder, lwcTestResultsFolder, relativeStateFolder, - relativeToolsFolder + relativeToolsFolder, + TOOLS }; diff --git a/packages/salesforcedx-utils-vscode/test/jest/helpers/paths.test.ts b/packages/salesforcedx-utils-vscode/test/jest/helpers/paths.test.ts index 26dd75b61b..93a5acc51d 100644 --- a/packages/salesforcedx-utils-vscode/test/jest/helpers/paths.test.ts +++ b/packages/salesforcedx-utils-vscode/test/jest/helpers/paths.test.ts @@ -13,7 +13,6 @@ jest.mock('@salesforce/core', () => { describe('test project paths', () => { const FAKE_WORKSPACE = '/here/is/a/fake/path/to/'; const FAKE_STATE_FOLDER = '.sfdx'; - const FAKE_TOOLS_FOLDER = 'tools'; describe('test stateFolder', () => { let getRootWorkspacePathStub: jest.SpyInstance; @@ -79,7 +78,7 @@ describe('test project paths', () => { it('should return a path to the relative tools folder', () => { const relativeToolsFolder = projectPaths.relativeToolsFolder(); - expect(relativeToolsFolder).toEqual(path.join(FAKE_STATE_FOLDER, FAKE_TOOLS_FOLDER)); + expect(relativeToolsFolder).toEqual(path.join(FAKE_STATE_FOLDER, projectPaths.TOOLS)); }); }); }); From 10a623c0b96c33c7cb2b950fd92649427af6f546 Mon Sep 17 00:00:00 2001 From: Ritam Agrawal Date: Tue, 1 Nov 2022 23:38:20 +0530 Subject: [PATCH 4/7] test: add jest test to core package --- .../salesforcedx-vscode-core/jest.config.js | 4 +++ .../salesforcedx-vscode-core/package.json | 3 ++- .../src/commands/isvdebugging/bootstrapCmd.ts | 4 +++ .../isvdebugging/bootstrapCmd.test.ts | 26 +++++++++++++++++++ scripts/setup-jest.ts | 1 + 5 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 packages/salesforcedx-vscode-core/jest.config.js create mode 100644 packages/salesforcedx-vscode-core/test/jest/commands/isvdebugging/bootstrapCmd.test.ts diff --git a/packages/salesforcedx-vscode-core/jest.config.js b/packages/salesforcedx-vscode-core/jest.config.js new file mode 100644 index 0000000000..806ac113d7 --- /dev/null +++ b/packages/salesforcedx-vscode-core/jest.config.js @@ -0,0 +1,4 @@ +//eslint:disable-next-line:no-var-requires +const baseConfig = require('../../config/jest.base.config'); + +module.exports = Object.assign({}, baseConfig); \ No newline at end of file diff --git a/packages/salesforcedx-vscode-core/package.json b/packages/salesforcedx-vscode-core/package.json index 29701a3537..b9e21f2b1d 100644 --- a/packages/salesforcedx-vscode-core/package.json +++ b/packages/salesforcedx-vscode-core/package.json @@ -107,7 +107,8 @@ "clean": "shx rm -rf node_modules && shx rm -rf out && shx rm -rf coverage && shx rm -rf .nyc_output", "test": "npm run test:vscode-integration", "test:vscode-integration": "cross-env CODE_TESTS_WORKSPACE='../system-tests/assets/sfdx-simple' node ../../scripts/run-vscode-integration-tests", - "test:vscode-insiders-integration": "cross-env CODE_VERSION=insiders npm run test:vscode-integration" + "test:vscode-insiders-integration": "cross-env CODE_VERSION=insiders npm run test:vscode-integration", + "test:unit": "jest --coverage" }, "nyc": { "reporter": [ diff --git a/packages/salesforcedx-vscode-core/src/commands/isvdebugging/bootstrapCmd.ts b/packages/salesforcedx-vscode-core/src/commands/isvdebugging/bootstrapCmd.ts index dbf96322b9..4522ca3da7 100644 --- a/packages/salesforcedx-vscode-core/src/commands/isvdebugging/bootstrapCmd.ts +++ b/packages/salesforcedx-vscode-core/src/commands/isvdebugging/bootstrapCmd.ts @@ -54,6 +54,10 @@ export interface InstalledPackageInfo { versionNumber: string; } +export const ISVDEBUGGER = 'isvdebuggermdapitmp'; +export const INSTALLED_PACKAGES = 'installed-packages'; +export const PACKAGE_XML = 'package.xml'; + export class IsvDebugBootstrapExecutor extends SfdxCommandletExecutor<{}> { public readonly relativeMetdataTempPath = path.join( projectPaths.relativeToolsFolder(), diff --git a/packages/salesforcedx-vscode-core/test/jest/commands/isvdebugging/bootstrapCmd.test.ts b/packages/salesforcedx-vscode-core/test/jest/commands/isvdebugging/bootstrapCmd.test.ts new file mode 100644 index 0000000000..2566c46d9e --- /dev/null +++ b/packages/salesforcedx-vscode-core/test/jest/commands/isvdebugging/bootstrapCmd.test.ts @@ -0,0 +1,26 @@ +import { projectPaths } from '@salesforce/salesforcedx-utils-vscode'; +import * as path from 'path'; +import { IsvDebugBootstrapExecutor, ISVDEBUGGER } from '../../../../src/commands/isvdebugging/bootstrapCmd'; + +describe('isvdebugging unit test', () => { + + const TOOLS_FOLDER = 'tools'; + let relativeToolsFolderStub: jest.SpyInstance; + + let isvDebugBootstrapExecutorInst: IsvDebugBootstrapExecutor; + + beforeEach(() => { + relativeToolsFolderStub = jest.spyOn(projectPaths, 'relativeToolsFolder').mockReturnValue(TOOLS_FOLDER); + isvDebugBootstrapExecutorInst = new IsvDebugBootstrapExecutor(); + + }); + + it('should be defined', () => { + expect(isvDebugBootstrapExecutorInst).toBeDefined(); + }); + + it('should test readonly relativeMetdataTempPath property', () => { + expect(isvDebugBootstrapExecutorInst.relativeMetdataTempPath).toEqual(path.join(TOOLS_FOLDER,ISVDEBUGGER)); + + }); +}); \ No newline at end of file diff --git a/scripts/setup-jest.ts b/scripts/setup-jest.ts index 6dad57651c..6ee18688f3 100644 --- a/scripts/setup-jest.ts +++ b/scripts/setup-jest.ts @@ -28,6 +28,7 @@ const getMockVSCode = () => { }; public dispose = () => {}; }, + TreeItem: jest.fn(), commands: jest.fn(), Disposable: jest.fn(), env: { From f267555f76b23e1a3262560ce4ba7a439f39979f Mon Sep 17 00:00:00 2001 From: Ritam Agrawal Date: Tue, 1 Nov 2022 23:42:38 +0530 Subject: [PATCH 5/7] fix: lint error --- .../test/jest/commands/isvdebugging/bootstrapCmd.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/salesforcedx-vscode-core/test/jest/commands/isvdebugging/bootstrapCmd.test.ts b/packages/salesforcedx-vscode-core/test/jest/commands/isvdebugging/bootstrapCmd.test.ts index 2566c46d9e..21800c195f 100644 --- a/packages/salesforcedx-vscode-core/test/jest/commands/isvdebugging/bootstrapCmd.test.ts +++ b/packages/salesforcedx-vscode-core/test/jest/commands/isvdebugging/bootstrapCmd.test.ts @@ -3,7 +3,7 @@ import * as path from 'path'; import { IsvDebugBootstrapExecutor, ISVDEBUGGER } from '../../../../src/commands/isvdebugging/bootstrapCmd'; describe('isvdebugging unit test', () => { - + const TOOLS_FOLDER = 'tools'; let relativeToolsFolderStub: jest.SpyInstance; @@ -18,9 +18,9 @@ describe('isvdebugging unit test', () => { it('should be defined', () => { expect(isvDebugBootstrapExecutorInst).toBeDefined(); }); - + it('should test readonly relativeMetdataTempPath property', () => { - expect(isvDebugBootstrapExecutorInst.relativeMetdataTempPath).toEqual(path.join(TOOLS_FOLDER,ISVDEBUGGER)); + expect(isvDebugBootstrapExecutorInst.relativeMetdataTempPath).toEqual(path.join(TOOLS_FOLDER, ISVDEBUGGER)); }); -}); \ No newline at end of file +}); From fb31e803cb05d32f9fbe10d068d13c2a27d45c0b Mon Sep 17 00:00:00 2001 From: Gordon Bockus Date: Wed, 2 Nov 2022 01:55:38 -0500 Subject: [PATCH 6/7] test: updates for running jest unit test in core --- .../src/commands/baseDeployRetrieve.ts | 2 +- .../src/commands/forceSourceDeployManifest.ts | 9 ++------- .../src/commands/forceSourceDeploySourcePath.ts | 2 +- .../commands/forceSourceRetrieveSourcePath.ts | 2 +- .../commands/util/conflictDetectionMessages.ts | 11 +++++++++++ .../src/commands/util/emptyPostChecker.ts | 16 ++++++++++++++++ .../src/commands/util/index.ts | 6 +++--- .../src/commands/util/postconditionCheckers.ts | 14 +------------- .../src/commands/util/sfdxCommandlet.ts | 16 ++++------------ .../commands/isvdebugging/bootstrapCmd.test.ts | 5 ++--- scripts/setup-jest.ts | 9 ++++++++- 11 files changed, 50 insertions(+), 42 deletions(-) create mode 100644 packages/salesforcedx-vscode-core/src/commands/util/conflictDetectionMessages.ts create mode 100644 packages/salesforcedx-vscode-core/src/commands/util/emptyPostChecker.ts diff --git a/packages/salesforcedx-vscode-core/src/commands/baseDeployRetrieve.ts b/packages/salesforcedx-vscode-core/src/commands/baseDeployRetrieve.ts index a9e3fa229e..67e035fb87 100644 --- a/packages/salesforcedx-vscode-core/src/commands/baseDeployRetrieve.ts +++ b/packages/salesforcedx-vscode-core/src/commands/baseDeployRetrieve.ts @@ -26,7 +26,6 @@ import { } from '@salesforce/source-deploy-retrieve/lib/src/client/types'; import { join } from 'path'; import * as vscode from 'vscode'; -import { BaseDeployExecutor } from '.'; import { channelService, OUTPUT_CHANNEL } from '../channels'; import { PersistentStorageService } from '../conflict/persistentStorageService'; import { TELEMETRY_METADATA_COUNT } from '../constants'; @@ -36,6 +35,7 @@ import { nls } from '../messages'; import { DeployQueue } from '../settings'; import { SfdxPackageDirectories } from '../sfdxProject'; import { OrgAuthInfo } from '../util'; +import { BaseDeployExecutor } from './baseDeployCommand'; import { createComponentCount, formatException } from './util'; type DeployRetrieveResult = DeployResult | RetrieveResult; diff --git a/packages/salesforcedx-vscode-core/src/commands/forceSourceDeployManifest.ts b/packages/salesforcedx-vscode-core/src/commands/forceSourceDeployManifest.ts index b00740f954..8d1ab0da55 100644 --- a/packages/salesforcedx-vscode-core/src/commands/forceSourceDeployManifest.ts +++ b/packages/salesforcedx-vscode-core/src/commands/forceSourceDeployManifest.ts @@ -4,17 +4,12 @@ * 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 { - Command, - SfdxCommandBuilder -} from '@salesforce/salesforcedx-utils-vscode'; -import { ContinueResponse } from '@salesforce/salesforcedx-utils-vscode'; +import { ContinueResponse, SfdxCommandBuilder } from '@salesforce/salesforcedx-utils-vscode'; import { ComponentSet } from '@salesforce/source-deploy-retrieve'; import { join } from 'path'; import * as vscode from 'vscode'; import { channelService } from '../channels'; import { - ConflictDetectionMessages, TimestampConflictChecker } from '../commands/util/postconditionCheckers'; import { nls } from '../messages'; @@ -23,7 +18,7 @@ import { SfdxPackageDirectories } from '../sfdxProject'; import { telemetryService } from '../telemetry'; import { workspaceUtils } from '../util'; import { DeployExecutor } from './baseDeployRetrieve'; -import { FilePathGatherer, SfdxCommandlet, SfdxWorkspaceChecker } from './util'; +import { ConflictDetectionMessages, FilePathGatherer, SfdxCommandlet, SfdxWorkspaceChecker } from './util'; export class LibrarySourceDeployManifestExecutor extends DeployExecutor< string diff --git a/packages/salesforcedx-vscode-core/src/commands/forceSourceDeploySourcePath.ts b/packages/salesforcedx-vscode-core/src/commands/forceSourceDeploySourcePath.ts index 002db2004f..85f30a3ab1 100644 --- a/packages/salesforcedx-vscode-core/src/commands/forceSourceDeploySourcePath.ts +++ b/packages/salesforcedx-vscode-core/src/commands/forceSourceDeploySourcePath.ts @@ -16,13 +16,13 @@ import { telemetryService } from '../telemetry'; import { DeployExecutor } from './baseDeployRetrieve'; import { SourcePathChecker } from './forceSourceRetrieveSourcePath'; import { + ConflictDetectionMessages, LibraryPathsGatherer, SfdxCommandlet, SfdxWorkspaceChecker } from './util'; import { CompositePostconditionChecker, - ConflictDetectionMessages, TimestampConflictChecker } from './util/postconditionCheckers'; diff --git a/packages/salesforcedx-vscode-core/src/commands/forceSourceRetrieveSourcePath.ts b/packages/salesforcedx-vscode-core/src/commands/forceSourceRetrieveSourcePath.ts index 5f41f03c77..d7a5facf0b 100644 --- a/packages/salesforcedx-vscode-core/src/commands/forceSourceRetrieveSourcePath.ts +++ b/packages/salesforcedx-vscode-core/src/commands/forceSourceRetrieveSourcePath.ts @@ -19,11 +19,11 @@ import { SfdxPackageDirectories, SfdxProjectConfig } from '../sfdxProject'; import { telemetryService } from '../telemetry'; import { RetrieveExecutor } from './baseDeployRetrieve'; import { + ConflictDetectionMessages, LibraryPathsGatherer, SfdxCommandlet, SfdxWorkspaceChecker } from './util'; -import { ConflictDetectionMessages } from './util/postconditionCheckers'; export class LibraryRetrieveSourcePathExecutor extends RetrieveExecutor< string[] diff --git a/packages/salesforcedx-vscode-core/src/commands/util/conflictDetectionMessages.ts b/packages/salesforcedx-vscode-core/src/commands/util/conflictDetectionMessages.ts new file mode 100644 index 0000000000..43bb159e01 --- /dev/null +++ b/packages/salesforcedx-vscode-core/src/commands/util/conflictDetectionMessages.ts @@ -0,0 +1,11 @@ +/* + * Copyright (c) 2022, 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 + */ + +export interface ConflictDetectionMessages { + warningMessageKey: string; + commandHint: (input: string | string[]) => string; +} diff --git a/packages/salesforcedx-vscode-core/src/commands/util/emptyPostChecker.ts b/packages/salesforcedx-vscode-core/src/commands/util/emptyPostChecker.ts new file mode 100644 index 0000000000..fd25e98194 --- /dev/null +++ b/packages/salesforcedx-vscode-core/src/commands/util/emptyPostChecker.ts @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2022, 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 { CancelResponse, ContinueResponse, PostconditionChecker } from '@salesforce/salesforcedx-utils-vscode'; + +export class EmptyPostChecker implements PostconditionChecker { + public async check( + inputs: ContinueResponse | CancelResponse + ): Promise | CancelResponse> { + return inputs; + } +} diff --git a/packages/salesforcedx-vscode-core/src/commands/util/index.ts b/packages/salesforcedx-vscode-core/src/commands/util/index.ts index 8465d63e19..ce9ca671e4 100644 --- a/packages/salesforcedx-vscode-core/src/commands/util/index.ts +++ b/packages/salesforcedx-vscode-core/src/commands/util/index.ts @@ -24,9 +24,9 @@ export { SelectUsername } from './parameterGatherers'; export { - ConflictDetectionMessages, - EmptyPostChecker -} from './postconditionCheckers'; + ConflictDetectionMessages +} from './conflictDetectionMessages'; +export {EmptyPostChecker} from './emptyPostChecker'; export { CommandletExecutor, CommandParams, diff --git a/packages/salesforcedx-vscode-core/src/commands/util/postconditionCheckers.ts b/packages/salesforcedx-vscode-core/src/commands/util/postconditionCheckers.ts index 91cb442286..5281d1eb29 100644 --- a/packages/salesforcedx-vscode-core/src/commands/util/postconditionCheckers.ts +++ b/packages/salesforcedx-vscode-core/src/commands/util/postconditionCheckers.ts @@ -25,6 +25,7 @@ import { notificationService } from '../../notifications'; import { DeployQueue, sfdxCoreSettings } from '../../settings'; import { telemetryService } from '../../telemetry'; import { MetadataDictionary, workspaceUtils } from '../../util'; +import { ConflictDetectionMessages } from './conflictDetectionMessages'; import { PathStrategyFactory } from './sourcePathStrategies'; type OneOrMany = LocalComponent | LocalComponent[]; @@ -54,14 +55,6 @@ export class CompositePostconditionChecker } } -export class EmptyPostChecker implements PostconditionChecker { - public async check( - inputs: ContinueResponse | CancelResponse - ): Promise | CancelResponse> { - return inputs; - } -} - /* tslint:disable-next-line:prefer-for-of */ export class OverwriteComponentPrompt implements PostconditionChecker { @@ -206,11 +199,6 @@ export class OverwriteComponentPrompt } } -export interface ConflictDetectionMessages { - warningMessageKey: string; - commandHint: (input: string | string[]) => string; -} - export class TimestampConflictChecker implements PostconditionChecker { private isManifest: boolean; private messages: ConflictDetectionMessages; diff --git a/packages/salesforcedx-vscode-core/src/commands/util/sfdxCommandlet.ts b/packages/salesforcedx-vscode-core/src/commands/util/sfdxCommandlet.ts index 069cc4c0de..f424566cf9 100644 --- a/packages/salesforcedx-vscode-core/src/commands/util/sfdxCommandlet.ts +++ b/packages/salesforcedx-vscode-core/src/commands/util/sfdxCommandlet.ts @@ -7,27 +7,19 @@ import { CliCommandExecutor, Command, - CommandExecution -} from '@salesforce/salesforcedx-utils-vscode'; -import { - Measurements, - Properties, - TelemetryData -} from '@salesforce/salesforcedx-utils-vscode'; -import { - ContinueResponse, - ParametersGatherer, + CommandExecution, ContinueResponse, Measurements, ParametersGatherer, PostconditionChecker, - PreconditionChecker + PreconditionChecker, Properties, + TelemetryData } from '@salesforce/salesforcedx-utils-vscode'; import * as vscode from 'vscode'; -import { EmptyPostChecker } from '.'; import { channelService } from '../../channels'; import { notificationService, ProgressNotification } from '../../notifications'; import { sfdxCoreSettings } from '../../settings'; import { taskViewService } from '../../statuses'; import { telemetryService } from '../../telemetry'; import { workspaceUtils } from '../../util'; +import { EmptyPostChecker } from './emptyPostChecker'; export enum CommandVersion { Beta = 'beta', diff --git a/packages/salesforcedx-vscode-core/test/jest/commands/isvdebugging/bootstrapCmd.test.ts b/packages/salesforcedx-vscode-core/test/jest/commands/isvdebugging/bootstrapCmd.test.ts index 21800c195f..56c2c358f7 100644 --- a/packages/salesforcedx-vscode-core/test/jest/commands/isvdebugging/bootstrapCmd.test.ts +++ b/packages/salesforcedx-vscode-core/test/jest/commands/isvdebugging/bootstrapCmd.test.ts @@ -11,16 +11,15 @@ describe('isvdebugging unit test', () => { beforeEach(() => { relativeToolsFolderStub = jest.spyOn(projectPaths, 'relativeToolsFolder').mockReturnValue(TOOLS_FOLDER); - isvDebugBootstrapExecutorInst = new IsvDebugBootstrapExecutor(); - }); it('should be defined', () => { + isvDebugBootstrapExecutorInst = new IsvDebugBootstrapExecutor(); expect(isvDebugBootstrapExecutorInst).toBeDefined(); }); it('should test readonly relativeMetdataTempPath property', () => { + isvDebugBootstrapExecutorInst = new IsvDebugBootstrapExecutor(); expect(isvDebugBootstrapExecutorInst.relativeMetdataTempPath).toEqual(path.join(TOOLS_FOLDER, ISVDEBUGGER)); - }); }); diff --git a/scripts/setup-jest.ts b/scripts/setup-jest.ts index 6ee18688f3..db0367a3d5 100644 --- a/scripts/setup-jest.ts +++ b/scripts/setup-jest.ts @@ -36,6 +36,9 @@ const getMockVSCode = () => { }, EventEmitter: EventEmitter, ExtensionMode: { Production: 1, Development: 2, Test: 3 }, + languages: { + createDiagnosticCollection: jest.fn() + }, Uri: { parse: jest.fn(), file: jest.fn() @@ -64,7 +67,11 @@ const getMockVSCode = () => { }; }, onDidChangeConfiguration: jest.fn(), - createFileSystemWatcher: jest.fn(), + createFileSystemWatcher: jest.fn().mockReturnValue({ + onDidChange: jest.fn(), + onDidCreate: jest.fn(), + onDidDelete: jest.fn() + }), workspaceFolders: [] } }; From d41019ed30fbbb870ec57832473cef16aabed58a Mon Sep 17 00:00:00 2001 From: Ritam Agrawal Date: Wed, 2 Nov 2022 23:21:39 +0530 Subject: [PATCH 7/7] test: add more jest test --- .../commands/isvdebugging/bootstrapCmd.test.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/salesforcedx-vscode-core/test/jest/commands/isvdebugging/bootstrapCmd.test.ts b/packages/salesforcedx-vscode-core/test/jest/commands/isvdebugging/bootstrapCmd.test.ts index 56c2c358f7..4c9af839f2 100644 --- a/packages/salesforcedx-vscode-core/test/jest/commands/isvdebugging/bootstrapCmd.test.ts +++ b/packages/salesforcedx-vscode-core/test/jest/commands/isvdebugging/bootstrapCmd.test.ts @@ -1,6 +1,6 @@ import { projectPaths } from '@salesforce/salesforcedx-utils-vscode'; import * as path from 'path'; -import { IsvDebugBootstrapExecutor, ISVDEBUGGER } from '../../../../src/commands/isvdebugging/bootstrapCmd'; +import { INSTALLED_PACKAGES, IsvDebugBootstrapExecutor, ISVDEBUGGER, PACKAGE_XML } from '../../../../src/commands/isvdebugging/bootstrapCmd'; describe('isvdebugging unit test', () => { @@ -21,5 +21,17 @@ describe('isvdebugging unit test', () => { it('should test readonly relativeMetdataTempPath property', () => { isvDebugBootstrapExecutorInst = new IsvDebugBootstrapExecutor(); expect(isvDebugBootstrapExecutorInst.relativeMetdataTempPath).toEqual(path.join(TOOLS_FOLDER, ISVDEBUGGER)); + expect(relativeToolsFolderStub).toBeCalled(); + }); + + it('should test readonly relativeApexPackageXmlPath property', () => { + isvDebugBootstrapExecutorInst = new IsvDebugBootstrapExecutor(); + expect(isvDebugBootstrapExecutorInst.relativeApexPackageXmlPath).toEqual(path.join(isvDebugBootstrapExecutorInst.relativeMetdataTempPath, PACKAGE_XML)); + }); + + it('should test readonly relativeInstalledPackagesPath property', () => { + isvDebugBootstrapExecutorInst = new IsvDebugBootstrapExecutor(); + expect(isvDebugBootstrapExecutorInst.relativeInstalledPackagesPath).toEqual(path.join(TOOLS_FOLDER, INSTALLED_PACKAGES)); + expect(relativeToolsFolderStub).toBeCalled(); }); });