Skip to content

feat: enable sugar ref take 2 for vue3-jest #377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions e2e/3.x/babel-in-package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
"test": "jest --no-cache test.js"
},
"dependencies": {
"vue": "^3.0.3"
"vue": "^3.2.6"
},
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/preset-env": "^7.9.0",
"@vue/compiler-sfc": "^3.0.3",
"@vue/compiler-sfc": "^3.2.6",
"coffeescript": "^2.3.2",
"jest": "^27.0.0",
"ts-jest": "^27.0.1",
Expand Down
12 changes: 8 additions & 4 deletions e2e/3.x/basic/__snapshots__/test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ exports.render = void 0;
var vue_1 = require(\\"vue\\");
var _hoisted_1 = { class: \\"hello\\" };
function render(_ctx, _cache) {
return (vue_1.openBlock(), vue_1.createBlock(\\"div\\", _hoisted_1, [
vue_1.createVNode(\\"h1\\", { class: _ctx.headingClasses }, vue_1.toDisplayString(_ctx.msg), 3 /* TEXT, CLASS */)
return ((0, vue_1.openBlock)(), (0, vue_1.createElementBlock)(\\"div\\", _hoisted_1, [
(0, vue_1.createElementVNode)(\\"h1\\", {
class: (0, vue_1.normalizeClass)(_ctx.headingClasses)
}, (0, vue_1.toDisplayString)(_ctx.msg), 3 /* TEXT, CLASS */)
]));
}
exports.render = render;
Expand Down Expand Up @@ -82,8 +84,10 @@ exports.render = void 0;
var vue_1 = require(\\"vue\\");
var _hoisted_1 = { class: \\"hello\\" };
function render(_ctx, _cache) {
return (vue_1.openBlock(), vue_1.createBlock(\\"div\\", _hoisted_1, [
vue_1.createVNode(\\"h1\\", { class: _ctx.headingClasses }, vue_1.toDisplayString(_ctx.msg), 3 /* TEXT, CLASS */)
return ((0, vue_1.openBlock)(), (0, vue_1.createElementBlock)(\\"div\\", _hoisted_1, [
(0, vue_1.createElementVNode)(\\"h1\\", {
class: (0, vue_1.normalizeClass)(_ctx.headingClasses)
}, (0, vue_1.toDisplayString)(_ctx.msg), 3 /* TEXT, CLASS */)
]));
}
exports.render = render;
Expand Down
17 changes: 17 additions & 0 deletions e2e/3.x/basic/components/ScriptSetupSugarRef.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<template>
<button @click="increase">Count: {{ num }}</button>
<Basic />
<span>{{ msg }}</span>
</template>

<script setup lang="ts">
import Basic from './Basic.vue'

let num = $ref(5)
const greet = () => console.log('greet')
const increase = () => {
greet()
num.value++
}
const msg = 'hello world'
</script>
4 changes: 2 additions & 2 deletions e2e/3.x/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
"test": "jest --no-cache --coverage test.js"
},
"dependencies": {
"vue": "^3.0.3"
"vue": "^3.2.6"
},
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/preset-env": "^7.9.0",
"@vue/compiler-sfc": "^3.0.3",
"@vue/compiler-sfc": "^3.2.6",
"babel-helper-vue-jsx-merge-props": "^2.0.3",
"babel-plugin-syntax-jsx": "^6.18.0",
"babel-plugin-transform-vue-jsx": "^3.7.0",
Expand Down
7 changes: 7 additions & 0 deletions e2e/3.x/basic/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import NoScript from './components/NoScript.vue'
import PugRelative from './components/PugRelativeExtends.vue'
import { randomExport } from './components/NamedExport.vue'
import ScriptSetup from './components/ScriptSetup.vue'
import ScriptSetupSugarRef from './components/ScriptSetupSugarRef.vue'
import FunctionalRenderFn from './components/FunctionalRenderFn.vue'

// TODO: JSX for Vue 3? TSX?
Expand All @@ -44,6 +45,12 @@ test('supports <script setup>', () => {
expect(document.body.outerHTML).toContain('Welcome to Your Vue.js App')
})

test('supports <script setup> with sugar ref', () => {
mount(ScriptSetupSugarRef)
expect(document.body.outerHTML).toContain('Count: 5')
expect(document.body.outerHTML).toContain('Welcome to Your Vue.js App')
})

test('processes .vue files', () => {
mount(Basic)
expect(document.querySelector('h1').textContent).toBe(
Expand Down
4 changes: 2 additions & 2 deletions e2e/3.x/custom-transformers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"test": "jest --no-cache --coverage test.js"
},
"dependencies": {
"@vue/compiler-sfc": "^3.0.3",
"vue": "^3.0.3"
"@vue/compiler-sfc": "^3.2.6",
"vue": "^3.2.6"
},
"devDependencies": {
"@babel/core": "^7.9.0",
Expand Down
2 changes: 1 addition & 1 deletion e2e/3.x/javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"test": "jest --no-cache test.js"
},
"dependencies": {
"vue": "^3.0.3"
"vue": "^3.2.6"
},
"devDependencies": {
"@babel/core": "^7.9.0",
Expand Down
4 changes: 2 additions & 2 deletions e2e/3.x/style/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"test": "jest --no-cache test.js"
},
"dependencies": {
"@vue/compiler-sfc": "^3.0.3",
"vue": "^3.0.3"
"@vue/compiler-sfc": "^3.2.6",
"vue": "^3.2.6"
},
"devDependencies": {
"@babel/core": "^7.9.0",
Expand Down
4 changes: 2 additions & 2 deletions e2e/3.x/typescript-with-babel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"test": "jest --no-cache ./sub-project/test.js"
},
"dependencies": {
"@vue/compiler-sfc": "^3.0.3",
"vue": "^3.0.3"
"@vue/compiler-sfc": "^3.2.6",
"vue": "^3.2.6"
},
"devDependencies": {
"@babel/core": "^7.9.0",
Expand Down
4 changes: 2 additions & 2 deletions e2e/3.x/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"test": "jest --no-cache ./src/test.ts"
},
"dependencies": {
"@vue/compiler-sfc": "^3.0.3",
"vue": "^3.0.3"
"@vue/compiler-sfc": "^3.2.6",
"vue": "^3.2.6"
},
"devDependencies": {
"@types/jest": "16.0.10",
Expand Down
10 changes: 8 additions & 2 deletions packages/vue3-jest/lib/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ function processScriptSetup(descriptor, filePath, config) {
if (!descriptor.scriptSetup) {
return null
}
const content = compileScript(descriptor, { id: filePath })
const content = compileScript(descriptor, {
id: filePath,
refTransform: true
})
const contentMap = mapLines(descriptor.scriptSetup.map, content.map)

const vueJestConfig = getVueJestConfig(config)
Expand Down Expand Up @@ -81,7 +84,10 @@ function processTemplate(descriptor, filename, config) {

let bindings
if (scriptSetup) {
const scriptSetupResult = compileScript(descriptor, { id: filename })
const scriptSetupResult = compileScript(descriptor, {
id: filename,
refTransform: true
})
bindings = scriptSetupResult.bindings
}

Expand Down
4 changes: 2 additions & 2 deletions packages/vue3-jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"license": "MIT",
"devDependencies": {
"@babel/core": "^7.9.0",
"@vue/compiler-sfc": "^3.0.3",
"@vue/compiler-sfc": "^3.2.6",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^27.0.0",
"conventional-changelog": "^1.1.5",
Expand All @@ -34,7 +34,7 @@
"semantic-release": "^15.13.2",
"ts-jest": "^27.0.1",
"typescript": "^4.1.2",
"vue": "^3.0.3"
"vue": "^3.2.6"
},
"peerDependencies": {
"@babel/core": "7.x",
Expand Down
Loading