Skip to content

Commit ba325b4

Browse files
committed
Test with Vitest: @ffmpeg/core in Node.js, @ffmpeg/ffmpeg and @ffmpeg/util in Chromium
- vitest.config.js has a project per package and core: core-st and core-mt run the core in Node.js, where exec() may block; browser-st and browser-mt run the FFmpeg class and util in cross-origin isolated Chromium (Vitest browser mode with Playwright) - tests/helpers: fixtures for a core or loaded FFmpeg per file and an empty directory per test, and a Vite plugin for HTTP edge cases - the core is also built for Node.js, and its ESM build is marked as a module - CI runs the core tests on Node.js 22, 24 and 26 and the browser tests once - the old mocha-headless-chrome suite is removed
1 parent 48df259 commit ba325b4

39 files changed

Lines changed: 411 additions & 613 deletions

‎.github/workflows/CI.yml‎

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,28 +56,55 @@ jobs:
5656
name: ffmpeg-core-mt
5757
path: packages/core-mt/dist/*
5858
tests:
59+
# Node 22 (the oldest LTS release), 24 and 26.
5960
runs-on: ubuntu-latest
60-
needs:
61-
- build-core
62-
- build-core-mt
61+
needs: [build-core, build-core-mt]
62+
strategy:
63+
matrix:
64+
node: [22, 24, 26]
6365
steps:
64-
- name: Checkout Source Code
65-
uses: actions/checkout@v2
66-
- name: Download ffmpeg-core
67-
uses: actions/download-artifact@v4
66+
- uses: actions/checkout@v4
67+
with:
68+
submodules: true
69+
- uses: actions/download-artifact@v4
70+
with:
71+
name: ffmpeg-core
72+
path: packages/core/dist
73+
- uses: actions/download-artifact@v4
74+
with:
75+
name: ffmpeg-core-mt
76+
path: packages/core-mt/dist
77+
- uses: pnpm/action-setup@v6
78+
- uses: actions/setup-node@v4
79+
with:
80+
node-version: ${{ matrix.node }}
81+
cache: pnpm
82+
- run: pnpm install --frozen-lockfile
83+
- run: pnpm test --project core-st --project core-mt
84+
browser:
85+
# @ffmpeg/ffmpeg and @ffmpeg/util in Chromium.
86+
runs-on: ubuntu-latest
87+
needs: [build-core, build-core-mt]
88+
strategy:
89+
matrix:
90+
node: [22, 24, 26]
91+
steps:
92+
- uses: actions/checkout@v4
93+
with:
94+
submodules: true
95+
- uses: actions/download-artifact@v4
6896
with:
6997
name: ffmpeg-core
7098
path: packages/core/dist
71-
- name: Download ffmpeg-core-mt
72-
uses: actions/download-artifact@v4
99+
- uses: actions/download-artifact@v4
73100
with:
74101
name: ffmpeg-core-mt
75102
path: packages/core-mt/dist
76103
- uses: pnpm/action-setup@v6
77-
- name: Use Node.js 24
78-
uses: actions/setup-node@v4
104+
- uses: actions/setup-node@v4
79105
with:
80-
node-version: 24.x
106+
node-version: ${{ matrix.node }}
81107
cache: pnpm
82-
- name: Install dependencies
83-
run: pnpm install --frozen-lockfile
108+
- run: pnpm install --frozen-lockfile
109+
- run: pnpm test:install
110+
- run: pnpm test --project browser-st --project browser-mt

‎Dockerfile‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ RUN mkdir -p /src/dist/umd && bash -x /src/build.sh \
198198
RUN mkdir -p /src/dist/esm && bash -x /src/build.sh \
199199
${FFMPEG_LIBS} \
200200
-sEXPORT_ES6 \
201-
-o dist/esm/ffmpeg-core.js
201+
-o dist/esm/ffmpeg-core.js && \
202+
echo '{"type": "module"}' > dist/esm/package.json
202203

203204
# Export ffmpeg-core.wasm to dist/, use `docker buildx build -o . .` to get assets
204205
FROM scratch AS exportor

‎apps/vanilla-app/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "browser example",
55
"private": true,
66
"scripts": {
7-
"download": "node ../../scripts/download-assets.js",
7+
"download": "node ../../scripts/download-assets.cjs",
88
"prestart": "pnpm download",
99
"start": "node server.js"
1010
},

‎build/ffmpeg-wasm.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ CONF_FLAGS=(
3030
-lswscale
3131
-Wno-deprecated-declarations
3232
$LDFLAGS
33-
-sENVIRONMENT=worker
33+
-sENVIRONMENT=web,worker,node # node: the core tests run in Node.js
3434
-sWASM_BIGINT # enable big int support
3535
-sDEFAULT_TO_CXX # x265, zimg and harfbuzz are C++
3636
-sUSE_SDL=2 # use emscripten SDL2 lib port

‎package.json‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "root",
33
"private": true,
4+
"type": "module",
45
"packageManager": "pnpm@12.6.0",
56
"engines": {
67
"node": ">=22"
@@ -10,9 +11,14 @@
1011
"build": "pnpm -r --filter './packages/*' build",
1112
"build:wasm": "bash scripts/build-wasm.sh",
1213
"prepublishOnly": "pnpm build",
13-
"postinstall": "pnpm build"
14+
"postinstall": "pnpm build",
15+
"pretest": "pnpm build",
16+
"test": "vitest run",
17+
"test:install": "playwright install --with-deps chromium"
1418
},
1519
"devDependencies": {
20+
"@ffmpeg/ffmpeg": "workspace:*",
21+
"@ffmpeg/util": "workspace:*",
1622
"@vitest/browser-playwright": "^5.0.2",
1723
"playwright": "^1.63.0",
1824
"vitest": "^5.0.2"

‎packages/util/tests/.eslintrc‎

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

‎packages/util/tests/constants.js‎

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

‎packages/util/tests/ffmpeg.test.html‎

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

‎packages/util/tests/ffmpeg.test.js‎

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

‎pnpm-lock.yaml‎

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)