customize-cra icon indicating copy to clipboard operation
customize-cra copied to clipboard

Using customizers for jest configuration

Open kenlyon opened this issue 3 years ago • 3 comments

I am trying to add a babel plugin to the jest configuration for my cra app.

My config-overrides file is exporting the advanced syntax:

module.exports = {
    jest: (config) => {
        // Do some stuff.
        return config;
    },
    webpack: override(
        // Using some customize-cra functions successfully.
    ),
}

I'm getting errors whenever I attempt to use override() with a customizer within the jest section:

<my-project>\node_modules\customize-cra\index.js:34
  let loaders = config.module.rules.find(rule => Array.isArray(rule.oneOf))

It seems these functions expect a webpack config rather than a jest one?

Do any of your functions work with the jest configuration?

kenlyon avatar Jun 03 '22 22:06 kenlyon

A workaround I found (and documented in my personal repo) is to add the jest configuration function as a property of the export.

So in your case, it would look something like

const options = override(...);

const jestConfig = (config) => {
  // Do some stuff.
  return config;
};

options.jest = jestConfig;

module.exports = options;

mickelsonmichael avatar Jul 05 '23 16:07 mickelsonmichael

@mickelsonmichael Thanks for your reply. I don't quite remember what my goal was at the time, but I think I was hoping to actually use override() to combine customizers for jest specifically.

kenlyon avatar Jul 11 '23 20:07 kenlyon

Yes it's definitely not an ideal solution, but hopefully it works for some while we wait for the proper overrides

mickelsonmichael avatar Jul 12 '23 11:07 mickelsonmichael