Skip to content

Commit 0ced11d

Browse files
authored
Merge pull request vuejs#264 from vuejs/lm/issue-263
Support latest <script setup>
2 parents ea21eb1 + 14e1861 commit 0ced11d

File tree

5 files changed

+107
-61
lines changed

5 files changed

+107
-61
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"@types/estree": "^0.0.42",
2424
"@types/jest": "25.2.1",
2525
"@types/node": "12.12.35",
26-
"@vue/compiler-sfc": "^3.0.2",
26+
"@vue/compiler-sfc": "3.0.3",
2727
"babel-jest": "^25.2.3",
2828
"babel-preset-jest": "^25.2.1",
2929
"dom-event-types": "^1.0.0",
@@ -39,7 +39,7 @@
3939
"ts-jest": "25.2.1",
4040
"tsd": "0.11.0",
4141
"typescript": "^3.7.5",
42-
"vue": "^3.0.2",
42+
"vue": "3.0.3",
4343
"vue-class-component": "^8.0.0-beta.4",
4444
"vue-jest": "^5.0.0-alpha.6",
4545
"vue-router": "^4.0.0-rc.1",

src/mount.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,20 @@ export function mount(
426426
// mount the app!
427427
const vm = app.mount(el)
428428

429-
const App = vm.$refs[MOUNT_COMPONENT_REF] as ComponentPublicInstance
430-
return createWrapper(app, App, setProps)
429+
// Ingore Avoid app logic that relies on enumerating keys on a component instance... warning
430+
const warnSave = console.warn
431+
console.warn = () => {}
432+
433+
// get `vm`.
434+
// for some unknown reason, getting the `vm` for components using `<script setup>`
435+
// as of Vue 3.0.3 works differently.
436+
// if `appRef` has keys, use that (vm always has keys like $el, $props etc).
437+
// if not, use the return value from app.mount.
438+
const appRef = vm.$refs[MOUNT_COMPONENT_REF] as ComponentPublicInstance
439+
const $vm = Reflect.ownKeys(appRef).length ? appRef : vm
440+
console.warn = warnSave
441+
442+
return createWrapper(app, $vm, setProps)
431443
}
432444

433445
export const shallowMount: typeof mount = (component: any, options?: any) => {

tests/components/ScriptSetup.vue

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<script setup lang="ts">
2+
// imported components are also directly usable in template
3+
import { ref } from 'vue'
4+
import Hello from './Hello.vue'
5+
6+
// write Composition API code just like in a normal setup()
7+
// but no need to manually return everything
8+
const count = ref(0)
9+
const inc = () => { count.value++ }
10+
</script>
11+
12+
<template>
13+
<button @click="inc">{{ count }}</button>
14+
<Hello />
15+
</template>

tests/features/sfc.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
import { mount } from '../../src'
22
import Hello from '../components/Hello.vue'
3+
import ScriptSetup from '../components/ScriptSetup.vue'
34

45
describe('sfc', () => {
56
it('mounts an sfc via vue-test-transformer', () => {
67
const wrapper = mount(Hello)
78
expect(wrapper.find('#msg').text()).toBe('Hello world')
89
})
10+
11+
// rfc: https://github.com/vuejs/rfcs/pull/228
12+
it('works with <script setup> (as of Vue 3.0.3)', async () => {
13+
const wrapper = mount(ScriptSetup)
14+
expect(wrapper.findComponent(Hello).exists()).toBe(true)
15+
16+
await wrapper.find('button').trigger('click')
17+
expect(wrapper.html()).toContain('1')
18+
})
919
})

yarn.lock

Lines changed: 66 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,9 @@
272272
integrity sha512-kFsOS0IbsuhO5ojF8Hc8z/8vEIOkylVBrjiZUbLTE3XFe0Qi+uu6HjzQixkFaqr0ZPAMZcBVxEwmsnsLPZ2Xsw==
273273

274274
"@babel/parser@^7.12.0":
275-
version "7.12.2"
276-
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.12.2.tgz#9d2fcf24cafe85333ab0aff9f26b81bba356004d"
277-
integrity sha512-LMN+SqTiZEonUw4hQA0A3zG8DnN0E1F4K107LbDDUnC+0chML1rvWgsHloC9weB4RmZweE0uhFq0eGX7Nr/PBQ==
275+
version "7.12.7"
276+
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.12.7.tgz#fee7b39fe809d0e73e5b25eecaf5780ef3d73056"
277+
integrity sha512-oWR02Ubp4xTLCAqPRiNIuMVgNO5Aif/xpXtabhzW2HWUD47XJsAB4Zd/Rg30+XeQA3juXigV7hlquOTmwqLiwg==
278278

279279
"@babel/plugin-proposal-async-generator-functions@^7.8.3":
280280
version "7.8.3"
@@ -804,7 +804,7 @@
804804
lodash "^4.17.13"
805805
to-fast-properties "^2.0.0"
806806

807-
"@babel/types@^7.10.4", "@babel/types@^7.12.0", "@babel/types@^7.3.3":
807+
"@babel/types@^7.10.4", "@babel/types@^7.3.3":
808808
version "7.12.1"
809809
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.12.1.tgz#e109d9ab99a8de735be287ee3d6a9947a190c4ae"
810810
integrity sha512-BzSY3NJBKM4kyatSOWh3D/JJ2O3CVzBybHWxtgxnggaxEuaSTTDqeiSb/xk9lrkw2Tbqyivw5ZU4rT+EfznQsA==
@@ -813,6 +813,15 @@
813813
lodash "^4.17.19"
814814
to-fast-properties "^2.0.0"
815815

816+
"@babel/types@^7.12.0":
817+
version "7.12.7"
818+
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.12.7.tgz#6039ff1e242640a29452c9ae572162ec9a8f5d13"
819+
integrity sha512-MNyI92qZq6jrQkXvtIiykvl4WtoRrVV9MPn+ZfsoEENjiWcBQ3ZSHrkxnJWgWtLX3XXqX5hrSQ+X69wkmesXuQ==
820+
dependencies:
821+
"@babel/helper-validator-identifier" "^7.10.4"
822+
lodash "^4.17.19"
823+
to-fast-properties "^2.0.0"
824+
816825
"@bcoe/v8-coverage@^0.2.3":
817826
version "0.2.3"
818827
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
@@ -1272,36 +1281,36 @@
12721281
dependencies:
12731282
"@types/yargs-parser" "*"
12741283

1275-
1276-
version "3.0.2"
1277-
resolved "https://registry.yarnpkg.com/@vue/compiler-core/-/compiler-core-3.0.2.tgz#7790b7a1fcbba5ace4d81a70ce59096fa5c95734"
1278-
integrity sha512-GOlEMTlC/OdzBkKaKOniYErbkjoKxkBOmulxGmMR10I2JJX6TvXd/peaO/kla2xhpliV/M6Z4TLJp0yjAvRIAw==
1284+
1285+
version "3.0.3"
1286+
resolved "https://registry.yarnpkg.com/@vue/compiler-core/-/compiler-core-3.0.3.tgz#dbb4d5eb91f294038f0bed170a1c25f59f7dc74f"
1287+
integrity sha512-iWlRT8RYLmz7zkg84pTOriNUzjH7XACWN++ImFkskWXWeev29IKi7p76T9jKDaMZoPiGcUZ0k9wayuASWVxOwg==
12791288
dependencies:
12801289
"@babel/parser" "^7.12.0"
12811290
"@babel/types" "^7.12.0"
1282-
"@vue/shared" "3.0.2"
1291+
"@vue/shared" "3.0.3"
12831292
estree-walker "^2.0.1"
12841293
source-map "^0.6.1"
12851294

1286-
1287-
version "3.0.2"
1288-
resolved "https://registry.yarnpkg.com/@vue/compiler-dom/-/compiler-dom-3.0.2.tgz#1d40de04bcdf9aabb79fb6a802dd70a2f3c2992a"
1289-
integrity sha512-jvaL4QF2yXBJVD+JLbM2YA3e5fNfflJnfQ+GtfYk46ENGsEetqbkZqcX7fO+RHdG8tZBo7LCNBvgD0QLr+V4sg==
1295+
1296+
version "3.0.3"
1297+
resolved "https://registry.yarnpkg.com/@vue/compiler-dom/-/compiler-dom-3.0.3.tgz#582ba30bc82da8409868bc1153ff0e0e2be617e5"
1298+
integrity sha512-6GdUbDPjsc0MDZGAgpi4lox+d+aW9/brscwBOLOFfy9wcI9b6yLPmBbjdIsJq3pYdJWbdvACdJ77avBBdHEP8A==
12901299
dependencies:
1291-
"@vue/compiler-core" "3.0.2"
1292-
"@vue/shared" "3.0.2"
1300+
"@vue/compiler-core" "3.0.3"
1301+
"@vue/shared" "3.0.3"
12931302

1294-
"@vue/compiler-sfc@^3.0.2":
1295-
version "3.0.2"
1296-
resolved "https://registry.yarnpkg.com/@vue/compiler-sfc/-/compiler-sfc-3.0.2.tgz#22c70fed72c347a4d5fa2db2e80594b3193dce57"
1297-
integrity sha512-viYjT5ehDSLM3v0jQ9hbTs4I5e/7lSlYsDOp7TQ1qcwHRvzoTQMTkFpY/Iae+LFKM124Ld17tBfXgfrZl9dt+g==
1303+
1304+
version "3.0.3"
1305+
resolved "https://registry.yarnpkg.com/@vue/compiler-sfc/-/compiler-sfc-3.0.3.tgz#7fad9d40e139dd717713c0db701e1eb776f8349f"
1306+
integrity sha512-YocHSirye85kRVC4lU0+SE6uhrwGJzbhwkrqG4g6kmsAUopZ0qUjbICMlej5bYx2+AUz9yBIM7hpK8nIKFVFjg==
12981307
dependencies:
12991308
"@babel/parser" "^7.12.0"
13001309
"@babel/types" "^7.12.0"
1301-
"@vue/compiler-core" "3.0.2"
1302-
"@vue/compiler-dom" "3.0.2"
1303-
"@vue/compiler-ssr" "3.0.2"
1304-
"@vue/shared" "3.0.2"
1310+
"@vue/compiler-core" "3.0.3"
1311+
"@vue/compiler-dom" "3.0.3"
1312+
"@vue/compiler-ssr" "3.0.3"
1313+
"@vue/shared" "3.0.3"
13051314
consolidate "^0.16.0"
13061315
estree-walker "^2.0.1"
13071316
hash-sum "^2.0.0"
@@ -1313,42 +1322,42 @@
13131322
postcss-selector-parser "^6.0.4"
13141323
source-map "^0.6.1"
13151324

1316-
1317-
version "3.0.2"
1318-
resolved "https://registry.yarnpkg.com/@vue/compiler-ssr/-/compiler-ssr-3.0.2.tgz#73af4d274a79bfcc72a996a9b45f1072e7deaa26"
1319-
integrity sha512-gOgK1lf+0bFl+kQj6TU0TU1jIDFlsPRlSBZaUUA16DGeeiJrFanhsMuIs/l9U0IBFr/VJcHgzYpTXqHp95luHw==
1325+
1326+
version "3.0.3"
1327+
resolved "https://registry.yarnpkg.com/@vue/compiler-ssr/-/compiler-ssr-3.0.3.tgz#7d9e5c1b8c71d69865ac6c48d2e6eb2eecb68501"
1328+
integrity sha512-IjJMoHCiDk939Ix7Q5wrex59TVJr6JFQ95gf36f4G4UrVau0GGY/3HudnWT/6eyWJ7267+odqQs1uCZgDfL/Ww==
13201329
dependencies:
1321-
"@vue/compiler-dom" "3.0.2"
1322-
"@vue/shared" "3.0.2"
1330+
"@vue/compiler-dom" "3.0.3"
1331+
"@vue/shared" "3.0.3"
13231332

1324-
1325-
version "3.0.2"
1326-
resolved "https://registry.yarnpkg.com/@vue/reactivity/-/reactivity-3.0.2.tgz#42ed5af6025b494a5e69b05169fcddf04eebfe77"
1327-
integrity sha512-GdRloNcBar4yqWGXOcba1t//j/WizwfthfPUYkjcIPHjYnA/vTEQYp0C9+ZjPdinv1WRK1BSMeN/xj31kQES4A==
1333+
1334+
version "3.0.3"
1335+
resolved "https://registry.yarnpkg.com/@vue/reactivity/-/reactivity-3.0.3.tgz#681ee01ceff9219bc4da6bbb7d9c97d452e44d1d"
1336+
integrity sha512-t39Qmc42MX7wJtf8L6tHlu17eP9Rc5w4aRnxpLHNWoaRxddv/7FBhWqusJ2Bwkk8ixFHOQeejcLMt5G469WYJw==
13281337
dependencies:
1329-
"@vue/shared" "3.0.2"
1338+
"@vue/shared" "3.0.3"
13301339

1331-
1332-
version "3.0.2"
1333-
resolved "https://registry.yarnpkg.com/@vue/runtime-core/-/runtime-core-3.0.2.tgz#d7ed462af1cb0bf9836668e4e6fab3f2f4b1bc00"
1334-
integrity sha512-3m/jOs2xSipEFah9FgpEzvC9nERFonVGLN06+pf8iYPIy54Nlv7D2cyrk3Lhbjz4w3PbIrkxJnoTJYvJM7HDfA==
1340+
1341+
version "3.0.3"
1342+
resolved "https://registry.yarnpkg.com/@vue/runtime-core/-/runtime-core-3.0.3.tgz#edab3c9ad122cf8afd034b174cd20c073fbf950a"
1343+
integrity sha512-Fd1JVnYI6at0W/2ERwJuTSq4S22gNt8bKEbICcvCAac7hJUZ1rylThlrhsvrgA+DVkWU01r0niNZQ4UddlNw7g==
13351344
dependencies:
1336-
"@vue/reactivity" "3.0.2"
1337-
"@vue/shared" "3.0.2"
1345+
"@vue/reactivity" "3.0.3"
1346+
"@vue/shared" "3.0.3"
13381347

1339-
1340-
version "3.0.2"
1341-
resolved "https://registry.yarnpkg.com/@vue/runtime-dom/-/runtime-dom-3.0.2.tgz#9d166d03225558025d3d80f5039b646e0051b71c"
1342-
integrity sha512-vqC1KK1yWthTw1FKzajT0gYQaEqAq7bpeeXQC473nllGC5YHbJhNAJLSmrDun1tjXqGF0UNCWYljYm+++BJv6w==
1348+
1349+
version "3.0.3"
1350+
resolved "https://registry.yarnpkg.com/@vue/runtime-dom/-/runtime-dom-3.0.3.tgz#5e3e5e5418b9defcac988d2be0cf65596fa2cc03"
1351+
integrity sha512-ytTvSlRaEYvLQUkkpruIBizWIwuIeHER0Ch/evO6kUaPLjZjX3NerVxA40cqJx8rRjb9keQso21U2Jcpk8GsTg==
13431352
dependencies:
1344-
"@vue/runtime-core" "3.0.2"
1345-
"@vue/shared" "3.0.2"
1353+
"@vue/runtime-core" "3.0.3"
1354+
"@vue/shared" "3.0.3"
13461355
csstype "^2.6.8"
13471356

1348-
1349-
version "3.0.2"
1350-
resolved "https://registry.yarnpkg.com/@vue/shared/-/shared-3.0.2.tgz#419bd85a2ebdbd4f42963e98c5a1b103452176d9"
1351-
integrity sha512-Zx869zlNoujFOclKIoYmkh8ES2RcS/+Jn546yOiPyZ+3+Ejivnr+fb8l+DdXUEFjo+iVDNR3KyLzg03aBFfZ4Q==
1357+
1358+
version "3.0.3"
1359+
resolved "https://registry.yarnpkg.com/@vue/shared/-/shared-3.0.3.tgz#ef12ebff93a446df281e8a0fd765b5aea8e7745b"
1360+
integrity sha512-yGgkF7u4W0Dmwri9XdeY50kOowN4UIX7aBQ///jbxx37itpzVjK7QzvD3ltQtPfWaJDGBfssGL0wpAgwX9OJpQ==
13521361

13531362
abab@^2.0.0:
13541363
version "2.0.5"
@@ -6180,14 +6189,14 @@ vue-router@^4.0.0-rc.1:
61806189
resolved "https://registry.yarnpkg.com/vue-router/-/vue-router-4.0.0-rc.1.tgz#42f41315849163a1243886c9aa6d7c14f24fd003"
61816190
integrity sha512-N3SSOIiRFo1/D6EkHGuahUSuyDvFhKizN5zVXkALX7wv0hYYndV49KwzRF5lKsAIt+OlDl7y+sNmwNewb7a4iw==
61826191

6183-
vue@^3.0.2:
6184-
version "3.0.2"
6185-
resolved "https://registry.yarnpkg.com/vue/-/vue-3.0.2.tgz#9d5b7b2983f35e64a34d13c7c9d6831239feca3c"
6186-
integrity sha512-ciKFjutKRs+2Vbvgrist1oDd5wZQqtOel/K//ku54zLbf8tcTV+XbyAfanTHcTkML9CUj09vnC+y+5uaOz2/9g==
6192+
6193+
version "3.0.3"
6194+
resolved "https://registry.yarnpkg.com/vue/-/vue-3.0.3.tgz#ad94a475e6ebbf3904673b6a0ae46e47b957bd72"
6195+
integrity sha512-BZG5meD5vLWdvfnRL5WqfDy+cnXO1X/SweModGUna78bdFPZW6+ZO1tU9p0acrskX3DKFcfSp2s4SZnMjABx6w==
61876196
dependencies:
6188-
"@vue/compiler-dom" "3.0.2"
6189-
"@vue/runtime-dom" "3.0.2"
6190-
"@vue/shared" "3.0.2"
6197+
"@vue/compiler-dom" "3.0.3"
6198+
"@vue/runtime-dom" "3.0.3"
6199+
"@vue/shared" "3.0.3"
61916200

61926201
vuex@^4.0.0-beta.4:
61936202
version "4.0.0-beta.4"

0 commit comments

Comments
 (0)