Skip to content

Commit

Permalink
Merge pull request #322 from zyulyaev/fix-cli-extra-args
Browse files Browse the repository at this point in the history
Fix extra args not being passed to jest
  • Loading branch information
yannbf committed Jul 14, 2023
2 parents 316d290 + 051dea3 commit e3406ed
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
18 changes: 17 additions & 1 deletion src/util/getCliOptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,28 @@ import { getCliOptions } from './getCliOptions';
import * as cliHelper from './getParsedCliOptions';

describe('getCliOptions', () => {
let originalArgv: string[] = process.argv;

afterEach(() => {
process.argv = originalArgv;
});

it('returns custom options if passed', () => {
const customConfig = { configDir: 'custom', indexJson: true };
jest
.spyOn(cliHelper, 'getParsedCliOptions')
.mockReturnValue({ options: customConfig, extraArgs: [] });
.mockReturnValueOnce({ options: customConfig, extraArgs: [] });
const opts = getCliOptions();
expect(opts.runnerOptions).toMatchObject(customConfig);
});

it('returns extra args if passed', () => {
const extraArgs = ['TestName', 'AnotherTestName'];
// mock argv to avoid side effect from running tests e.g. jest --coverage,
// which would end up caught by getCliOptions
process.argv = [];
jest.spyOn(cliHelper, 'getParsedCliOptions').mockReturnValueOnce({ options: {}, extraArgs });
const opts = getCliOptions();
expect(opts.jestOptions).toEqual(extraArgs);
});
});
6 changes: 2 additions & 4 deletions src/util/getCliOptions.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { getParsedCliOptions } from './getParsedCliOptions';
import type { BrowserType } from 'jest-playwright-preset';

export type JestOptions = {
[key: string]: any;
};
export type JestOptions = string[];

export type CliOptions = {
runnerOptions: {
Expand Down Expand Up @@ -63,7 +61,7 @@ export const getCliOptions = (): CliOptions => {
}, defaultOptions);

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

return finalOptions;
Expand Down

0 comments on commit e3406ed

Please sign in to comment.