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 realpath to match transformers #5000

Merged
merged 6 commits into from
Dec 4, 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 @@ -48,6 +48,8 @@
issue. ([#4669](https://github.com/facebook/jest/pull/4669))
* `[jest-cli]` Fix `--onlyChanged` path case sensitivity on Windows platform
([#4730](https://github.com/facebook/jest/pull/4730))
* `[jest-runtime]` Use realpath to match transformers
([#5000](https://github.com/facebook/jest/pull/5000))

### Features

Expand Down
12 changes: 12 additions & 0 deletions integration_tests/__tests__/transform-linked-modules.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// @flow

'use strict';

const runJest = require('../runJest');

it('should transform linked modules', () => {
const result = runJest.json('transform-linked-modules', ['--no-cache']).json;

expect(result.success).toBe(true);
expect(result.numTotalTests).toBe(2);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
test('normal file', () => {
const normal = require('../ignored/normal');
expect(normal).toEqual('ignored/normal');
});

test('symlink', () => {
const symlink = require('../ignored/symlink');
expect(symlink).toEqual('transformed');
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 'ignored/normal';
13 changes: 13 additions & 0 deletions integration_tests/transform-linked-modules/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"jest": {
"testEnvironment": "node",
"transformIgnorePatterns": [
"/node_modules/",
"<rootDir>/__tests__",
"<rootDir>/ignored/"
],
"transform": {
"^.+\\.js$": "<rootDir>/preprocessor.js"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 'package/index';
5 changes: 5 additions & 0 deletions integration_tests/transform-linked-modules/preprocessor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
process() {
return 'module.exports = "transformed"';
},
};
12 changes: 11 additions & 1 deletion packages/jest-runtime/src/script_transformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,22 @@ export default class ScriptTransformer {
}).code;
}

_getRealPath(filepath: Path): Path {
try {
// $FlowFixMe
return process.binding('fs').realpath(filepath) || filepath;
} catch (err) {
return filepath;
}
}

transformSource(
filename: Path,
filepath: Path,
content: string,
instrument: boolean,
mapCoverage: boolean,
) {
const filename = this._getRealPath(filepath);
const transform = this._getTransformer(filename);
const cacheFilePath = this._getFileCachePath(
filename,
Expand Down