From 0e16326f9b59f21bb54616d314f09fa1f59a3629 Mon Sep 17 00:00:00 2001 From: Dmitrii Abramov Date: Tue, 25 Jul 2017 13:05:59 -0700 Subject: [PATCH] glob projects --- .../__tests__/multi_project_runner.test.js | 16 ++++++++++++++++ packages/jest-config/src/normalize.js | 10 +++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/integration_tests/__tests__/multi_project_runner.test.js b/integration_tests/__tests__/multi_project_runner.test.js index 9fc0807cbfc2..eb94d271bf11 100644 --- a/integration_tests/__tests__/multi_project_runner.test.js +++ b/integration_tests/__tests__/multi_project_runner.test.js @@ -128,6 +128,22 @@ test('resolves projects and their properly', () => { expect(stderr).toMatch(' PASS project1/__tests__/test.test.js'); expect(stderr).toMatch(' PASS project2/__tests__/test.test.js'); + // Use globs + writeFiles(DIR, { + 'dir1/random_file': '', + 'dir2/random_file': '', + 'package.json': JSON.stringify({ + jest: { + projects: ['**/*.conf.json'], + }, + }), + }); + + ({stderr} = runJest(DIR)); + expect(stderr).toMatch('Ran all test suites in 2 projects.'); + expect(stderr).toMatch(' PASS project1/__tests__/test.test.js'); + expect(stderr).toMatch(' PASS project2/__tests__/test.test.js'); + // Include two projects that will resolve to the same config writeFiles(DIR, { 'dir1/random_file': '', diff --git a/packages/jest-config/src/normalize.js b/packages/jest-config/src/normalize.js index d5e8196d8b52..fac5ff528266 100644 --- a/packages/jest-config/src/normalize.js +++ b/packages/jest-config/src/normalize.js @@ -12,6 +12,7 @@ import type {Argv} from 'types/Argv'; import type {InitialOptions, ReporterConfig} from 'types/Config'; import crypto from 'crypto'; +import glob from 'glob'; import path from 'path'; import {ValidationError, validate} from 'jest-validate'; import validatePattern from './validate_pattern'; @@ -428,7 +429,14 @@ function normalize(options: InitialOptions, argv: Argv) { break; case 'projects': value = (options[key] || []) - .map(project => _replaceRootDirTags(options.rootDir, project)); + .map(project => _replaceRootDirTags(options.rootDir, project)) + .reduce((projects, project) => { + // Project can be specified as globs. If a glob matches any files, + // We expand it to these paths. If not, we keep the original path + // for the future resolution. + const globMatches = glob.sync(project); + return projects.concat(globMatches.length ? globMatches : project); + }, []); break; case 'moduleDirectories': case 'testMatch':