When using the transform configuration, for transpiling my JS using Babel, I get an error from jest stating:
TypeError: customJSTransformer.includes is not a function
This error occurs, since the setupBabelJest assumes, that the JS transform property is an array:
https://github.com/facebook/jest/blob/master/packages/jest-config/src/normalize.js#L138
But the value returned by babelJest.createTransformer() is an Object with implements the Jest Transformer.
I'm not shure how a fix might be possible, otherwhise I would include a PR.
Maybe the if chain could first check, if it an Object and then else if () check if it's an array afterwards.
jest.config.js:
const babelJest = require("babel-jest");
module.exports = {
transform: {
"^.+\\.jsx?$": babelJest.createTransformer({
presets: [
[
require.resolve("babel-preset-env"),
{
targets: {
node: "10"
}
}
]
]
})
}
};
command:
jest
The transformer should be appended correctly and without error to the jest Config
https://github.com/NicolaiSchmid/jest-error
yarnyarn testnpx envinfo --preset jestPaste the results here:
System:
OS: Linux 4.15 Ubuntu 18.04.1 LTS (Bionic Beaver)
CPU: x64 Intel(R) Core(TM) i5-4430 CPU @ 3.00GHz
Binaries:
Node: 9.4.0 - ~/.nvm/versions/node/v9.4.0/bin/node
Yarn: 1.9.4 - /usr/bin/yarn
npm: 6.3.0 - ~/.nvm/versions/node/v9.4.0/bin/npm
We do not have support for creating a transformer that way. It needs to be a separate file, then you can do require.resolve on it.
I do think supporting it would be good though, so keeping this open as a feature request
Should I do a PR for it? I could free up some time in the coming week.
I have a similar error but with Array.reverse is not a function I tried with a custom transform, and with the babel.config.js on the root of the package (sub-package on monorepo) and didn't work, I also tested passing directly the configuration options to the transformer and didn't work.
module.exports = babelJest.createTransformer({
rootMode: 'upward',
});
"jest": {
"transform": {
"^.+\\.js$": "<rootDir>/config/babelJest.js"
}
}
I have no idea what Array.reverse is. Array.prototype.reverse has existed forever (sine IE 5.5), but I doubt this is a problem with Jest
With webpack or storybook this error didn't happen only with jest, I'll test passing the babel config directly on create transform
Most helpful comment
We do not have support for creating a transformer that way. It needs to be a separate file, then you can do
require.resolveon it.I do think supporting it would be good though, so keeping this open as a feature request