Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

594
Visualizações
Jest Projects in a Monorepo unable to find config files in projects

Having trouble setting up jest projects. Project A has some additional configuration that it runs (setupJest, creates some custom matchers, etc) that project B does not have. When I run jest I get this error for every single test it tries to run:

Test suite failed to run
File not found: <rootDir>/src/tsconfig.spec.json (resolved as: repo\src\tsconfig.spec.json)

There is no src folder in the repo root, only inside the individual project folders. I'm also not referencing src\tsconfig.spec.json anywhere in my setups. So I'm a bit confused at this point as to what to try. I've tried putting rootDir on everything and spelling out the paths, but nothing seems to work. Any suggestions or ideas or help would be REALLY welcome.

For reference, repo is a folder on a windows drive that holds the repo. e.g. c:\companyName\productName\

This is my structure

repo
  |- jest.config.js
  |- projects
       |- projectA
            |- jest.config.js
            |- tsconfig.spec.json
            |- src
                 |- setupJest.js
       |- projectB
            |- jest.config.js
            |- tsconfig.spec.json

root jest.config.js:

module.exports = {
    preset: 'jest-preset-angular',
    projects: [
        '<rootDir>/projects/projectA/jest.config.js',
        '<rootDir>/projects/projectB/jest.config.js'
    ]
    reporters: ['jest-silent-reporter'],
};

projectA jest.config.js:

module.exports = {
    globals: {
        'ts-jest': {
            tsConfig: 'tsconfig.spec.json',
            stringifyContentPathRegex: '\\.html$',
            astTransformers: ['jest-preset-angular/InlineHtmlStripStylesTransformer'],
            diagnostics: false,
        },
    },
    setupFilesAfterEnv: ['src/setupJest.ts'],
};

projectB jest.config.js:

module.exports = {
    globals: {
    'ts-jest': {
        tsConfig: 'tsconfig.spec.json',
            stringifyContentPathRegex: '\\.html$',
            astTransformers: ['jest-preset-angular/InlineHtmlStripStylesTransformer'],
            diagnostics: false,
        },
    },
};
over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Okay, so after 4 days of intense digging through reported issues on github and a handful of youtube tutorials I could find, I muddled my way to getting this to work.

root jest.config.js

globals: {
    'ts-jest': {
        astTransformers: ['jest-preset-angular/InlineHtmlStripStylesTransformer'],
        diagnostics: false,
        stringifyContentPathRegex: '\\.html$',
    },
},
moduleDirectories: ['node_modules', './'],
modulePaths: ['node_modules', './'],
preset: 'ts-jest',
projects: ['projects/projectA', 'projects/projectB'],
reporters: ['jest-silent-reporter'],
testEnvironment: 'node',
transform: {
    '\\.ts$': ['ts-jest'],
    '\\.html$': ['ts-jest'],
},
verbose: true,

projectA/B jest.config.js

module.exports = {
globals: {
    'ts-jest': {
        astTransformers: ['jest-preset-angular/InlineHtmlStripStylesTransformer'],
        diagnostics: false,
        stringifyContentPathRegex: '\\.html$',
        tsConfig: '<rootDir>/projects/projectA/tsconfig.spec.json',
    },
},
displayName: 'projectA',
moduleDirectories: ['node_modules', './'],
modulePaths: ['node_modules', './'],
name: 'projectA',
rootDir: './../../',
testMatch: ['<rootDir>/projects/projectA/**/*.spec.ts'],
transform: {
    '\\.ts$': ['ts-jest'],
    '\\.html$': ['ts-jest'],
},
};

Turns out the really important bit is the "rootDir: './../../'" piece. The rest was somewhat specific to fixing the other errors that came up as I worked through them, but once I got the rootDir defined properly from the sub projects, it actually started seeing all of them properly. So that is the key. jest.config.js (regardless of where it is in the project) defines rootDir relative to itself. So when it got to a project folder and accessed the config it remapped the rootDir and got lost. Defining root from the sub projects as the same as the parent jest config fixes the problem. Jest's documentation isn't exactly clear on this point.

over 4 years ago · Santiago Trujillo Relatório

0

jest.config.json in every project.

module.exports = {
    preset: 'ts-jest',
    globals: {
        'ts-jest': {
            tsconfig: require.resolve('./tsconfig.jest.json'),
        },
    },
};

require.resolve will find the right path

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda