Skip to content

Commit bee5d0d

Browse files
committed
error in haste map as well and add tests verifying it
1 parent d0bccc4 commit bee5d0d

File tree

5 files changed

+60
-5
lines changed

5 files changed

+60
-5
lines changed

e2e/__tests__/crawlSymlinks.test.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,15 @@ test('Node crawler does not pick up symlinked files by default', () => {
7474
test('Should throw if watchman used with haste.enableSymlinks', () => {
7575
init({'.watchmanconfig': JSON.stringify({})});
7676

77-
const {stdout, stderr, exitCode} = runJest(DIR, [
78-
'--haste={"enableSymlinks": true}',
79-
'--watchman',
80-
]);
77+
// it should throw both if watchman is explicitly provided and not
78+
const run1 = runJest(DIR, ['--haste={"enableSymlinks": true}']);
79+
const run2 = runJest(DIR, ['--haste={"enableSymlinks": true}', '--watchman']);
80+
81+
expect(run1.exitCode).toEqual(run2.exitCode);
82+
expect(run1.stderr).toEqual(run2.stderr);
83+
expect(run1.stdout).toEqual(run2.stdout);
84+
85+
const {exitCode, stderr, stdout} = run1;
8186

8287
expect(stdout).toEqual('');
8388
expect(wrap(stderr)).toMatchInlineSnapshot(`

packages/jest-config/src/__tests__/normalize.test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,3 +1714,26 @@ describe('testTimeout', () => {
17141714
).toThrowErrorMatchingSnapshot();
17151715
});
17161716
});
1717+
1718+
describe('haste.enableSymlinks', () => {
1719+
it('should throw if watchman is not disabled', () => {
1720+
expect(() =>
1721+
normalize({haste: {enableSymlinks: true}, rootDir: '/root/'}, {}),
1722+
).toThrow('haste.enableSymlinks is incompatible with watchman');
1723+
1724+
expect(() =>
1725+
normalize(
1726+
{haste: {enableSymlinks: true}, rootDir: '/root/', watchman: true},
1727+
{},
1728+
),
1729+
).toThrow('haste.enableSymlinks is incompatible with watchman');
1730+
1731+
const {options} = normalize(
1732+
{haste: {enableSymlinks: true}, rootDir: '/root/', watchman: false},
1733+
{},
1734+
);
1735+
1736+
expect(options.haste.enableSymlinks).toBe(true);
1737+
expect(options.watchman).toBe(false);
1738+
});
1739+
});

packages/jest-config/src/normalize.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,10 @@ export default function normalize(
577577
});
578578
}
579579

580+
if (options.watchman == null) {
581+
options.watchman = DEFAULT_CONFIG.watchman;
582+
}
583+
580584
const optionKeys = Object.keys(options) as Array<keyof Config.InitialOptions>;
581585

582586
optionKeys.reduce((newOptions, key: keyof Config.InitialOptions) => {

packages/jest-haste-map/src/__tests__/index.test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,29 @@ describe('HasteMap', () => {
517517
});
518518
});
519519

520+
it('throws if both symlinks and watchman is enabled', () => {
521+
expect(
522+
() => new HasteMap({...defaultConfig, enableSymlinks: true}),
523+
).toThrow('Set either `enableSymlinks` to false or `watchman` to false.');
524+
expect(
525+
() =>
526+
new HasteMap({
527+
...defaultConfig,
528+
enableSymlinks: true,
529+
useWatchman: true,
530+
}),
531+
).toThrow('Set either `enableSymlinks` to false or `watchman` to false.');
532+
533+
expect(
534+
() =>
535+
new HasteMap({
536+
...defaultConfig,
537+
enableSymlinks: true,
538+
useWatchman: false,
539+
}),
540+
).not.toThrow();
541+
});
542+
520543
describe('builds a haste map on a fresh cache with SHA-1s', () => {
521544
[false, true].forEach(useWatchman => {
522545
it('uses watchman: ' + useWatchman, async () => {

packages/jest-haste-map/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ class HasteMap extends EventEmitter {
282282
throw new Error(
283283
'jest-haste-map: enableSymlinks config option was set, but ' +
284284
'is incompatible with watchman.\n' +
285-
'Set either `enableSymlinks` to false or `watchman` to false ',
285+
'Set either `enableSymlinks` to false or `watchman` to false.',
286286
);
287287
}
288288

0 commit comments

Comments
 (0)