@component-hook/create-app 0.2.4-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/index.js +3 -0
- package/dist/index.mjs +105 -0
- package/package.json +46 -0
- package/template-vue/.github/actions/setup-environment/action.yml +45 -0
- package/template-vue/.github/renovate.json +12 -0
- package/template-vue/.github/workflows/ci.yml +22 -0
- package/template-vue/.github/workflows/deploy.yml +27 -0
- package/template-vue/.github/workflows/preview.yml +17 -0
- package/template-vue/.gitlab/setup.yml +18 -0
- package/template-vue/.husky/commit-msg +3 -0
- package/template-vue/.husky/pre-commit +3 -0
- package/template-vue/.vscode/extensions.json +10 -0
- package/template-vue/.vscode/settings.json +27 -0
- package/template-vue/LICENSE +21 -0
- package/template-vue/README.md.art +100 -0
- package/template-vue/_gitignore +38 -0
- package/template-vue/_gitlab-ci.yml +22 -0
- package/template-vue/commitlint.config.js +3 -0
- package/template-vue/eslint.config.js +18 -0
- package/template-vue/index.html.art +26 -0
- package/template-vue/lint-staged.config.js +4 -0
- package/template-vue/package.json +73 -0
- package/template-vue/playwright.config.ts +60 -0
- package/template-vue/postcss.config.js +14 -0
- package/template-vue/prettier.config.js +11 -0
- package/template-vue/public/mockServiceWorker.js +307 -0
- package/template-vue/public/vite.svg +1 -0
- package/template-vue/src/App.vue +7 -0
- package/template-vue/src/__tests__/e2e/IndexPage.spec.ts +49 -0
- package/template-vue/src/__tests__/setup/unit-test.ts +6 -0
- package/template-vue/src/__tests__/unit/components/indexPage/HelloWorld.test.ts +57 -0
- package/template-vue/src/__tests__/unit/render/index.ts +28 -0
- package/template-vue/src/assets/images/svgIcons/vue.svg +1 -0
- package/template-vue/src/components/common/SvgIcon.vue +29 -0
- package/template-vue/src/components/indexPage/HelloWorld.vue +59 -0
- package/template-vue/src/components.d.ts +14 -0
- package/template-vue/src/locales/en-US.json +3 -0
- package/template-vue/src/locales/zh-TW.json +3 -0
- package/template-vue/src/main.ts +25 -0
- package/template-vue/src/mocks/browser.ts +4 -0
- package/template-vue/src/mocks/handlers/index.ts +1 -0
- package/template-vue/src/mocks/server.ts +4 -0
- package/template-vue/src/pages/IndexPage.vue +34 -0
- package/template-vue/src/plugins/i18n.ts +15 -0
- package/template-vue/src/router/index.ts +23 -0
- package/template-vue/src/stores/index.ts +3 -0
- package/template-vue/src/stores/modules/config.ts +20 -0
- package/template-vue/src/styles/common/all.postcss +1 -0
- package/template-vue/src/styles/common/button.postcss +12 -0
- package/template-vue/src/styles/index.postcss +1 -0
- package/template-vue/src/styles/tailwind.postcss +39 -0
- package/template-vue/src/vite-env.d.ts +12 -0
- package/template-vue/tailwind.config.js +20 -0
- package/template-vue/tsconfig.app.json +13 -0
- package/template-vue/tsconfig.json +14 -0
- package/template-vue/tsconfig.node.json +12 -0
- package/template-vue/tsconfig.vitest.json +8 -0
- package/template-vue/vite.config.ts +49 -0
- package/template-vue/vitest.config.ts +21 -0
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/* tslint:disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Mock Service Worker.
|
|
6
|
+
* @see https://github.com/mswjs/msw
|
|
7
|
+
* - Please do NOT modify this file.
|
|
8
|
+
* - Please do NOT serve this file on production.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const PACKAGE_VERSION = '2.6.8'
|
|
12
|
+
const INTEGRITY_CHECKSUM = '00729d72e3b82faf54ca8b9621dbb96f'
|
|
13
|
+
const IS_MOCKED_RESPONSE = Symbol('isMockedResponse')
|
|
14
|
+
const activeClientIds = new Set()
|
|
15
|
+
|
|
16
|
+
self.addEventListener('install', function () {
|
|
17
|
+
self.skipWaiting()
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
self.addEventListener('activate', function (event) {
|
|
21
|
+
event.waitUntil(self.clients.claim())
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
self.addEventListener('message', async function (event) {
|
|
25
|
+
const clientId = event.source.id
|
|
26
|
+
|
|
27
|
+
if (!clientId || !self.clients) {
|
|
28
|
+
return
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const client = await self.clients.get(clientId)
|
|
32
|
+
|
|
33
|
+
if (!client) {
|
|
34
|
+
return
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const allClients = await self.clients.matchAll({
|
|
38
|
+
type: 'window',
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
switch (event.data) {
|
|
42
|
+
case 'KEEPALIVE_REQUEST': {
|
|
43
|
+
sendToClient(client, {
|
|
44
|
+
type: 'KEEPALIVE_RESPONSE',
|
|
45
|
+
})
|
|
46
|
+
break
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
case 'INTEGRITY_CHECK_REQUEST': {
|
|
50
|
+
sendToClient(client, {
|
|
51
|
+
type: 'INTEGRITY_CHECK_RESPONSE',
|
|
52
|
+
payload: {
|
|
53
|
+
packageVersion: PACKAGE_VERSION,
|
|
54
|
+
checksum: INTEGRITY_CHECKSUM,
|
|
55
|
+
},
|
|
56
|
+
})
|
|
57
|
+
break
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
case 'MOCK_ACTIVATE': {
|
|
61
|
+
activeClientIds.add(clientId)
|
|
62
|
+
|
|
63
|
+
sendToClient(client, {
|
|
64
|
+
type: 'MOCKING_ENABLED',
|
|
65
|
+
payload: {
|
|
66
|
+
client: {
|
|
67
|
+
id: client.id,
|
|
68
|
+
frameType: client.frameType,
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
})
|
|
72
|
+
break
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
case 'MOCK_DEACTIVATE': {
|
|
76
|
+
activeClientIds.delete(clientId)
|
|
77
|
+
break
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
case 'CLIENT_CLOSED': {
|
|
81
|
+
activeClientIds.delete(clientId)
|
|
82
|
+
|
|
83
|
+
const remainingClients = allClients.filter((client) => {
|
|
84
|
+
return client.id !== clientId
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
// Unregister itself when there are no more clients
|
|
88
|
+
if (remainingClients.length === 0) {
|
|
89
|
+
self.registration.unregister()
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
break
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
self.addEventListener('fetch', function (event) {
|
|
98
|
+
const { request } = event
|
|
99
|
+
|
|
100
|
+
// Bypass navigation requests.
|
|
101
|
+
if (request.mode === 'navigate') {
|
|
102
|
+
return
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Opening the DevTools triggers the "only-if-cached" request
|
|
106
|
+
// that cannot be handled by the worker. Bypass such requests.
|
|
107
|
+
if (request.cache === 'only-if-cached' && request.mode !== 'same-origin') {
|
|
108
|
+
return
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Bypass all requests when there are no active clients.
|
|
112
|
+
// Prevents the self-unregistered worked from handling requests
|
|
113
|
+
// after it's been deleted (still remains active until the next reload).
|
|
114
|
+
if (activeClientIds.size === 0) {
|
|
115
|
+
return
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Generate unique request ID.
|
|
119
|
+
const requestId = crypto.randomUUID()
|
|
120
|
+
event.respondWith(handleRequest(event, requestId))
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
async function handleRequest(event, requestId) {
|
|
124
|
+
const client = await resolveMainClient(event)
|
|
125
|
+
const response = await getResponse(event, client, requestId)
|
|
126
|
+
|
|
127
|
+
// Send back the response clone for the "response:*" life-cycle events.
|
|
128
|
+
// Ensure MSW is active and ready to handle the message, otherwise
|
|
129
|
+
// this message will pend indefinitely.
|
|
130
|
+
if (client && activeClientIds.has(client.id)) {
|
|
131
|
+
;(async function () {
|
|
132
|
+
const responseClone = response.clone()
|
|
133
|
+
|
|
134
|
+
sendToClient(
|
|
135
|
+
client,
|
|
136
|
+
{
|
|
137
|
+
type: 'RESPONSE',
|
|
138
|
+
payload: {
|
|
139
|
+
requestId,
|
|
140
|
+
isMockedResponse: IS_MOCKED_RESPONSE in response,
|
|
141
|
+
type: responseClone.type,
|
|
142
|
+
status: responseClone.status,
|
|
143
|
+
statusText: responseClone.statusText,
|
|
144
|
+
body: responseClone.body,
|
|
145
|
+
headers: Object.fromEntries(responseClone.headers.entries()),
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
[responseClone.body],
|
|
149
|
+
)
|
|
150
|
+
})()
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return response
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Resolve the main client for the given event.
|
|
157
|
+
// Client that issues a request doesn't necessarily equal the client
|
|
158
|
+
// that registered the worker. It's with the latter the worker should
|
|
159
|
+
// communicate with during the response resolving phase.
|
|
160
|
+
async function resolveMainClient(event) {
|
|
161
|
+
const client = await self.clients.get(event.clientId)
|
|
162
|
+
|
|
163
|
+
if (activeClientIds.has(event.clientId)) {
|
|
164
|
+
return client
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (client?.frameType === 'top-level') {
|
|
168
|
+
return client
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const allClients = await self.clients.matchAll({
|
|
172
|
+
type: 'window',
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
return allClients
|
|
176
|
+
.filter((client) => {
|
|
177
|
+
// Get only those clients that are currently visible.
|
|
178
|
+
return client.visibilityState === 'visible'
|
|
179
|
+
})
|
|
180
|
+
.find((client) => {
|
|
181
|
+
// Find the client ID that's recorded in the
|
|
182
|
+
// set of clients that have registered the worker.
|
|
183
|
+
return activeClientIds.has(client.id)
|
|
184
|
+
})
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
async function getResponse(event, client, requestId) {
|
|
188
|
+
const { request } = event
|
|
189
|
+
|
|
190
|
+
// Clone the request because it might've been already used
|
|
191
|
+
// (i.e. its body has been read and sent to the client).
|
|
192
|
+
const requestClone = request.clone()
|
|
193
|
+
|
|
194
|
+
function passthrough() {
|
|
195
|
+
// Cast the request headers to a new Headers instance
|
|
196
|
+
// so the headers can be manipulated with.
|
|
197
|
+
const headers = new Headers(requestClone.headers)
|
|
198
|
+
|
|
199
|
+
// Remove the "accept" header value that marked this request as passthrough.
|
|
200
|
+
// This prevents request alteration and also keeps it compliant with the
|
|
201
|
+
// user-defined CORS policies.
|
|
202
|
+
const acceptHeader = headers.get('accept')
|
|
203
|
+
if (acceptHeader) {
|
|
204
|
+
const values = acceptHeader.split(',').map((value) => value.trim())
|
|
205
|
+
const filteredValues = values.filter(
|
|
206
|
+
(value) => value !== 'msw/passthrough',
|
|
207
|
+
)
|
|
208
|
+
|
|
209
|
+
if (filteredValues.length > 0) {
|
|
210
|
+
headers.set('accept', filteredValues.join(', '))
|
|
211
|
+
} else {
|
|
212
|
+
headers.delete('accept')
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return fetch(requestClone, { headers })
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// Bypass mocking when the client is not active.
|
|
220
|
+
if (!client) {
|
|
221
|
+
return passthrough()
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// Bypass initial page load requests (i.e. static assets).
|
|
225
|
+
// The absence of the immediate/parent client in the map of the active clients
|
|
226
|
+
// means that MSW hasn't dispatched the "MOCK_ACTIVATE" event yet
|
|
227
|
+
// and is not ready to handle requests.
|
|
228
|
+
if (!activeClientIds.has(client.id)) {
|
|
229
|
+
return passthrough()
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// Notify the client that a request has been intercepted.
|
|
233
|
+
const requestBuffer = await request.arrayBuffer()
|
|
234
|
+
const clientMessage = await sendToClient(
|
|
235
|
+
client,
|
|
236
|
+
{
|
|
237
|
+
type: 'REQUEST',
|
|
238
|
+
payload: {
|
|
239
|
+
id: requestId,
|
|
240
|
+
url: request.url,
|
|
241
|
+
mode: request.mode,
|
|
242
|
+
method: request.method,
|
|
243
|
+
headers: Object.fromEntries(request.headers.entries()),
|
|
244
|
+
cache: request.cache,
|
|
245
|
+
credentials: request.credentials,
|
|
246
|
+
destination: request.destination,
|
|
247
|
+
integrity: request.integrity,
|
|
248
|
+
redirect: request.redirect,
|
|
249
|
+
referrer: request.referrer,
|
|
250
|
+
referrerPolicy: request.referrerPolicy,
|
|
251
|
+
body: requestBuffer,
|
|
252
|
+
keepalive: request.keepalive,
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
[requestBuffer],
|
|
256
|
+
)
|
|
257
|
+
|
|
258
|
+
switch (clientMessage.type) {
|
|
259
|
+
case 'MOCK_RESPONSE': {
|
|
260
|
+
return respondWithMock(clientMessage.data)
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
case 'PASSTHROUGH': {
|
|
264
|
+
return passthrough()
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
return passthrough()
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function sendToClient(client, message, transferrables = []) {
|
|
272
|
+
return new Promise((resolve, reject) => {
|
|
273
|
+
const channel = new MessageChannel()
|
|
274
|
+
|
|
275
|
+
channel.port1.onmessage = (event) => {
|
|
276
|
+
if (event.data && event.data.error) {
|
|
277
|
+
return reject(event.data.error)
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
resolve(event.data)
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
client.postMessage(
|
|
284
|
+
message,
|
|
285
|
+
[channel.port2].concat(transferrables.filter(Boolean)),
|
|
286
|
+
)
|
|
287
|
+
})
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
async function respondWithMock(response) {
|
|
291
|
+
// Setting response status code to 0 is a no-op.
|
|
292
|
+
// However, when responding with a "Response.error()", the produced Response
|
|
293
|
+
// instance will have status code set to 0. Since it's not possible to create
|
|
294
|
+
// a Response instance with status code 0, handle that use-case separately.
|
|
295
|
+
if (response.status === 0) {
|
|
296
|
+
return Response.error()
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
const mockedResponse = new Response(response.body, response)
|
|
300
|
+
|
|
301
|
+
Reflect.defineProperty(mockedResponse, IS_MOCKED_RESPONSE, {
|
|
302
|
+
value: true,
|
|
303
|
+
enumerable: true,
|
|
304
|
+
})
|
|
305
|
+
|
|
306
|
+
return mockedResponse
|
|
307
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { test, expect } from '@playwright/test';
|
|
2
|
+
|
|
3
|
+
test.beforeEach(async ({ page }) => {
|
|
4
|
+
await page.goto('/');
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
test('click Vite logo open Vite official website blank tab', async ({ page, context }) => {
|
|
8
|
+
await page.getByRole('link', { name: 'Vite logo' }).click();
|
|
9
|
+
const newPage = await context.waitForEvent('page');
|
|
10
|
+
await newPage.waitForLoadState();
|
|
11
|
+
await expect(newPage).toHaveTitle('Vite | Next Generation Frontend Tooling');
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test('click Vue logo open Vue official website blank tab', async ({ page, context }) => {
|
|
15
|
+
await page.getByTitle('#icon-vue').click();
|
|
16
|
+
const newPage = await context.waitForEvent('page');
|
|
17
|
+
await newPage.waitForLoadState();
|
|
18
|
+
await expect(newPage).toHaveTitle('Vue.js - The Progressive JavaScript Framework | Vue.js');
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test('homepage count button interact', async ({ page }) => {
|
|
22
|
+
await page.getByRole('button', { name: 'count is 0' }).click();
|
|
23
|
+
await expect(page.getByRole('button', { name: 'count is 1' })).toBeVisible();
|
|
24
|
+
await page.getByRole('button', { name: 'count is 1' }).click();
|
|
25
|
+
await expect(page.getByRole('button', { name: 'count is 2' })).toBeVisible();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('locale change interact', async ({ page }) => {
|
|
29
|
+
await page.getByRole('button', { name: 'English' }).click();
|
|
30
|
+
await expect(page.getByRole('button', { name: '中文' })).toBeVisible();
|
|
31
|
+
await page.getByRole('button', { name: '中文' }).click();
|
|
32
|
+
await expect(page.getByRole('button', { name: 'English' })).toBeVisible();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('click create-vue link open Vue quick start blank tab', async ({ page, context }) => {
|
|
36
|
+
await page.getByRole('link', { name: 'create-vue' }).click();
|
|
37
|
+
const newPage = await context.waitForEvent('page');
|
|
38
|
+
await newPage.waitForLoadState();
|
|
39
|
+
await expect(newPage).toHaveTitle('Quick Start | Vue.js');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('click Volar link open language-tools github blank tab', async ({ page, context }) => {
|
|
43
|
+
await page.getByRole('link', { name: 'Volar' }).click();
|
|
44
|
+
const newPage = await context.waitForEvent('page');
|
|
45
|
+
await newPage.waitForLoadState();
|
|
46
|
+
await expect(newPage).toHaveTitle(
|
|
47
|
+
'GitHub - vuejs/language-tools: ⚡ High-performance Vue language tooling based-on Volar.js',
|
|
48
|
+
);
|
|
49
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { screen } from '@testing-library/vue';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
3
|
+
import HelloWorld from '@/components/indexPage/HelloWorld.vue';
|
|
4
|
+
import { renderComponent } from '@/__tests__/unit/render';
|
|
5
|
+
import { useConfigStore } from '@/stores';
|
|
6
|
+
import i18n from '@/plugins/i18n';
|
|
7
|
+
|
|
8
|
+
describe('HelloWorld component', () => {
|
|
9
|
+
const { t } = i18n.global;
|
|
10
|
+
|
|
11
|
+
it('renders the correct content', () => {
|
|
12
|
+
const msg = 'Hello World!';
|
|
13
|
+
const { version } = useConfigStore();
|
|
14
|
+
|
|
15
|
+
renderComponent(HelloWorld, { props: { msg } });
|
|
16
|
+
expect(screen.getByRole('heading', { name: msg })).toBeInTheDocument();
|
|
17
|
+
expect(screen.getByRole('button', { name: /count is 0/i })).toBeInTheDocument();
|
|
18
|
+
expect(screen.getByText(/check out , the official vue \+ vite starter/i)).toBeInTheDocument();
|
|
19
|
+
expect(screen.getByRole('link', { name: /create-vue/i })).toBeInTheDocument();
|
|
20
|
+
expect(screen.getByText(/install in your ide for a better dx/i)).toBeInTheDocument();
|
|
21
|
+
expect(screen.getByRole('link', { name: /volar/i })).toBeInTheDocument();
|
|
22
|
+
expect(screen.getByText(/click on the vite and vue logos to learn more/i)).toBeInTheDocument();
|
|
23
|
+
expect(screen.getByText(version)).toBeInTheDocument();
|
|
24
|
+
expect(screen.getByRole('button', { name: t('language') })).toBeInTheDocument();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('count button interact', async () => {
|
|
28
|
+
renderComponent(HelloWorld, { props: { msg: '' } });
|
|
29
|
+
const countButton = screen.getByRole('button', { name: /count is 0/i });
|
|
30
|
+
|
|
31
|
+
await userEvent.click(countButton);
|
|
32
|
+
expect(countButton).toHaveTextContent(/count is 1/i);
|
|
33
|
+
await userEvent.click(countButton);
|
|
34
|
+
await userEvent.click(countButton);
|
|
35
|
+
expect(countButton).toHaveTextContent(/count is 3/i);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('link correct attribute', () => {
|
|
39
|
+
renderComponent(HelloWorld, { props: { msg: '' } });
|
|
40
|
+
const createVueLink = screen.getByRole('link', { name: /create-vue/i });
|
|
41
|
+
const volarLink = screen.getByRole('link', { name: /volar/i });
|
|
42
|
+
|
|
43
|
+
expect(createVueLink).toHaveAttribute('href', 'https://vuejs.org/guide/quick-start.html#local');
|
|
44
|
+
expect(createVueLink).toHaveAttribute('target', '_blank');
|
|
45
|
+
expect(volarLink).toHaveAttribute('href', 'https://github.com/vuejs/language-tools');
|
|
46
|
+
expect(volarLink).toHaveAttribute('target', '_blank');
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('locale change interact', async () => {
|
|
50
|
+
renderComponent(HelloWorld, { props: { msg: '' } });
|
|
51
|
+
const localeButton = screen.getByRole('button', { name: t('language') });
|
|
52
|
+
|
|
53
|
+
expect(localeButton).toHaveTextContent('English');
|
|
54
|
+
await userEvent.click(localeButton);
|
|
55
|
+
expect(localeButton).toHaveTextContent('中文');
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Component } from 'vue';
|
|
2
|
+
import { createRouter, createMemoryHistory } from 'vue-router';
|
|
3
|
+
import { render } from '@testing-library/vue';
|
|
4
|
+
import type { RenderOptions } from '@testing-library/vue/types';
|
|
5
|
+
import { setActivePinia, createPinia } from 'pinia';
|
|
6
|
+
import i18n from '@/plugins/i18n';
|
|
7
|
+
import { routes } from '@/router';
|
|
8
|
+
|
|
9
|
+
interface RenderComponentOptions extends RenderOptions<unknown> {
|
|
10
|
+
provide?: Record<PropertyKey, unknown>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const pinia = createPinia();
|
|
14
|
+
const router = createRouter({ history: createMemoryHistory(), routes });
|
|
15
|
+
|
|
16
|
+
setActivePinia(pinia);
|
|
17
|
+
|
|
18
|
+
export function renderComponent(testComponent: Component, options?: RenderComponentOptions) {
|
|
19
|
+
const { provide, ...componentOptions } = options ?? {};
|
|
20
|
+
|
|
21
|
+
return render(testComponent, {
|
|
22
|
+
...componentOptions,
|
|
23
|
+
global: {
|
|
24
|
+
plugins: [pinia, i18n, router],
|
|
25
|
+
provide,
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="37.07" height="36" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 198"><path fill="#41B883" d="M204.8 0H256L128 220.8L0 0h97.92L128 51.2L157.44 0h47.36Z"></path><path fill="#41B883" d="m0 0l128 220.8L256 0h-51.2L128 132.48L50.56 0H0Z"></path><path fill="#35495E" d="M50.56 0L128 133.12L204.8 0h-47.36L128 51.2L97.92 0H50.56Z"></path></svg>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed } from 'vue';
|
|
3
|
+
|
|
4
|
+
interface Props {
|
|
5
|
+
name: string;
|
|
6
|
+
prefix?: string;
|
|
7
|
+
color?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
defineOptions({ name: 'SvgIcon' });
|
|
11
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
12
|
+
prefix: 'icon',
|
|
13
|
+
color: '#333',
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const symbolId = computed(() => `#${props.prefix}-${props.name}`);
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<template>
|
|
20
|
+
<svg
|
|
21
|
+
aria-hidden="true"
|
|
22
|
+
:title="symbolId"
|
|
23
|
+
>
|
|
24
|
+
<use
|
|
25
|
+
:href="symbolId"
|
|
26
|
+
:fill="color"
|
|
27
|
+
/>
|
|
28
|
+
</svg>
|
|
29
|
+
</template>
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ref } from 'vue';
|
|
3
|
+
import { useI18n } from 'vue-i18n';
|
|
4
|
+
import { useConfigStore } from '@/stores';
|
|
5
|
+
|
|
6
|
+
defineProps<{ msg: string }>();
|
|
7
|
+
|
|
8
|
+
const { locale } = useI18n();
|
|
9
|
+
const { version } = useConfigStore();
|
|
10
|
+
const count = ref(0);
|
|
11
|
+
|
|
12
|
+
function changeLocale() {
|
|
13
|
+
locale.value = locale.value === 'en-US' ? 'zh-TW' : 'en-US';
|
|
14
|
+
}
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<template>
|
|
18
|
+
<h1>{{ msg }}</h1>
|
|
19
|
+
|
|
20
|
+
<div class="p-8">
|
|
21
|
+
<button
|
|
22
|
+
type="button"
|
|
23
|
+
@click="count++"
|
|
24
|
+
>
|
|
25
|
+
count is {{ count }}
|
|
26
|
+
</button>
|
|
27
|
+
</div>
|
|
28
|
+
|
|
29
|
+
<p>
|
|
30
|
+
Check out
|
|
31
|
+
<a
|
|
32
|
+
href="https://vuejs.org/guide/quick-start.html#local"
|
|
33
|
+
target="_blank"
|
|
34
|
+
>create-vue</a
|
|
35
|
+
>, the official Vue + Vite starter
|
|
36
|
+
</p>
|
|
37
|
+
<p>
|
|
38
|
+
Install
|
|
39
|
+
<a
|
|
40
|
+
href="https://github.com/vuejs/language-tools"
|
|
41
|
+
target="_blank"
|
|
42
|
+
>Volar</a
|
|
43
|
+
>
|
|
44
|
+
in your IDE for a better DX
|
|
45
|
+
</p>
|
|
46
|
+
<p class="read-the-docs">Click on the Vite and Vue logos to learn more</p>
|
|
47
|
+
<p class="read-the-docs">
|
|
48
|
+
{{ version }}
|
|
49
|
+
</p>
|
|
50
|
+
<button @click="changeLocale">
|
|
51
|
+
{{ $t('language') }}
|
|
52
|
+
</button>
|
|
53
|
+
</template>
|
|
54
|
+
|
|
55
|
+
<style lang="postcss" scoped>
|
|
56
|
+
.read-the-docs {
|
|
57
|
+
@apply text-[#888];
|
|
58
|
+
}
|
|
59
|
+
</style>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
// Generated by unplugin-vue-components
|
|
4
|
+
// Read more: https://github.com/vuejs/core/pull/3399
|
|
5
|
+
export {}
|
|
6
|
+
|
|
7
|
+
/* prettier-ignore */
|
|
8
|
+
declare module 'vue' {
|
|
9
|
+
export interface GlobalComponents {
|
|
10
|
+
RouterLink: typeof import('vue-router')['RouterLink']
|
|
11
|
+
RouterView: typeof import('vue-router')['RouterView']
|
|
12
|
+
SvgIcon: typeof import('./components/common/SvgIcon.vue')['default']
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createApp } from 'vue';
|
|
2
|
+
import { createPinia } from 'pinia';
|
|
3
|
+
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate';
|
|
4
|
+
import 'virtual:svg-icons-register';
|
|
5
|
+
|
|
6
|
+
import '@/styles/tailwind.postcss';
|
|
7
|
+
import '@/styles/index.postcss';
|
|
8
|
+
import App from './App.vue';
|
|
9
|
+
import router from '@/router';
|
|
10
|
+
import i18NPlugin from '@/plugins/i18n';
|
|
11
|
+
|
|
12
|
+
if (process.env.NODE_ENV === 'mockServiceWorker') {
|
|
13
|
+
const { worker } = await import('@/mocks/browser');
|
|
14
|
+
|
|
15
|
+
worker.start();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const pinia = createPinia();
|
|
19
|
+
const app = createApp(App);
|
|
20
|
+
|
|
21
|
+
pinia.use(piniaPluginPersistedstate);
|
|
22
|
+
app.use(pinia);
|
|
23
|
+
app.use(router);
|
|
24
|
+
app.use(i18NPlugin);
|
|
25
|
+
app.mount('#app');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const handlers = [];
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import HelloWorld from '@/components/indexPage/HelloWorld.vue';
|
|
3
|
+
</script>
|
|
4
|
+
|
|
5
|
+
<template>
|
|
6
|
+
<div>
|
|
7
|
+
<a
|
|
8
|
+
href="https://vitejs.dev"
|
|
9
|
+
target="_blank"
|
|
10
|
+
>
|
|
11
|
+
<img
|
|
12
|
+
src="/vite.svg"
|
|
13
|
+
class="logo"
|
|
14
|
+
alt="Vite logo"
|
|
15
|
+
/>
|
|
16
|
+
</a>
|
|
17
|
+
<a
|
|
18
|
+
href="https://vuejs.org/"
|
|
19
|
+
target="_blank"
|
|
20
|
+
>
|
|
21
|
+
<svg-icon
|
|
22
|
+
name="vue"
|
|
23
|
+
class="logo hover:drop-shadow-[0_0_2em_#42b883aa]"
|
|
24
|
+
/>
|
|
25
|
+
</a>
|
|
26
|
+
</div>
|
|
27
|
+
<hello-world msg="Vite + Vue" />
|
|
28
|
+
</template>
|
|
29
|
+
|
|
30
|
+
<style lang="postcss" scoped>
|
|
31
|
+
.logo {
|
|
32
|
+
@apply w-24 h-24 p-6 mx-auto will-change-[filter] transition-[filter] duration-300 hover:drop-shadow-[0_0_2em_#646cffaa];
|
|
33
|
+
}
|
|
34
|
+
</style>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createI18n } from 'vue-i18n';
|
|
2
|
+
import enUS from '@/locales/en-US.json';
|
|
3
|
+
import zhTW from '@/locales/zh-TW.json';
|
|
4
|
+
|
|
5
|
+
const i18n = createI18n({
|
|
6
|
+
legacy: import.meta.env.MODE === 'test',
|
|
7
|
+
locale: navigator.language,
|
|
8
|
+
fallbackLocale: 'en-US',
|
|
9
|
+
messages: {
|
|
10
|
+
'zh-TW': zhTW,
|
|
11
|
+
'en-US': enUS,
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export default i18n;
|