diff --git a/.gitignore b/.gitignore index 44d7ab20ab8c..2e5405cb7275 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ /examples/*/node_modules/ /examples/mongodb/globalConfig.json +/e2e/preserve-symlinks/* /e2e/*/node_modules /e2e/*/.pnp /e2e/*/.pnp.js diff --git a/e2e/__tests__/preserveSymlinks.ts b/e2e/__tests__/preserveSymlinks.ts index 0c4edd2b457c..f672fbd51649 100644 --- a/e2e/__tests__/preserveSymlinks.ts +++ b/e2e/__tests__/preserveSymlinks.ts @@ -5,12 +5,55 @@ * LICENSE file in the root directory of this source tree. */ -import {resolve} from 'path'; +import {existsSync, mkdirSync, rmdirSync, symlinkSync, unlinkSync} from 'fs'; +import {join, resolve} from 'path'; + import {wrap} from 'jest-snapshot-serializer-raw'; import runJest from '../runJest'; import {extractSummary} from '../Utils'; import HasteMap = require('jest-haste-map'); +const destRoot = resolve(__dirname, '../preserve-symlinks'); +const srcRoot = resolve(__dirname, '../symlinked-source-dir'); + +const files = [ + 'package.json', + 'a.js', + 'b.js', + 'ab.js', + '__tests__/a.test.js', + '__tests__/b.test.js', + '__tests__/ab.test.js', +]; + +function cleanup() { + files + .map(f => join(destRoot, f)) + .filter(f => existsSync(f)) + .forEach(f => { + unlinkSync(f); + }); + if (existsSync(join(destRoot, '__tests__'))) { + rmdirSync(join(destRoot, '__tests__')); + } + if (existsSync(destRoot)) { + rmdirSync(destRoot); + } +} + +beforeAll(() => { + cleanup(); + mkdirSync(destRoot); + mkdirSync(join(destRoot, '__tests__')); + files.forEach(f => { + symlinkSync(join(srcRoot, f), join(destRoot, f)); + }); +}); + +afterAll(() => { + cleanup(); +}); + test('preserving symlinks', () => { const {stderr, exitCode} = runJest('preserve-symlinks', ['--no-watchman'], { preserveSymlinks: '1', @@ -48,15 +91,19 @@ test('hasteMap finds symlinks correctly', async () => { }; const hasteMap = new HasteMap(options); const result = await hasteMap.build(); - console.log('FILES', result.hasteFS.getAllFiles()); - expect(result.hasteFS.getAllFiles()).toMatchInlineSnapshot(` + expect( + result.hasteFS + .getAllFiles() + .map(f => f.split('preserve-symlinks').pop()) + .sort(), + ).toMatchInlineSnapshot(` Array [ - "/Users/giancarloanemone/dev/jest/e2e/preserve-symlinks/a.js", - "/Users/giancarloanemone/dev/jest/e2e/preserve-symlinks/ab.js", - "/Users/giancarloanemone/dev/jest/e2e/preserve-symlinks/b.js", - "/Users/giancarloanemone/dev/jest/e2e/preserve-symlinks/__tests__/b.test.js", - "/Users/giancarloanemone/dev/jest/e2e/preserve-symlinks/__tests__/a.test.js", - "/Users/giancarloanemone/dev/jest/e2e/preserve-symlinks/__tests__/ab.test.js", + "/__tests__/a.test.js", + "/__tests__/ab.test.js", + "/__tests__/b.test.js", + "/a.js", + "/ab.js", + "/b.js", ] `); }); diff --git a/e2e/preserve-symlinks/__tests__/a.test.js b/e2e/preserve-symlinks/__tests__/a.test.js deleted file mode 120000 index d21cc3ad3f38..000000000000 --- a/e2e/preserve-symlinks/__tests__/a.test.js +++ /dev/null @@ -1 +0,0 @@ -/Users/giancarloanemone/dev/jest/e2e/symlinked-source-dir/__tests__/a.test.js \ No newline at end of file diff --git a/e2e/preserve-symlinks/__tests__/ab.test.js b/e2e/preserve-symlinks/__tests__/ab.test.js deleted file mode 120000 index 281965e8f810..000000000000 --- a/e2e/preserve-symlinks/__tests__/ab.test.js +++ /dev/null @@ -1 +0,0 @@ -/Users/giancarloanemone/dev/jest/e2e/symlinked-source-dir/__tests__/ab.test.js \ No newline at end of file diff --git a/e2e/preserve-symlinks/__tests__/b.test.js b/e2e/preserve-symlinks/__tests__/b.test.js deleted file mode 120000 index 8cec34cfa58a..000000000000 --- a/e2e/preserve-symlinks/__tests__/b.test.js +++ /dev/null @@ -1 +0,0 @@ -/Users/giancarloanemone/dev/jest/e2e/symlinked-source-dir/__tests__/b.test.js \ No newline at end of file diff --git a/e2e/preserve-symlinks/a.js b/e2e/preserve-symlinks/a.js deleted file mode 120000 index e6733a77642a..000000000000 --- a/e2e/preserve-symlinks/a.js +++ /dev/null @@ -1 +0,0 @@ -/Users/giancarloanemone/dev/jest/e2e/symlinked-source-dir/a.js \ No newline at end of file diff --git a/e2e/preserve-symlinks/ab.js b/e2e/preserve-symlinks/ab.js deleted file mode 120000 index 03fd4c7fcce9..000000000000 --- a/e2e/preserve-symlinks/ab.js +++ /dev/null @@ -1 +0,0 @@ -/Users/giancarloanemone/dev/jest/e2e/symlinked-source-dir/ab.js \ No newline at end of file diff --git a/e2e/preserve-symlinks/b.js b/e2e/preserve-symlinks/b.js deleted file mode 120000 index 352da31561eb..000000000000 --- a/e2e/preserve-symlinks/b.js +++ /dev/null @@ -1 +0,0 @@ -/Users/giancarloanemone/dev/jest/e2e/symlinked-source-dir/b.js \ No newline at end of file diff --git a/e2e/preserve-symlinks/package.json b/e2e/preserve-symlinks/package.json deleted file mode 120000 index 95df2d0867d3..000000000000 --- a/e2e/preserve-symlinks/package.json +++ /dev/null @@ -1 +0,0 @@ -/Users/giancarloanemone/dev/jest/e2e/symlinked-source-dir/package.json \ No newline at end of file diff --git a/e2e/symlinked-source-dir/__tests__/a.test.js b/e2e/symlinked-source-dir/__tests__/a.test.js index 1991c012fc6d..7ae15d959838 100644 --- a/e2e/symlinked-source-dir/__tests__/a.test.js +++ b/e2e/symlinked-source-dir/__tests__/a.test.js @@ -1,3 +1,10 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + */ const a = require('../a'); test('a', () => { diff --git a/e2e/symlinked-source-dir/__tests__/ab.test.js b/e2e/symlinked-source-dir/__tests__/ab.test.js index f0980440f386..b312f6d57c34 100644 --- a/e2e/symlinked-source-dir/__tests__/ab.test.js +++ b/e2e/symlinked-source-dir/__tests__/ab.test.js @@ -1,3 +1,10 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + */ const ab = require('../ab'); test('ab', () => { diff --git a/e2e/symlinked-source-dir/__tests__/b.test.js b/e2e/symlinked-source-dir/__tests__/b.test.js index 9e74fd60121b..4c95a97391eb 100644 --- a/e2e/symlinked-source-dir/__tests__/b.test.js +++ b/e2e/symlinked-source-dir/__tests__/b.test.js @@ -1,3 +1,10 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + */ const b = require('../b'); test('b', () => { diff --git a/e2e/symlinked-source-dir/a.js b/e2e/symlinked-source-dir/a.js index 544895056c9c..c3e6f1d5f6cb 100644 --- a/e2e/symlinked-source-dir/a.js +++ b/e2e/symlinked-source-dir/a.js @@ -1,3 +1,10 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + */ module.exports = function a() { return 'a'; }; diff --git a/e2e/symlinked-source-dir/ab.js b/e2e/symlinked-source-dir/ab.js index 3bcd7ae6967f..30b92befb9c2 100644 --- a/e2e/symlinked-source-dir/ab.js +++ b/e2e/symlinked-source-dir/ab.js @@ -1,3 +1,10 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + */ const a = require('./a'); const b = require('./b'); diff --git a/e2e/symlinked-source-dir/b.js b/e2e/symlinked-source-dir/b.js index 2e0736bb64de..503a0820a921 100644 --- a/e2e/symlinked-source-dir/b.js +++ b/e2e/symlinked-source-dir/b.js @@ -1,3 +1,10 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + */ module.exports = function b() { return 'b'; };