1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

"Error: Preset jest.preset.js not found" when using IntelliJ to run Jest tests in NX Workspace

Discussão em 'Angular' iniciado por tmptplayer, Setembro 24, 2024.

  1. tmptplayer

    tmptplayer Guest

    I have an NX workspace with Node + Angular libraries. When upgrading from NX version 13.x to 14.x, NX reconfigured Jest through its automated migration process.

    When running the project:test generator, my jest tests work as expected. However, when trying to run unit tests directly through the IDE (IntelliJ), I get the following error:

    Error: ● Validation Error:

    Preset jest.preset.js not found.

    Configuration Documentation:
    https://jestjs.io/docs/configuration



    The project is setup with project level configuration files, as shown below.

    module.exports = {
    coverageDirectory: '<path>',
    displayName : '<name>',
    globals : {
    'ts-jest': {
    stringifyContentPathRegex: '\\.(html|svg)$',
    tsconfig : '<rootDir>/tsconfig.spec.json'
    }
    },

    setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],

    snapshotSerializers : [
    'jest-preset-angular/build/serializers/no-ng-attributes',
    'jest-preset-angular/build/serializers/ng-snapshot',
    'jest-preset-angular/build/serializers/html-comment'
    ],
    transform : {
    '^.+.(ts|mjs|js|html)$': 'jest-preset-angular'
    },
    transformIgnorePatterns: ['node_modules/(?!.*.mjs$)'],
    preset : '../../../../../jest.preset.ts'
    };


    The preset file exits and looks like:

    const nxPreset = require('@nrwl/jest/preset');

    module.exports = { ...nxPreset };


    I also have a global jest.config.ts file. This file does have a reference to jest.preset.js which does not exist within its scope. Also, not existing, is a globally scoped test-setup.ts file. Shown below:

    const { getJestProjects } = require('@nrwl/jest');

    module.exports = {
    globals: {
    'ts-jest': {
    astTransformers: {
    before: [
    'jest-preset-angular/build/InlineFilesTransformer',
    'jest-preset-angular/build/StripStylesTransformer'
    ]
    },
    stringifyContentPathRegex: '\\.(html|svg)$',
    tsconfig: '<rootDir>/tsconfig.spec.json'
    }
    },
    preset : 'jest.preset.js',
    setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
    snapshotSerializers: [
    'jest-preset-angular/build/serializers/no-ng-attributes',
    'jest-preset-angular/build/serializers/ng-snapshot',
    'jest-preset-angular/build/serializers/html-comment'
    ],
    projects: [
    ...getJestProjects(),
    //Lots of projects
    ]
    };



    I imagine that there was something awry in the migration, but I do not understand jest configuration well enough to know how to deconflict these. There are multiple issues in the global config file, however when I eliminate the global config file I get a host of other errors (as in it appears that it tries to run my ts tests in js).

    Any thoughts as to how I could rectify this issue would be appreciated.

    Continue reading...

Compartilhe esta Página