esjest-transform
(DEPRECATED, use esbuild-jest instead)
A fast jest transform.
In your jest configuration, add:
module.exports = {
// ...
transform: {
"\\.[jt]sx?$": "esjest-transform",
},
// ...
};
Category: JavaScript / Miscellaneous |
Watchers: 1 |
Star: 47 |
Fork: 1 |
Last update: Mar 11, 2021 |
(DEPRECATED, use esbuild-jest instead)
A fast jest transform.
In your jest configuration, add:
module.exports = {
// ...
transform: {
"\\.[jt]sx?$": "esjest-transform",
},
// ...
};
● Test suite failed to run
SyntaxError: /Users/haroen.viaene/Developer/algolia/instantsearch.js/src/components/GeoSearchControls/__tests__/GeoSearchToggle-test.js: Unexpected token, expected "," (21:23)
19 |
20 | const wrapper = shallow(
> 21 | <GeoSearchToggle {...props}>
| ^
22 | Clear the current map refinement
23 | </GeoSearchToggle>
24 | );
at Object._raise (node_modules/esjest-transform/node_modules/@babel/parser/src/parser/error.js:97:45)
babel config:
/* eslint-disable import/no-commonjs */
const wrapWarningWithDevCheck = require('./scripts/babel/wrap-warning-with-dev-check');
const isCJS = process.env.BABEL_ENV === 'cjs';
const isES = process.env.BABEL_ENV === 'es';
const isUMD = process.env.BABEL_ENV === 'umd';
const clean = x => x.filter(Boolean);
module.exports = api => {
const isTest = api.env('test');
const modules = isTest || isCJS ? 'commonjs' : false;
const targets = {};
if (isTest) {
targets.node = true;
} else {
targets.browsers = ['last 2 versions', 'ie >= 9'];
}
const testPlugins = [
'@babel/plugin-proposal-class-properties',
wrapWarningWithDevCheck,
];
const buildPlugins = clean([
'@babel/plugin-proposal-class-properties',
'@babel/plugin-transform-react-constant-elements',
[
'babel-plugin-transform-react-remove-prop-types',
{
mode: 'remove',
removeImport: true,
},
],
'babel-plugin-transform-react-pure-class-to-function',
wrapWarningWithDevCheck,
(isCJS || isES) && [
'inline-replace-variables',
{
__DEV__: {
type: 'node',
replacement: "process.env.NODE_ENV === 'development'",
},
},
],
// this plugin is used to test if we need polyfills, not to actually insert them
// only UMD, since cjs & esm have false positives due to imports
isUMD && [
'polyfill-es-shims',
{
method: 'usage-global',
targets: {
ie: 11,
},
shouldInjectPolyfill(name, defaultShouldInject) {
const exclude = [
// false positives (we access these from objects only)
'Array.prototype.item',
'String.prototype.item',
'Array.prototype.values',
'Function.prototype.name',
// we require polyfills for this already
'Array.prototype.includes',
// false positive (babel doesn't know types)
// this is actually only called on arrays
'String.prototype.includes',
];
if (defaultShouldInject && !exclude.includes(name)) {
throw new Error(
`Usage of a builtin which isn't allowed to be polyfilled: ${name}`
);
}
return false;
},
},
],
]);
return {
presets: [
'@babel/preset-typescript',
'@babel/preset-react',
[
'@babel/preset-env',
{
modules,
targets,
},
],
],
plugins: isTest ? testPlugins : buildPlugins,
};
};
I ran this in on my work setup, which is a windows VM and couldn't see any real benefits of switching over to esjest-transform
or esbuild-jest
. All the test's ran without issues which is roughly about 700 test's. Using the babel transformations, I was seeing about 5 minutes after cleaning the cache. With esjest-transform
it went beyond the 5 minute mark.
FAIL src/widgets/pagination/__tests__/pagination-test.js
● Test suite failed to run
Cannot find module '@jest/globals' from 'pagination-test.js'
23 | });
24 |
> 25 | describe('Usage', () => {
| ^
26 | it('throws without container', () => {
27 | expect(() => {
28 | pagination({ container: undefined });
at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:276:11)
at _getJestObj (src/widgets/pagination/__tests__/pagination-test.js:25:7)
at Object.<anonymous> (src/widgets/pagination/__tests__/pagination-test.js:8:1)
this didn't happen in every test, and on different spots in the code, some describe, some expect, some an unrelated code point