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

221
Views
setupFiles not running while working with different projects

While I was setting up multi project jest testing I wanted to have mongodb connected before running any tests, so i placed that code in a setup file. But its not working as it should be.

My root jest.config.js file looks like this

module.exports = {
projects: [
    '<rootDir>/shared/utilities/jest.config.js',
    // '<rootDir>/jest-prettier.config.js',
],
setupFiles: ['./jest.setup.js', 'dotenv/config'],
}

And in /shared/utilities/jest.config.js i have

const { resolve } = require('path')
const root = resolve(__dirname, '../../')
module.exports = {
    rootDir: root,
    displayName: 'utilities',
  testEnvironment: 'node',
  restoreMocks: true,
  coveragePathIgnorePatterns: ['node_modules', 'tests'],
  coverageReporters: ['json-summary', 'text', 'lcov', 'clover', 'html'],
};

The jest.setup.js file does not execute while running jest

const mongoose = require("mongoose");

beforeAll(async() => {
  conso.log("Connecting to MongoDB...");
  await mongoose.connect(process.env.MONGO_TEST_DB_URL, {
    useNewUrlParser: true,
    useUnifiedTopology: true,
    useCreateIndex: true,
    useFindAndModify: false,
  });
},30000);

afterAll(() => {
    mongoose.connection.close();
});
about 4 years ago · Juan Pablo Isaza
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!