Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use fs.realpathSync.native if available #5031

Merged
merged 3 commits into from
Dec 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
([#4494](https://github.com/facebook/jest/pull/4494))
* `[jest-cli]` Throw if `maxWorkers` doesn't have a value
([#4591](https://github.com/facebook/jest/pull/4591))
* `[jest-cli]` Use `fs.realpathSync.native` if available
([#5031](https://github.com/facebook/jest/pull/5031))
* `[jest-config]` Fix `--passWithNoTests`
([#4639](https://github.com/facebook/jest/pull/4639))
* `[jest-config]` Support `rootDir` tag in testEnvironment
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-cli/src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
Console,
clearLine,
createDirectory,
realpath,
validateCLIOptions,
} from 'jest-util';
import {readConfig} from 'jest-config';
Expand Down Expand Up @@ -143,8 +144,7 @@ const getProjectListFromCLIArgs = (argv, project: ?Path) => {

if (!projects.length && process.platform === 'win32') {
try {
// $FlowFixMe
projects.push(process.binding('fs').realpath(process.cwd()));
projects.push(realpath(process.cwd()));
} catch (err) {
// do nothing, just catch error
// process.binding('fs').realpath can throw, e.g. on mapped drives
Expand Down
5 changes: 2 additions & 3 deletions packages/jest-runtime/src/script_transformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type {
import crypto from 'crypto';
import path from 'path';
import vm from 'vm';
import {createDirectory} from 'jest-util';
import {createDirectory, realpath} from 'jest-util';
import fs from 'graceful-fs';
import {transform as babelTransform} from 'babel-core';
import babelPluginIstanbul from 'babel-plugin-istanbul';
Expand Down Expand Up @@ -184,8 +184,7 @@ export default class ScriptTransformer {

_getRealPath(filepath: Path): Path {
try {
// $FlowFixMe
return process.binding('fs').realpath(filepath) || filepath;
return realpath(filepath) || filepath;
} catch (err) {
return filepath;
}
Expand Down
11 changes: 11 additions & 0 deletions packages/jest-util/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

import mkdirp from 'mkdirp';
import fs from 'fs';

import BufferedConsole from './buffered_console';
import clearLine from './clear_line';
Expand All @@ -30,6 +31,15 @@ const createDirectory = (path: string) => {
}
};

const realpath = (filepath: string) => {
if (typeof fs.realpathSync.native === 'function') {
return fs.realpathSync.native(filepath);
}

// $FlowFixMe: This is need for node@<9.2
return process.binding('fs').realpath(filepath, 'utf8');
};

module.exports = {
BufferedConsole,
Console,
Expand All @@ -40,6 +50,7 @@ module.exports = {
formatTestResults,
getConsoleOutput,
installCommonGlobals,
realpath,
setGlobal,
validateCLIOptions,
};