Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

589
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!