Jest: Can not use custom transfom by runCLI

Created on 31 Jan 2018  路  1Comment  路  Source: facebook/jest

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.

Most helpful comment

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 ?

>All comments

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 ?

Was this page helpful?
0 / 5 - 0 ratings