-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Build If-merge #927
Merged
Merged
Build If-merge #927
Changes from 14 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
729080a
fix(util): improve `isDirectoryExists` function in the fs.ts
manushak b5222ef
test(mocks): update fs.ts mocks
manushak c52ae5a
fix(config): move `DIRECTORY_NOT_FOUND` from if-check into common config
manushak 431b30a
fix(util): move `DIRECTORY_NOT_FOUND` from if-check into common config
manushak d02cf9c
fix(config): remove `optional: false` from if-csv to allow the lib to…
manushak 0ebccdf
fix(config): remove `PARAMS_NOT_PRESENT` unneseccary string from if-csv
manushak 0dafebd
test(util): update if-check test related to changes
manushak addd01b
feat(config): add config and string for if-merge
manushak 875c863
feat(types): add `IFMergeArgs` type
manushak a11de2e
feat(util): add args.ts for if-merge
manushak 0b680ee
feat(util): add helpers functions for if-merge
manushak ac575ef
test(util): add tests for args.ts and helpers.ts
manushak 54a46d9
feat(src): add if-merge logic
manushak 1fa4326
feat(package): add `if-merge` command tool into package.json
manushak 8196169
Update package.json
manushak 49b2b5b
fix(package): revert package name to correct one
manushak 6f99d7f
test(util): add eslint comment
manushak a828eb3
feat(util): imporve `mergeManifests` helper function
manushak 5729b2b
fix(config): add `output` flag
manushak 902a810
fix(types): add `output` into IFMergeArgs type
manushak 7efa837
fix(util): update logic to print result if the `output` is not provided
manushak ec1693b
test(util): update tests
manushak 862ca01
Merge branch 'main' into if-merge
manushak dd24689
fix(util): compose unique name for tree children
manushak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,163 @@ | ||
import * as path from 'path'; | ||
|
||
jest.mock('../../../common/util/fs', () => ({ | ||
isFileExists: () => { | ||
if (process.env.fileExists === 'true') { | ||
return true; | ||
} | ||
return false; | ||
}, | ||
isDirectoryExists: () => { | ||
if (process.env.directoryExists === 'true') { | ||
return true; | ||
} | ||
return false; | ||
}, | ||
})); | ||
|
||
jest.mock('ts-command-line-args', () => ({ | ||
__esModule: true, | ||
parse: () => { | ||
switch (process.env.result) { | ||
case 'manifests-are-provided': | ||
return {manifests: ['mock-manifest1.yaml', 'mock-manifest2.yaml']}; | ||
case 'directory-is-provided': | ||
return {manifests: ['/mock-directory']}; | ||
case 'flags-are-not-provided': | ||
return {manifests: undefined, name: undefined, description: undefined}; | ||
case 'manifest-is-not-yaml': | ||
return {manifests: ['mock-manifest1.yaml', './mock-manifest2']}; | ||
case 'env-throw-error': | ||
throw new Error('mock-error'); | ||
case 'env-throw': | ||
throw 'mock-error'; | ||
default: | ||
return { | ||
manifests: ['mock-manifest1.yaml', 'mock-manifest2.yaml'], | ||
output: 'mock-output', | ||
}; | ||
} | ||
}, | ||
})); | ||
|
||
import {ERRORS} from '@grnsft/if-core/utils'; | ||
|
||
import {parseIfMergeArgs} from '../../../if-merge/util/args'; | ||
|
||
import {STRINGS as COMMON_STRINGS} from '../../../common/config'; | ||
|
||
import {STRINGS} from '../../../if-merge/config'; | ||
|
||
const {InvalidDirectoryError, CliSourceFileError, ParseCliParamsError} = ERRORS; | ||
|
||
const {DIRECTORY_NOT_FOUND, MANIFEST_NOT_FOUND} = COMMON_STRINGS; | ||
const {MANIFEST_IS_NOT_YAML} = STRINGS; | ||
|
||
describe('if-merge/util/args: ', () => { | ||
const originalEnv = process.env; | ||
|
||
describe('parseIfMergeArgs(): ', () => { | ||
const manifests = [ | ||
path.join(process.cwd(), 'mock-manifest1.yaml'), | ||
path.join(process.cwd(), 'mock-manifest2.yaml'), | ||
]; | ||
it('executes when `manifest` is provided.', async () => { | ||
process.env.fileExists = 'true'; | ||
process.env.result = 'manifests-are-provided'; | ||
const response = await parseIfMergeArgs(); | ||
|
||
expect.assertions(1); | ||
|
||
expect(response).toEqual({ | ||
name: undefined, | ||
description: undefined, | ||
manifests, | ||
}); | ||
}); | ||
|
||
it('executes when the directory is provided.', async () => { | ||
process.env.directoryExists = 'true'; | ||
process.env.result = 'directory-is-provided'; | ||
|
||
const response = await parseIfMergeArgs(); | ||
|
||
expect.assertions(1); | ||
|
||
expect(response).toEqual({ | ||
name: undefined, | ||
description: undefined, | ||
manifests: ['/mock-directory'], | ||
}); | ||
}); | ||
|
||
it('throws an error when the directory does not exist.', async () => { | ||
process.env.directoryExists = 'false'; | ||
process.env.result = 'directory-is-provided'; | ||
expect.assertions(1); | ||
|
||
try { | ||
await parseIfMergeArgs(); | ||
} catch (error) { | ||
expect(error).toEqual(new InvalidDirectoryError(DIRECTORY_NOT_FOUND)); | ||
} | ||
}); | ||
|
||
it('throws an error if one of manifests is not a yaml.', async () => { | ||
process.env.fileExists = 'true'; | ||
process.env.result = 'manifest-is-not-yaml'; | ||
expect.assertions(1); | ||
|
||
try { | ||
await parseIfMergeArgs(); | ||
} catch (error) { | ||
if (error instanceof Error) { | ||
expect(error).toEqual( | ||
new CliSourceFileError(MANIFEST_IS_NOT_YAML('./mock-manifest2')) | ||
); | ||
} | ||
} | ||
}); | ||
|
||
it('throws an error if `manifest` path is invalid.', async () => { | ||
process.env.fileExists = 'false'; | ||
process.env.result = 'manifest-is-not-yaml'; | ||
expect.assertions(1); | ||
|
||
try { | ||
await parseIfMergeArgs(); | ||
} catch (error) { | ||
if (error instanceof Error) { | ||
expect(error).toEqual( | ||
new ParseCliParamsError(`mock-manifest1.yaml ${MANIFEST_NOT_FOUND}`) | ||
); | ||
} | ||
} | ||
}); | ||
|
||
it('throws an error if parsing failed.', async () => { | ||
process.env.result = 'env-throw-error'; | ||
expect.assertions(1); | ||
|
||
try { | ||
await parseIfMergeArgs(); | ||
} catch (error) { | ||
if (error instanceof Error) { | ||
expect(error).toEqual(new ParseCliParamsError('mock-error')); | ||
} | ||
} | ||
}); | ||
|
||
it('throws error if parsing failed (not instance of error).', async () => { | ||
process.env.result = 'env-throw'; | ||
expect.assertions(1); | ||
|
||
try { | ||
await parseIfMergeArgs(); | ||
} catch (error) { | ||
expect(error).toEqual('mock-error'); | ||
} | ||
}); | ||
}); | ||
|
||
process.env = originalEnv; | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this bug is still here, please fix when you have window