From 5b0532ab694ee1c6f84c8afd258a04c1b1cb87b7 Mon Sep 17 00:00:00 2001 From: Andrei Draganescu Date: Tue, 26 Feb 2019 23:07:01 +0200 Subject: [PATCH 1/9] added an interactive argument to the test-e2e script --- packages/scripts/scripts/test-e2e.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/scripts/scripts/test-e2e.js b/packages/scripts/scripts/test-e2e.js index fc2e8b42f345d..d5c7442542041 100644 --- a/packages/scripts/scripts/test-e2e.js +++ b/packages/scripts/scripts/test-e2e.js @@ -20,6 +20,7 @@ const jest = require( 'jest' ); const { fromConfigRoot, getCliArgs, + getCliArg, hasCliArg, hasProjectFile, hasJestConfig, @@ -42,4 +43,9 @@ const runInBand = ! hasRunInBand ? [ '--runInBand' ] : []; +if ( hasCliArg( 'interactive' ) ) { + process.env.PUPPETEER_HEADLESS = false; + process.env.PUPPETEER_SLOWMO = 80; +} + jest.run( [ ...config, ...runInBand, ...getCliArgs() ] ); From 283643bae2a4038108517fd06611f001095fe50e Mon Sep 17 00:00:00 2001 From: Andrei Draganescu Date: Tue, 26 Feb 2019 23:12:16 +0200 Subject: [PATCH 2/9] mend --- packages/scripts/scripts/test-e2e.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/scripts/scripts/test-e2e.js b/packages/scripts/scripts/test-e2e.js index d5c7442542041..24d886820b120 100644 --- a/packages/scripts/scripts/test-e2e.js +++ b/packages/scripts/scripts/test-e2e.js @@ -20,7 +20,6 @@ const jest = require( 'jest' ); const { fromConfigRoot, getCliArgs, - getCliArg, hasCliArg, hasProjectFile, hasJestConfig, From d81db1392c7d8c76c644fb5c7e1e004570ce31ea Mon Sep 17 00:00:00 2001 From: Andrei Draganescu Date: Thu, 7 Mar 2019 09:39:50 +0200 Subject: [PATCH 3/9] added a way to bypass certain args from Jest, reverted to normal argument passing using double dash --- packages/scripts/scripts/test-e2e.js | 11 +++++++---- packages/scripts/utils/cli.js | 15 +++++++++++++++ packages/scripts/utils/index.js | 2 ++ 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/packages/scripts/scripts/test-e2e.js b/packages/scripts/scripts/test-e2e.js index 24d886820b120..45121af28e6a3 100644 --- a/packages/scripts/scripts/test-e2e.js +++ b/packages/scripts/scripts/test-e2e.js @@ -19,10 +19,11 @@ const jest = require( 'jest' ); */ const { fromConfigRoot, - getCliArgs, + getCliArg, hasCliArg, hasProjectFile, hasJestConfig, + cleanUpArgs, } = require( '../utils' ); // Provides a default config path for Puppeteer when jest-puppeteer.config.js @@ -42,9 +43,11 @@ const runInBand = ! hasRunInBand ? [ '--runInBand' ] : []; -if ( hasCliArg( 'interactive' ) ) { +const cleanUpPrefixes = [ '--puppeteer-' ]; + +if ( hasCliArg( '--puppeteer-interactive' ) ) { process.env.PUPPETEER_HEADLESS = false; - process.env.PUPPETEER_SLOWMO = 80; + process.env.PUPPETEER_SLOWMO = getCliArg( '--puppeteer-slowmo' ) || 80; } -jest.run( [ ...config, ...runInBand, ...getCliArgs() ] ); +jest.run( [ ...config, ...runInBand, ...cleanUpArgs( cleanUpPrefixes ) ] ); diff --git a/packages/scripts/utils/cli.js b/packages/scripts/utils/cli.js index 3778379ced192..3e0c036ff5e62 100644 --- a/packages/scripts/utils/cli.js +++ b/packages/scripts/utils/cli.js @@ -24,6 +24,20 @@ const getCliArg = ( arg ) => { } }; +const cleanUpArgs = ( prefixes ) => { + const cliArgs = getCliArgs(); + for ( let i = 0; i < cliArgs.length; i++ ) { + const cliArg = cliArgs[ i ]; + const name = cliArg.split( '=' )[ 0 ]; + for ( const prefix of prefixes ) { + if ( name.indexOf( prefix ) !== -1 ) { + cliArgs.splice( i, 1 ); + } + } + } + return cliArgs; +}; + const hasCliArg = ( arg ) => getCliArg( arg ) !== undefined; const handleSignal = ( signal ) => { @@ -82,4 +96,5 @@ module.exports = { getCliArgs, hasCliArg, spawnScript, + cleanUpArgs, }; diff --git a/packages/scripts/utils/index.js b/packages/scripts/utils/index.js index 0837f7ab80996..aebbcdca71800 100644 --- a/packages/scripts/utils/index.js +++ b/packages/scripts/utils/index.js @@ -6,6 +6,7 @@ const { getCliArgs, hasCliArg, spawnScript, + cleanUpArgs, } = require( './cli' ); const { getWebpackArgs, @@ -35,4 +36,5 @@ module.exports = { hasPackageProp, hasProjectFile, spawnScript, + cleanUpArgs, }; From 76ccbc52e73553a2caac6fd85f00217f7143e218 Mon Sep 17 00:00:00 2001 From: Andrei Draganescu Date: Thu, 7 Mar 2019 11:33:31 +0200 Subject: [PATCH 4/9] simplified the argument cleanup function --- packages/scripts/utils/cli.js | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/packages/scripts/utils/cli.js b/packages/scripts/utils/cli.js index 3e0c036ff5e62..f5bf6cc01f284 100644 --- a/packages/scripts/utils/cli.js +++ b/packages/scripts/utils/cli.js @@ -25,17 +25,9 @@ const getCliArg = ( arg ) => { }; const cleanUpArgs = ( prefixes ) => { - const cliArgs = getCliArgs(); - for ( let i = 0; i < cliArgs.length; i++ ) { - const cliArg = cliArgs[ i ]; - const name = cliArg.split( '=' )[ 0 ]; - for ( const prefix of prefixes ) { - if ( name.indexOf( prefix ) !== -1 ) { - cliArgs.splice( i, 1 ); - } - } - } - return cliArgs; + return getCliArgs().filter( ( arg ) => { + return ! prefixes.some( ( prefix ) => arg.startsWith( prefix ) ); + } ); }; const hasCliArg = ( arg ) => getCliArg( arg ) !== undefined; From b0b15029658ad806a0996d581a81204e4ca0fbd0 Mon Sep 17 00:00:00 2001 From: Andrei Draganescu Date: Thu, 7 Mar 2019 11:56:23 +0200 Subject: [PATCH 5/9] simplified the argument cleanup function --- packages/scripts/utils/cli.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/scripts/utils/cli.js b/packages/scripts/utils/cli.js index f5bf6cc01f284..73012707f53d4 100644 --- a/packages/scripts/utils/cli.js +++ b/packages/scripts/utils/cli.js @@ -25,7 +25,7 @@ const getCliArg = ( arg ) => { }; const cleanUpArgs = ( prefixes ) => { - return getCliArgs().filter( ( arg ) => { + return getCliArgs().filter( ( arg ) => { return ! prefixes.some( ( prefix ) => arg.startsWith( prefix ) ); } ); }; From 829d6e78229f530d12ebd97bf3b8eb84e115e131 Mon Sep 17 00:00:00 2001 From: Andrei Draganescu Date: Thu, 7 Mar 2019 09:39:50 +0200 Subject: [PATCH 6/9] added a way to bypass certain args from Jest, reverted to normal argument passing using double dash --- packages/scripts/utils/cli.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/scripts/utils/cli.js b/packages/scripts/utils/cli.js index 73012707f53d4..3e0c036ff5e62 100644 --- a/packages/scripts/utils/cli.js +++ b/packages/scripts/utils/cli.js @@ -25,9 +25,17 @@ const getCliArg = ( arg ) => { }; const cleanUpArgs = ( prefixes ) => { - return getCliArgs().filter( ( arg ) => { - return ! prefixes.some( ( prefix ) => arg.startsWith( prefix ) ); - } ); + const cliArgs = getCliArgs(); + for ( let i = 0; i < cliArgs.length; i++ ) { + const cliArg = cliArgs[ i ]; + const name = cliArg.split( '=' )[ 0 ]; + for ( const prefix of prefixes ) { + if ( name.indexOf( prefix ) !== -1 ) { + cliArgs.splice( i, 1 ); + } + } + } + return cliArgs; }; const hasCliArg = ( arg ) => getCliArg( arg ) !== undefined; From 745311c3e123234c0423804261c93a582e6e072f Mon Sep 17 00:00:00 2001 From: Andrei Draganescu Date: Thu, 7 Mar 2019 11:33:31 +0200 Subject: [PATCH 7/9] simplified the argument cleanup function --- packages/scripts/utils/cli.js | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/packages/scripts/utils/cli.js b/packages/scripts/utils/cli.js index 3e0c036ff5e62..f5bf6cc01f284 100644 --- a/packages/scripts/utils/cli.js +++ b/packages/scripts/utils/cli.js @@ -25,17 +25,9 @@ const getCliArg = ( arg ) => { }; const cleanUpArgs = ( prefixes ) => { - const cliArgs = getCliArgs(); - for ( let i = 0; i < cliArgs.length; i++ ) { - const cliArg = cliArgs[ i ]; - const name = cliArg.split( '=' )[ 0 ]; - for ( const prefix of prefixes ) { - if ( name.indexOf( prefix ) !== -1 ) { - cliArgs.splice( i, 1 ); - } - } - } - return cliArgs; + return getCliArgs().filter( ( arg ) => { + return ! prefixes.some( ( prefix ) => arg.startsWith( prefix ) ); + } ); }; const hasCliArg = ( arg ) => getCliArg( arg ) !== undefined; From 3bb652a8845d12c521b54503d5c24dd465195515 Mon Sep 17 00:00:00 2001 From: Andrei Draganescu Date: Thu, 7 Mar 2019 11:56:23 +0200 Subject: [PATCH 8/9] simplified the argument cleanup function --- packages/scripts/utils/cli.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/scripts/utils/cli.js b/packages/scripts/utils/cli.js index f5bf6cc01f284..73012707f53d4 100644 --- a/packages/scripts/utils/cli.js +++ b/packages/scripts/utils/cli.js @@ -25,7 +25,7 @@ const getCliArg = ( arg ) => { }; const cleanUpArgs = ( prefixes ) => { - return getCliArgs().filter( ( arg ) => { + return getCliArgs().filter( ( arg ) => { return ! prefixes.some( ( prefix ) => arg.startsWith( prefix ) ); } ); }; From a50944e80971e2cc75ab14c4efa191b7c954766b Mon Sep 17 00:00:00 2001 From: Andrei Draganescu Date: Fri, 15 Mar 2019 10:52:44 +0900 Subject: [PATCH 9/9] cleaned up the code by moving the prefixed arguments removal to getcliargs --- packages/scripts/scripts/test-e2e.js | 6 +++--- packages/scripts/utils/cli.js | 7 ------- packages/scripts/utils/process.js | 10 +++++++++- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/packages/scripts/scripts/test-e2e.js b/packages/scripts/scripts/test-e2e.js index 45121af28e6a3..8105891c8d838 100644 --- a/packages/scripts/scripts/test-e2e.js +++ b/packages/scripts/scripts/test-e2e.js @@ -20,10 +20,10 @@ const jest = require( 'jest' ); const { fromConfigRoot, getCliArg, + getCliArgs, hasCliArg, hasProjectFile, hasJestConfig, - cleanUpArgs, } = require( '../utils' ); // Provides a default config path for Puppeteer when jest-puppeteer.config.js @@ -46,8 +46,8 @@ const runInBand = ! hasRunInBand ? const cleanUpPrefixes = [ '--puppeteer-' ]; if ( hasCliArg( '--puppeteer-interactive' ) ) { - process.env.PUPPETEER_HEADLESS = false; + process.env.PUPPETEER_HEADLESS = 'false'; process.env.PUPPETEER_SLOWMO = getCliArg( '--puppeteer-slowmo' ) || 80; } -jest.run( [ ...config, ...runInBand, ...cleanUpArgs( cleanUpPrefixes ) ] ); +jest.run( [ ...config, ...runInBand, ...getCliArgs( cleanUpPrefixes ) ] ); diff --git a/packages/scripts/utils/cli.js b/packages/scripts/utils/cli.js index 73012707f53d4..3778379ced192 100644 --- a/packages/scripts/utils/cli.js +++ b/packages/scripts/utils/cli.js @@ -24,12 +24,6 @@ const getCliArg = ( arg ) => { } }; -const cleanUpArgs = ( prefixes ) => { - return getCliArgs().filter( ( arg ) => { - return ! prefixes.some( ( prefix ) => arg.startsWith( prefix ) ); - } ); -}; - const hasCliArg = ( arg ) => getCliArg( arg ) !== undefined; const handleSignal = ( signal ) => { @@ -88,5 +82,4 @@ module.exports = { getCliArgs, hasCliArg, spawnScript, - cleanUpArgs, }; diff --git a/packages/scripts/utils/process.js b/packages/scripts/utils/process.js index f8d3a0f6b2057..cfa38afa26aa9 100644 --- a/packages/scripts/utils/process.js +++ b/packages/scripts/utils/process.js @@ -1,4 +1,12 @@ -const getCliArgs = () => process.argv.slice( 2 ); +const getCliArgs = ( excludePrefixes ) => { + const args = process.argv.slice( 2 ); + if ( excludePrefixes ) { + return args.filter( ( arg ) => { + return ! excludePrefixes.some( ( prefix ) => arg.startsWith( prefix ) ); + } ); + } + return args; +}; module.exports = { exit: process.exit,