-
Notifications
You must be signed in to change notification settings - Fork 29
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
feat: understands --config <FILE>
option in conventionalChangelogArgs
#927
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,26 @@ | ||||||
const path = require('path'); | ||||||
import { prepareParams } from '../updateChangelog'; | ||||||
import { parseArgs } from '../../../util'; | ||||||
import tempWrite from 'temp-write'; | ||||||
|
||||||
describe('prepareParams', () => { | ||||||
it('loads configuration from --config option', () => { | ||||||
parseArgs.mockImplementation(jest.requireActual('../../../util').parseArgs); | ||||||
const config = { | ||||||
writerOpts: { | ||||||
headerPartial: '## {{version}}', | ||||||
}, | ||||||
}; | ||||||
const configString = `module.exports = ${JSON.stringify(config)};`; | ||||||
const configPath = tempWrite.sync(configString); | ||||||
const configDir = path.basename(path.dirname(configPath)); | ||||||
|
||||||
const { args } = prepareParams({ | ||||||
dir: configDir, | ||||||
conventionalChangelogArgs: `-i CHANGELOG.md -s --config ${configPath}`, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed you added the There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
We have these two lines expecting to have |
||||||
revisionRange: '1.0.0..1.0.1', | ||||||
reject: () => {}, | ||||||
}); | ||||||
expect(args.config).toEqual(config); | ||||||
}); | ||||||
}); |
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 includingutil
. 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 underutil
globally, which madeparseArgs
returned nothing. So it made the test case failed. This lineparseArgs.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 theconsole.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).