From b4de4cbf478a4c124afde7506adabe2bdbd862a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AD=94=E7=8E=8B=E5=B0=91=E5=B9=B4?= Date: Fri, 8 Nov 2024 05:56:29 +0800 Subject: [PATCH] ci: add edge environment unit test (#55) --- .github/workflows/ci.yml | 54 ++++++++++++++++++++++++++-------------- package.json | 2 ++ pnpm-lock.yaml | 34 +++++++++++++++++++++---- 3 files changed, 66 insertions(+), 24 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8947554..fc68e75 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,46 +30,41 @@ jobs: - run: pnpm run typecheck - run: pnpm run lint - coverage: + unit-test-node: needs: - lint runs-on: ubuntu-latest + strategy: + matrix: + node-version: [18.x, 20.x, 22.x] steps: - uses: actions/checkout@v4 - run: corepack enable - - name: Use Node.js + - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v4 with: - node-version: 20 + node-version: ${{ matrix.node-version }} cache: pnpm - run: pnpm install --no-frozen-lockfile + - run: pnpm run test - - run: pnpm run coverage - - name: Upload coverage reports to Codecov - uses: codecov/codecov-action@v4 - with: - token: ${{ secrets.CODECOV_TOKEN }} - - unit-test: + unit-test-edge: needs: - - coverage + - lint runs-on: ubuntu-latest - strategy: - matrix: - node-version: [18.x, 20.x, 22.x] steps: - uses: actions/checkout@v4 - run: corepack enable - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v4 + - uses: actions/setup-node@v4 with: - node-version: ${{ matrix.node-version }} + node-version: 20 cache: pnpm - run: pnpm install --no-frozen-lockfile - - - run: pnpm run test + - run: pnpm run test:edge jsr-dry-run: + needs: + - lint runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -80,3 +75,24 @@ jobs: cache: pnpm - run: pnpm install - run: pnpm exec jsr publish --dry-run + + coverage: + needs: + - unit-test-node + - jsr-dry-run + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - run: corepack enable + - name: Use Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: pnpm + - run: pnpm install --no-frozen-lockfile + + - run: pnpm run coverage + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/package.json b/package.json index 1d6f44b..96a2583 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "lint": "eslint --quiet .", "test": "vitest run", "test:watch": "vitest", + "test:edge": "vitest run --environment edge-runtime", "coverage": "vitest run --coverage" }, "peerDependencies": { @@ -58,6 +59,7 @@ "defu": "^6.1.4" }, "devDependencies": { + "@edge-runtime/vm": "^4.0.4", "@eslint/js": "^9.5.0", "@types/node": "^20.14.2", "@vitest/coverage-v8": "^2.1.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9616771..4e1b8d8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11,6 +11,9 @@ importers: specifier: ^6.1.4 version: 6.1.4 devDependencies: + "@edge-runtime/vm": + specifier: ^4.0.4 + version: 4.0.4 "@eslint/js": specifier: ^9.5.0 version: 9.6.0 @@ -19,7 +22,7 @@ importers: version: 20.14.10 "@vitest/coverage-v8": specifier: ^2.1.3 - version: 2.1.3(vitest@2.1.3(@types/node@20.14.10)) + version: 2.1.3(vitest@2.1.3(@edge-runtime/vm@4.0.4)(@types/node@20.14.10)) eslint: specifier: ^8.57.0 version: 8.57.0 @@ -55,7 +58,7 @@ importers: version: 7.15.0(eslint@8.57.0)(typescript@5.5.3) vitest: specifier: ^2.1.3 - version: 2.1.3(@types/node@20.14.10) + version: 2.1.3(@edge-runtime/vm@4.0.4)(@types/node@20.14.10) packages: "@ampproject/remapping@2.3.0": @@ -100,6 +103,20 @@ packages: integrity: sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==, } + "@edge-runtime/primitives@5.1.1": + resolution: + { + integrity: sha512-osrHE4ObQ3XFkvd1sGBLkheV2mcHUqJI/Bum2AWA0R3U78h9lif3xZAdl6eLD/XnW4xhsdwjPUejLusXbjvI4Q==, + } + engines: { node: ">=16" } + + "@edge-runtime/vm@4.0.4": + resolution: + { + integrity: sha512-LqPw+yaSPpCNnVZl5XoHQAySEzlnZiC9gReUuQHMh9GI03KKqwpVqWkIK1UfK116Yww7f2WZuAgnY/nhHwTsJA==, + } + engines: { node: ">=16" } + "@esbuild/aix-ppc64@0.21.5": resolution: { @@ -2623,6 +2640,12 @@ snapshots: "@bcoe/v8-coverage@0.2.3": {} + "@edge-runtime/primitives@5.1.1": {} + + "@edge-runtime/vm@4.0.4": + dependencies: + "@edge-runtime/primitives": 5.1.1 + "@esbuild/aix-ppc64@0.21.5": optional: true @@ -2911,7 +2934,7 @@ snapshots: "@ungap/structured-clone@1.2.0": {} - "@vitest/coverage-v8@2.1.3(vitest@2.1.3(@types/node@20.14.10))": + "@vitest/coverage-v8@2.1.3(vitest@2.1.3(@edge-runtime/vm@4.0.4)(@types/node@20.14.10))": dependencies: "@ampproject/remapping": 2.3.0 "@bcoe/v8-coverage": 0.2.3 @@ -2925,7 +2948,7 @@ snapshots: std-env: 3.7.0 test-exclude: 7.0.1 tinyrainbow: 1.2.0 - vitest: 2.1.3(@types/node@20.14.10) + vitest: 2.1.3(@edge-runtime/vm@4.0.4)(@types/node@20.14.10) transitivePeerDependencies: - supports-color @@ -3949,7 +3972,7 @@ snapshots: "@types/node": 20.14.10 fsevents: 2.3.3 - vitest@2.1.3(@types/node@20.14.10): + vitest@2.1.3(@edge-runtime/vm@4.0.4)(@types/node@20.14.10): dependencies: "@vitest/expect": 2.1.3 "@vitest/mocker": 2.1.3(@vitest/spy@2.1.3)(vite@5.4.7(@types/node@20.14.10)) @@ -3971,6 +3994,7 @@ snapshots: vite-node: 2.1.3(@types/node@20.14.10) why-is-node-running: 2.3.0 optionalDependencies: + "@edge-runtime/vm": 4.0.4 "@types/node": 20.14.10 transitivePeerDependencies: - less