Skip to content

Commit

Permalink
fix: output format
Browse files Browse the repository at this point in the history
  • Loading branch information
scolladon committed Sep 8, 2023
1 parent f25b26f commit baa215c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 27 deletions.
32 changes: 11 additions & 21 deletions __tests__/unit/lib/utils/cliHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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',
Expand All @@ -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)

Expand All @@ -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}"}`)
)
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 2 additions & 0 deletions src/commands/sgd/source/delta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ export default class SourceDeltaGenerate extends SfdxCommand {

public async run(): Promise<Output> {
const output: Output = {
error: null,
output: this.flags.output,
success: true,
warnings: [],
}
try {
const jobResult = await sgd({
Expand Down
4 changes: 2 additions & 2 deletions src/types/output.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export type Output = {
error?: string
error: string | null
output: string
success: boolean
warnings?: string[]
warnings: string[]
}
9 changes: 7 additions & 2 deletions src/utils/childProcessUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions src/utils/repoSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down

0 comments on commit baa215c

Please sign in to comment.