-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
babel-jest createTransformer removed from Typescript? #11444
Comments
I can confirm that createTransformer is not working anymore for us TypeError: createTransformer is not a function
packages/main/test/babel-transformer.js |
I think you need to do like this const { configWeb } = require('babelconfig.js');
const transformer = require('babel-jest');
module.exports = transformer.createTransformer({
...configWeb,
}); |
this does not work as well |
using We might wanna export |
|
really? that works fine for me. $ node -p "require('babel-jest').default.createTransformer"
[Function: createTransformer] |
once resolved, can the docs be updated ASAP with the supported solution? https://babeljs.io/docs/en/config-files |
Babel docs are not kept in this repo |
(/cc @nicolo-ribaudo FYI) |
it is working now, maybe it was can cache issue |
the .default also worked for me. |
@SimenB although import { TransformOptions } from '@babel/core';
-import type { Transformer } from '@jest/transform';
-interface BabelJestTransformer extends Transformer {
- canInstrument: true;
-}
-declare const transformer: BabelJestTransformer & {
- createTransformer: (options?: TransformOptions) => BabelJestTransformer;
-};
-export = transformer;
+import type { SyncTransformer } from '@jest/transform';
+declare const transformer: SyncTransformer<TransformOptions>;
+export default transformer; I believe your suggestion to "export |
Just to note that we've also hit this issue, but not using the typescript at all: just a regular JS transform using the conventional pattern as currently given in the docs. Incidentally, here's a link to the docs in question, which give code that no longer works: Note: code something like the following provides a workaround which runs both on previous and newer versions, in case that's needed by anyone: const babelJestMd = require('babel-jest');
const babelJest = babelJestMd.__esModule ? babelJestMd.default : babelJestMd;
module.exports = babelJest.createTransformer({
// babel options
}); I note that Jest itself uses jest-utils |
see: ttps://github.com/jestjs/jest/issues/11444
* Upgrade babel-jest version This is to match with the current version of Jest. Also Jest is added as a peer dependency to reflect this. * Change the babel jest transform script This is done to reflect the new API changes in babel-jest. The second line is done so that it can stay backwards compatible with Jest 26 if needed. References: #3398 (comment) jestjs/jest#11444 (comment) * Use jsdom as a test environment to run jest This is done so the react testing-library can render the DOM elements in testing.
I opened a PR to add a named export for |
🐛 Bug Report
In babel-jest 26.6.3, the index.d.ts is this (containing createTransformer):
But in 27.0.1
it is
so createTransformer is no longer exposed. That usage is documented on lots of sites as the way to use babel-jest - i.e. https://babeljs.io/docs/en/config-files for example, which has you call like this, which no longer works:
Is this intentional to change the typescript to drop createTransformer? If so, can the doc be updated, and what's the alternative?
To Reproduce
Steps to reproduce the behavior:
Expected behavior
envinfo
26.6.3:
27.0.1:
The text was updated successfully, but these errors were encountered: