Skip to content

Commit

Permalink
test: add tests for CJS
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework committed Aug 26, 2022
1 parent 8771cbb commit 02eb856
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 8 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,16 @@ jobs:
- name: Test unit
run: pnpm run test-unit

- name: Test serve
- name: Test serve (ESM)
run: pnpm run test-serve

- name: Test build
- name: Test build (ESM)
run: pnpm run test-build

- name: Test serve (CJS)
if: ${{ matrix.node_version == 18 && matrix.os == 'ubuntu-latest' }}
run: pnpm run test-serve-cjs

- name: Test build (CJS)
if: ${{ matrix.node_version == 18 && matrix.os == 'ubuntu-latest' }}
run: pnpm run test-build-cjs
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
"test": "run-s test-unit test-serve test-build",
"test-unit": "vitest run",
"test-serve": "vitest run -c vitest.config.e2e.ts",
"test-build": "cross-env VITE_TEST_BUILD=1 vitest run -c vitest.config.e2e.ts",
"test-build": "cross-env-shell VITE_TEST_BUILD=1 vitest run -c vitest.config.e2e.ts",
"test-serve-cjs": "cross-env VITEST_TEST_CJS=1 pnpm run test-serve",
"test-build-cjs": "cross-env VITEST_TEST_CJS=1 pnpm run test-build",
"test-unit:watch": "vitest",
"changelog": "pnpm -r --filter=./packages/** run changelog",
"type-check": "pnpm -r --parallel --filter \"vite-plugin-checker\" exec tsc --noEmit",
Expand All @@ -43,7 +45,7 @@
"@types/debug": "^4.1.5",
"@types/fs-extra": "^9.0.11",
"@types/klaw": "^3.0.3",
"@types/node": "^15.0.0",
"@types/node": "^16.0.0",
"@types/prompts": "^2.0.13",
"@types/rimraf": "^3.0.0",
"@types/semver": "^7.3.6",
Expand All @@ -57,6 +59,7 @@
"eslint-config-alloy": "^4.5.1",
"eslint-plugin-svelte3": "^3.4.0",
"execa": "^5.1.1",
"fast-glob": "^3.2.7",
"fast-json-stable-stringify": "^2.1.0",
"fs-extra": "^10.0.0",
"jest-serializer-path": "^0.1.15",
Expand Down
1 change: 0 additions & 1 deletion packages/vite-plugin-checker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"types": "./dist/esm/main.d.ts",
"main": "./dist/cjs/main.js",
"type": "module",
"module": "./dist/esm/main.js",
"exports": {
".": {
"types": "./dist/esm/main.d.ts",
Expand Down
10 changes: 10 additions & 0 deletions playground/vitestGlobalSetup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from 'fs-extra'
import os from 'node:os'
import path from 'node:path'
import glob from 'fast-glob'
import { chromium } from 'playwright-chromium'

import type { BrowserServer } from 'playwright-chromium'
Expand Down Expand Up @@ -37,6 +38,15 @@ export async function setup(): Promise<void> {
throw error
}
})

if (process.env['VITEST_TEST_CJS']) {
const packageJsons = await glob(`${tempDir}/**/package.json`)
for (const packageJson of packageJsons) {
const packageJsonContents = await fs.readJson(packageJson)
delete packageJsonContents['module']
await fs.writeJson(packageJson, packageJsonContents, { spaces: 2 })
}
}
}

export async function teardown(): Promise<void> {
Expand Down
6 changes: 4 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vitest.config.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { resolve } from 'path'
import { defineConfig } from 'vitest/config'

const timeout = process.env.CI ? 50000 : 30000
const timeout = process.env.CI ? 80000 : 40000

export default defineConfig({
test: {
Expand Down

0 comments on commit 02eb856

Please sign in to comment.