Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

### Fixes

* `[jest-cli]` Check if the file belongs to the checked project before adding it
to the list ([#5335](https://github.com/facebook/jest/pull/5335))
* `[jest-cli]` Fix `EISDIR` when a directory is passed as an argument to `jest`.
([#5317](https://github.com/facebook/jest/pull/5317))
* `[jest-config]` Added restoreMocks config option.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Tests are executed only once even in an MPR 1`] = `
"PASS foo/folder/my-test-bar.js
✓ bar

"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ test('CLI accepts exact filenames', () => {
'./foo/baz.js',
'./foo',
]);
const {rest, summary} = extractSummary(stderr);

expect(status).toBe(0);

const {rest, summary} = extractSummary(stderr);

expect(rest).toMatchSnapshot();
expect(summary).toMatchSnapshot();
expect(stdout).toMatchSnapshot();
Expand Down
65 changes: 65 additions & 0 deletions integration-tests/__tests__/execute-tests-once-in-mpr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* Copyright (c) 2017-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

'use strict';

const path = require('path');
const skipOnWindows = require('../../scripts/skip_on_windows');
const {extractSummary, cleanup, writeFiles} = require('../utils');
const runJest = require('../runJest');

const DIR = path.resolve(__dirname, '../execute-tests-once-in-mpr');

skipOnWindows.suite();

beforeEach(() => cleanup(DIR));
afterAll(() => cleanup(DIR));

test('Tests are executed only once even in an MPR', () => {
// Make a global config that ignores all sub-projects.
const config = {
jest: {
projects: ['<rootDir>/foo/*/'],
testPathIgnorePatterns: ['/foo/'],
},
};

// Make a child config with a special regexp to ensure we execute the tests.
const childConfig = {
jest: {
testRegex: /my-test-.*\.js/.source,
},
};

/* eslint-disable sort-keys */
writeFiles(DIR, {
'foo/folder/my-test-bar.js': `test('bar', () => console.log('Bar!'));`,
'foo/folder/package.json': JSON.stringify(childConfig, null, 2),

'foo/directory/my-test-baz.js': `test('baz', () => console.log('Baz!'));`,
'foo/directory/package.json': JSON.stringify(childConfig, null, 2),

'foo/whatever/my-test-qux.js': `test('qux', () => console.log('Qux!'));`,
'foo/whatever/package.json': JSON.stringify(childConfig, null, 2),

'package.json': JSON.stringify(config, null, 2),
});
/* eslint-enable sort-keys */

const {stderr, status} = runJest(DIR, ['foo/folder/my-test-bar.js']);

expect(status).toBe(0);

const {rest, summary} = extractSummary(stderr);

// We have only one test passed, so total should equal to one, despite we have
// three projects.
expect(rest).toMatchSnapshot();
expect(summary).toMatch(/1 total/);
});
10 changes: 9 additions & 1 deletion packages/jest-cli/src/search_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,22 @@ export default class SearchSource {
} else if (globalConfig.findRelatedTests && paths && paths.length) {
return Promise.resolve(this.findRelatedTestsFromPattern(paths));
} else {
const allFiles = new Set(this._context.hasteFS.getAllFiles());
const validTestPaths =
paths &&
paths.filter(name => {
try {
return fs.lstatSync(name).isFile();
if (!fs.lstatSync(name).isFile()) {
// It exists, but it is not a file; return false.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you remove the "return false" here? It's literally the next line.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huh, I didn't spot that :D

return false;
}
} catch (e) {
// It does not exist; return false.
return false;
}

// It exists and it is a file; return true if it's in the project.
return allFiles.has(path.resolve(name));
});

if (validTestPaths && validTestPaths.length) {
Expand Down