Skip to content

Commit b85e8a3

Browse files
authored
dev/frontend tests (#6)
* Set up vitest and unit test * Extract a test util func * Add the pyodide-e2e CI job * Switch the ESM import path of transformers.js according to whether the env is browser or Node * Remove a test
1 parent 2574582 commit b85e8a3

File tree

6 files changed

+947
-4
lines changed

6 files changed

+947
-4
lines changed

.github/workflows/main.yml

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,50 @@ jobs:
7878
path: dist
7979
name: transformers_js_py-${{ github.ref_name }}.tgz
8080

81+
test-pyodide-e2e:
82+
if: ${{ !failure() }} # `!failure()` is necessary to avoid skipping this job after successful build: https://github.com/actions/runner/issues/491
83+
needs: [test-and-build]
84+
85+
runs-on: ubuntu-latest
86+
87+
steps:
88+
- uses: actions/checkout@v3
89+
90+
- name: Set up Python ${{ env.python-version }}
91+
uses: actions/setup-python@v4
92+
with:
93+
python-version: ${{ env.python-version }}
94+
95+
# Copied from https://github.com/python-poetry/poetry/blob/c71deb4b75b3672116b3199b2f9ab7e2bf520844/.github/workflows/main.yml#L46-L96
96+
- name: Get full Python version
97+
id: full-python-version
98+
run: echo version=$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))") >> $GITHUB_OUTPUT
99+
100+
- name: Bootstrap poetry
101+
run: |
102+
curl -sSL https://install.python-poetry.org | python - -y
103+
104+
- name: Update PATH
105+
run: echo "$HOME/.local/bin" >> $GITHUB_PATH
106+
107+
- uses: actions/download-artifact@v3
108+
with:
109+
name: transformers_js_py-${{ startsWith(github.ref, 'refs/tags/v') && github.ref_name || github.sha }}.tgz
110+
path: dist
111+
112+
- uses: pnpm/action-setup@v2
113+
with:
114+
version: 6.0.2
115+
run_install: |
116+
cwd: pyodide-e2e
117+
118+
- run: pnpm test
119+
working-directory: pyodide-e2e
120+
121+
81122
publish:
82123
if: ${{ !failure() && startsWith(github.ref, 'refs/tags/v') }} # `!failure()` is necessary to avoid skipping this job after successful build: https://github.com/actions/runner/issues/491
83-
needs: [test-and-build]
124+
needs: [test-pyodide-e2e]
84125

85126
permissions:
86127
contents: write # Necessary for creating releases: https://github.com/softprops/action-gh-release#permissions

pyodide-e2e/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@
88
"dev:front": "vite",
99
"dev:python": "chokidar \"../transformers_js/**/*.py\" --initial -c \"cd .. && poetry build\"",
1010
"build": "tsc && vite build",
11-
"preview": "vite preview"
11+
"preview": "vite preview",
12+
"test": "vitest"
1213
},
1314
"devDependencies": {
1415
"@types/node": "^20.4.3",
16+
"@xenova/transformers": "^2.4.2",
1517
"chokidar-cli": "^3.0.0",
1618
"npm-run-all": "^4.1.5",
19+
"pyodide": "^0.23.4",
1720
"typescript": "^5.0.2",
18-
"vite": "^4.4.0"
21+
"vite": "^4.4.0",
22+
"vitest": "^0.33.0"
1923
}
2024
}

0 commit comments

Comments
 (0)