Skip to content

Commit 2cd2b15

Browse files
authored
feat: Add Vitest snippets (#44)
* Fix issue in vue-script * Vitest snippets #23 * Vitest vue snippets #23 * Vitest Nuxt Snippets #23
1 parent 6ad824f commit 2cd2b15

File tree

6 files changed

+272
-19
lines changed

6 files changed

+272
-19
lines changed

README.md

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,23 @@ These snippets were made to speed up Vue 3 development. With it you can write bo
5959

6060
### Script
6161

62-
| Snippet | Purpose |
63-
| ------------------------ | ------------------------------------------- |
64-
| `vref` | Vue `ref` |
65-
| `vreactive` | Vue `reactive` |
66-
| `vcomputed` | Vue `computed` |
67-
| `vwatch` | Watcher |
68-
| `vwatcheffect` | Watch Effect |
69-
| `vonmounted` | onMounted hook |
70-
| `vonbeforemount` | onBeforeMount hook |
71-
| `vonbeforeupdate` | onBeforeUpdate hook |
72-
| `vonupdated` | onUpdated hook |
73-
| `vonerrorcaptured` | onErrorCaptured hook |
74-
| `vonunmounted` | onUnmounted hook |
75-
| `vonbeforeunmount` | onBeforeUnmount hook |
76-
| `vdefineprops` | Define props |
77-
| `vdefineemits` | Define emits |
78-
| `vsingleemit` | Single emit for defineEmits |
62+
| Snippet | Purpose |
63+
| ------------------ | --------------------------- |
64+
| `vref` | Vue `ref` |
65+
| `vreactive` | Vue `reactive` |
66+
| `vcomputed` | Vue `computed` |
67+
| `vwatch` | Watcher |
68+
| `vwatcheffect` | Watch Effect |
69+
| `vonmounted` | onMounted hook |
70+
| `vonbeforemount` | onBeforeMount hook |
71+
| `vonbeforeupdate` | onBeforeUpdate hook |
72+
| `vonupdated` | onUpdated hook |
73+
| `vonerrorcaptured` | onErrorCaptured hook |
74+
| `vonunmounted` | onUnmounted hook |
75+
| `vonbeforeunmount` | onBeforeUnmount hook |
76+
| `vdefineprops` | Define props |
77+
| `vdefineemits` | Define emits |
78+
| `vsingleemit` | Single emit for defineEmits |
7979

8080
### CSS
8181

@@ -151,6 +151,33 @@ These snippets were made to speed up Vue 3 development. With it you can write bo
151151
| `hcontrols-text` | Histoire controls - Text |
152152
| `hcontrols-textarea` | Histoire controls - Textarea |
153153

154+
### Vitest
155+
156+
| Snippet | Purpose |
157+
| ------------------------- | ------------------------------ |
158+
| `viconfig` | Vitest config for Vue 3 |
159+
| `viconfig-nuxt` | Vitest config for Nuxt 3 |
160+
| `videscribe` | Vitest Describe |
161+
| `videscribe-concurrent` | Vitest Describe - Concurrent |
162+
| `viit` | Vitest It |
163+
| `viit-concurrent` | Vitest It - Concurrent |
164+
| `viit-async` | Vitest It - Async |
165+
| `viit-async-concurrent` | Vitest It - Async Concurrent |
166+
| `viit-todo` | Vitest It - Todo |
167+
| `vitest` | Vitest Test |
168+
| `vitest-concurrent` | Vitest Test - Concurrent |
169+
| `vitest-async` | Vitest Test - Async |
170+
| `vitest-async-concurrent` | Vitest Test - Async Concurrent |
171+
| `vitest-todo` | Vitest Test - Todo |
172+
| `visnapshot` | Vitest Match Snapshot |
173+
| `visnapshot-inline` | Vitest Match Snapshot - Inline |
174+
| `vimount` | Vue Test Utils `mount` |
175+
| `vicomponent` | Vue Test Utils Component |
176+
| `vimount-suspended` | nuxt-vitest `mountSuspended` |
177+
| `vimocknuxtimport` | nuxt-vitest `mockNuxtImport` |
178+
| `vimockcomponent` | nuxt-vitest `mockComponent` |
179+
| `viregisterendpoint` | nuxt-vitest `registerEndpoint` |
180+
154181
## Contributing
155182

156183
This is an open source project open to anyone. Contributors are welcome on [GitHub](https://github.com/exer7um/vue3-vscode-snippets).

package.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,30 @@
118118
{
119119
"language": "typescript",
120120
"path": "./snippets/histoire/histoire-script.code-snippets"
121+
},
122+
{
123+
"language": "javascript",
124+
"path": "./snippets/vitest/vitest.code-snippets"
125+
},
126+
{
127+
"language": "typescript",
128+
"path": "./snippets/vitest/vitest.code-snippets"
129+
},
130+
{
131+
"language": "javascript",
132+
"path": "./snippets/vitest/vue.code-snippets"
133+
},
134+
{
135+
"language": "typescript",
136+
"path": "./snippets/vitest/vue.code-snippets"
137+
},
138+
{
139+
"language": "javascript",
140+
"path": "./snippets/vitest/nuxt.code-snippets"
141+
},
142+
{
143+
"language": "typescript",
144+
"path": "./snippets/vitest/nuxt.code-snippets"
121145
}
122146
]
123147
}

snippets/vitest/nuxt.code-snippets

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"Vitest Config - Nuxt 3": {
3+
"prefix": "viconfig-nuxt",
4+
"body": [
5+
"import { defineVitestConfig } from 'nuxt-vitest/config'",
6+
"",
7+
"export default defineVitestConfig({",
8+
"\ttest: {",
9+
"\t\tenvironment: 'nuxt'",
10+
"\t}",
11+
"})"
12+
],
13+
"description": "Vitest config for Nuxt 3"
14+
},
15+
"Vitest Nuxt Mount Suspended": {
16+
"prefix": "vimount-suspended",
17+
"body": [
18+
"const wrapper = await mountSuspended(${0})",
19+
],
20+
"description": "nuxt-vitest mountSuspended"
21+
},
22+
"Vitest Nuxt Mock Import": {
23+
"prefix": "vimocknuxtimport",
24+
"body": [
25+
"mockNuxtImport('${1:functionName}', () => {",
26+
"\treturn () => {",
27+
"\t\treturn { ${0} }",
28+
"\t}",
29+
"})"
30+
],
31+
"description": "nuxt-vitest mockNuxtImport"
32+
},
33+
"Vitest Nuxt Mock Component": {
34+
"prefix": "vimockcomponent",
35+
"body": [
36+
"mockComponent('${0}')",
37+
],
38+
"description": "nuxt-vitest mockComponent"
39+
},
40+
"Vitest Nuxt Register Endpoint": {
41+
"prefix": "viregisterendpoint",
42+
"body": [
43+
"registerEndpoint('/${1:endpoint}/', () => {",
44+
"\t{0}",
45+
"})"
46+
],
47+
"description": "nuxt-vitest registerEndpoint"
48+
},
49+
}

snippets/vitest/vitest.code-snippets

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
{
2+
"Vitest Config - Vue 3": {
3+
"prefix": "viconfig",
4+
"body": [
5+
"import { defineConfig } from 'vitest/config'",
6+
"",
7+
"export default defineConfig({",
8+
"\t${0}",
9+
"})"
10+
],
11+
"description": "Vitest config for Vue 3"
12+
},
13+
"Vitest Describe": {
14+
"prefix": "videscribe",
15+
"body": [
16+
"describe('${1:name}'), () => {",
17+
"\t${0}",
18+
"}"
19+
],
20+
"description": "Vitest Describe"
21+
},
22+
"Vitest Describe - Concurrent": {
23+
"prefix": "videscribe-concurrent",
24+
"body": [
25+
"describe.concurrent('${1:name}'), () => {",
26+
"\t${0}",
27+
"}"
28+
],
29+
"description": "Vitest Describe Concurrent"
30+
},
31+
"Vitest It": {
32+
"prefix": "viit",
33+
"body": [
34+
"it('${1:name}'), () => {",
35+
"\t${0}",
36+
"}"
37+
],
38+
"description": "Vitest It"
39+
},
40+
"Vitest It - Concurrent": {
41+
"prefix": "viit-concurrent",
42+
"body": [
43+
"it.concurrent('${1:name}'), () => {",
44+
"\t${0}",
45+
"}"
46+
],
47+
"description": "Vitest It Concurrent"
48+
},
49+
"Vitest It - Async": {
50+
"prefix": "viit-async",
51+
"body": [
52+
"it('${1:name}'), async () => {",
53+
"\t${0}",
54+
"}"
55+
],
56+
"description": "Vitest It Async"
57+
},
58+
"Vitest It - Async Concurrent": {
59+
"prefix": "viit-async-concurrent",
60+
"body": [
61+
"it.concurrent('${1:name}'), async () => {",
62+
"\t${0}",
63+
"}"
64+
],
65+
"description": "Vitest It Async Concurrent"
66+
},
67+
"Vitest It - Todo": {
68+
"prefix": "viit-todo",
69+
"body": [
70+
"it.todo('${1:name}')"
71+
],
72+
"description": "Vitest It Todo"
73+
},
74+
"Vitest Test": {
75+
"prefix": "vitest",
76+
"body": [
77+
"test('${1:name}'), () => {",
78+
"\t${0}",
79+
"}"
80+
],
81+
"description": "Vitest Test"
82+
},
83+
"Vitest Test - Concurrent": {
84+
"prefix": "vitest-concurrent",
85+
"body": [
86+
"test.concurrent('${1:name}'), () => {",
87+
"\t${0}",
88+
"}"
89+
],
90+
"description": "Vitest Test Concurrent"
91+
},
92+
"Vitest Test - Async": {
93+
"prefix": "vitest-async",
94+
"body": [
95+
"test('${1:name}'), async () => {",
96+
"\t${0}",
97+
"}"
98+
],
99+
"description": "Vitest Test Async"
100+
},
101+
"Vitest Test - Async Concurrent": {
102+
"prefix": "vitest-async-concurrent",
103+
"body": [
104+
"test.concurrent('${1:name}'), async () => {",
105+
"\t${0}",
106+
"}"
107+
],
108+
"description": "Vitest Test Async Concurrent"
109+
},
110+
"Vitest Test - Todo": {
111+
"prefix": "vitest-todo",
112+
"body": [
113+
"test.todo('${1:name}')"
114+
],
115+
"description": "Vitest Test Todo"
116+
},
117+
"Vitest Match Snapshot": {
118+
"prefix": "visnapshot",
119+
"body": [
120+
"expect(${0}).toMatchSnapshot()"
121+
],
122+
"description": "Vitest Match Snapshot"
123+
},
124+
"Vitest Match Snapshot - Inline": {
125+
"prefix": "visnapshot-inline",
126+
"body": [
127+
"expect(${0}).toMatchInlineSnapshot()"
128+
],
129+
"description": "Vitest Match Inline Snapshot"
130+
},
131+
}

snippets/vitest/vue.code-snippets

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"Vitest Vue Mount": {
3+
"prefix": "vimount",
4+
"body": [
5+
"const wrapper = mount(${0})",
6+
],
7+
"description": "Vue Test Utils Mount"
8+
},
9+
"Vitest Test Component": {
10+
"prefix": "vicomponent",
11+
"body": [
12+
"{",
13+
"\ttemplate: '${0}'",
14+
"\t\tdata() {",
15+
"\t\t\treturn {",
16+
"\t\t${2:variable}",
17+
"\t}",
18+
"}"
19+
],
20+
"description": "Vue Test Utils Component"
21+
}
22+
}

snippets/vue/vue-script.code-snippets

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,15 @@
111111
"prefix": "vdefineemits",
112112
"body": [
113113
"defineEmits<{",
114-
"\t${1:eventName}: [${2}]",
114+
"\t${1:eventName}: [${0}]",
115115
"}>()"
116116
],
117117
"description": "Vue defineEmits"
118118
},
119119
"Vue Single Emit": {
120120
"prefix": "vsingleemit",
121121
"body": [
122-
"${1:eventName}: [${2}]",
122+
"${1:eventName}: [${0}]",
123123
],
124124
"description": "Vue single emit for defineEmits"
125125
},

0 commit comments

Comments
 (0)