-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for NODE_PRESERVE_SYMLINKS and --preserve-symlinks behavior
- Loading branch information
Giancarlo Anemone
committed
May 5, 2020
1 parent
1add160
commit 185664c
Showing
21 changed files
with
239 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
import {join, resolve} from 'path'; | ||
import { | ||
existsSync, | ||
mkdirSync, | ||
rmdirSync, | ||
symlinkSync, | ||
unlinkSync, | ||
} from 'graceful-fs'; | ||
|
||
import runJest from '../runJest'; | ||
import {extractSummary} from '../Utils'; | ||
|
||
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 with environment variable', () => { | ||
const {stderr, exitCode} = runJest('preserve-symlinks', ['--no-watchman'], { | ||
preserveSymlinks: '1', | ||
}); | ||
const {summary, rest} = extractSummary(stderr); | ||
expect(exitCode).toEqual(0); | ||
expect(rest.split('\n').length).toEqual(3); | ||
expect(rest).toMatch('PASS __tests__/ab.test.js'); | ||
expect(rest).toMatch('PASS __tests__/a.test.js'); | ||
expect(rest).toMatch('PASS __tests__/b.test.js'); | ||
expect(summary).toMatch('Test Suites: 3 passed, 3 total'); | ||
expect(summary).toMatch('Tests: 3 passed, 3 total'); | ||
expect(summary).toMatch('Snapshots: 0 total'); | ||
}); | ||
|
||
test('preserving symlinks with --preserve-symlinks node flag', () => { | ||
const {stderr, exitCode} = runJest('preserve-symlinks', ['--no-watchman'], { | ||
nodeFlags: ['--preserve-symlinks'], | ||
}); | ||
const {summary, rest} = extractSummary(stderr); | ||
expect(exitCode).toEqual(0); | ||
expect(rest.split('\n').length).toEqual(3); | ||
expect(rest).toMatch('PASS __tests__/ab.test.js'); | ||
expect(rest).toMatch('PASS __tests__/a.test.js'); | ||
expect(rest).toMatch('PASS __tests__/b.test.js'); | ||
expect(summary).toMatch('Test Suites: 3 passed, 3 total'); | ||
expect(summary).toMatch('Tests: 3 passed, 3 total'); | ||
expect(summary).toMatch('Snapshots: 0 total'); | ||
}); | ||
|
||
test('no preserve symlinks configuration', () => { | ||
const {exitCode, stdout} = runJest('preserve-symlinks', ['--no-watchman']); | ||
expect(exitCode).toEqual(1); | ||
expect(stdout).toMatch('No tests found, exiting with code 1'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* 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', () => { | ||
expect(a()).toEqual('a'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* 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', () => { | ||
expect(ab()).toEqual('ab'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* 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', () => { | ||
expect(b()).toEqual('b'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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'; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* 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'); | ||
|
||
module.exports = function ab() { | ||
return a() + b(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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'; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"jest": { | ||
"testEnvironment": "node" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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. | ||
*/ | ||
|
||
declare module 'should-preserve-links' { | ||
export default function shouldPreserveLinks(): boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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. | ||
*/ | ||
|
||
declare module 'should-preserve-links' { | ||
export default function shouldPreserveLinks(): boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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. | ||
*/ | ||
|
||
declare module 'should-preserve-links' { | ||
export default function shouldPreserveLinks(): boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters