From 1efe013097865bc63e393211e8f750adbb587663 Mon Sep 17 00:00:00 2001 From: Eric Clemmons Date: Sun, 28 Jan 2018 11:29:22 -0600 Subject: [PATCH 1/4] Add test for workspaces with a README.md in the root --- .../__tests__/multi_project_runner.test.js | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/integration-tests/__tests__/multi_project_runner.test.js b/integration-tests/__tests__/multi_project_runner.test.js index a4ffc3f837aa..414655b910b5 100644 --- a/integration-tests/__tests__/multi_project_runner.test.js +++ b/integration-tests/__tests__/multi_project_runner.test.js @@ -154,6 +154,41 @@ test('"No tests found" message for projects', () => { ); }); +test('projects can be workspaces with non-JS/JSON files', () => { + const testDir = path.resolve(DIR, 'workspaces-test'); + + writeFiles(testDir, { + 'package.json': JSON.stringify({ + jest: { + projects: ['packages/*'], + }, + }), + 'packages/README.md': '# Packages README', + 'packages/project1/README.md': '# Project1 README', + 'packages/project1/__tests__/file1.test.js': ` + const file1 = require('file1'); + test('file1', () => {}); + `, + 'packages/project1/file1.js': fileContentWithProvidesModule('file1'), + 'packages/project1/package.json': '{}', + 'packages/project2/__tests__/file2.test.js': ` + const file2 = require('file2'); + test('file2', () => {}); + `, + 'packages/project2/file2.js': fileContentWithProvidesModule('file2'), + 'packages/project2/package.json': '{}', + }); + + const {status, stdout, stderr} = runJest(testDir); + + expect(stderr).toContain('Test Suites: 2 passed, 2 total'); + expect(stderr).toContain('PASS packages/project1/__tests__/file1.test.js'); + expect(stderr).toContain('PASS packages/project2/__tests__/file2.test.js'); + expect(stderr).toContain('Ran all test suites in 2 projects.'); + expect(stdout).toEqual(''); + expect(status).toEqual(0); +}); + test('objects in project configuration', () => { writeFiles(DIR, { '__tests__/file1.test.js': ` From d676e05656c8ffef9d315eb1efde98bbd075bdba Mon Sep 17 00:00:00 2001 From: Eric Clemmons Date: Sun, 28 Jan 2018 11:30:05 -0600 Subject: [PATCH 2/4] Filter projects to directories & require-able files only This ensures `packages/*` catches folders & not README.md --- packages/jest-cli/src/cli/index.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/jest-cli/src/cli/index.js b/packages/jest-cli/src/cli/index.js index b4725deba08b..f498d63c166c 100644 --- a/packages/jest-cli/src/cli/index.js +++ b/packages/jest-cli/src/cli/index.js @@ -24,6 +24,7 @@ import chalk from 'chalk'; import createContext from '../lib/create_context'; import exit from 'exit'; import getChangedFilesPromise from '../get_changed_files_promise'; +import fs from 'fs'; import handleDeprecationWarnings from '../lib/handle_deprecation_warnings'; import logDebugMessages from '../lib/log_debug_messages'; import {print as preRunMessagePrint} from '../pre_run_message'; @@ -246,9 +247,22 @@ const getConfigs = ( } if (projects.length > 1) { - const parsedConfigs = projects.map(root => - readConfig(argv, root, true, configPath), - ); + const parsedConfigs = projects + .filter(root => { + // Ignore globbed files that cannot be `require`d. + if ( + fs.existsSync(root) && + !fs.lstatSync(root).isDirectory() && + !root.endsWith('.js') && + !root.endsWith('.json') + ) { + return false; + } + + return true; + }) + .map(root => readConfig(argv, root, true, configPath)); + ensureNoDuplicateConfigs(parsedConfigs, projects); configs = parsedConfigs.map(({projectConfig}) => projectConfig); if (!hasDeprecationWarnings) { From 868419eceafaad8d7ae865630cb7dcc2438470e7 Mon Sep 17 00:00:00 2001 From: Eric Clemmons Date: Sun, 28 Jan 2018 11:32:08 -0600 Subject: [PATCH 3/4] Add reference to #5199 in CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index abc5632a67d4..4223e7449de3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ ### Fixes +* `[jest-cli]` Glob patterns ignore non-`require`-able files (e.g. `README.md`) + ([#5199](https://github.com/facebook/jest/issues/5199)) * `[jest]` Add `import-local` to `jest` package. ([#5353](https://github.com/facebook/jest/pull/5353)) * `[expect]` Support class instances in `.toHaveProperty()` matcher. From e57d517314adeb489b1fba43f3e2912ae7667308 Mon Sep 17 00:00:00 2001 From: Eric Clemmons Date: Sun, 28 Jan 2018 11:36:06 -0600 Subject: [PATCH 4/4] Remove custom testDir --- integration-tests/__tests__/multi_project_runner.test.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/integration-tests/__tests__/multi_project_runner.test.js b/integration-tests/__tests__/multi_project_runner.test.js index 414655b910b5..a8de0370dc56 100644 --- a/integration-tests/__tests__/multi_project_runner.test.js +++ b/integration-tests/__tests__/multi_project_runner.test.js @@ -155,9 +155,7 @@ test('"No tests found" message for projects', () => { }); test('projects can be workspaces with non-JS/JSON files', () => { - const testDir = path.resolve(DIR, 'workspaces-test'); - - writeFiles(testDir, { + writeFiles(DIR, { 'package.json': JSON.stringify({ jest: { projects: ['packages/*'], @@ -179,7 +177,7 @@ test('projects can be workspaces with non-JS/JSON files', () => { 'packages/project2/package.json': '{}', }); - const {status, stdout, stderr} = runJest(testDir); + const {status, stdout, stderr} = runJest(DIR); expect(stderr).toContain('Test Suites: 2 passed, 2 total'); expect(stderr).toContain('PASS packages/project1/__tests__/file1.test.js');