Installations
npm install @vue/vue3-jest
Developer Guide
Typescript
No
Module System
CommonJS
Min. Node Version
>10
Score
55.3
Supply Chain
49.5
Quality
78
Maintenance
100
Vulnerability
97
License
Releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (73.03%)
Vue (23.67%)
TypeScript (2.05%)
SCSS (0.42%)
Less (0.3%)
Pug (0.16%)
Sass (0.14%)
HTML (0.13%)
CSS (0.07%)
Stylus (0.04%)
Developer
vuejs
Download Statistics
Total Downloads
27,024,640
Last Day
11,636
Last Week
190,414
Last Month
1,218,538
Last Year
13,269,223
GitHub Statistics
750 Stars
521 Commits
156 Forks
21 Watching
17 Branches
139 Contributors
Package Meta Information
Latest Version
29.2.6
Package Id
@vue/vue3-jest@29.2.6
Unpacked Size
25.45 kB
Size
7.77 kB
File Count
17
Publised On
06 Sept 2023
Total Downloads
Cumulative downloads
Total Downloads
27,024,640
Last day
-80.3%
11,636
Compared to previous day
Last week
-40.2%
190,414
Compared to previous week
Last month
-7.5%
1,218,538
Compared to previous month
Last year
36.9%
13,269,223
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
vue-jest
Jest transformer for Vue Single File Components.
Installation
Since we need to support a variety of Vue and Jest versions, vue-jest doesn't follow semantic versioning.
Vue version | Jest Version | npm Package | Branch |
---|---|---|---|
Vue 2 | Jest 26 and below | vue-jest@4 | |
Vue 3 | Jest 26 and below | vue-jest@5 | |
Vue 2 | Jest 27 and above | @vue/vue2-jest@27 | 27.x |
Vue 3 | Jest 27 and above | @vue/vue3-jest@27 | 27.x |
Vue 2 | Jest 28 and above | @vue/vue2-jest@28 | 28.x |
Vue 3 | Jest 28 and above | @vue/vue3-jest@28 | 28.x |
1# Vue 2 2npm install --save-dev @vue/vue2-jest@28 # (use the appropriate version) 3yarn add @vue/vue2-jest@28 --dev 4 5# Vue 3 6npm install --save-dev @vue/vue3-jest@28 # (use the appropriate version) 7yarn add @vue/vue3-jest@28 --dev
Setup
To use vue-jest
as a transformer for your .vue
files, map them to the appropriate vue-jest
module:
1{ 2 "jest": { 3 "transform": { 4 "^.+\\.vue$": "@vue/vue2-jest" // Update to match your installed version 5 } 6 } 7}
A full config will look like this.
1{ 2 "jest": { 3 "moduleFileExtensions": ["js", "json", "vue"], 4 "transform": { 5 "^.+\\.js$": "babel-jest", 6 "^.+\\.vue$": "@vue/vue2-jest" 7 } 8 } 9}
Usage with Babel 7
If you use jest > 24.0.0 and babel-jest make sure to install babel-core@bridge
1npm install --save-dev babel-core@bridge 2yarn add babel-core@bridge --dev
Supported languages for SFC sections
vue-jest compiles <script />
, <template />
, and <style />
blocks with supported lang
attributes into JavaScript that Jest can run.
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
.
Compiler Options in Vue 3
These options can be used to define Vue compiler options in @vue/vue3-jest
.
For example, to enable propsDestructureTransform
:
1globals: { 2 'vue-jest': { 3 compilerOptions: { 4 propsDestructureTransform: true 5 } 6 } 7}
or disable refTransform
(which is enabled by default):
1globals: { 2 'vue-jest': { 3 compilerOptions: { 4 refTransform: false 5 } 6 } 7}
Supporting custom blocks
A great feature of the Vue SFC compiler is that it can support custom blocks. You might want to use those blocks in your tests. To render out custom blocks for testing purposes, you'll need to write a transformer. Once you have your transformer, you'll add an entry to vue-jest's transform map. This is how vue-i18n's <i18n>
custom blocks are supported in unit tests.
A package.json
Example
1{ 2 "jest": { 3 "moduleFileExtensions": ["js", "json", "vue"], 4 "transform": { 5 "^.+\\.js$": "babel-jest", 6 "^.+\\.vue$": "@vue/vue2-jest" 7 }, 8 "globals": { 9 "vue-jest": { 10 "transform": { 11 "your-custom-block": "./custom-block-processor.js" 12 } 13 } 14 } 15 } 16}
Tip: Need programmatic configuration? Use the --config option in Jest CLI, and export a
.js
file
A jest.config.js
Example - If you're using a dedicated configuration file like you can reference and require your processor in the config file instead of using a file reference.
1module.exports = { 2 globals: { 3 'vue-jest': { 4 transform: { 5 'your-custom-block': require('./custom-block-processor') 6 } 7 } 8 } 9}
Writing a processor
Processors must return an object with a "process" method, like so...
1module.exports = { 2 /** 3 * Process the content inside of a custom block and prepare it for execution in a testing environment 4 * @param {SFCCustomBlock[]} blocks All of the blocks matching your type, returned from `@vue/component-compiler-utils` 5 * @param {string} vueOptionsNamespace The internal namespace for a component's Vue Options in vue-jest 6 * @param {string} filename The SFC file being processed 7 * @param {Object} config The full Jest config 8 * @returns {string} The code to be output after processing all of the blocks matched by this type 9 */ 10 process({ blocks, vueOptionsNamespace, filename, config }) {} 11}
templateCompiler
You can provide TemplateCompileOptions in templateCompiler
section like this:
1{ 2 "jest": { 3 "globals": { 4 "vue-jest": { 5 "templateCompiler": { 6 "transpileOptions": { 7 "transforms": { 8 "dangerousTaggedTemplateString": true 9 } 10 } 11 } 12 } 13 } 14 } 15}
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().
1{ 2 "jest": { 3 "globals": { 4 "vue-jest": { 5 "pug": { 6 "basedir": "mybasedir" 7 } 8 } 9 } 10 } 11}
-
jade (
lang="jade"
) -
haml (
lang="haml"
)
Supported style languages
-
stylus (
lang="stylus"
,lang="styl"
) -
sass (
lang="sass"
), and -
scss (
lang="scss"
)-
The Sass compiler supports Jest's moduleNameMapper which is the suggested way of dealing with Webpack aliases. Webpack's
sass-loader
uses a special syntax for indicating non-relative imports, so you'll likely need to copy this syntax into yourmoduleNameMapper
entries if you make use of it. For aliases of bare imports (imports that require node module resolution), the aliased value must also be prepended with this~
orvue-jest
's custom resolver won't recognize it.1{ 2 "jest": { 3 "moduleNameMapper": { 4 "^~foo/(.*)": "<rootDir>/foo/$1", 5 // @import '~foo'; -> @import 'path/to/project/foo'; 6 "^~bar/(.*)": "~baz/lib/$1" 7 // @import '~bar/qux'; -> @import 'path/to/project/node_modules/baz/lib/qux'; 8 // Notice how the tilde (~) was needed on the bare import to baz. 9 } 10 } 11}
-
To import globally included files (ie. variables, mixins, etc.), include them in the Jest configuration at
jest.globals['vue-jest'].resources.scss
:1{ 2 "jest": { 3 "globals": { 4 "vue-jest": { 5 "resources": { 6 "scss": [ 7 "./node_modules/package/_mixins.scss", 8 "./src/assets/css/globals.scss" 9 ] 10 } 11 } 12 } 13 } 14}
-
CSS options
experimentalCSSCompile
: Boolean
Default true. Turn off CSS compilation
hideStyleWarn
: Boolean
Default false. Hide warnings about CSS compilation
resources
:
1{ 2 "jest": { 3 "globals": { 4 "vue-jest": { 5 "hideStyleWarn": true, 6 "experimentalCSSCompile": true 7 } 8 } 9 } 10}
Style options
Possbility to change style loader options (sass, scss, less etc).
styleOptions
: Object
Default {}
.
1{ 2 "jest": { 3 "globals": { 4 "vue-jest": { 5 "styleOptions": { 6 "quietDeps" // e.q. sass options https://sass-lang.com/documentation/js-api#quietdeps 7 // unfortunately rest options like `data`, `file` doesnt work because @vue/compiler-component-utils internally overwrite options with their values 8 }, 9 } 10 } 11 } 12}
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 18/29 approved changesets -- score normalized to 6
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/node.yml:1
- Info: no jobLevel write permissions found
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.yml:27: update your workflow using https://app.stepsecurity.io/secureworkflow/vuejs/vue-jest/node.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.yml:29: update your workflow using https://app.stepsecurity.io/secureworkflow/vuejs/vue-jest/node.yml/master?enable=pin
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
- Warn: branch protection not enabled for branch '26.x'
- Warn: branch protection not enabled for branch 'next'
- Warn: branch protection not enabled for branch 'v3'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 20 are checked with a SAST tool
Reason
51 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-wxhq-pm8v-cw75
- Warn: Project is vulnerable to: GHSA-257v-vj4p-3w2h
- Warn: Project is vulnerable to: GHSA-4vmm-mhcq-4x9j
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-ff7x-qrg7-qggm
- Warn: Project is vulnerable to: GHSA-pfrx-2q88-qq97
- Warn: Project is vulnerable to: GHSA-rc47-6667-2j5j
- Warn: Project is vulnerable to: GHSA-78xj-cgh5-2h22
- Warn: Project is vulnerable to: GHSA-2p57-rm9w-gvfp
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-5v2h-r2cx-5xgj
- Warn: Project is vulnerable to: GHSA-rrrm-qjm4-v8hf
- Warn: Project is vulnerable to: GHSA-4xcv-9jjx-gfj3
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-qrpm-p2h7-hrv2
- Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55
- Warn: Project is vulnerable to: GHSA-r683-j2x4-v87g
- Warn: Project is vulnerable to: GHSA-566m-qj78-rww5
- Warn: Project is vulnerable to: GHSA-7fh5-64p2-3v2j
- Warn: Project is vulnerable to: GHSA-6fw4-hr69-g3rv
- Warn: Project is vulnerable to: GHSA-p493-635q-r6gr
- Warn: Project is vulnerable to: GHSA-3965-hpx2-q597
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-r2j6-p67h-q639
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-44c6-4v22-4mhx
- Warn: Project is vulnerable to: GHSA-4x5v-gmq8-25ch
- Warn: Project is vulnerable to: GHSA-3f95-r44v-8mrg
- Warn: Project is vulnerable to: GHSA-28xr-mwxg-3qc8
- Warn: Project is vulnerable to: GHSA-9p95-fxvg-qgq2
- Warn: Project is vulnerable to: GHSA-9w5j-4mwv-2wj8
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-7p7h-4mm5-852v
- Warn: Project is vulnerable to: GHSA-38fc-wpqx-33j7
- Warn: Project is vulnerable to: GHSA-34r7-q49f-h37c
- Warn: Project is vulnerable to: GHSA-c9f4-xj24-8jqx
- Warn: Project is vulnerable to: GHSA-5j4c-8p2g-v4jx
- Warn: Project is vulnerable to: GHSA-g3ch-rx76-35fx
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
- Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp
Score
3.1
/10
Last Scanned on 2024-12-16
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to @vue/vue3-jest
vue3-jest
Jest Vue transform
vue3-snapshot-serializer
Vitest snapshot serializer for Vue 3 components
@kairo/vue3-jest
Jest Vue SFC transform for kairo
generator-quality-vue3-plugin
Yeoman generator to create a Vue3 plugin with eslint, prettier, commitlint, husky, babel and other tools.