From 84cfea8615d56620f0c2448cdcd99d711cd39df0 Mon Sep 17 00:00:00 2001 From: Qijia Liu Date: Sun, 19 Oct 2025 09:57:49 -0400 Subject: [PATCH 1/4] js: add tests !macos !windows --- .github/workflows/js.yml | 168 ++++++++++++++++++++++++--------------- .gitignore | 5 ++ eslint.config.mjs | 3 + package.json | 17 ++++ playwright.config.ts | 11 +++ tests/test-mozc.spec.ts | 18 +++++ tests/util.ts | 27 +++++++ tsconfig.json | 12 +++ 8 files changed, 198 insertions(+), 63 deletions(-) create mode 100644 eslint.config.mjs create mode 100644 package.json create mode 100644 playwright.config.ts create mode 100644 tests/test-mozc.spec.ts create mode 100644 tests/util.ts create mode 100644 tsconfig.json diff --git a/.github/workflows/js.yml b/.github/workflows/js.yml index 180f7c2..7b360bc 100644 --- a/.github/workflows/js.yml +++ b/.github/workflows/js.yml @@ -9,85 +9,127 @@ on: type: string jobs: - build: - runs-on: ubuntu-24.04 - env: - EMSCRIPTEN_VERSION: '4.0.17' - steps: - - uses: actions/checkout@v5 - with: - submodules: recursive + # build: + # runs-on: ubuntu-24.04 + # env: + # EMSCRIPTEN_VERSION: '4.0.17' + # steps: + # - uses: actions/checkout@v5 + # with: + # submodules: recursive - - uses: actions/checkout@v5 - with: - submodules: recursive - repository: google/mozc - path: fcitx5-mozc/mozc - ref: ${{ inputs.mozc_sha }} + # - uses: actions/checkout@v5 + # with: + # submodules: recursive + # repository: google/mozc + # path: fcitx5-mozc/mozc + # ref: ${{ inputs.mozc_sha }} - - uses: actions/checkout@v5 - with: - repository: emscripten-core/emsdk - path: emsdk + # - uses: actions/checkout@v5 + # with: + # repository: emscripten-core/emsdk + # path: emsdk - - uses: actions/setup-python@v6 - with: - python-version: '3.14' + # - uses: actions/setup-python@v6 + # with: + # python-version: '3.14' - - name: Install dependencies - run: | - sudo apt install -y ninja-build \ - gettext \ - marisa - ./scripts/install-deps.sh js - pip install dirhash + # - name: Install dependencies + # run: | + # sudo apt install -y ninja-build \ + # gettext \ + # marisa + # ./scripts/install-deps.sh js + # pip install dirhash - - name: Install Fcitx5 dev package - run: | - wget https://github.com/fcitx-contrib/fcitx5-js/releases/download/latest/fcitx5-js-dev.tar.bz2 - tar xjf fcitx5-js-dev.tar.bz2 -C build/js/usr + # - name: Install Fcitx5 dev package + # run: | + # wget https://github.com/fcitx-contrib/fcitx5-js/releases/download/latest/fcitx5-js-dev.tar.bz2 + # tar xjf fcitx5-js-dev.tar.bz2 -C build/js/usr - - name: Install emsdk - working-directory: emsdk - run: | - ./emsdk install ${{ env.EMSCRIPTEN_VERSION }} - ./emsdk activate ${{ env.EMSCRIPTEN_VERSION }} + # - name: Install emsdk + # working-directory: emsdk + # run: | + # ./emsdk install ${{ env.EMSCRIPTEN_VERSION }} + # ./emsdk activate ${{ env.EMSCRIPTEN_VERSION }} - - name: Build - run: | - . emsdk/emsdk_env.sh - git apply --directory=libime patches/libime.patch - git apply --directory=fcitx5-chinese-addons patches/chinese-addons.patch - git apply --directory=fcitx5-rime patches/rime.log.patch - git apply --directory=fcitx5-rime patches/rime.js.patch - emcmake cmake -B build/js -G Ninja -DCMAKE_BUILD_TYPE=Release - cmake --build build/js - ./scripts/install.sh js - - - name: Upload artifact - uses: actions/upload-artifact@v4 + # - name: Build + # run: | + # . emsdk/emsdk_env.sh + # git apply --directory=libime patches/libime.patch + # git apply --directory=fcitx5-chinese-addons patches/chinese-addons.patch + # git apply --directory=fcitx5-rime patches/rime.log.patch + # git apply --directory=fcitx5-rime patches/rime.js.patch + # emcmake cmake -B build/js -G Ninja -DCMAKE_BUILD_TYPE=Release + # cmake --build build/js + # ./scripts/install.sh js + + # - name: Upload artifact + # uses: actions/upload-artifact@v4 + # with: + # name: artifact-js + # path: | + # build/js/*.zip + + # - name: Check validity + # run: | + # python scripts/check-shared-files.py build/js/*/usr/plugin/*.json + + # - name: Setup tmate session + # if: ${{ failure() }} + # uses: mxschmitt/action-tmate@v3 + + # compare: + # needs: build + # if: ${{ github.ref != 'refs/heads/master' }} + # uses: ./.github/workflows/compare.yml + # with: + # platform: js + + test: + # needs: build + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - { os: ubuntu-24.04 } + - { os: ubuntu-24.04-arm } + - { os: macos-26 } + - { os: windows-2025 } + steps: + - uses: actions/checkout@v5 + + - uses: actions/setup-node@v6 with: - name: artifact-js - path: | - build/js/*.zip + node-version: 24.x - - name: Check validity + - name: Download artifact + # uses: actions/download-artifact@v5 + # with: + # path: build/js run: | - python scripts/check-shared-files.py build/js/*/usr/plugin/*.json + mkdir -p build/js + curl -LO --output-dir build/js https://github.com/fcitx-contrib/fcitx5-plugins/releases/download/js/mozc.zip + + - name: Install dependencies + run: | + curl -LO --output-dir cache https://github.com/fcitx-contrib/fcitx5-online/releases/download/latest/fcitx5-online.zip + unzip cache/fcitx5-online.zip + npm i -g pnpm + pnpm i + npx playwright install + npx playwright install-deps + + - name: Test + run: pnpm run test - name: Setup tmate session if: ${{ failure() }} uses: mxschmitt/action-tmate@v3 - compare: - needs: build - if: ${{ github.ref != 'refs/heads/master' }} - uses: ./.github/workflows/compare.yml - with: - platform: js - release: - needs: build + needs: test if: ${{ github.ref == 'refs/heads/master' }} runs-on: ubuntu-latest steps: diff --git a/.gitignore b/.gitignore index dd5b3dc..64b6931 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,8 @@ cache/js meta-*.json *.gz *.bz2 +node_modules +pnpm-lock.yaml +*.tsbuildinfo +fcitx5-online* +test-results diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 0000000..0aa96e7 --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,3 @@ +import antfu from '@antfu/eslint-config' + +export default antfu({}) diff --git a/package.json b/package.json new file mode 100644 index 0000000..50ca0a2 --- /dev/null +++ b/package.json @@ -0,0 +1,17 @@ +{ + "name": "fcitx5-plugins", + "type": "module", + "scripts": { + "lint": "eslint tests", + "lint:fix": "eslint --fix tests", + "check": "tsc --noEmit", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "devDependencies": { + "@antfu/eslint-config": "^6.0.0", + "@playwright/test": "1.55", + "eslint": "^9.38.0", + "serve": "^14.2.5", + "typescript": "^5.9.3" + } +} diff --git a/playwright.config.ts b/playwright.config.ts new file mode 100644 index 0000000..1d3a18c --- /dev/null +++ b/playwright.config.ts @@ -0,0 +1,11 @@ +import { defineConfig } from '@playwright/test' + +export default defineConfig({ + testDir: 'tests', + fullyParallel: true, + webServer: { + command: 'npx serve -l 9000 -S fcitx5-online', + port: 9000, + reuseExistingServer: true, + }, +}) diff --git a/tests/test-mozc.spec.ts b/tests/test-mozc.spec.ts new file mode 100644 index 0000000..a7bd3fd --- /dev/null +++ b/tests/test-mozc.spec.ts @@ -0,0 +1,18 @@ +import { test } from '@playwright/test' +import { expectCandidate, expectText, init } from './util' + +test('Mizu', async ({ page }) => { + test.skip(page.context().browser()!.browserType().name() === 'chromium', 'Chromium rejects big wasm executable.') + await init(page, 'mozc', 'Mozc') + + await page.keyboard.type('m') + await page.keyboard.type('i') + await page.keyboard.type('z') + await page.keyboard.type('u') + await expectCandidate(page, '水') + await expectText(page, 'みず') + + await page.keyboard.press(' ') + await page.keyboard.press('Enter') + await expectText(page, '水') +}) diff --git a/tests/util.ts b/tests/util.ts new file mode 100644 index 0000000..48dbac6 --- /dev/null +++ b/tests/util.ts @@ -0,0 +1,27 @@ +import type { Page } from '@playwright/test' +import { expect } from '@playwright/test' + +export async function init(page: Page, plugin: string, im: string) { + await page.goto('http://localhost:9000') + + // Install plugin. + await page.locator('.my-column > :first-child div:nth-child(6)').click() + const [fileChooser] = await Promise.all([ + page.waitForEvent('filechooser'), + page.locator('.n-upload-trigger').click(), + ]) + await fileChooser.setFiles([`build/js/${plugin}.zip`]) + await page.keyboard.press('Escape') + + // Select IM. + await page.locator('.my-column > :first-child .n-select').click() + await page.locator('.n-base-select-option').getByText(im).click() +} + +export function expectCandidate(page: Page, text: string) { + return expect(page.locator('.fcitx-candidate').first().locator('.fcitx-text')).toHaveText(new RegExp(`^${text}$`)) +} + +export function expectText(page: Page, text: string) { + return expect(page.locator('.my-column > :nth-child(2) textarea')).toHaveValue(text) +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..626af97 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "composite": true, + "target": "ESNext", + "module": "ESNext", + "moduleResolution": "bundler", + "resolveJsonModule": true, + "allowSyntheticDefaultImports": true, + "skipLibCheck": true + }, + "include": ["tests/**/*.ts"] +} From ea1a59d54a3202be78e1600d6847449a67456c39 Mon Sep 17 00:00:00 2001 From: Qijia Liu Date: Sun, 19 Oct 2025 10:00:45 -0400 Subject: [PATCH 2/4] fix --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 50ca0a2..a676b50 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "lint": "eslint tests", "lint:fix": "eslint --fix tests", "check": "tsc --noEmit", - "test": "echo \"Error: no test specified\" && exit 1" + "test": "playwright test --browser all" }, "devDependencies": { "@antfu/eslint-config": "^6.0.0", From fa2c7457d2235a0986b1f478271d659fe732cb64 Mon Sep 17 00:00:00 2001 From: Qijia Liu Date: Sun, 19 Oct 2025 10:05:44 -0400 Subject: [PATCH 3/4] restore build --- .github/workflows/js.yml | 167 +++++++++++++++++++-------------------- 1 file changed, 80 insertions(+), 87 deletions(-) diff --git a/.github/workflows/js.yml b/.github/workflows/js.yml index 7b360bc..b863bc5 100644 --- a/.github/workflows/js.yml +++ b/.github/workflows/js.yml @@ -9,85 +9,85 @@ on: type: string jobs: - # build: - # runs-on: ubuntu-24.04 - # env: - # EMSCRIPTEN_VERSION: '4.0.17' - # steps: - # - uses: actions/checkout@v5 - # with: - # submodules: recursive - - # - uses: actions/checkout@v5 - # with: - # submodules: recursive - # repository: google/mozc - # path: fcitx5-mozc/mozc - # ref: ${{ inputs.mozc_sha }} - - # - uses: actions/checkout@v5 - # with: - # repository: emscripten-core/emsdk - # path: emsdk - - # - uses: actions/setup-python@v6 - # with: - # python-version: '3.14' - - # - name: Install dependencies - # run: | - # sudo apt install -y ninja-build \ - # gettext \ - # marisa - # ./scripts/install-deps.sh js - # pip install dirhash - - # - name: Install Fcitx5 dev package - # run: | - # wget https://github.com/fcitx-contrib/fcitx5-js/releases/download/latest/fcitx5-js-dev.tar.bz2 - # tar xjf fcitx5-js-dev.tar.bz2 -C build/js/usr - - # - name: Install emsdk - # working-directory: emsdk - # run: | - # ./emsdk install ${{ env.EMSCRIPTEN_VERSION }} - # ./emsdk activate ${{ env.EMSCRIPTEN_VERSION }} - - # - name: Build - # run: | - # . emsdk/emsdk_env.sh - # git apply --directory=libime patches/libime.patch - # git apply --directory=fcitx5-chinese-addons patches/chinese-addons.patch - # git apply --directory=fcitx5-rime patches/rime.log.patch - # git apply --directory=fcitx5-rime patches/rime.js.patch - # emcmake cmake -B build/js -G Ninja -DCMAKE_BUILD_TYPE=Release - # cmake --build build/js - # ./scripts/install.sh js - - # - name: Upload artifact - # uses: actions/upload-artifact@v4 - # with: - # name: artifact-js - # path: | - # build/js/*.zip - - # - name: Check validity - # run: | - # python scripts/check-shared-files.py build/js/*/usr/plugin/*.json - - # - name: Setup tmate session - # if: ${{ failure() }} - # uses: mxschmitt/action-tmate@v3 - - # compare: - # needs: build - # if: ${{ github.ref != 'refs/heads/master' }} - # uses: ./.github/workflows/compare.yml - # with: - # platform: js + build: + runs-on: ubuntu-24.04 + env: + EMSCRIPTEN_VERSION: '4.0.17' + steps: + - uses: actions/checkout@v5 + with: + submodules: recursive + + - uses: actions/checkout@v5 + with: + submodules: recursive + repository: google/mozc + path: fcitx5-mozc/mozc + ref: ${{ inputs.mozc_sha }} + + - uses: actions/checkout@v5 + with: + repository: emscripten-core/emsdk + path: emsdk + + - uses: actions/setup-python@v6 + with: + python-version: '3.14' + + - name: Install dependencies + run: | + sudo apt install -y ninja-build \ + gettext \ + marisa + ./scripts/install-deps.sh js + pip install dirhash + + - name: Install Fcitx5 dev package + run: | + wget https://github.com/fcitx-contrib/fcitx5-js/releases/download/latest/fcitx5-js-dev.tar.bz2 + tar xjf fcitx5-js-dev.tar.bz2 -C build/js/usr + + - name: Install emsdk + working-directory: emsdk + run: | + ./emsdk install ${{ env.EMSCRIPTEN_VERSION }} + ./emsdk activate ${{ env.EMSCRIPTEN_VERSION }} + + - name: Build + run: | + . emsdk/emsdk_env.sh + git apply --directory=libime patches/libime.patch + git apply --directory=fcitx5-chinese-addons patches/chinese-addons.patch + git apply --directory=fcitx5-rime patches/rime.log.patch + git apply --directory=fcitx5-rime patches/rime.js.patch + emcmake cmake -B build/js -G Ninja -DCMAKE_BUILD_TYPE=Release + cmake --build build/js + ./scripts/install.sh js + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: artifact-js + path: | + build/js/*.zip + + - name: Check validity + run: | + python scripts/check-shared-files.py build/js/*/usr/plugin/*.json + + - name: Setup tmate session + if: ${{ failure() }} + uses: mxschmitt/action-tmate@v3 + + compare: + needs: build + if: ${{ github.ref != 'refs/heads/master' }} + uses: ./.github/workflows/compare.yml + with: + platform: js test: - # needs: build + needs: build runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -105,12 +105,9 @@ jobs: node-version: 24.x - name: Download artifact - # uses: actions/download-artifact@v5 - # with: - # path: build/js - run: | - mkdir -p build/js - curl -LO --output-dir build/js https://github.com/fcitx-contrib/fcitx5-plugins/releases/download/js/mozc.zip + uses: actions/download-artifact@v5 + with: + path: build/js - name: Install dependencies run: | @@ -124,10 +121,6 @@ jobs: - name: Test run: pnpm run test - - name: Setup tmate session - if: ${{ failure() }} - uses: mxschmitt/action-tmate@v3 - release: needs: test if: ${{ github.ref == 'refs/heads/master' }} From 07a16a2d0287bab080e5cc082ac9349e986d7ec9 Mon Sep 17 00:00:00 2001 From: Qijia Liu Date: Sun, 19 Oct 2025 10:41:54 -0400 Subject: [PATCH 4/4] skip webkit test for ubuntu --- .github/workflows/js.yml | 7 +++++++ package.json | 7 +++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/.github/workflows/js.yml b/.github/workflows/js.yml index b863bc5..107ab7b 100644 --- a/.github/workflows/js.yml +++ b/.github/workflows/js.yml @@ -119,8 +119,15 @@ jobs: npx playwright install-deps - name: Test + if: ${{ startsWith(matrix.os, 'macos') || startsWith(matrix.os, 'windows') }} run: pnpm run test + - name: Test + if: ${{ startsWith(matrix.os, 'ubuntu') }} + run: | + pnpm run test:chromium + pnpm run test:firefox + release: needs: test if: ${{ github.ref == 'refs/heads/master' }} diff --git a/package.json b/package.json index a676b50..035e8c2 100644 --- a/package.json +++ b/package.json @@ -5,11 +5,14 @@ "lint": "eslint tests", "lint:fix": "eslint --fix tests", "check": "tsc --noEmit", - "test": "playwright test --browser all" + "test": "playwright test --browser all", + "test:chromium": "playwright test --browser chromium", + "test:firefox": "playwright test --browser firefox", + "test:webkit": "playwright test --browser webkit" }, "devDependencies": { "@antfu/eslint-config": "^6.0.0", - "@playwright/test": "1.55", + "@playwright/test": "^1.56.1", "eslint": "^9.38.0", "serve": "^14.2.5", "typescript": "^5.9.3"