File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ Object {
1818}
1919` ;
2020
21- exports [` jest should returns correct config and go thru backports 1` ] = `
21+ exports [` jest should return correct config and go thru backports 1` ] = `
2222Object {
2323 " __backported" : true ,
2424 " globals" : Object {},
@@ -126,6 +126,32 @@ Array [
126126]
127127` ;
128128
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+
129155exports [` tsJest should return correct defaults 1` ] = `
130156Object {
131157 " babelConfig" : undefined ,
Original file line number Diff line number Diff line change @@ -122,7 +122,7 @@ describe('projectPackageJson', () => {
122122} )
123123
124124describe ( 'jest' , ( ) => {
125- it ( 'should returns correct config and go thru backports' , ( ) => {
125+ it ( 'should return correct config and go thru backports' , ( ) => {
126126 expect ( createConfigSet ( ) . jest ) . toMatchSnapshot ( )
127127 expect ( backports . backportJestConfig ) . toHaveBeenCalledTimes ( 1 )
128128 } )
@@ -150,6 +150,37 @@ describe('jest', () => {
150150 } )
151151} )
152152
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+
153184describe ( 'tsJest' , ( ) => {
154185 const getConfigSet = ( tsJest ?: TsJestGlobalOptions ) => createConfigSet ( { tsJestConfig : tsJest } )
155186 const getTsJest = ( tsJest ?: TsJestGlobalOptions ) => getConfigSet ( tsJest ) . tsJest
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ import {
2525
2626import { digest as MY_DIGEST , version as MY_VERSION } from '..'
2727import { createCompilerInstance } from '../compiler/instance'
28+ import { DEFAULT_JEST_TEST_MATCH } from '../constants'
2829import { internals as internalAstTransformers } from '../transformers'
2930import {
3031 AstTransformerDesc ,
@@ -197,7 +198,18 @@ export class ConfigSet {
197198 */
198199 @Memoize ( )
199200 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
201213 }
202214
203215 /**
Original file line number Diff line number Diff line change 1+ /**
2+ * @internal
3+ */
14export const LINE_FEED = '\n'
2-
5+ /**
6+ * @internal
7+ */
38export const EXTENSION_REGEX = / \. [ ^ . ] + $ /
9+ /**
10+ * @internal
11+ */
412export const TS_TSX_REGEX = / \. t s x ? $ /
13+ /**
14+ * @internal
15+ */
516export const JS_JSX_REGEX = / \. j s x ? $ /
17+ /**
18+ * @internal
19+ */
620export 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