@@ -21,81 +21,88 @@ beforeEach(() => {
2121 jest . resetAllMocks ( ) ;
2222} ) ;
2323
24+ const config = { rootDir : '' } ;
25+
2426describe ( 'TestPathPatterns' , ( ) => {
2527 describe ( 'isSet' , ( ) => {
2628 it ( 'returns false if no patterns specified' , ( ) => {
27- const testPathPatterns = new TestPathPatterns ( [ ] ) ;
29+ const testPathPatterns = new TestPathPatterns ( [ ] , config ) ;
2830 expect ( testPathPatterns . isSet ( ) ) . toBe ( false ) ;
2931 } ) ;
3032
3133 it ( 'returns true if patterns specified' , ( ) => {
32- const testPathPatterns = new TestPathPatterns ( [ 'a' ] ) ;
34+ const testPathPatterns = new TestPathPatterns ( [ 'a' ] , config ) ;
3335 expect ( testPathPatterns . isSet ( ) ) . toBe ( true ) ;
3436 } ) ;
3537 } ) ;
3638
3739 describe ( 'isValid' , ( ) => {
3840 it ( 'returns true for empty patterns' , ( ) => {
39- const testPathPatterns = new TestPathPatterns ( [ ] ) ;
41+ const testPathPatterns = new TestPathPatterns ( [ ] , config ) ;
4042 expect ( testPathPatterns . isValid ( ) ) . toBe ( true ) ;
4143 } ) ;
4244
4345 it ( 'returns true for valid patterns' , ( ) => {
44- const testPathPatterns = new TestPathPatterns ( [ 'abc+' , 'z.*' ] ) ;
46+ const testPathPatterns = new TestPathPatterns ( [ 'abc+' , 'z.*' ] , config ) ;
4547 expect ( testPathPatterns . isValid ( ) ) . toBe ( true ) ;
4648 } ) ;
4749
4850 it ( 'returns false for at least one invalid pattern' , ( ) => {
49- const testPathPatterns = new TestPathPatterns ( [ 'abc+' , '(' , 'z.*' ] ) ;
51+ const testPathPatterns = new TestPathPatterns (
52+ [ 'abc+' , '(' , 'z.*' ] ,
53+ config ,
54+ ) ;
5055 expect ( testPathPatterns . isValid ( ) ) . toBe ( false ) ;
5156 } ) ;
5257 } ) ;
5358
5459 describe ( 'isMatch' , ( ) => {
5560 it ( 'returns true with no patterns' , ( ) => {
56- const testPathPatterns = new TestPathPatterns ( [ ] ) ;
61+ const testPathPatterns = new TestPathPatterns ( [ ] , config ) ;
5762 expect ( testPathPatterns . isMatch ( '/a/b' ) ) . toBe ( true ) ;
5863 } ) ;
5964
6065 it ( 'returns true for same path' , ( ) => {
61- const testPathPatterns = new TestPathPatterns ( [ '/a/b' ] ) ;
66+ const testPathPatterns = new TestPathPatterns ( [ '/a/b' ] , config ) ;
6267 expect ( testPathPatterns . isMatch ( '/a/b' ) ) . toBe ( true ) ;
6368 } ) ;
6469
6570 it ( 'returns true for same path with case insensitive' , ( ) => {
66- const testPathPatternsUpper = new TestPathPatterns ( [ '/A/B' ] ) ;
71+ const testPathPatternsUpper = new TestPathPatterns ( [ '/A/B' ] , config ) ;
6772 expect ( testPathPatternsUpper . isMatch ( '/a/b' ) ) . toBe ( true ) ;
6873 expect ( testPathPatternsUpper . isMatch ( '/A/B' ) ) . toBe ( true ) ;
6974
70- const testPathPatternsLower = new TestPathPatterns ( [ '/a/b' ] ) ;
75+ const testPathPatternsLower = new TestPathPatterns ( [ '/a/b' ] , config ) ;
7176 expect ( testPathPatternsLower . isMatch ( '/A/B' ) ) . toBe ( true ) ;
7277 expect ( testPathPatternsLower . isMatch ( '/a/b' ) ) . toBe ( true ) ;
7378 } ) ;
7479
7580 it ( 'returns true for contained path' , ( ) => {
76- const testPathPatterns = new TestPathPatterns ( [ 'b/c' ] ) ;
81+ const testPathPatterns = new TestPathPatterns ( [ 'b/c' ] , config ) ;
7782 expect ( testPathPatterns . isMatch ( '/a/b/c/d' ) ) . toBe ( true ) ;
7883 } ) ;
7984
8085 it ( 'returns true for explicit relative path' , ( ) => {
81- const testPathPatterns = new TestPathPatterns ( [ './b/c' ] ) ;
86+ const testPathPatterns = new TestPathPatterns ( [ './b/c' ] , {
87+ rootDir : '/a' ,
88+ } ) ;
8289 expect ( testPathPatterns . isMatch ( '/a/b/c' ) ) . toBe ( true ) ;
8390 } ) ;
8491
8592 it ( 'returns true for partial file match' , ( ) => {
86- const testPathPatterns = new TestPathPatterns ( [ 'aaa' ] ) ;
93+ const testPathPatterns = new TestPathPatterns ( [ 'aaa' ] , config ) ;
8794 expect ( testPathPatterns . isMatch ( '/foo/..aaa..' ) ) . toBe ( true ) ;
8895 expect ( testPathPatterns . isMatch ( '/foo/..aaa' ) ) . toBe ( true ) ;
8996 expect ( testPathPatterns . isMatch ( '/foo/aaa..' ) ) . toBe ( true ) ;
9097 } ) ;
9198
9299 it ( 'returns true for path suffix' , ( ) => {
93- const testPathPatterns = new TestPathPatterns ( [ 'c/d' ] ) ;
100+ const testPathPatterns = new TestPathPatterns ( [ 'c/d' ] , config ) ;
94101 expect ( testPathPatterns . isMatch ( '/a/b/c/d' ) ) . toBe ( true ) ;
95102 } ) ;
96103
97104 it ( 'returns true if regex matches' , ( ) => {
98- const testPathPatterns = new TestPathPatterns ( [ 'ab*c?' ] ) ;
105+ const testPathPatterns = new TestPathPatterns ( [ 'ab*c?' ] , config ) ;
99106
100107 expect ( testPathPatterns . isMatch ( '/foo/a' ) ) . toBe ( true ) ;
101108 expect ( testPathPatterns . isMatch ( '/foo/ab' ) ) . toBe ( true ) ;
@@ -123,7 +130,7 @@ describe('TestPathPatterns', () => {
123130 } ) ;
124131
125132 it ( 'returns true if match any paths' , ( ) => {
126- const testPathPatterns = new TestPathPatterns ( [ 'a/b' , 'c/d' ] ) ;
133+ const testPathPatterns = new TestPathPatterns ( [ 'a/b' , 'c/d' ] , config ) ;
127134
128135 expect ( testPathPatterns . isMatch ( '/foo/a/b' ) ) . toBe ( true ) ;
129136 expect ( testPathPatterns . isMatch ( '/foo/c/d' ) ) . toBe ( true ) ;
@@ -134,20 +141,20 @@ describe('TestPathPatterns', () => {
134141
135142 it ( 'does not normalize Windows paths on POSIX' , ( ) => {
136143 mockSep . mockReturnValue ( '/' ) ;
137- const testPathPatterns = new TestPathPatterns ( [ 'a\\z' , 'a\\\\z' ] ) ;
144+ const testPathPatterns = new TestPathPatterns ( [ 'a\\z' , 'a\\\\z' ] , config ) ;
138145 expect ( testPathPatterns . isMatch ( '/foo/a/z' ) ) . toBe ( false ) ;
139146 } ) ;
140147
141148 it ( 'normalizes paths for Windows' , ( ) => {
142149 mockSep . mockReturnValue ( '\\' ) ;
143- const testPathPatterns = new TestPathPatterns ( [ 'a/b' ] ) ;
150+ const testPathPatterns = new TestPathPatterns ( [ 'a/b' ] , config ) ;
144151 expect ( testPathPatterns . isMatch ( '\\foo\\a\\b' ) ) . toBe ( true ) ;
145152 } ) ;
146153 } ) ;
147154
148155 describe ( 'toPretty' , ( ) => {
149156 it ( 'renders a human-readable string' , ( ) => {
150- const testPathPatterns = new TestPathPatterns ( [ 'a/b' , 'c/d' ] ) ;
157+ const testPathPatterns = new TestPathPatterns ( [ 'a/b' , 'c/d' ] , config ) ;
151158 expect ( testPathPatterns . toPretty ( ) ) . toMatchSnapshot ( ) ;
152159 } ) ;
153160 } ) ;
0 commit comments