Skip to content

Commit 665250c

Browse files
authored
js: add tests !macos !windows (#203)
1 parent 366ed76 commit 665250c

File tree

8 files changed

+139
-1
lines changed

8 files changed

+139
-1
lines changed

.github/workflows/js.yml

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,50 @@ jobs:
8686
with:
8787
platform: js
8888

89-
release:
89+
test:
9090
needs: build
91+
runs-on: ${{ matrix.os }}
92+
strategy:
93+
fail-fast: false
94+
matrix:
95+
include:
96+
- { os: ubuntu-24.04 }
97+
- { os: ubuntu-24.04-arm }
98+
- { os: macos-26 }
99+
- { os: windows-2025 }
100+
steps:
101+
- uses: actions/checkout@v5
102+
103+
- uses: actions/setup-node@v6
104+
with:
105+
node-version: 24.x
106+
107+
- name: Download artifact
108+
uses: actions/download-artifact@v5
109+
with:
110+
path: build/js
111+
112+
- name: Install dependencies
113+
run: |
114+
curl -LO --output-dir cache https://github.com/fcitx-contrib/fcitx5-online/releases/download/latest/fcitx5-online.zip
115+
unzip cache/fcitx5-online.zip
116+
npm i -g pnpm
117+
pnpm i
118+
npx playwright install
119+
npx playwright install-deps
120+
121+
- name: Test
122+
if: ${{ startsWith(matrix.os, 'macos') || startsWith(matrix.os, 'windows') }}
123+
run: pnpm run test
124+
125+
- name: Test
126+
if: ${{ startsWith(matrix.os, 'ubuntu') }}
127+
run: |
128+
pnpm run test:chromium
129+
pnpm run test:firefox
130+
131+
release:
132+
needs: test
91133
if: ${{ github.ref == 'refs/heads/master' }}
92134
runs-on: ubuntu-latest
93135
steps:

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,8 @@ cache/js
55
meta-*.json
66
*.gz
77
*.bz2
8+
node_modules
9+
pnpm-lock.yaml
10+
*.tsbuildinfo
11+
fcitx5-online*
12+
test-results

eslint.config.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import antfu from '@antfu/eslint-config'
2+
3+
export default antfu({})

package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "fcitx5-plugins",
3+
"type": "module",
4+
"scripts": {
5+
"lint": "eslint tests",
6+
"lint:fix": "eslint --fix tests",
7+
"check": "tsc --noEmit",
8+
"test": "playwright test --browser all",
9+
"test:chromium": "playwright test --browser chromium",
10+
"test:firefox": "playwright test --browser firefox",
11+
"test:webkit": "playwright test --browser webkit"
12+
},
13+
"devDependencies": {
14+
"@antfu/eslint-config": "^6.0.0",
15+
"@playwright/test": "^1.56.1",
16+
"eslint": "^9.38.0",
17+
"serve": "^14.2.5",
18+
"typescript": "^5.9.3"
19+
}
20+
}

playwright.config.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { defineConfig } from '@playwright/test'
2+
3+
export default defineConfig({
4+
testDir: 'tests',
5+
fullyParallel: true,
6+
webServer: {
7+
command: 'npx serve -l 9000 -S fcitx5-online',
8+
port: 9000,
9+
reuseExistingServer: true,
10+
},
11+
})

tests/test-mozc.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { test } from '@playwright/test'
2+
import { expectCandidate, expectText, init } from './util'
3+
4+
test('Mizu', async ({ page }) => {
5+
test.skip(page.context().browser()!.browserType().name() === 'chromium', 'Chromium rejects big wasm executable.')
6+
await init(page, 'mozc', 'Mozc')
7+
8+
await page.keyboard.type('m')
9+
await page.keyboard.type('i')
10+
await page.keyboard.type('z')
11+
await page.keyboard.type('u')
12+
await expectCandidate(page, '水')
13+
await expectText(page, 'みず')
14+
15+
await page.keyboard.press(' ')
16+
await page.keyboard.press('Enter')
17+
await expectText(page, '水')
18+
})

tests/util.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import type { Page } from '@playwright/test'
2+
import { expect } from '@playwright/test'
3+
4+
export async function init(page: Page, plugin: string, im: string) {
5+
await page.goto('http://localhost:9000')
6+
7+
// Install plugin.
8+
await page.locator('.my-column > :first-child div:nth-child(6)').click()
9+
const [fileChooser] = await Promise.all([
10+
page.waitForEvent('filechooser'),
11+
page.locator('.n-upload-trigger').click(),
12+
])
13+
await fileChooser.setFiles([`build/js/${plugin}.zip`])
14+
await page.keyboard.press('Escape')
15+
16+
// Select IM.
17+
await page.locator('.my-column > :first-child .n-select').click()
18+
await page.locator('.n-base-select-option').getByText(im).click()
19+
}
20+
21+
export function expectCandidate(page: Page, text: string) {
22+
return expect(page.locator('.fcitx-candidate').first().locator('.fcitx-text')).toHaveText(new RegExp(`^${text}$`))
23+
}
24+
25+
export function expectText(page: Page, text: string) {
26+
return expect(page.locator('.my-column > :nth-child(2) textarea')).toHaveValue(text)
27+
}

tsconfig.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"compilerOptions": {
3+
"composite": true,
4+
"target": "ESNext",
5+
"module": "ESNext",
6+
"moduleResolution": "bundler",
7+
"resolveJsonModule": true,
8+
"allowSyntheticDefaultImports": true,
9+
"skipLibCheck": true
10+
},
11+
"include": ["tests/**/*.ts"]
12+
}

0 commit comments

Comments
 (0)