From bd801756eb62803dd705aebf6deba14d196cce2a Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Thu, 19 Mar 2020 12:08:09 +0100 Subject: [PATCH] cli: support ts jest config and make test setup module optional --- packages/cli/config/jest.js | 12 ++++++++++-- packages/core/{jest.config.js => jest.config.ts} | 0 2 files changed, 10 insertions(+), 2 deletions(-) rename packages/core/{jest.config.js => jest.config.ts} (100%) diff --git a/packages/cli/config/jest.js b/packages/cli/config/jest.js index d849bf307f..e443ceec1b 100644 --- a/packages/cli/config/jest.js +++ b/packages/cli/config/jest.js @@ -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 = ['/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: ['/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. diff --git a/packages/core/jest.config.js b/packages/core/jest.config.ts similarity index 100% rename from packages/core/jest.config.js rename to packages/core/jest.config.ts