|
| 1 | +/** |
| 2 | + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + */ |
| 7 | +import {tmpdir} from 'os'; |
| 8 | +import * as path from 'path'; |
| 9 | +import {wrap} from 'jest-snapshot-serializer-raw'; |
| 10 | +import {cleanup, writeFiles, writeSymlinks} from '../Utils'; |
| 11 | +import runJest from '../runJest'; |
| 12 | + |
| 13 | +const DIR = path.resolve(tmpdir(), 'crawl-symlinks-test'); |
| 14 | + |
| 15 | +beforeEach(() => { |
| 16 | + cleanup(DIR); |
| 17 | + |
| 18 | + writeFiles(DIR, { |
| 19 | + 'package.json': JSON.stringify({ |
| 20 | + jest: { |
| 21 | + testMatch: ['<rootDir>/test-files/test.js'], |
| 22 | + }, |
| 23 | + }), |
| 24 | + 'symlinked-files/test.js': ` |
| 25 | + test('1+1', () => { |
| 26 | + expect(1).toBe(1); |
| 27 | + }); |
| 28 | + `, |
| 29 | + }); |
| 30 | + |
| 31 | + writeSymlinks(DIR, { |
| 32 | + 'symlinked-files/test.js': 'test-files/test.js', |
| 33 | + }); |
| 34 | +}); |
| 35 | + |
| 36 | +afterEach(() => { |
| 37 | + cleanup(DIR); |
| 38 | +}); |
| 39 | + |
| 40 | +test('Node crawler picks up symlinked files when option is set as flag', () => { |
| 41 | + // Symlinks are only enabled on windows with developer mode. |
| 42 | + // https://blogs.windows.com/windowsdeveloper/2016/12/02/symlinks-windows-10/ |
| 43 | + if (process.platform === 'win32') { |
| 44 | + return; |
| 45 | + } |
| 46 | + |
| 47 | + const {stdout, stderr, exitCode} = runJest(DIR, [ |
| 48 | + '--haste={"enableSymlinks": true}', |
| 49 | + '--no-watchman', |
| 50 | + ]); |
| 51 | + |
| 52 | + expect(stdout).toEqual(''); |
| 53 | + expect(stderr).toContain('Test Suites: 1 passed, 1 total'); |
| 54 | + expect(exitCode).toEqual(0); |
| 55 | +}); |
| 56 | + |
| 57 | +test('Node crawler does not pick up symlinked files by default', () => { |
| 58 | + const {stdout, stderr, exitCode} = runJest(DIR, ['--no-watchman']); |
| 59 | + expect(stdout).toContain('No tests found, exiting with code 1'); |
| 60 | + expect(stderr).toEqual(''); |
| 61 | + expect(exitCode).toEqual(1); |
| 62 | +}); |
| 63 | + |
| 64 | +test('Should throw if watchman used with haste.enableSymlinks', () => { |
| 65 | + // it should throw both if watchman is explicitly provided and not |
| 66 | + const run1 = runJest(DIR, ['--haste={"enableSymlinks": true}']); |
| 67 | + const run2 = runJest(DIR, ['--haste={"enableSymlinks": true}', '--watchman']); |
| 68 | + |
| 69 | + expect(run1.exitCode).toEqual(run2.exitCode); |
| 70 | + expect(run1.stderr).toEqual(run2.stderr); |
| 71 | + expect(run1.stdout).toEqual(run2.stdout); |
| 72 | + |
| 73 | + const {exitCode, stderr, stdout} = run1; |
| 74 | + |
| 75 | + expect(stdout).toEqual(''); |
| 76 | + expect(wrap(stderr)).toMatchInlineSnapshot(` |
| 77 | + Validation Error: |
| 78 | +
|
| 79 | + haste.enableSymlinks is incompatible with watchman |
| 80 | +
|
| 81 | + Either set haste.enableSymlinks to false or do not use watchman |
| 82 | + `); |
| 83 | + expect(exitCode).toEqual(1); |
| 84 | +}); |
0 commit comments