diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c60e81dd02b..4f32bc6a534b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -118,6 +118,7 @@ - `[jest-config]` Normalize `config.cwd` and `config.rootDir` using `realpath ([#7598](https://github.com/facebook/jest/pull/7598)) - `[jest-environment-node]` Fix buffer property is not ArrayBuffer issue. ([#7626](https://github.com/facebook/jest/pull/7626)) - `[babel-plugin-jest-hoist]` Ignore TS type annotations when looking for out-of-scope references ([#7641](https://github.com/facebook/jest/pull/7641)) +- `[jest-config]` Add name to project if one does not exist to pick correct resolver ([#5862](https://github.com/facebook/jest/pull/5862)) ### Chore & Maintenance diff --git a/e2e/__tests__/multiProjectRunner.test.js b/e2e/__tests__/multiProjectRunner.test.js index b423df611b51..b3438cb90905 100644 --- a/e2e/__tests__/multiProjectRunner.test.js +++ b/e2e/__tests__/multiProjectRunner.test.js @@ -399,3 +399,41 @@ test('Does transform files with the corresponding project transformer', () => { expect(stderr).toMatch('PASS project1/__tests__/project1.test.js'); expect(stderr).toMatch('PASS project2/__tests__/project2.test.js'); }); + +test("doesn't bleed module file extensions resolution with multiple workers", () => { + writeFiles(DIR, { + '.watchmanconfig': '', + 'file.js': 'module.exports = "file1"', + 'file.p2.js': 'module.exports = "file2"', + 'package.json': '{}', + 'project1/__tests__/project1.test.js': ` + const file = require('../../file'); + test('file 1', () => expect(file).toBe('file1')); + `, + 'project1/jest.config.js': ` + module.exports = { + rootDir: '..', + };`, + 'project2/__tests__/project2.test.js': ` + const file = require('../../file'); + test('file 2', () => expect(file).toBe('file2')); + `, + 'project2/jest.config.js': ` + module.exports = { + rootDir: '..', + moduleFileExtensions: ['p2.js', 'js'] + };`, + }); + + const {stderr} = runJest(DIR, [ + '--no-watchman', + '-w=2', + '--projects', + 'project1', + 'project2', + ]); + + expect(stderr).toMatch('Ran all test suites in 2 projects.'); + expect(stderr).toMatch('PASS project1/__tests__/project1.test.js'); + expect(stderr).toMatch('PASS project2/__tests__/project2.test.js'); +}); diff --git a/packages/jest-config/package.json b/packages/jest-config/package.json index f41992144802..63d03d525a13 100644 --- a/packages/jest-config/package.json +++ b/packages/jest-config/package.json @@ -23,7 +23,8 @@ "jest-validate": "^23.6.0", "micromatch": "^3.1.10", "pretty-format": "^23.6.0", - "realpath-native": "^1.0.2" + "realpath-native": "^1.0.2", + "uuid": "^3.3.2" }, "engines": { "node": ">= 6" diff --git a/packages/jest-config/src/__tests__/normalize.test.js b/packages/jest-config/src/__tests__/normalize.test.js index 6e021f4e81e4..ffebc661caa9 100644 --- a/packages/jest-config/src/__tests__/normalize.test.js +++ b/packages/jest-config/src/__tests__/normalize.test.js @@ -12,7 +12,6 @@ import normalize from '../normalize'; jest.mock('jest-resolve'); jest.mock('path', () => jest.requireActual('path').posix); -const crypto = require('crypto'); const path = require('path'); const DEFAULT_JS_PATTERN = require('../constants').DEFAULT_JS_PATTERN; const DEFAULT_CSS_PATTERN = '^.+\\.(css)$'; @@ -47,20 +46,16 @@ beforeEach(() => { require('jest-resolve').findNodeModule = findNodeModule; }); -it('picks a name based on the rootDir', () => { +it('assigns a random 32-byte hash as a name to avoid clashes', () => { const rootDir = '/root/path/foo'; - const expected = crypto - .createHash('md5') - .update('/root/path/foo') - .digest('hex'); - expect( - normalize( - { - rootDir, - }, - {}, - ).options.name, - ).toBe(expected); + const {name: name1} = normalize({rootDir}, {}).options; + const {name: name2} = normalize({rootDir}, {}).options; + + expect(name1).toEqual(expect.any(String)); + expect(name1).toHaveLength(32); + expect(name2).toEqual(expect.any(String)); + expect(name2).toHaveLength(32); + expect(name1).not.toBe(name2); }); it('keeps custom names based on the rootDir', () => { diff --git a/packages/jest-config/src/normalize.js b/packages/jest-config/src/normalize.js index a001625daf47..f63714494aca 100644 --- a/packages/jest-config/src/normalize.js +++ b/packages/jest-config/src/normalize.js @@ -17,6 +17,7 @@ import type { } from 'types/Config'; import crypto from 'crypto'; +import uuid from 'uuid/v4'; import glob from 'glob'; import path from 'path'; import {ValidationError, validate} from 'jest-validate'; @@ -268,6 +269,7 @@ const normalizeMissingOptions = (options: InitialOptions): InitialOptions => { options.name = crypto .createHash('md5') .update(options.rootDir) + .update(uuid()) .digest('hex'); }