Skip to content

Commit

Permalink
restore param so as not to break API stability
Browse files Browse the repository at this point in the history
  • Loading branch information
alicewriteswrongs committed Jul 22, 2022
1 parent 010c4c4 commit a578412
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
6 changes: 4 additions & 2 deletions src/cli/parse-flags.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LogLevel, LOG_LEVELS, TaskCommand } from '../declarations';
import { CompilerSystem, LogLevel, LOG_LEVELS, TaskCommand } from '../declarations';
import { dashToPascalCase, toDashCase } from '@utils';
import {
BOOLEAN_CLI_ARGS,
Expand All @@ -20,9 +20,11 @@ import {
* Parse command line arguments into a structured `ConfigFlags` object
*
* @param args an array of CLI flags
* @param _sys an optional compiler system
* @returns a structured ConfigFlags object
*/
export const parseFlags = (args: string[]): ConfigFlags => {
export const parseFlags = (args: string[], _sys?: CompilerSystem): ConfigFlags => {
// TODO(STENCIL-509): remove the _sys parameter here ^^ (for v3)
const flags: ConfigFlags = createConfigFlags();

// cmd line has more priority over npm scripts cmd
Expand Down
3 changes: 2 additions & 1 deletion src/cli/public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export declare function run(init: CliInitOptions): Promise<void>;
*/
export declare function runTask(coreCompiler: any, config: Config, task: TaskCommand): Promise<void>;

export declare function parseFlags(args: string[], sys?: CompilerSystem): ConfigFlags;
// TODO(STENCIL-509): remove the _sys parameter here (for v3)
export declare function parseFlags(args: string[], _sys?: CompilerSystem): ConfigFlags;

export { CompilerSystem, Config, ConfigFlags, Logger, TaskCommand };
26 changes: 13 additions & 13 deletions src/testing/jest/test/jest-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('jest-config', () => {
it('pass --maxWorkers=2 arg when --max-workers=2', () => {
const args = ['test', '--ci', '--max-workers=2'];
const config = mockValidatedConfig({ testing: {} });
config.flags = parseFlags(args, config.sys);
config.flags = parseFlags(args);

expect(config.flags.args).toEqual(['--ci', '--max-workers=2']);
expect(config.flags.unknownArgs).toEqual([]);
Expand All @@ -21,7 +21,7 @@ describe('jest-config', () => {
it('marks outputFile as a Jest argument', () => {
const args = ['test', '--ci', '--outputFile=path/to/my-file'];
const config = mockValidatedConfig({ testing: {} });
config.flags = parseFlags(args, config.sys);
config.flags = parseFlags(args);
expect(config.flags.args).toEqual(['--ci', '--outputFile=path/to/my-file']);
expect(config.flags.unknownArgs).toEqual([]);
const jestArgv = buildJestArgv(config);
Expand All @@ -31,7 +31,7 @@ describe('jest-config', () => {
it('pass --maxWorkers=2 arg when e2e test and --ci', () => {
const args = ['test', '--ci', '--e2e', '--max-workers=2'];
const config = mockValidatedConfig({ testing: {} });
config.flags = parseFlags(args, config.sys);
config.flags = parseFlags(args);

expect(config.flags.args).toEqual(['--ci', '--e2e', '--max-workers=2']);
expect(config.flags.unknownArgs).toEqual([]);
Expand All @@ -44,7 +44,7 @@ describe('jest-config', () => {
it('forces --maxWorkers=4 arg when e2e test and --ci', () => {
const args = ['test', '--ci', '--e2e'];
const config = mockValidatedConfig({ testing: {} });
config.flags = parseFlags(args, config.sys);
config.flags = parseFlags(args);

expect(config.flags.args).toEqual(['--ci', '--e2e']);
expect(config.flags.unknownArgs).toEqual([]);
Expand All @@ -57,7 +57,7 @@ describe('jest-config', () => {
it('pass --maxWorkers=2 arg to jest', () => {
const args = ['test', '--maxWorkers=2'];
const config = mockValidatedConfig({ testing: {} });
config.flags = parseFlags(args, config.sys);
config.flags = parseFlags(args);

expect(config.flags.args).toEqual(['--maxWorkers=2']);
expect(config.flags.unknownArgs).toEqual([]);
Expand All @@ -69,7 +69,7 @@ describe('jest-config', () => {
it('pass --ci arg to jest', () => {
const args = ['test', '--ci'];
const config = mockValidatedConfig({ testing: {} });
config.flags = parseFlags(args, config.sys);
config.flags = parseFlags(args);

expect(config.flags.args).toEqual(['--ci']);
expect(config.flags.unknownArgs).toEqual([]);
Expand All @@ -82,7 +82,7 @@ describe('jest-config', () => {
it('sets legacy jest options', () => {
const args = ['test'];
const config = mockValidatedConfig({ testing: {} });
config.flags = parseFlags(args, config.sys);
config.flags = parseFlags(args);

const jestArgv = buildJestArgv(config);

Expand Down Expand Up @@ -111,7 +111,7 @@ describe('jest-config', () => {
it('pass test spec arg to jest', () => {
const args = ['test', 'hello.spec.ts'];
const config = mockValidatedConfig({ testing: {} });
config.flags = parseFlags(args, config.sys);
config.flags = parseFlags(args);

expect(config.flags.args).toEqual(['hello.spec.ts']);
expect(config.flags.unknownArgs).toEqual(['hello.spec.ts']);
Expand All @@ -127,7 +127,7 @@ describe('jest-config', () => {
testMatch: ['hello.spec.ts'],
},
});
config.flags = parseFlags(args, config.sys);
config.flags = parseFlags(args);

expect(config.flags.task).toBe('test');

Expand All @@ -143,7 +143,7 @@ describe('jest-config', () => {
rootDir,
testing: { reporters: ['default', ['jest-junit', { suiteName: 'jest tests' }]] },
});
config.flags = parseFlags(args, config.sys);
config.flags = parseFlags(args);

const jestArgv = buildJestArgv(config);
const parsedConfig = JSON.parse(jestArgv.config) as d.JestConfig;
Expand All @@ -157,7 +157,7 @@ describe('jest-config', () => {
const rootDir = path.resolve('/');
const args = ['test'];
const config = mockValidatedConfig({ rootDir, testing: {} });
config.flags = parseFlags(args, config.sys);
config.flags = parseFlags(args);

const jestArgv = buildJestArgv(config);
const parsedConfig = JSON.parse(jestArgv.config) as d.JestConfig;
Expand All @@ -168,7 +168,7 @@ describe('jest-config', () => {
const rootDir = path.resolve('/');
const args = ['test'];
const config = mockValidatedConfig({ rootDir, testing: { collectCoverageFrom: ['**/*.+(ts|tsx)'] } });
config.flags = parseFlags(args, config.sys);
config.flags = parseFlags(args);

const jestArgv = buildJestArgv(config);
const parsedConfig = JSON.parse(jestArgv.config) as d.JestConfig;
Expand All @@ -179,7 +179,7 @@ describe('jest-config', () => {
it('passed flags should be respected over defaults', () => {
const args = ['test', '--spec', '--passWithNoTests'];
const config = mockValidatedConfig({ testing: {} });
config.flags = parseFlags(args, config.sys);
config.flags = parseFlags(args);

expect(config.flags.args).toEqual(['--spec', '--passWithNoTests']);
expect(config.flags.unknownArgs).toEqual([]);
Expand Down

0 comments on commit a578412

Please sign in to comment.