cli: support ts jest config and make test setup module optional

This commit is contained in:
Patrik Oldsberg
2020-03-19 12:08:09 +01:00
parent 52f56ab9b0
commit bd801756eb
2 changed files with 10 additions and 2 deletions
+10 -2
View File
@@ -21,14 +21,22 @@ const path = require('path');
// manually extend @spotify/web-scripts/config/jest.config.js that is desired
if (fs.existsSync('jest.config.js')) {
module.exports = require(path.resolve('jest.config.js'));
} else if (fs.existsSync('jest.config.ts')) {
module.exports = require(path.resolve('jest.config.ts'));
} else {
const extraOptions = {};
// Use src/setupTests.ts as the default location for configuring test env
if (fs.existsSync('src/setupTests.ts')) {
extraOptions.setupFilesAfterEnv = ['<rootDir>/setupTests.ts'];
}
module.exports = {
// We base the jest config on web-scripts, it's pretty flat so we skip any complex merging of config objects
// Config can be found here: https://github.com/spotify/web-scripts/blob/master/packages/web-scripts/config/jest.config.js
...require('@spotify/web-scripts/config/jest.config.js'),
// Use src/setupTests.ts as the default location for configuring test env
setupFilesAfterEnv: ['<rootDir>/setupTests.ts'],
...extraOptions,
// If the package has a jest object in package.json we merge that config in. This is the recommended
// location for configuring tests.