forked from vuejs/vue-cli
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move jest configs into presets (vuejs#4597)
* refactor: move jest configs into a preset This could significantly reduce the size of default boilerplate, and gives us more control on the internal config details, thus potentially making future upgrades easier. * fix: add back applyTS
- Loading branch information
1 parent
cc06091
commit 2e1e92b
Showing
9 changed files
with
125 additions
and
122 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module.exports = { | ||
moduleFileExtensions: [ | ||
'js', | ||
'jsx', | ||
'json', | ||
// tell Jest to handle *.vue files | ||
'vue' | ||
], | ||
transform: { | ||
// process *.vue files with vue-jest | ||
'^.+\\.vue$': require.resolve('vue-jest'), | ||
'.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$': | ||
require.resolve('jest-transform-stub'), | ||
'^.+\\.jsx?$': require.resolve('babel-jest') | ||
}, | ||
transformIgnorePatterns: ['/node_modules/'], | ||
// support the same @ -> src alias mapping in source code | ||
moduleNameMapper: { | ||
'^@/(.*)$': '<rootDir>/src/$1' | ||
}, | ||
// serializer for snapshots | ||
snapshotSerializers: [ | ||
'jest-serializer-vue' | ||
], | ||
testMatch: [ | ||
'**/tests/unit/**/*.spec.[jt]s?(x)', | ||
'**/__tests__/*.[jt]s?(x)' | ||
], | ||
// https://github.com/facebook/jest/issues/6766 | ||
testURL: 'http://localhost/', | ||
watchPlugins: [ | ||
require.resolve('jest-watch-typeahead/filename'), | ||
require.resolve('jest-watch-typeahead/testname') | ||
] | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/@vue/cli-plugin-unit-jest/preset/no-babel/esmoduleTransformer.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const babelJest = require('babel-jest') | ||
|
||
module.exports = babelJest.createTransformer({ | ||
plugins: ['@babel/plugin-transform-modules-commonjs'], | ||
babelrc: false, | ||
configFile: false | ||
}) |
21 changes: 21 additions & 0 deletions
21
packages/@vue/cli-plugin-unit-jest/preset/no-babel/jest-preset.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const deepmerge = require('deepmerge') | ||
const defaultPreset = require('../jest-preset') | ||
|
||
// If no default babel preset exists, | ||
// we need to use a customized babel transformer to deal with es modules | ||
|
||
module.exports = deepmerge( | ||
defaultPreset, | ||
{ | ||
transform: { | ||
'^.+\\.jsx?$': require.resolve('./esmoduleTransformer') | ||
}, | ||
globals: { | ||
'vue-jest': { | ||
babelConfig: { | ||
plugins: [require('babel-plugin-transform-es2015-modules-commonjs')] | ||
} | ||
} | ||
} | ||
} | ||
) |
13 changes: 13 additions & 0 deletions
13
packages/@vue/cli-plugin-unit-jest/preset/typescript-and-babel/jest-preset.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const deepmerge = require('deepmerge') | ||
const defaultTsPreset = require('../typescript/jest-preset') | ||
|
||
module.exports = deepmerge( | ||
defaultTsPreset, | ||
{ | ||
globals: { | ||
'ts-jest': { | ||
babelConfig: true | ||
} | ||
} | ||
} | ||
) |
12 changes: 12 additions & 0 deletions
12
packages/@vue/cli-plugin-unit-jest/preset/typescript/jest-preset.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const deepmerge = require('deepmerge') | ||
const defaultPreset = require('../jest-preset') | ||
|
||
module.exports = deepmerge( | ||
defaultPreset, | ||
{ | ||
moduleFileExtensions: ['ts', 'tsx'], | ||
transform: { | ||
'^.+\\.tsx?$': require.resolve('ts-jest') | ||
} | ||
} | ||
) |