Skip to content
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

Can not use custom transfom by runCLI #5429

Closed
fattydevelop opened this issue Jan 31, 2018 · 4 comments
Closed

Can not use custom transfom by runCLI #5429

fattydevelop opened this issue Jan 31, 2018 · 4 comments

Comments

@fattydevelop
Copy link

Do you want to request a feature or report a bug?
BUG
What is the current behavior?
can not use transform api like other api do.

jestCli.runCLI(
        {
            transform: {
                '^.+\\.jsx?$': require.resolve('../configs/jest.transform.js')
            },
            transformIgnorePatterns: ['/3333/'],
            testMatch: ['<rootDir>/test/*.js?(x)'],
            slient: false,
            cache: false,
            debug: true
        },
        [cwd],
        function(success) {
            console.log(success);
        }
    );

here's custom transform define.

const babelConfig = require('./babel');
module.exports = require('babel-jest').createTransformer(babelConfig);

when I console the jest debug info there's no key of transform . And also transform can't work.
image

What is the expected behavior?

transform

Please provide your exact Jest configuration and mention your Jest, node,
yarn/npm version and operating system.

node 8.9.4 npm 5.6.0 jest-cli ^22.1.4

thanks for help.

@fattydevelop
Copy link
Author

I have found the solution by search source code .

For transform set loadUtils use isJSONString to validate config. So I must stringify before use.

transform: JSON.stringify({'^.+\\.jsx?$': require.resolve('../configs/jest.transform.js')})

I guess other object setting also need stringify before use. I'll close this issue by case, but it's really confused to stringify a config. BTW, do we have a chance to modify it or it's by design ?

@o-alexandrov
Copy link

Still the case, even for the latest jest 27.0.0-next.7.

  • using JSON.stringify(...) is required to pass transform option to runCLI

Apologies for pinging; please, consider to reopen @SimenB

@SimenB
Copy link
Member

SimenB commented Apr 14, 2021

Jest does not have a public programmatic API, you can track #5048.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants