File tree 4 files changed +92
-4
lines changed
4 files changed +92
-4
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ Object {
18
18
}
19
19
` ;
20
20
21
- exports [` jest should returns correct config and go thru backports 1` ] = `
21
+ exports [` jest should return correct config and go thru backports 1` ] = `
22
22
Object {
23
23
" __backported" : true ,
24
24
" globals" : Object {},
@@ -126,6 +126,32 @@ Array [
126
126
]
127
127
` ;
128
128
129
+ exports [` testMatchPatterns should return an array of patterns based on testRegex and testMatch from jestConfig 1` ] = `
130
+ Array [
131
+ "**/__tests__/**/*.[jt]s?(x)",
132
+ "**/?(*.)+(spec|test).[jt]s?(x)",
133
+ ]
134
+ ` ;
135
+
136
+ exports [` testMatchPatterns should return an array of patterns based on testRegex and testMatch from jestConfig 2` ] = `
137
+ Array [
138
+ /\\ .\\ *\\\\\\ .\\ (spec\\ |test\\ )\\\\\\ .\\ [jt\\ ]sx\\ ?\\ $/,
139
+ ]
140
+ ` ;
141
+
142
+ exports [` testMatchPatterns should return an array of patterns based on testRegex and testMatch from jestConfig 3` ] = `
143
+ Array [
144
+ "**/?(*.)+(spec|test).[tj]s?(x)",
145
+ ]
146
+ ` ;
147
+
148
+ exports [` testMatchPatterns should return an array of patterns based on testRegex and testMatch from jestConfig 4` ] = `
149
+ Array [
150
+ "**/?(*.)+(spec|test).[tj]s?(x)",
151
+ "**/?(*.)+(foo|bar).[tj]s?(x)",
152
+ ]
153
+ ` ;
154
+
129
155
exports [` tsJest should return correct defaults 1` ] = `
130
156
Object {
131
157
" babelConfig" : undefined ,
Original file line number Diff line number Diff line change @@ -122,7 +122,7 @@ describe('projectPackageJson', () => {
122
122
} )
123
123
124
124
describe ( 'jest' , ( ) => {
125
- it ( 'should returns correct config and go thru backports' , ( ) => {
125
+ it ( 'should return correct config and go thru backports' , ( ) => {
126
126
expect ( createConfigSet ( ) . jest ) . toMatchSnapshot ( )
127
127
expect ( backports . backportJestConfig ) . toHaveBeenCalledTimes ( 1 )
128
128
} )
@@ -150,6 +150,37 @@ describe('jest', () => {
150
150
} )
151
151
} )
152
152
153
+ describe ( 'testMatchPatterns' , ( ) => {
154
+ it . each ( [
155
+ {
156
+ jestConfig : {
157
+ testRegex : [ { } ] ,
158
+ testMatch : [ ] ,
159
+ } as any ,
160
+ } ,
161
+ {
162
+ jestConfig : {
163
+ testMatch : [ ] ,
164
+ testRegex : [ / .* \. ( s p e c | t e s t ) \. [ j t ] s x ? $ / ] ,
165
+ } as any ,
166
+ } ,
167
+ {
168
+ jestConfig : {
169
+ testMatch : [ '**/?(*.)+(spec|test).[tj]s?(x)' ] ,
170
+ testRegex : [ ] ,
171
+ } as any ,
172
+ } ,
173
+ {
174
+ jestConfig : {
175
+ testMatch : [ '**/?(*.)+(spec|test).[tj]s?(x)' ] ,
176
+ testRegex : [ '**/?(*.)+(foo|bar).[tj]s?(x)' ] ,
177
+ } as any ,
178
+ } ,
179
+ ] ) ( 'should return an array of patterns based on testRegex and testMatch from jestConfig' , config => {
180
+ expect ( createConfigSet ( config ) . testMatchPatterns ) . toMatchSnapshot ( )
181
+ } )
182
+ } )
183
+
153
184
describe ( 'tsJest' , ( ) => {
154
185
const getConfigSet = ( tsJest ?: TsJestGlobalOptions ) => createConfigSet ( { tsJestConfig : tsJest } )
155
186
const getTsJest = ( tsJest ?: TsJestGlobalOptions ) => getConfigSet ( tsJest ) . tsJest
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ import {
25
25
26
26
import { digest as MY_DIGEST , version as MY_VERSION } from '..'
27
27
import { createCompilerInstance } from '../compiler/instance'
28
+ import { DEFAULT_JEST_TEST_MATCH } from '../constants'
28
29
import { internals as internalAstTransformers } from '../transformers'
29
30
import {
30
31
AstTransformerDesc ,
@@ -197,7 +198,18 @@ export class ConfigSet {
197
198
*/
198
199
@Memoize ( )
199
200
get testMatchPatterns ( ) : ( string | RegExp ) [ ] {
200
- return [ ...this . jest . testMatch , ...this . jest . testRegex ]
201
+ const matchablePatterns = [ ...this . jest . testMatch , ...this . jest . testRegex ] . filter ( pattern => {
202
+ /**
203
+ * jest config testRegex doesn't always deliver the correct RegExp object
204
+ * See https://github.com/facebook/jest/issues/9778
205
+ */
206
+ return pattern instanceof RegExp || typeof pattern === 'string'
207
+ } )
208
+ if ( ! matchablePatterns . length ) {
209
+ matchablePatterns . push ( ...DEFAULT_JEST_TEST_MATCH )
210
+ }
211
+
212
+ return matchablePatterns
201
213
}
202
214
203
215
/**
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @internal
3
+ */
1
4
export const LINE_FEED = '\n'
2
-
5
+ /**
6
+ * @internal
7
+ */
3
8
export const EXTENSION_REGEX = / \. [ ^ . ] + $ /
9
+ /**
10
+ * @internal
11
+ */
4
12
export const TS_TSX_REGEX = / \. t s x ? $ /
13
+ /**
14
+ * @internal
15
+ */
5
16
export const JS_JSX_REGEX = / \. j s x ? $ /
17
+ /**
18
+ * @internal
19
+ */
6
20
export const JSON_REGEX = / \. j s o n $ / i
21
+ /**
22
+ * @internal
23
+ * See https://jestjs.io/docs/en/configuration#testmatch-arraystring
24
+ */
25
+ export const DEFAULT_JEST_TEST_MATCH = [ '**/__tests__/**/*.[jt]s?(x)' , '**/?(*.)+(spec|test).[jt]s?(x)' ]
You can’t perform that action at this time.
0 commit comments