diff --git a/__tests__/unit/lib/utils/cliHelper.test.ts b/__tests__/unit/lib/utils/cliHelper.test.ts index b8490c0f..5f976b2e 100644 --- a/__tests__/unit/lib/utils/cliHelper.test.ts +++ b/__tests__/unit/lib/utils/cliHelper.test.ts @@ -45,23 +45,22 @@ const mockedDirExists = jest.mocked(dirExists) const mockedFileExists = jest.mocked(fileExists) const mockedIsGit = jest.mocked(isGit) -mockedDirExists.mockImplementation(() => Promise.resolve(true)) -mockedFileExists.mockImplementation(() => Promise.resolve(true)) -mockedIsGit.mockImplementation(() => Promise.resolve(true)) - describe(`test if the application`, () => { let work: Work beforeEach(() => { work = getWork() work.config.to = 'test' work.config.apiVersion = 46 + mockedFileExists.mockImplementation(() => Promise.resolve(true)) + mockedDirExists.mockImplementation(() => Promise.resolve(true)) + mockedIsGit.mockImplementation(() => Promise.resolve(true)) + mockGetCommitRefType.mockImplementation(() => + Promise.resolve(COMMIT_REF_TYPE) + ) }) it('resume nicely when everything is well configured', async () => { // Arrange - mockGetCommitRefType.mockImplementation(() => - Promise.resolve(COMMIT_REF_TYPE) - ) const cliHelper = new CLIHelper({ ...work, config: { @@ -203,18 +202,6 @@ describe(`test if the application`, () => { await expect(cliHelper.validateConfig()).rejects.toThrow() }) - it('throws errors when apiVersion parameter is NaN', async () => { - const cliHelper = new CLIHelper({ - ...work, - config: { - ...work.config, - apiVersion: NaN, - }, - }) - expect.assertions(1) - await expect(cliHelper.validateConfig()).rejects.toThrow() - }) - it('throws errors when output folder does not exist', async () => { const cliHelper = new CLIHelper({ ...work, @@ -479,6 +466,7 @@ describe(`test if the application`, () => { beforeAll(async () => { latestAPIVersionSupported = await getLatestSupportedVersion() }) + beforeEach(jest.resetAllMocks) describe('when apiVersion parameter is set with supported value', () => { it.each([46, 52, 55])( 'config.apiVersion (%s) equals the parameter', @@ -501,7 +489,7 @@ describe(`test if the application`, () => { `config.apiVersion (%s) equals the latest version `, async version => { // Arrange - mockedFileExists.mockResolvedValueOnce(false) + mockedFileExists.mockImplementation(() => Promise.resolve(false)) work.config.apiVersion = version const cliHelper = new CLIHelper(work) @@ -518,10 +506,11 @@ describe(`test if the application`, () => { describe('when apiVersion parameter is not set', () => { describe('when sfdx-project.json file exist', () => { describe('when "sourceApiVersion" attribute is set with supported value', () => { - it.each(['46', '52', '55', '46.0', '52.0', '55.0'])( + it.each([46, 52, 53, 46.0, 52.0, 55.0])( 'config.apiVersion (%s) equals the "sourceApiVersion" attribute', async version => { // Arrange + mockedFileExists.mockImplementation(() => Promise.resolve(true)) mockedReadFile.mockImplementation(() => Promise.resolve(`{"sourceApiVersion":"${version}"}`) ) @@ -579,6 +568,7 @@ describe(`test if the application`, () => { describe('when sfdx-project.json file does not exist', () => { it('config.apiVersion equals the latest version', async () => { // Arrange + mockedFileExists.mockImplementation(() => Promise.resolve(false)) work.config.apiVersion = -1 const cliHelper = new CLIHelper(work) diff --git a/src/commands/sgd/source/delta.ts b/src/commands/sgd/source/delta.ts index 6b353c3f..868b3f73 100644 --- a/src/commands/sgd/source/delta.ts +++ b/src/commands/sgd/source/delta.ts @@ -79,8 +79,10 @@ export default class SourceDeltaGenerate extends SfdxCommand { public async run(): Promise { const output: Output = { + error: null, output: this.flags.output, success: true, + warnings: [], } try { const jobResult = await sgd({ diff --git a/src/types/output.ts b/src/types/output.ts index b000c29e..3dd1eed0 100644 --- a/src/types/output.ts +++ b/src/types/output.ts @@ -1,6 +1,6 @@ export type Output = { - error?: string + error: string | null output: string success: boolean - warnings?: string[] + warnings: string[] } diff --git a/src/utils/childProcessUtils.ts b/src/utils/childProcessUtils.ts index 25a15d3a..251e554a 100644 --- a/src/utils/childProcessUtils.ts +++ b/src/utils/childProcessUtils.ts @@ -4,9 +4,14 @@ import { normalize, sep } from 'path' export const EOLRegex: RegExp = /\r?\n/g -export const treatPathSep = (data: string) => data.replace(/[/\\]+/g, sep) +export const treatPathSep = (data: string) => data?.replace(/[/\\]+/g, sep) -export const sanitizePath = (data: string) => normalize(treatPathSep(data)) +export const sanitizePath = (data: string) => { + if (data) { + return normalize(treatPathSep(data)) + } + return data +} export const getSpawnContentByLine = async ( command: string, diff --git a/src/utils/repoSetup.ts b/src/utils/repoSetup.ts index a6e84413..520ed825 100644 --- a/src/utils/repoSetup.ts +++ b/src/utils/repoSetup.ts @@ -11,10 +11,9 @@ const gitConfig = ['config', 'core.quotepath', 'off'] export default class RepoSetup { protected readonly spawnConfig: SpawnOptionsWithoutStdio - // eslint-disable-next-line no-unused-vars constructor(protected readonly config: Config) { this.spawnConfig = { - cwd: this.config.repo, + cwd: config.repo, } }