66 * Each of these configurations requires a separate AVA config file like
77 * test/_ava.special.config.js and a name.
88 * The ses-ava command will by default run all tests in every mode but allows
9- * the user to pass --only-* and --no-* at any argument position for any of
10- * the named configurations to filter.
9+ * the user to pass --only <name> and --exclude <name> (or shorthands -o <name>
10+ * and -x <name>) at any argument position for any of the named configurations
11+ * to filter.
1112 * Consequently, the "test" script for a package using ses-ava can simply be
1213 * "ses-ava" and preserves the filtering behaviors of the underlying "ava"
1314 * sessions if run like `yarn test -m file`.
@@ -46,8 +47,6 @@ export const main = async () => {
4647 if ( ava ) sesAvaConfigs . default = undefined ;
4748 const keys = Object . keys ( sesAvaConfigs ) ;
4849 const allConfigNames = new Set ( keys ) ;
49- const noFlags = new Map ( keys . map ( key => [ `--no-config-${ key } ` , key ] ) ) ;
50- const onlyFlags = new Map ( keys . map ( key => [ `--only-config-${ key } ` , key ] ) ) ;
5150
5251 // Parse arguments.
5352 const passThroughArgs = [ ] ;
@@ -56,38 +55,43 @@ export const main = async () => {
5655 let failFast = false ;
5756 let firstArg = true ;
5857 const argsIterator = process . argv . slice ( 2 ) [ Symbol . iterator ] ( ) ;
59- for ( const arg of argsIterator ) {
60- if ( arg === '--' ) {
58+ for ( const rawArg of argsIterator ) {
59+ if ( rawArg === '--' ) {
6160 passThroughArgs . push ( ...argsIterator ) ;
6261 break ;
6362 }
64- const noKey = noFlags . get ( arg ) ;
65- const onlyKey = onlyFlags . get ( arg ) ;
66- const equalsAt = arg . indexOf ( '=' ) ;
67- if ( passThroughFlags . has ( arg ) ) {
68- passThroughArgs . push ( arg ) ;
69- } else if ( arg . startsWith ( '--' ) && equalsAt !== - 1 ) {
70- const flag = arg . slice ( 0 , equalsAt ) ;
71- if ( ! passThroughArgOptions . has ( flag ) ) {
72- throw new Error ( `Unrecognized flag ${ flag } ` ) ;
63+ const charsBeforeOptArg = rawArg . startsWith ( '--' ) ? rawArg . indexOf ( '=' ) : 2 ;
64+ const arg =
65+ charsBeforeOptArg !== - 1 ? rawArg . slice ( 0 , charsBeforeOptArg ) : rawArg ;
66+ const getOptArg = ( ) => {
67+ if ( charsBeforeOptArg !== - 1 ) {
68+ if ( rawArg . startsWith ( '--' ) ) return rawArg . slice ( charsBeforeOptArg + 1 ) ;
69+ if ( rawArg . length > 2 ) return rawArg . slice ( 2 ) ;
7370 }
74- passThroughArgs . push ( arg ) ;
75- } else if ( passThroughArgOptions . has ( arg ) ) {
76- const { value : nextArg , done } = argsIterator . next ( ) ;
71+ const { value, done } = argsIterator . next ( ) ;
7772 if ( done ) {
7873 throw new Error ( `Expected argument after ${ arg } ` ) ;
7974 }
80- passThroughArgs . push ( arg , nextArg ) ;
81- } else if ( arg === '--fail-fast' ) {
75+ return value ;
76+ } ;
77+ if ( passThroughFlags . has ( arg ) ) {
78+ passThroughArgs . push ( rawArg ) ;
79+ } else if ( passThroughArgOptions . has ( arg ) ) {
80+ if ( arg !== rawArg ) {
81+ passThroughArgs . push ( rawArg ) ;
82+ } else {
83+ passThroughArgs . push ( arg , getOptArg ( ) ) ;
84+ }
85+ } else if ( rawArg === '--fail-fast' ) {
8286 // Pass-through too
83- passThroughArgs . push ( arg ) ;
87+ passThroughArgs . push ( rawArg ) ;
8488 failFast = true ;
8589 } else if ( arg === 'reset-cache' && firstArg ) {
86- passThroughArgs . push ( arg ) ;
87- } else if ( noKey ) {
88- noConfigNames . add ( noKey ) ;
89- } else if ( onlyKey ) {
90- onlyConfigNames . add ( onlyKey ) ;
90+ passThroughArgs . push ( rawArg ) ;
91+ } else if ( arg === '--exclude' || arg === '-x' ) {
92+ noConfigNames . add ( getOptArg ( ) ) ;
93+ } else if ( arg === '--only' || arg === '-o' ) {
94+ onlyConfigNames . add ( getOptArg ( ) ) ;
9195 } else if ( arg . startsWith ( '-' ) ) {
9296 throw new Error (
9397 `Unknown flag ${ arg } . If this is an ava flag, pass through after --.` ,
@@ -102,11 +106,9 @@ export const main = async () => {
102106 const configs = new Set ( ) ;
103107 for ( const config of noConfigNames ) {
104108 if ( onlyConfigNames . has ( config ) ) {
105- // Ask not the advice of wizards, for they will say both --no-config- and
106- // --only-config-.
107- throw new Error (
108- `ses-ava cannot respect both --no-config-${ config } and --only-config-${ config } ` ,
109- ) ;
109+ // Ask not the advice of wizards, for they will say both --include and
110+ // --exclude.
111+ throw new Error ( `ses-ava cannot both include and exclude ${ config } ` ) ;
110112 }
111113 }
112114 for ( const config of onlyConfigNames . size > 0
0 commit comments