-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
/
preprocessor.js
39 lines (34 loc) · 1 KB
/
preprocessor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* 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 {transformSync: babelTransform} = require('@babel/core');
const {default: babelIstanbulPlugin} = require('babel-plugin-istanbul');
// This is imported from this repo
const jestPreset = require.resolve('babel-preset-jest');
const options = {
presets: ['@babel/preset-env', jestPreset],
retainLines: true,
sourceMaps: 'inline',
};
module.exports = {
canInstrument: true,
process(src, filename, transformOptions) {
options.filename = filename;
if (transformOptions.instrument) {
options.auxiliaryCommentBefore = ' istanbul ignore next ';
options.plugins = [
[
babelIstanbulPlugin,
{
cwd: transformOptions.config.rootDir,
exclude: [],
},
],
];
}
return babelTransform(src, options) || src;
},
};