diff --git a/packages/jest-config/src/__tests__/normalize-test.js b/packages/jest-config/src/__tests__/normalize-test.js index 7605164cef53..e1b9edf5c498 100644 --- a/packages/jest-config/src/__tests__/normalize-test.js +++ b/packages/jest-config/src/__tests__/normalize-test.js @@ -730,6 +730,41 @@ describe('testMatch', () => { ); }).toThrowErrorMatchingSnapshot(); }); + + it('normalizes testMatch', () => { + const {options} = normalize( + { + rootDir: '/root', + testMatch: ['/**/*.js'], + }, + {}, + ); + + expect(options.testMatch).toEqual(['/root/**/*.js']); + }); +}); + +describe('moduleDirectories', () => { + it('defaults to node_modules', () => { + const {options} = normalize({rootDir: '/root'}, {}); + + expect(options.moduleDirectories).toEqual(['node_modules']); + }); + + it('normalizes moduleDirectories', () => { + const {options} = normalize( + { + moduleDirectories: ['/src', '/node_modules'], + rootDir: '/root', + }, + {}, + ); + + expect(options.moduleDirectories).toEqual([ + '/root/src', + '/root/node_modules', + ]); + }); }); describe('preset', () => { diff --git a/packages/jest-config/src/normalize.js b/packages/jest-config/src/normalize.js index 29830d4f60b7..f33b02d7604d 100644 --- a/packages/jest-config/src/normalize.js +++ b/packages/jest-config/src/normalize.js @@ -397,6 +397,10 @@ function normalize(options: InitialOptions, argv: Argv) { ); value = list; break; + case 'moduleDirectories': + case 'testMatch': + value = _replaceRootDirTags(options.rootDir, options[key]); + break; case 'automock': case 'bail': case 'browser': @@ -409,7 +413,6 @@ function normalize(options: InitialOptions, argv: Argv) { case 'globals': case 'logHeapUsage': case 'mapCoverage': - case 'moduleDirectories': case 'moduleFileExtensions': case 'name': case 'noStackTrace': @@ -421,7 +424,6 @@ function normalize(options: InitialOptions, argv: Argv) { case 'rootDir': case 'silent': case 'testEnvironment': - case 'testMatch': case 'testNamePattern': case 'testRegex': case 'testURL':