forked from sourcegraph/sourcegraph-public-snapshot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
babel.config.jest.js
44 lines (38 loc) · 1.37 KB
/
babel.config.jest.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
40
41
42
43
44
// @ts-check
const path = require('path')
// A minimal babel config only for jest transformations.
// All typescript and react transformations are done by previous
// bazel build rules, so we only need to do jest transformations here.
const logger = require('signale')
// TODO(bazel): drop when non-bazel removed.
if (!(process.env.JS_BINARY__TARGET || process.env.BAZEL_BINDIR || process.env.BAZEL_TEST)) {
throw new Error(__filename + ' is only for use with Bazel')
}
/** @type {import('@babel/core').ConfigFunction} */
module.exports = api => {
api.cache.forever()
/**
* Whether to instrument files with istanbul for code coverage.
* This is needed for e2e test coverage.
*/
const instrument = Boolean(process.env.COVERAGE_INSTRUMENT && JSON.parse(process.env.COVERAGE_INSTRUMENT))
if (instrument) {
logger.info('Instrumenting code for coverage tracking')
}
return {
presets: [
// Can't put this in plugins because it needs to run as the last plugin.
...(instrument ? [{ plugins: [['babel-plugin-istanbul', { cwd: path.resolve(__dirname) }]] }] : []),
[
'@babel/preset-env',
{
targets: {
// We only run jest tests in node. All the browser related transformations
// are already completed on the previous transpilation step.
node: '16',
},
},
],
],
}
}