-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow to pass compilerOptions via the Jest config for Vue 3 (#412)
* chore: update to vue v3.2.22 Note that this also removes the now unneeded `@vue/compiler-sfc` dependency. Fixes #410 * feat: allow to pass compilerOptions via the Jest config for Vue 3 These options can be used to define Vue compiler options in `@vue/vue3-jest`. For example, to enable the newly intrioduced `propsDestructureTransform` in Vue v3.2.20: ```js globals: { 'vue-jest': { compilerOptions: { propsDestructureTransform: true } } } ``` or to disable `refTransform` (which is enabled by default): ```js globals: { 'vue-jest': { compilerOptions: { refTransform: false } } } ```
- Loading branch information
Showing
7 changed files
with
136 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"name": "vue3-typescript-with-compiler-options", | ||
"version": "1.0.0", | ||
"license": "MIT", | ||
"private": true, | ||
"scripts": { | ||
"test": "jest --no-cache ./src/test.ts" | ||
}, | ||
"dependencies": { | ||
"vue": "^3.2.22" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "16.0.10", | ||
"jest": "^27.0.0", | ||
"ts-jest": "^27.0.1", | ||
"typescript": "^4.1.2", | ||
"@vue/vue3-jest": "^27.0.0-alpha.1" | ||
}, | ||
"jest": { | ||
"testEnvironment": "jsdom", | ||
"moduleFileExtensions": [ | ||
"js", | ||
"ts", | ||
"json", | ||
"vue" | ||
], | ||
"moduleNameMapper": { | ||
"^@/(.*)$": "<rootDir>/src/$1" | ||
}, | ||
"transform": { | ||
"^.+\\.ts$": "ts-jest", | ||
"^.+\\.vue$": "@vue/vue3-jest" | ||
}, | ||
"globals": { | ||
"vue-jest": { | ||
"compilerOptions": { | ||
"propsDestructureTransform": true | ||
} | ||
} | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
e2e/3.x/typescript-with-compiler-options/src/components/PropsDestructureTransform.vue
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 @@ | ||
<template> | ||
<h1>{{ name }}</h1> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
const { name = 'name' } = defineProps<{ name?: string }>() | ||
</script> |
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,5 @@ | ||
declare module '*.vue' { | ||
import type { DefineComponent } from 'vue'; | ||
const component: DefineComponent<{}, {}, any>; | ||
export default component; | ||
} |
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,25 @@ | ||
import { createApp, h } from 'vue' | ||
|
||
import PropsDestructureTransform from '@/components/PropsDestructureTransform.vue' | ||
|
||
function mount(Component: any) { | ||
document.getElementsByTagName('html')[0].innerHTML = '' | ||
const el = document.createElement('div') | ||
el.id = 'app' | ||
document.body.appendChild(el) | ||
const Parent = { | ||
render() { | ||
return h(Component) | ||
} | ||
} | ||
createApp(Parent).mount(el) | ||
} | ||
|
||
test('support additional compiler options like `propsDestructureTransform`', () => { | ||
// `propsDestructureTransform` is a new compiler option in v3.2.20 | ||
// that allows to destructure props with default values and retain reactivity | ||
// The option is passed to the compiler via `globals.vue-jest.compilerOptions` of the Jest config in the package.json | ||
mount(PropsDestructureTransform) | ||
// if the option is properly passed, then the default value of the props is used | ||
expect(document.querySelector('h1')!.textContent).toBe('name') | ||
}) |
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,24 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"module": "esnext", | ||
"strict": true, | ||
"jsx": "preserve", | ||
"importHelpers": true, | ||
"moduleResolution": "node", | ||
"skipLibCheck": true, | ||
"esModuleInterop": true, | ||
"allowSyntheticDefaultImports": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"useDefineForClassFields": true, | ||
"sourceMap": true, | ||
"baseUrl": ".", | ||
"types": ["webpack-env", "jest"], | ||
"paths": { | ||
"@/*": ["src/*"] | ||
}, | ||
"lib": ["esnext", "dom", "dom.iterable", "scripthost"] | ||
}, | ||
"include": ["src/**/*.ts", "src/**/*.vue"], | ||
"exclude": ["node_modules"] | ||
} |
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