Skip to content

Commit

Permalink
Use fs.realpathSync.native if available (#5031)
Browse files Browse the repository at this point in the history
* Pass in encoding to `realpath` call

Fixes #5030

* Use `fs.realpathSync.native` if it exists

* update changelog
  • Loading branch information
SimenB authored and cpojer committed Dec 7, 2017
1 parent 158ecd3 commit 357a119
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
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,
};

0 comments on commit 357a119

Please sign in to comment.