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 abc5aaa commit fb2e526
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 0 deletions.
25 changes: 25 additions & 0 deletions e2e/__tests__/crawlSymlinks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
import {tmpdir} from 'os';
import * as path from 'path';
import {wrap} from 'jest-snapshot-serializer-raw';
import {cleanup, writeFiles, writeSymlinks} from '../Utils';
import runJest from '../runJest';

Expand Down Expand Up @@ -69,3 +70,27 @@ test('Node crawler does not pick up symlinked files by default', () => {
expect(stderr).toEqual('');
expect(exitCode).toEqual(1);
});

test('Should throw if watchman used with haste.enableSymlinks', () => {
init({'.watchmanconfig': JSON.stringify({})});

// 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(`
Validation Error:
haste.enableSymlinks is incompatible with watchman
Either set haste.enableSymlinks to false or do not use watchman
`);
expect(exitCode).toEqual(1);
});
23 changes: 23 additions & 0 deletions packages/jest-config/src/__tests__/normalize.test.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
36 changes: 36 additions & 0 deletions packages/jest-haste-map/src/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,42 @@ describe('HasteMap', () => {
});
});

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

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

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
8 changes: 8 additions & 0 deletions packages/jest-haste-map/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,14 @@ class HasteMap extends EventEmitter {
this._options.ignorePattern = new RegExp(VCS_DIRECTORIES);
}

if (this._options.enableSymlinks && this._options.useWatchman) {
throw new Error(
'jest-haste-map: enableSymlinks config option was set, but ' +
'is incompatible with watchman.\n' +
'Set either `enableSymlinks` to false or `useWatchman` to false.',
);
}

const rootDirHash = createHash('md5').update(options.rootDir).digest('hex');
let hasteImplHash = '';
let dependencyExtractorHash = '';
Expand Down

0 comments on commit fb2e526

Please sign in to comment.