Created
November 17, 2021 15:18
-
-
Save gabrielfalcao/5e6f868ed963f9bae61a6d02b31b614c to your computer and use it in GitHub Desktop.
Jest Config to declare a test pyramid based on "projects"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example of test pyramid using jest | |
// Basic usage: | |
// jest --selectProjects 'unit tests' | |
// Assumes that you organize tests under __${type}_tests__/**/*.js | |
// | |
const path = require('path'); | |
const correctPath = value => path.resolve(__dirname, value || ''); | |
const testOfType = (name, config = {}) => ({ | |
displayName: { | |
name: `${name} tests`, | |
color: `green`, | |
}, | |
collectCoverage: true, | |
moduleNameMapper: { | |
// rename @my-project to the import path of your module | |
//'@my-project/(.*)': '<rootDir>/$1', // use this if your files are not under "src" | |
'@my-project': '<rootDir>/src' | |
}, | |
testMatch: [`__${name}_tests__/*.test.js`, `**/__${name}_tests__/*.test.js`].map(correctPath), | |
coveragePathIgnorePatterns: ['/node_modules/', `.*__${name}_tests__.*`], | |
testPathIgnorePatterns: ['/node_modules/'], | |
...config, | |
}); | |
const config = { | |
rootDir: correctPath(), | |
passWithNoTests: true, | |
projects: [ | |
testOfType('unit', { | |
resetMocks: true, | |
coveragePathIgnorePatterns: ['/node_modules/', '.*__unit_tests__.*', '.*__mocks__.*'], | |
}), | |
testOfType('functional'), | |
], | |
}; | |
module.exports = config; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment