Skip to content

Commit

Permalink
error in haste map as well and add tests verifying it
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Nov 2, 2020
1 parent d0bccc4 commit bee5d0d
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 5 deletions.
13 changes: 9 additions & 4 deletions e2e/__tests__/crawlSymlinks.test.ts
Expand Up @@ -74,10 +74,15 @@ test('Node crawler does not pick up symlinked files by default', () => {
test('Should throw if watchman used with haste.enableSymlinks', () => {
init({'.watchmanconfig': JSON.stringify({})});

const {stdout, stderr, exitCode} = runJest(DIR, [
'--haste={"enableSymlinks": true}',
'--watchman',
]);
// it should throw both if watchman is explicitly provided and not
const run1 = runJest(DIR, ['--haste={"enableSymlinks": true}']);
const run2 = runJest(DIR, ['--haste={"enableSymlinks": true}', '--watchman']);

expect(run1.exitCode).toEqual(run2.exitCode);
expect(run1.stderr).toEqual(run2.stderr);
expect(run1.stdout).toEqual(run2.stdout);

const {exitCode, stderr, stdout} = run1;

expect(stdout).toEqual('');
expect(wrap(stderr)).toMatchInlineSnapshot(`
Expand Down
23 changes: 23 additions & 0 deletions packages/jest-config/src/__tests__/normalize.test.js
Expand Up @@ -1714,3 +1714,26 @@ describe('testTimeout', () => {
).toThrowErrorMatchingSnapshot();
});
});

describe('haste.enableSymlinks', () => {
it('should throw if watchman is not disabled', () => {
expect(() =>
normalize({haste: {enableSymlinks: true}, rootDir: '/root/'}, {}),
).toThrow('haste.enableSymlinks is incompatible with watchman');

expect(() =>
normalize(
{haste: {enableSymlinks: true}, rootDir: '/root/', watchman: true},
{},
),
).toThrow('haste.enableSymlinks is incompatible with watchman');

const {options} = normalize(
{haste: {enableSymlinks: true}, rootDir: '/root/', watchman: false},
{},
);

expect(options.haste.enableSymlinks).toBe(true);
expect(options.watchman).toBe(false);
});
});
4 changes: 4 additions & 0 deletions packages/jest-config/src/normalize.ts
Expand Up @@ -577,6 +577,10 @@ export default function normalize(
});
}

if (options.watchman == null) {
options.watchman = DEFAULT_CONFIG.watchman;
}

const optionKeys = Object.keys(options) as Array<keyof Config.InitialOptions>;

optionKeys.reduce((newOptions, key: keyof Config.InitialOptions) => {
Expand Down
23 changes: 23 additions & 0 deletions packages/jest-haste-map/src/__tests__/index.test.js
Expand Up @@ -517,6 +517,29 @@ describe('HasteMap', () => {
});
});

it('throws if both symlinks and watchman is enabled', () => {
expect(
() => new HasteMap({...defaultConfig, enableSymlinks: true}),
).toThrow('Set either `enableSymlinks` to false or `watchman` to false.');
expect(
() =>
new HasteMap({
...defaultConfig,
enableSymlinks: true,
useWatchman: true,
}),
).toThrow('Set either `enableSymlinks` to false or `watchman` to false.');

expect(
() =>
new HasteMap({
...defaultConfig,
enableSymlinks: true,
useWatchman: false,
}),
).not.toThrow();
});

describe('builds a haste map on a fresh cache with SHA-1s', () => {
[false, true].forEach(useWatchman => {
it('uses watchman: ' + useWatchman, async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-haste-map/src/index.ts
Expand Up @@ -282,7 +282,7 @@ class HasteMap extends EventEmitter {
throw new Error(
'jest-haste-map: enableSymlinks config option was set, but ' +
'is incompatible with watchman.\n' +
'Set either `enableSymlinks` to false or `watchman` to false ',
'Set either `enableSymlinks` to false or `watchman` to false.',
);
}

Expand Down

0 comments on commit bee5d0d

Please sign in to comment.