-
Notifications
You must be signed in to change notification settings - Fork 30
feat: understands --config <FILE> option in conventionalChangelogArgs
#927
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
Conversation
6de01f3 to
fdaa4df
Compare
fdaa4df to
2c57b65
Compare
packages/shipjs/src/step/prepare/__tests__/updateChangelog.spec.js
Outdated
Show resolved
Hide resolved
…c.js Co-authored-by: Haroen Viaene <hello@haroen.me>
|
|
||
| describe('prepareParams', () => { | ||
| it('loads configuration from --config option', () => { | ||
| parseArgs.mockImplementation(jest.requireActual('../../../util').parseArgs); |
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.
I had to restore the original implementation of parseArgs because I made a wrong choice in the beginning of Ship.js to globally mock many things including util. It's so hidden and hard to find out things like this :(
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.
Yes something was wrong with the parseArgs but I just discovered this morning that you finished the PR.
Just to understand: what does this test mock exactly? It seems we are mocking parseArgs but at the end, the config seems correctly generated, how does that work?
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.
Actually parseArgs was not supposed to be mocked, but I mocked everything under util globally, which made parseArgs returned nothing. So it made the test case failed. This line parseArgs.mockImplementation(jest.requireActual('../../../util').parseArgs); is restoring its original implementation.
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.
Got it, that's why it was returning me undefined and I couldn't see the console.log() I've added in its implementation! Thanks for letting me know. (my 2 cents on that, you should probably do it the other way around when testing: avoid to use global mocking, and use it explicitely when you need it in your tests).
| const { args } = prepareParams({ | ||
| dir: configDir, | ||
| conventionalChangelogArgs: `--config ${configPath}`, | ||
| conventionalChangelogArgs: `-i CHANGELOG.md -s --config ${configPath}`, |
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.
I noticed you added the -i/--infile option so that there is not the undefined error down the line with this flag. Too late for this PR as you already closed it, but maybe things could be improved here: arguments parsing shouldn't yield an error if a flag is missing, no?
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.
You're right.
shipjs/packages/shipjs/src/step/prepare/updateChangelog.js
Lines 100 to 101 in 06c7226
| args.infile = path.resolve(dir, args.infile); | |
| args.outfile = path.resolve(dir, args.outfile); |
We have these two lines expecting to have infile and outfile inside the parsed args. So the correct way to fix it would be to throw a better error message to dev and to document that these are mandatory.
No description provided.