import type * as d from '@stencil/core/internal' ; import type { Config } from '@jest/types' ; import { isString } from '@utils' ; returns function getLegacyJestOptions ( ) { return { detectLeaks : false , 'detect-leaks' : false , detectOpenHandles : false , 'detect-open-handles' : false , errorOnDeprecated : false , 'error-on-deprecated' : false , listTests : false , 'list-tests' : false , maxConcurrency : 5 , 'max-concurrency' : 5 , notifyMode : 'failure-change' , 'notify-mode' : 'failure-change' , passWithNoTests : false , 'pass-with-no-tests' : false , runTestsByPath : false , 'run-tests-by-path' : false , testLocationInResults : false , 'test-location-in-results' : false , } ; } param config returns export function buildJestArgv ( config ) { const yargs = require ( 'yargs' ) ; const args = [ ... config . flags . unknownArgs . slice ( ) , ... config . flags . knownArgs . slice ( ) ] ; if ( ! args . some ( ( a ) => a . startsWith ( '--max-workers' ) || a . startsWith ( '--maxWorkers' ) ) ) { args . push ( `--max-workers=${ config . maxConcurrentWorkers }` ) ; } if ( config . flags . devtools ) { args . push ( '--runInBand' ) ; } config . logger . info ( config . logger . magenta ( `jest args: ${ args . join ( ' ' ) }` ) ) ; let jestArgv = yargs ( args ) . argv as Config . Argv ; jestArgv = { ... jestArgv , ... getLegacyJestOptions ( ) } ; jestArgv . config = buildJestConfig ( config ) ; if ( typeof jestArgv . maxWorkers === 'string' ) { try { jestArgv . maxWorkers = parseInt ( jestArgv . maxWorkers , 10 ) ; } catch ( e ) { } } if ( typeof jestArgv . ci === 'string' ) { jestArgv . ci = jestArgv . ci === 'true' || jestArgv . ci === '' ; } return jestArgv ; } param config returns export function buildJestConfig ( config ) { const stencilConfigTesting = config . testing ; const jestDefaults = require ( 'jest-config' ) . defaults ; const validJestConfigKeys = Object . keys ( jestDefaults ) ; const jestConfig = { } ; Object . keys ( stencilConfigTesting ) . forEach ( ( key ) => { if ( validJestConfigKeys . includes ( key ) ) { ( jestConfig as any ) [ key ] = ( stencilConfigTesting as any ) [ key ] ; } } ) ; jestConfig . rootDir = config . rootDir ; if ( isString ( stencilConfigTesting . collectCoverage ) ) { jestConfig . collectCoverage = stencilConfigTesting . collectCoverage ; } if ( Array . isArray ( stencilConfigTesting . collectCoverageFrom ) ) { jestConfig . collectCoverageFrom = stencilConfigTesting . collectCoverageFrom ; } if ( isString ( stencilConfigTesting . coverageDirectory ) ) { jestConfig . coverageDirectory = stencilConfigTesting . coverageDirectory ; } if ( stencilConfigTesting . coverageThreshold ) { jestConfig . coverageThreshold = stencilConfigTesting . coverageThreshold ; } if ( isString ( stencilConfigTesting . globalSetup ) ) { jestConfig . globalSetup = stencilConfigTesting . globalSetup ; } if ( isString ( stencilConfigTesting . globalTeardown ) ) { jestConfig . globalTeardown = stencilConfigTesting . globalTeardown ; } if ( isString ( stencilConfigTesting . preset ) ) { jestConfig . preset = stencilConfigTesting . preset ; } if ( stencilConfigTesting . projects ) { jestConfig . projects = stencilConfigTesting . projects ; } if ( Array . isArray ( stencilConfigTesting . reporters ) ) { jestConfig . reporters = stencilConfigTesting . reporters ; } if ( isString ( stencilConfigTesting . testResultsProcessor ) ) { jestConfig . testResultsProcessor = stencilConfigTesting . testResultsProcessor ; } if ( stencilConfigTesting . transform ) { jestConfig . transform = stencilConfigTesting . transform ; } if ( stencilConfigTesting . verbose ) { jestConfig . verbose = stencilConfigTesting . verbose ; } jestConfig . testRunner = 'jest-jasmine2' ; return JSON . stringify ( jestConfig ) ; } export function getProjectListFromCLIArgs ( config , argv ) { const projects = argv . projects ? argv . projects : [ ] ; projects . push ( config . rootDir ) ; return projects ; }