Skip to content

Commit

Permalink
Filter non-JS files from require when using glob with --projects (#…
Browse files Browse the repository at this point in the history
…5412)

* Add test for workspaces with a README.md in the root

* Filter projects to directories & require-able files only

This ensures `packages/*` catches folders & not README.md

* Add reference to #5199 in CHANGELOG.md

* Remove custom testDir
  • Loading branch information
ericclemmons authored and cpojer committed Feb 1, 2018
1 parent c885f41 commit dea270b
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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-mock]` Add backticks support (\`\`) to `mock` a certain package via the
`__mocks__` folder. ([#5426](https://github.com/facebook/jest/pull/5426))
* `[jest-message-util]` Prevent an `ENOENT` crash when the test file contained a
Expand Down
33 changes: 33 additions & 0 deletions integration-tests/__tests__/multi_project_runner.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,39 @@ test('"No tests found" message for projects', () => {
);
});

test('projects can be workspaces with non-JS/JSON files', () => {
writeFiles(DIR, {
'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(DIR);

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': `
Expand Down
20 changes: 17 additions & 3 deletions packages/jest-cli/src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit dea270b

Please sign in to comment.