Skip to content

Commit 9c98a59

Browse files
committed
Merge pull request facebook#4656 from spicyj/jest-fast
hax to make jest fast
2 parents 2a82689 + a8b6c82 commit 9c98a59

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

scripts/jest/preprocessor.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
var path = require('path');
4+
35
var babel = require('babel');
46
var coffee = require('coffee-script');
57

@@ -19,15 +21,16 @@ var babelPluginDEV = require('fbjs/scripts/babel/dev-expression');
1921
var babelPluginModules = require('fbjs/scripts/babel/rewrite-modules');
2022

2123
module.exports = {
22-
process: function(src, path) {
23-
if (path.match(/\.coffee$/)) {
24+
process: function(src, filePath) {
25+
if (filePath.match(/\.coffee$/)) {
2426
return coffee.compile(src, {'bare': true});
2527
}
26-
if (path.match(/\.ts$/) && !path.match(/\.d\.ts$/)) {
27-
return ts.compile(src, path);
28+
if (filePath.match(/\.ts$/) && !filePath.match(/\.d\.ts$/)) {
29+
return ts.compile(src, filePath);
2830
}
2931
// TODO: make sure this stays in sync with gulpfile
30-
if (!path.match(/\/node_modules\//) && !path.match(/\/third_party\//)) {
32+
if (!filePath.match(/\/node_modules\//) &&
33+
!filePath.match(/\/third_party\//)) {
3134
var rv = babel.transform(src, {
3235
nonStandard: true,
3336
blacklist: [
@@ -38,11 +41,26 @@ module.exports = {
3841
'es7.trailingFunctionCommas',
3942
],
4043
plugins: [babelPluginDEV, babelPluginModules],
41-
ignore: ['third_party'],
42-
filename: path,
44+
filename: filePath,
4345
retainLines: true,
4446
_moduleMap: moduleMap,
4547
}).code;
48+
49+
// hax to turn fbjs/lib/foo into /path/to/node_modules/fbjs/lib/foo
50+
// because jest is slooow with node_modules paths (facebook/jest#465)
51+
rv = rv.replace(
52+
/require\('(fbjs\/lib\/.+)'\)/g,
53+
function(call, arg) {
54+
return (
55+
'require(' +
56+
JSON.stringify(
57+
path.join(__dirname, '../../node_modules', arg)
58+
) +
59+
')'
60+
);
61+
}
62+
);
63+
4664
return rv;
4765
}
4866
return src;

0 commit comments

Comments
 (0)