Skip to content

Commit

Permalink
Move validation logic to jest-config
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmeku committed Nov 2, 2020
1 parent 5a7c9ca commit 5c365ab
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 53 deletions.
2 changes: 1 addition & 1 deletion docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ type HasteConfig = {
computeSha1?: boolean;
/** The platform to use as the default, e.g. 'ios'. */
defaultPlatform?: string | null;
/**
/**
* Whether to follow symlinks when crawling for files.
* This options cannot be used in projects which use watchman.
* Projects with a .watchmanconfig will error if this option is set to true.
Expand Down
16 changes: 0 additions & 16 deletions e2e/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,19 +290,3 @@ export const testIfHg = (...args: Parameters<typeof test>) => {
test.skip(...args);
}
};

// Certain environments (like CITGM and GH Actions) do not come with watchman installed
let watchmanIsInstalled: boolean | null = null;

export const testIfWatchman = (...args: Parameters<typeof test>) => {
if (watchmanIsInstalled === null) {
watchmanIsInstalled = which.sync('watchman', {nothrow: true}) !== null;
}

if (watchmanIsInstalled) {
test(...args);
} else {
console.warn('watchman is not installed - skipping some tests');
test.skip(...args);
}
};
21 changes: 1 addition & 20 deletions e2e/__tests__/crawlSymlinks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
*/
import {tmpdir} from 'os';
import * as path from 'path';

import runJest from '../runJest';
import {cleanup, writeFiles, writeSymlinks} from '../Utils';
import runJest from '../runJest';

const DIR = path.resolve(tmpdir(), 'crawl-symlinks-test');

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

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

const {stdout, stderr, exitCode} = runJest(DIR, [
'--haste={"enableSymlinks": true}',
]);

expect(stderr).toEqual('');
expect(stdout).toContain(
'jest-haste-map: haste.enableSymlinks config option was set, but ' +
'is incompatible with watchman.\n' +
' Either set haste.enableSymlinks to false or remove ' +
'.watchmanconfig to disable watchman. \n' +
' Exiting with code 1.',
);
expect(exitCode).toEqual(1);
});
8 changes: 8 additions & 0 deletions packages/jest-config/src/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,14 @@ export default function normalize(
return newOptions;
}, newOptions);

if (options.watchman && options.haste?.enableSymlinks) {
throw new ValidationError(
'Validation Error',
'haste.enableSymlinks is incompatible with watchman',
'Either set haste.enableSymlinks to false or do not use watchman',
);
}

newOptions.roots.forEach((root, i) => {
verifyDirectoryExists(root, `roots[${i}]`);
});
Expand Down
16 changes: 0 additions & 16 deletions packages/jest-haste-map/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {EventEmitter} from 'events';
import {tmpdir} from 'os';
import * as path from 'path';
import type {Stats} from 'graceful-fs';
import {existsSync} from 'graceful-fs';
import {NodeWatcher, Watcher as SaneWatcher} from 'sane';
import type {Config} from '@jest/types';
import {escapePathForRegex} from 'jest-regex-util';
Expand Down Expand Up @@ -750,21 +749,6 @@ class HasteMap extends EventEmitter {
roots: options.roots,
};

if (options.enableSymlinks) {
const watchmanConfigPath = path.join(options.rootDir, '.watchmanconfig');

if (existsSync(watchmanConfigPath)) {
this._console.error(
'jest-haste-map: haste.enableSymlinks config option was set, but ' +
'is incompatible with watchman.\n' +
' Either set haste.enableSymlinks to false or remove ' +
'.watchmanconfig to disable watchman. \n' +
' Exiting with code 1.',
);
process.exit(1);
}
}

const retry = (error: Error) => {
if (crawl === watchmanCrawl) {
this._console.warn(
Expand Down

0 comments on commit 5c365ab

Please sign in to comment.