Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sets project name if empty fixes #5597 #5862

Merged
merged 27 commits into from
Jan 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5756129
sets project name if empty fixes #5597
Mar 23, 2018
50d9933
added to changelog
Mar 23, 2018
6036dfa
cr comments
Mar 23, 2018
be1cc18
removed unused import
Mar 23, 2018
6054f0b
fixed tests
Mar 23, 2018
feb9751
use inital options instead of project config
Mar 23, 2018
0bf6d8e
fix unintentional type change
paularmstrong Mar 23, 2018
4f72619
fixed path string and deleted unneeded test files
Mar 26, 2018
b7c061f
Merge branch 'master' into set_project_name_if_empty
Mar 26, 2018
0713d0f
merged in master
Mar 26, 2018
65c64d9
updated snapshots and tests
Mar 26, 2018
a856fb1
removed updated snapshots put change under fixes
Mar 26, 2018
04b0bb6
Merge branch 'master' into set_project_name_if_empty
Mar 26, 2018
80d21e6
merged master
Apr 9, 2018
2f14830
Merge branch 'master' into set_project_name_if_empty
cbelsole Apr 9, 2018
30fecea
Merge branch 'master' into set_project_name_if_empty
SimenB Aug 9, 2018
54302cf
Merge remote-tracking branch 'origin' into set_project_name_if_empty
cbelsole Aug 10, 2018
be40277
Merge remote-tracking branch 'root/master' into set_project_name_if_e…
cbelsole Dec 29, 2018
8c8761d
unique names across config and projects
cbelsole Dec 29, 2018
78801aa
fixed changelog
cbelsole Dec 29, 2018
9bbbd61
Update CHANGELOG.md
SimenB Dec 29, 2018
61523b0
Merge branch 'master' into set_project_name_if_empty
SimenB Jan 20, 2019
44aa91d
use Set
SimenB Jan 20, 2019
a370c21
use random uuid for assigning project name
thymikee Jan 20, 2019
1ab0bac
remove unnecessary test
thymikee Jan 20, 2019
691339f
fix lint
thymikee Jan 20, 2019
6fcab16
add e2e test
thymikee Jan 20, 2019
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

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", () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

While running a repro again, I discovered this only happens when we run multiple workers, so added this test. It fails without uuid.

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