Skip to content

Commit

Permalink
sets project name if empty fixes #5597 (#5862)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbelsole authored and SimenB committed Jan 20, 2019
1 parent b450d78 commit 388942f
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,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

Expand Down
38 changes: 38 additions & 0 deletions e2e/__tests__/multiProjectRunner.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
3 changes: 2 additions & 1 deletion packages/jest-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
23 changes: 9 additions & 14 deletions packages/jest-config/src/__tests__/normalize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)$';
Expand Down Expand Up @@ -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', () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-config/src/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -268,6 +269,7 @@ const normalizeMissingOptions = (options: InitialOptions): InitialOptions => {
options.name = crypto
.createHash('md5')
.update(options.rootDir)
.update(uuid())
.digest('hex');
}

Expand Down

0 comments on commit 388942f

Please sign in to comment.