Skip to content

Commit e679552

Browse files
authored
re-structure project environment (#380)
* chore: use pnpm * chore: pass params to test:unit * fix: re-structure e2e and example * add todo memo * add more task * fix: use pnpm on github actions
1 parent b7421c1 commit e679552

37 files changed

+12700
-15082
lines changed

.github/workflows/build.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,18 @@ jobs:
2626
steps:
2727
- name: Checkout
2828
uses: actions/checkout@v4
29+
30+
- name: Enable corepack
31+
run: corepack enable
32+
2933
- name: Setup Node.js ${{ matrix.node }}
3034
uses: actions/setup-node@v4
3135
with:
3236
node-version: ${{ matrix.node }}
33-
cache: 'yarn'
34-
- name: Install
35-
run: yarn --immutable
36-
- name: Build
37-
run: yarn build
37+
cache: 'pnpm'
38+
39+
- name: Install dependencies
40+
run: pnpm install
41+
42+
- name: Building
43+
run: pnpm build

.github/workflows/lint.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,18 @@ jobs:
2626
steps:
2727
- name: Checkout
2828
uses: actions/checkout@v4
29+
30+
- name: Enable corepack
31+
run: corepack enable
32+
2933
- name: Setup Node.js ${{ matrix.node }}
3034
uses: actions/setup-node@v4
3135
with:
3236
node-version: ${{ matrix.node }}
33-
cache: 'yarn'
34-
- name: Install
35-
run: yarn --immutable
36-
- name: Lint
37-
run: yarn lint
37+
cache: 'pnpm'
38+
39+
- name: Install dependencies
40+
run: pnpm install
41+
42+
- name: Linting
43+
run: pnpm lint

.github/workflows/test.yml

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,35 @@ jobs:
2626
steps:
2727
- name: Checkout
2828
uses: actions/checkout@v4
29+
30+
- name: Enable corepack
31+
run: corepack enable
32+
2933
- name: Setup Node.js ${{ matrix.node }}
3034
uses: actions/setup-node@v4
3135
with:
3236
node-version: ${{ matrix.node }}
33-
cache: 'yarn'
34-
- name: Install
35-
run: yarn --immutable
36-
- name: Test
37-
run: yarn test
37+
cache: 'pnpm'
38+
39+
- name: Install dependencies
40+
run: pnpm install
41+
42+
# https://github.com/vitejs/vite/blob/main/.github/workflows/ci.yml#L62
43+
# Install playwright's binary under custom directory to cache
44+
- name: Set Playwright path
45+
run: echo "PLAYWRIGHT_BROWSERS_PATH=$HOME/.cache/playwright-bin" >> $GITHUB_ENV
46+
47+
- name: Cache Playwright's binary
48+
uses: actions/cache@v4
49+
with:
50+
# Playwright removes unused browsers automatically
51+
# So does not need to add playwright version to key
52+
key: ${{ runner.os }}-playwright-bin-v1
53+
path: ${{ env.PLAYWRIGHT_BROWSERS_PATH }}
54+
55+
- name: Install Playwright
56+
# does not need to explicitly set chromium after https://github.com/microsoft/playwright/issues/14862 is solved
57+
run: pnpm playwright install chromium
58+
59+
- name: Testing
60+
run: pnpm test

.yarn/releases/yarn-3.1.1.cjs

Lines changed: 0 additions & 768 deletions
This file was deleted.

TODO.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# TODO
2+
- [ ] upgrade vitest 1.0 (need to fix `checkInstallPackage` issue in test env)
3+
- [ ] drop fully jest pupeeter for rollup-plugin-vue-i18n, vue-i18n-loader, and vite-plugin-vue-i18n
4+
- [ ] ESLint: migrate flat config style

e2e/helper.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { Page } from 'playwright'
2+
3+
export async function getText(
4+
page: Page,
5+
selector: string,
6+
options?: Parameters<Page['locator']>[1]
7+
) {
8+
return (await page.locator(selector, options).allTextContents())[0]
9+
}

e2e/setup-server.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { getRandomPort, waitForPort } from 'get-port-please'
2+
import { ChildProcess, spawn } from 'node:child_process'
3+
4+
export type ServerContext = {
5+
serverProcess: ChildProcess
6+
url: (val: string) => string
7+
}
8+
export async function startServer(): Promise<ServerContext> {
9+
const host = '127.0.0.1'
10+
const port = await getRandomPort(host)
11+
12+
const serverProcess = spawn(
13+
'pnpm',
14+
['play:vite', '--port', String(port), '--host', host],
15+
{ stdio: 'inherit', env: { ...process.env } }
16+
)
17+
18+
await waitForPort(port, { retries: 32, host })
19+
20+
return {
21+
serverProcess,
22+
url: (val: string) => `http://${host}:${port}${val}`
23+
}
24+
}

e2e/vite.spec.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { startServer } from './setup-server'
2+
import { getText } from './helper'
3+
4+
import type { ServerContext } from './setup-server'
5+
import type { Browser, Page } from 'playwright'
6+
7+
// TODO: extract to shim.d.ts
8+
// eslint-disable-next-line @typescript-eslint/no-namespace
9+
declare namespace global {
10+
let browser: Browser
11+
let page: Page
12+
}
13+
14+
let ctx: ServerContext
15+
describe('vite', () => {
16+
beforeAll(async () => {
17+
ctx = await startServer()
18+
await global.page.goto(ctx.url('/'))
19+
})
20+
21+
afterAll(async () => {
22+
ctx.serverProcess.kill()
23+
})
24+
25+
test('initial rendering', async () => {
26+
expect(await getText(global.page, '#lang label')).toMatch('言語')
27+
expect(await getText(global.page, '#fruits label')).toMatch(
28+
'バナナが欲しい?'
29+
)
30+
expect(await getText(global.page, '#msg')).toMatch('こんにちは、世界!')
31+
expect(await getText(global.page, '#custom-directive')).toMatch('やあ!')
32+
})
33+
34+
test('change locale', async () => {
35+
await global.page.selectOption('#lang select', 'en')
36+
expect(await getText(global.page, '#lang label')).toMatch('Language')
37+
expect(await getText(global.page, '#msg')).toMatch('hello, world!')
38+
expect(await getText(global.page, '#custom-directive')).toMatch('Hi!')
39+
})
40+
41+
test('change banana select', async () => {
42+
await global.page.selectOption('#fruits select', '3')
43+
expect(await getText(global.page, '#banana')).toMatch('バナナ 3 個')
44+
})
45+
})

packages/unplugin-vue-i18n/examples/vite/src/App.vue renamed to examples/vite/src/App.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<template>
2-
<form>
2+
<form id="lang">
33
<label>{{ t('language') }}</label>
44
<select v-model="locale">
55
<option value="en">en</option>
66
<option value="ja">ja</option>
77
</select>
88
</form>
9-
<p>{{ t('hello') }}</p>
10-
<p v-t="'hi'"></p>
9+
<p id="msg">{{ t('hello') }}</p>
10+
<p id="custom-directive" v-t="'hi'"></p>
1111
<Banana />
1212
</template>
1313

0 commit comments

Comments
 (0)