From 12321fdd51ad26f4c30864c77e9edad2cb1859c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Wed, 10 May 2017 23:01:27 +0200 Subject: [PATCH] Replace in testMatch and moduleDirectories (#3538) --- .../src/__tests__/normalize-test.js | 35 +++++++++++++++++++ packages/jest-config/src/normalize.js | 6 ++-- 2 files changed, 39 insertions(+), 2 deletions(-) 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':