@@ -42,8 +42,45 @@ describe('Should create a correct regular expression for excluding node_modules'
4242 } ) ;
4343} ) ;
4444
45+ describe ( 'Should be able to convert wildcards in parameters to matching pattern in the regular expression' , ( ) => {
46+ /**
47+ * @type {TestCase[] }
48+ */
49+ const testCases = [
50+ {
51+ description : 'Wildcard occurs in the only argument' ,
52+ params : [ 'react-*' ] ,
53+ expected : X
54+ ? / n o d e _ m o d u l e s \\ (? ! ( r e a c t \- (?: .* ) ) \\ ) / i
55+ : / n o d e _ m o d u l e s \/ (? ! ( r e a c t \- (?: .* ) ) \/ ) / i
56+ } ,
57+ {
58+ description : 'Wildcard occurs in the second argument out of three' ,
59+ params : [ 'abc' , 'mno*' , 'xvz' ] ,
60+ expected : X
61+ ? / n o d e _ m o d u l e s \\ (? ! ( a b c | m n o (?: .* ) | x v z ) \\ ) / i
62+ : / n o d e _ m o d u l e s \/ (? ! ( a b c | m n o (?: .* ) | x v z ) \/ ) / i
63+ } ,
64+ {
65+ description : 'Wildcard used for scoped packages' ,
66+ params : [ '@awesomecorp/*' ] ,
67+ expected : X
68+ ? / n o d e _ m o d u l e s \\ (? ! ( @ a w e s o m e c o r p \\ (?: .* ) ) \\ ) / i
69+ : / n o d e _ m o d u l e s \/ (? ! ( @ a w e s o m e c o r p \/ (?: .* ) ) \/ ) / i
70+ }
71+ ] ;
72+
73+ testCases . forEach ( function ( { params, expected, description } , i ) {
74+ test ( `Test case #${ i + 1 } : ${ description } ` , function ( ) {
75+ const result = babelLoaderExcludeNodeModulesExcept ( params ) ;
76+ expect ( result ) . toEqual ( expected ) ;
77+ } ) ;
78+ } ) ;
79+ } ) ;
80+
4581/**
4682 * @typedef {Object } TestCase
4783 * @property {string[] } params
4884 * @property {RegExp } expected
85+ * @property {string } [description]
4986 */
0 commit comments