jest-runner-eslint or any with CRA and react-app-rewired

53 views Asked by At

I'm trying to inject my custom jest config to react app with react-app-rewired. When I use single config all works ok. But when I try to split the config into multiple projects and use jest.config.projects, my serializers don't load. As it would no find the node_modules. bellow settings that work for me now, but I cannot split this into seperate projetcs

testEnvironment: 'jest-environment-jsdom',
modulePaths: ['<rootDir>/tests'],
moduleDirectories: ['node_modules', '<rootDir>/src', '<rootDir>/tests'],
roots: ['<rootDir>/src', '<rootDir>/tests'],
moduleNameMapper: {
    '@tests/(.*)': ['<rootDir>/tests/$1'],
    '\\.module\\.css$': 'identity-obj-proxy',
    '\\.css$': require.resolve('./tests/style-mock.ts'),
},
moduleFileExtensions: [...defaults.moduleFileExtensions, 'tsx', 'ts', 'js', '.json'],
setupFilesAfterEnv: ['@testing-library/jest-dom'],
snapshotSerializers: ['@emotion/jest/serializer'],
collectCoverageFrom: ['**/src/**/*.(js|ts|tsx|jsx)'],

I wanted to do it to have jest-runner-eslint working by adding this as project:

{
  displayName: 'lint',
  runner: 'jest-runner-eslint',
  testMatch: ['<rootDir>/**/*.js'],
}

oh and i tried testMatch: ['<rootDir>/**/*.(js|jsx|ts|tsx)']

in config-overrides.js I just merge both:

jest: function (config) {
    const customJestConfig = require('./jest.config.js');
    return { ...config, ...customJestConfig };
  },

anyone can help me to split this setting into projects???

something like :

jest: function (config) {
    const customJestConfig = require('./jest.config.js');
    customJestConfig.projects = [
      { displayName: 'tests' },
      {
        rootDir: path.join(__dirname, '..'),
        displayName: 'lint',
        runner: 'jest-runner-eslint',
        testMatch: ['<rootDir>/**/*.js'],
      },
    ];
    return { ...config, ...customJestConfig };
  },
0

There are 0 answers