Skip to content

Commit

Permalink
fix(cli/jest): add root config check
Browse files Browse the repository at this point in the history
affects: @varlet/cli
  • Loading branch information
haoziqaq committed Oct 18, 2021
1 parent 1955aa4 commit 052a338
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion packages/varlet-cli/src/config/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
import { JEST_MEDIA_MOCK, JEST_STYLE_MOCK, DOCS_DIR_NAME, TESTS_DIR_NAME, EXAMPLE_DIR_NAME } from '../shared/constant'
import {
JEST_MEDIA_MOCK,
JEST_STYLE_MOCK,
DOCS_DIR_NAME,
TESTS_DIR_NAME,
EXAMPLE_DIR_NAME,
CWD,
} from '../shared/constant'
import { resolve } from 'path'
import { pathExistsSync } from 'fs-extra'

function getRootConfig() {
const file = resolve(CWD, 'jest.config.js')

if (pathExistsSync(file)) {
delete require.cache[require.resolve(file)]
return require(file)
}

return {}
}

module.exports = {
moduleNameMapper: {
Expand All @@ -18,4 +38,5 @@ module.exports = {
],
moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx', 'vue'],
transformIgnorePatterns: ['/node_modules/(?!(@varlet/cli))/'],
...getRootConfig(),
}

0 comments on commit 052a338

Please sign in to comment.