Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions packages/jest/src/options-converter.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
import { SchemaObject as JestBuilderSchema } from './schema';

const POSITIONAL_ARRAY_OPTIONS = new Set(['findRelatedTests']);

export class OptionsConverter {
convertToCliArgs(options: Partial<JestBuilderSchema>): string[] {
const argv = [];
const argv: string[] = [];
const positionalsToAppend: string[] = [];
let nonFlagArgs: string | undefined;
for (const option of Object.keys(options)) {
let optionValue = options[option];
const optionValue = (options as Record<string, unknown>)[option];
if (option == '--') {
nonFlagArgs = (optionValue as string[]).join(' ');
} else if (
POSITIONAL_ARRAY_OPTIONS.has(option) &&
(Array.isArray(optionValue) || typeof optionValue === 'string')
) {
argv.push(`--${option}`);
const items = Array.isArray(optionValue) ? optionValue : [optionValue];
for (const item of items) {
for (const file of String(item).split(',')) {
if (file) positionalsToAppend.push(file);
}
}
} else if (optionValue === true) {
argv.push(`--${option}`);
} else if (typeof optionValue === 'string' || typeof optionValue === 'number') {
Expand All @@ -18,6 +32,7 @@ export class OptionsConverter {
}
}
}
argv.push(...positionalsToAppend);
if (nonFlagArgs) {
argv.push(nonFlagArgs);
}
Expand Down
16 changes: 16 additions & 0 deletions packages/jest/tests/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,22 @@ module.exports = [
command:
'node ../../../packages/jest/tests/validate.js my-shared-library --find-related-tests projects/my-shared-library/src/lib/my-shared-library.service.ts projects/my-shared-library/src/lib/my-shared-library.component.ts --expect-suites=2 --expect-tests=2',
},
{
id: 'multi-project-find-related-single',
name: 'jest: --find-related-tests single file filters correctly',
purpose: '--find-related-tests with one source file runs only its related spec',
app: 'examples/jest/multiple-apps',
command:
'node ../../../packages/jest/tests/validate.js my-shared-library --find-related-tests projects/my-shared-library/src/lib/my-shared-library.service.ts --expect-suites=1 --expect-tests=1',
},
{
id: 'multi-project-find-related-comma',
name: 'jest: --find-related-tests comma-separated paths',
purpose: 'Comma-separated --find-related-tests value is split into positional file args',
app: 'examples/jest/multiple-apps',
command:
'node ../../../packages/jest/tests/validate.js my-shared-library --find-related-tests=projects/my-shared-library/src/lib/my-shared-library.service.ts,projects/my-shared-library/src/lib/my-shared-library.component.ts --expect-suites=2 --expect-tests=2',
},

// E2E sanity
{
Expand Down
Loading