-
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add test for the new output behavior
- Loading branch information
Showing
2 changed files
with
104 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
'use strict' | ||
const CLIHelper = require('../../../../src/utils/cliHelper') | ||
const gc = require('../../../../src/utils/gitConstants') | ||
|
||
const child_process = require('child_process') | ||
jest.mock('child_process', () => ({ spawnSync: jest.fn() })) | ||
jest.mock('fs-extra') | ||
jest.mock('fs') | ||
jest.mock('git-state') | ||
jest.mock('fast-xml-parser') | ||
|
||
const fsMocked = require('fs') | ||
const fseMocked = require('fs-extra') | ||
|
||
const testConfig = { | ||
output: 'output', | ||
repo: '', | ||
source: '', | ||
to: 'test', | ||
apiVersion: '46', | ||
} | ||
|
||
describe(`test if the appli`, () => { | ||
let cliHelper | ||
beforeAll(() => { | ||
fsMocked.errorMode = false | ||
fseMocked.errorMode = false | ||
fseMocked.outputFileSyncError = false | ||
fsMocked.__setMockFiles({ | ||
output: '', | ||
'.': '', | ||
}) | ||
child_process.spawnSync.mockImplementation(() => ({ stdout: '' })) | ||
}) | ||
|
||
test('throw errors when to parameter is not filled', () => { | ||
cliHelper = new CLIHelper({ ...testConfig, to: undefined }) | ||
expect(() => { | ||
cliHelper.validateConfig() | ||
}).toThrow() | ||
}) | ||
|
||
test('throw errors when apiVersion parameter is NaN', () => { | ||
cliHelper = new CLIHelper({ ...testConfig, apiVersion: 'NotANumber' }) | ||
expect(() => { | ||
cliHelper.validateConfig() | ||
}).toThrow() | ||
}) | ||
|
||
test('throw errors when output folder does not exist', () => { | ||
cliHelper = new CLIHelper({ ...testConfig, to: undefined }) | ||
expect(() => { | ||
cliHelper.validateConfig({ | ||
...testConfig, | ||
output: 'not/exist/folder', | ||
}) | ||
}).toThrow() | ||
}) | ||
|
||
test('throw errors when output is not a folder', () => { | ||
cliHelper = new CLIHelper({ ...testConfig, output: 'file' }) | ||
expect(() => { | ||
cliHelper.validateConfig() | ||
}).toThrow() | ||
}) | ||
|
||
test('throw errors when repo is not git repository', () => { | ||
cliHelper = new CLIHelper({ | ||
...testConfig, | ||
repo: 'not/git/folder', | ||
}) | ||
expect(() => { | ||
cliHelper.validateConfig() | ||
}).toThrow() | ||
}) | ||
|
||
test('throw errors when "-t" and "-d" are set', () => { | ||
const notHeadSHA = 'test' | ||
child_process.spawnSync | ||
.mockReturnValueOnce({ stdout: Buffer.from('HEAD', gc.UTF8_ENCODING) }) | ||
.mockReturnValueOnce({ | ||
stdout: Buffer.from(notHeadSHA, gc.UTF8_ENCODING), | ||
}) | ||
cliHelper = new CLIHelper({ | ||
...testConfig, | ||
to: notHeadSHA, | ||
generateDelta: true, | ||
}) | ||
expect(() => { | ||
cliHelper.validateConfig() | ||
}).toThrow() | ||
}) | ||
|
||
test('throw errors when "-d" is set and "-r" equals "-o', () => { | ||
cliHelper = new CLIHelper({ | ||
...testConfig, | ||
output: '', | ||
generateDelta: true, | ||
}) | ||
expect(() => { | ||
cliHelper.validateConfig() | ||
}).toThrow() | ||
}) | ||
}) |