vue-jest-babel7
forked from vuejs/vue-jest
Changed
修改 babel-core 为 @bebel/core。其余无改动
Jest Vue transformer with source map support
NOTE: This is documentation for
vue-jest@3.x
. View the vue-jest@2.x documentation
Usage
npm install --save-dev vue-jest
Setup
To define vue-jest
as a transformer for your .vue
files, map them to the vue-jest
module:
A full config will look like this.
If you're on a version of Jest older than 22.4.0, you need to set mapCoverage
to true
in order to use source maps.
Example Projects
Example repositories testing Vue components with jest and vue-jest:
Supported langs
vue-jest compiles the script and template of SFCs into a JavaScript file that Jest can run. Currently, SCSS, SASS and Stylus are the only style languages that are compiled.
Supported script languages
- typescript (
lang="ts"
,lang="typescript"
) - coffeescript (
lang="coffee"
,lang="coffeescript"
)
Global Jest options
You can change the behavior of vue-jest
by using jest.globals
.
Tip: Need programmatic configuration? Use the --config option in Jest CLI, and export a
.js
file
babelConfig
Provide babelConfig
in one of the following formats:
<Boolean>
<Object>
<String>
Boolean
true
- Enable Babel processing.vue-jest
will try to find Babel configuration using find-babel-config.
This is the default behavior if babelConfig is not defined.
false
- Skip Babel processing entirely:
Object
Provide inline Babel options:
String
If a string is provided, it will be an assumed path to a babel configuration file (e.g. .babelrc
, .babelrc.js
).
- Config file should export a Babel configuration object.
- Should not point to a project-wide configuration file (babel.config.js), which exports a function.
To use the Config Function API, use inline options instead. i.e.:
tsConfig
Provide tsConfig
in one of the following formats:
<Boolean>
<Object>
<String>
Boolean
true
- Process TypeScript files using custom configuration.vue-jest
will try to find TypeScript configuration using tsconfig.loadSync.
This is the default behavior if tsConfig is not defined.
false
- Process TypeScript files using the default configuration provided by vue-jest.
Object
Provide inline TypeScript compiler options:
String
If a string is provided, it will be an assumed path to a TypeScript configuration file:
Supported template languages
-
pug (
lang="pug"
)- To give options for the Pug compiler, enter them into the Jest configuration. The options will be passed to pug.compile().
-
jade (
lang="jade"
) -
haml (
lang="haml"
)
Supported style languages
- stylus (
lang="stylus"
,lang="styl"
) - sass (
lang="sass"
)- The SASS compiler supports jest's moduleNameMapper which is the suggested way of dealing with Webpack aliases.
- scss (
lang="scss"
)-
The SCSS compiler supports jest's moduleNameMapper which is the suggested way of dealing with Webpack aliases.
-
To import globally included files (ie. variables, mixins, etc.), include them in the Jest configuration at
jest.globals['vue-jest'].resources.scss
:
-
CSS options
experimentalCSSCompile
: Boolean
Default true. Turn off CSS compilation
hideStyleWarn
: Boolean
Default false. Hide warnings about CSS compilation
resources
: