diff --git a/index.d.ts b/index.d.ts index 8c9ca4a..b6ae6c6 100644 --- a/index.d.ts +++ b/index.d.ts @@ -16,6 +16,7 @@ export {JESParserPluginOptions, JESParserOptions, createProjectWorkspace, Projec export interface RunArgs { args: string[]; replace?: boolean; // default is false + skipConversion?: boolean, // if true, args will not go through any conversion, such as dashed arg conversion. } export type SnapshotData = Record; export interface Options { diff --git a/src/Runner.js b/src/Runner.js index 8f0440f..dfa8c3d 100644 --- a/src/Runner.js +++ b/src/Runner.js @@ -53,9 +53,21 @@ export default class Runner extends EventEmitter { this._exited = false; } + __convertDashedArgs(args: string[]): string[] { + if (!this.workspace.useDashedArgs) { + return args; + } + + return args.map((arg) => + arg && arg.startsWith('--') && arg.length > 2 ? arg.replace(/(\B)([A-Z])/gm, '-$2').toLowerCase() : arg + ); + } + _getArgs(): string[] { if (this.options.args && this.options.args.replace) { - return this.options.args.args; + return this.options.args.skipConversion + ? this.options.args.args + : this.__convertDashedArgs(this.options.args.args); } // Handle the arg change on v18 @@ -88,11 +100,7 @@ export default class Runner extends EventEmitter { if (this.options.args) { args.push(...this.options.args.args); } - if (this.workspace.useDashedArgs) { - args = args.map((arg) => - arg && arg.startsWith('--') && arg.length > 2 ? arg.replace(/(\B)([A-Z])/gm, '-$2').toLowerCase() : arg - ); - } + args = this.__convertDashedArgs(args); return args; } diff --git a/src/__tests__/runner.test.js b/src/__tests__/runner.test.js index 23107a1..d860865 100644 --- a/src/__tests__/runner.test.js +++ b/src/__tests__/runner.test.js @@ -327,11 +327,14 @@ describe('Runner', () => { expect(args[0]).toBe(expected); }); - it('converts user passed in args', () => { - const expected = '--foo-bar-baz'; - + it.each` + argOption | expected + ${{args: ['--fooBarBaz']}} | ${'--foo-bar-baz'} + ${{args: ['--fooBarBaz'], replace: true}} | ${'--foo-bar-baz'} + ${{args: ['--fooBarBaz'], replace: true, skipConversion: true}} | ${'--fooBarBaz'} + `('converts user passed in args', ({argOption, expected}) => { const workspace: any = {useDashedArgs: true}; - const options = {args: {args: ['--fooBarBaz']}}; + const options = {args: argOption}; const sut = new Runner(workspace, options); sut.start(false); diff --git a/src/types.js b/src/types.js index 8fe302b..29a899b 100644 --- a/src/types.js +++ b/src/types.js @@ -18,6 +18,7 @@ export type Location = { export type RunArgs = { args: Array, replace?: boolean, // default is false + skipConversion?: boolean, // if true, args will not go through any conversion, such as dashed arg conversion. }; export type Options = {