Skip to content

Commit

Permalink
fix: pass extra args to jest
Browse files Browse the repository at this point in the history
  • Loading branch information
yannbf committed Feb 10, 2022
1 parent 7eac123 commit d7bde1d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/util/getCliOptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ describe('getCliOptions', () => {

it('returns custom options if passed', () => {
const customConfig = { configDir: 'custom', storiesJson: true };
jest.spyOn(cliHelper, 'getParsedCliOptions').mockReturnValue(customConfig);
jest
.spyOn(cliHelper, 'getParsedCliOptions')
.mockReturnValue({ options: customConfig, extraArgs: [] });
const opts = getCliOptions();
expect(opts.runnerOptions).toMatchObject(customConfig);
});
Expand Down
10 changes: 8 additions & 2 deletions src/util/getCliOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ export const defaultRunnerOptions: CliOptions['runnerOptions'] = {
};

export const getCliOptions = () => {
const allOptions = getParsedCliOptions();
const { options: allOptions, extraArgs } = getParsedCliOptions();

const defaultOptions: CliOptions = {
runnerOptions: { ...defaultRunnerOptions },
jestOptions: process.argv.splice(0, 2),
};

return Object.keys(allOptions).reduce((acc, key: any) => {
const finalOptions = Object.keys(allOptions).reduce((acc, key: any) => {
if (STORYBOOK_RUNNER_COMMANDS.includes(key)) {
//@ts-ignore
acc.runnerOptions[key] = allOptions[key];
Expand All @@ -41,4 +41,10 @@ export const getCliOptions = () => {

return acc;
}, defaultOptions);

if (extraArgs.length) {
finalOptions.jestOptions.push(...extraArgs);
}

return finalOptions;
};
5 changes: 4 additions & 1 deletion src/util/getParsedCliOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,8 @@ export const getParsedCliOptions = () => {
}
}

return program.opts();
return {
options: program.opts(),
extraArgs: program.args,
};
};

0 comments on commit d7bde1d

Please sign in to comment.