@@ -1031,15 +1031,6 @@ describe('testPathPattern', () => {
10311031 const initialOptions = { rootDir : '/root' } ;
10321032 const consoleLog = console . log ;
10331033
1034- function testWindowsPathSeparator ( argv , expected ) {
1035- jest . resetModules ( ) ;
1036- jest . mock ( 'path' , ( ) => require . requireActual ( 'path' ) . win32 ) ;
1037- require ( 'jest-resolve' ) . findNodeModule = findNodeModule ;
1038-
1039- const { options} = require ( '../normalize' ) . default ( initialOptions , argv ) ;
1040- expect ( options . testPathPattern ) . toBe ( expected ) ;
1041- }
1042-
10431034 beforeEach ( ( ) => {
10441035 console . log = jest . fn ( ) ;
10451036 } ) ;
@@ -1053,62 +1044,85 @@ describe('testPathPattern', () => {
10531044 expect ( options . testPathPattern ) . toBe ( '' ) ;
10541045 } ) ;
10551046
1056- describe ( '--testPathPattern' , ( ) => {
1057- it ( 'uses testPathPattern if set' , ( ) => {
1058- const { options} = normalize ( initialOptions , { testPathPattern : [ 'a/b' ] } ) ;
1059- expect ( options . testPathPattern ) . toBe ( 'a/b' ) ;
1060- } ) ;
1047+ const cliOptions = [
1048+ { name : '--testPathPattern' , property : 'testPathPattern' } ,
1049+ { name : '<regexForTestFiles>' , property : '_' } ,
1050+ ] ;
1051+ for ( const opt of cliOptions ) {
1052+ describe ( opt . name , ( ) => {
1053+ it ( 'uses ' + opt . name + ' if set' , ( ) => {
1054+ const argv = { [ opt . property ] : [ 'a/b' ] } ;
1055+ const { options} = normalize ( initialOptions , argv ) ;
10611056
1062- it ( 'ignores invalid regular expressions and logs a warning' , ( ) => {
1063- const { options} = normalize ( initialOptions , { testPathPattern : [ 'a(' ] } ) ;
1064- expect ( options . testPathPattern ) . toBe ( '' ) ;
1065- expect ( console . log . mock . calls [ 0 ] [ 0 ] ) . toMatchSnapshot ( ) ;
1066- } ) ;
1057+ expect ( options . testPathPattern ) . toBe ( 'a/b' ) ;
1058+ } ) ;
10671059
1068- it ( 'escapes Windows path separators ' , ( ) => {
1069- testWindowsPathSeparator ( { testPathPattern : [ 'a\\b ' ] } , 'a\\\\b' ) ;
1070- } ) ;
1060+ it ( 'ignores invalid regular expressions and logs a warning ' , ( ) => {
1061+ const argv = { [ opt . property ] : [ 'a( ' ] } ;
1062+ const { options } = normalize ( initialOptions , argv ) ;
10711063
1072- it ( 'joins multiple --testPathPatterns if set' , ( ) => {
1073- const { options} = normalize ( initialOptions , {
1074- testPathPattern : [ 'a/b' , 'c/d' ] ,
1064+ expect ( options . testPathPattern ) . toBe ( '' ) ;
1065+ expect ( console . log . mock . calls [ 0 ] [ 0 ] ) . toMatchSnapshot ( ) ;
10751066 } ) ;
1076- expect ( options . testPathPattern ) . toBe ( 'a/b|c/d' ) ;
1077- } ) ;
10781067
1079- it ( 'escapes Windows path separators in multiple args' , ( ) => {
1080- testWindowsPathSeparator (
1081- { testPathPattern : [ 'a\\b' , 'c\\d' ] } ,
1082- 'a\\\\b|c\\\\d' ,
1083- ) ;
1084- } ) ;
1085- } ) ;
1068+ it ( 'joins multiple ' + opt . name + ' if set' , ( ) => {
1069+ const argv = { testPathPattern : [ 'a/b' , 'c/d' ] } ;
1070+ const { options} = normalize ( initialOptions , argv ) ;
10861071
1087- describe ( '<regexForTestFiles>' , ( ) => {
1088- it ( 'uses <regexForTestFiles> if set' , ( ) => {
1089- const { options} = normalize ( initialOptions , { _ : [ 'a/b' ] } ) ;
1090- expect ( options . testPathPattern ) . toBe ( 'a/b' ) ;
1091- } ) ;
1092-
1093- it ( 'ignores invalid regular expressions and logs a warning' , ( ) => {
1094- const { options} = normalize ( initialOptions , { _ : [ 'a(' ] } ) ;
1095- expect ( options . testPathPattern ) . toBe ( '' ) ;
1096- expect ( console . log . mock . calls [ 0 ] [ 0 ] ) . toMatchSnapshot ( ) ;
1097- } ) ;
1072+ expect ( options . testPathPattern ) . toBe ( 'a/b|c/d' ) ;
1073+ } ) ;
10981074
1099- it ( 'escapes Windows path separators' , ( ) => {
1100- testWindowsPathSeparator ( { _ : [ 'a\\b' ] } , 'a\\\\b' ) ;
1101- } ) ;
1075+ describe ( 'posix' , ( ) => {
1076+ it ( 'should not escape the pattern' , ( ) => {
1077+ const argv = { [ opt . property ] : [ 'a\\/b' , 'a/b' , 'a\\b' , 'a\\\\b' ] } ;
1078+ const { options} = normalize ( initialOptions , argv ) ;
11021079
1103- it ( 'joins multiple <regexForTestFiles> if set' , ( ) => {
1104- const { options} = normalize ( initialOptions , { _ : [ 'a/b' , 'c/d' ] } ) ;
1105- expect ( options . testPathPattern ) . toBe ( 'a/b|c/d' ) ;
1106- } ) ;
1080+ expect ( options . testPathPattern ) . toBe ( 'a\\/b|a/b|a\\b|a\\\\b' ) ;
1081+ } ) ;
1082+ } ) ;
11071083
1108- it ( 'escapes Windows path separators in multiple args' , ( ) => {
1109- testWindowsPathSeparator ( { _ : [ 'a\\b' , 'c\\d' ] } , 'a\\\\b|c\\\\d' ) ;
1084+ describe ( 'win32' , ( ) => {
1085+ beforeEach ( ( ) => {
1086+ jest . mock ( 'path' , ( ) => require . requireActual ( 'path' ) . win32 ) ;
1087+ require ( 'jest-resolve' ) . findNodeModule = findNodeModule ;
1088+ } ) ;
1089+
1090+ afterEach ( ( ) => {
1091+ jest . resetModules ( ) ;
1092+ } ) ;
1093+
1094+ it ( 'preserves any use of "\\"' , ( ) => {
1095+ const argv = { [ opt . property ] : [ 'a\\b' , 'c\\\\d' ] } ;
1096+ const { options} = require ( '../normalize' ) . default (
1097+ initialOptions ,
1098+ argv ,
1099+ ) ;
1100+
1101+ expect ( options . testPathPattern ) . toBe ( 'a\\b|c\\\\d' ) ;
1102+ } ) ;
1103+
1104+ it ( 'replaces POSIX path separators' , ( ) => {
1105+ const argv = { [ opt . property ] : [ 'a/b' ] } ;
1106+ const { options} = require ( '../normalize' ) . default (
1107+ initialOptions ,
1108+ argv ,
1109+ ) ;
1110+
1111+ expect ( options . testPathPattern ) . toBe ( 'a\\\\b' ) ;
1112+ } ) ;
1113+
1114+ it ( 'replaces POSIX paths in multiple args' , ( ) => {
1115+ const argv = { [ opt . property ] : [ 'a/b' , 'c/d' ] } ;
1116+ const { options} = require ( '../normalize' ) . default (
1117+ initialOptions ,
1118+ argv ,
1119+ ) ;
1120+
1121+ expect ( options . testPathPattern ) . toBe ( 'a\\\\b|c\\\\d' ) ;
1122+ } ) ;
1123+ } ) ;
11101124 } ) ;
1111- } ) ;
1125+ }
11121126
11131127 it ( 'joins multiple --testPathPatterns and <regexForTestFiles>' , ( ) => {
11141128 const { options} = normalize ( initialOptions , {
0 commit comments