From c4ecac608f2f37c6d9626ec2268e129ead8470ab Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Sun, 3 Dec 2023 23:04:16 +0800 Subject: [PATCH] test: use vitest beta (#475) --- .github/workflows/nodejs.yml | 3 +- .github/workflows/release.yml | 2 -- package.json | 58 ++++++++++++++++++----------------- scripts/pre_test.js | 15 +++++++++ vite.config.ts | 5 +++ 5 files changed, 51 insertions(+), 32 deletions(-) create mode 100644 scripts/pre_test.js diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index b06328ac..80eae696 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -7,8 +7,6 @@ on: pull_request: branches: [ master ] - workflow_dispatch: {} - jobs: Job: name: Node.js @@ -16,3 +14,4 @@ jobs: with: os: 'ubuntu-latest, macos-latest, windows-latest' version: '14.19.3, 14, 16, 18, 20' + install: 'npx npminstall' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a4e1158f..1c6cbb18 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,5 +11,3 @@ jobs: secrets: NPM_TOKEN: ${{ secrets.NPM_TOKEN }} GIT_TOKEN: ${{ secrets.GIT_TOKEN }} - with: - checkTest: false diff --git a/package.json b/package.json index 8d7581c8..e2b0d0b6 100644 --- a/package.json +++ b/package.json @@ -18,30 +18,6 @@ ], "author": "fengmk2 (https://github.com/fengmk2)", "homepage": "https://github.com/node-modules/urllib", - "type": "module", - "tshy": { - "exports": { - ".": "./src/index.ts", - "./package.json": "./package.json" - } - }, - "exports": { - ".": { - "import": { - "types": "./dist/esm/index.d.ts", - "default": "./dist/esm/index.js" - }, - "require": { - "types": "./dist/commonjs/index.d.ts", - "default": "./dist/commonjs/index.js" - } - }, - "./package.json": "./package.json" - }, - "files": [ - "dist", - "src" - ], "repository": { "type": "git", "url": "git://github.com/node-modules/urllib.git" @@ -62,6 +38,7 @@ "test": "npm run lint && vitest run", "test-keepalive": "cross-env TEST_KEEPALIVE_COUNT=50 vitest run --test-timeout 180000 keep-alive-header.test.ts", "cov": "vitest run --coverage", + "preci": "node scripts/pre_test.js", "ci": "npm run lint && npm run cov && node scripts/build_test.js", "contributor": "git-contributor", "clean": "rm -rf dist", @@ -91,7 +68,7 @@ "@types/qs": "^6.9.7", "@types/selfsigned": "^2.0.1", "@types/tar-stream": "^2.2.2", - "@vitest/coverage-v8": "^0.32.0", + "@vitest/coverage-v8": "beta", "busboy": "^1.6.0", "cross-env": "^7.0.3", "eslint": "^8.25.0", @@ -101,14 +78,39 @@ "proxy": "^1.0.2", "selfsigned": "^2.0.1", "tar-stream": "^2.2.0", - "tshy": "^1.0.0-3", + "tshy": "^1.0.0", "tshy-after": "^1.0.0", "typescript": "^5.0.4", - "vitest": "^0.32.0" + "vitest": "beta" }, "engines": { "node": ">= 14.19.3" }, "license": "MIT", - "types": "./dist/commonjs/index.d.ts" + "type": "module", + "tshy": { + "exports": { + ".": "./src/index.ts", + "./package.json": "./package.json" + } + }, + "exports": { + ".": { + "import": { + "types": "./dist/esm/index.d.ts", + "default": "./dist/esm/index.js" + }, + "require": { + "types": "./dist/commonjs/index.d.ts", + "default": "./dist/commonjs/index.js" + } + }, + "./package.json": "./package.json" + }, + "files": [ + "dist", + "src" + ], + "types": "./dist/commonjs/index.d.ts", + "main": "./dist/commonjs/index.js" } diff --git a/scripts/pre_test.js b/scripts/pre_test.js new file mode 100644 index 00000000..239ffd40 --- /dev/null +++ b/scripts/pre_test.js @@ -0,0 +1,15 @@ +import { execSync } from 'child_process'; + +function main() { + if (!process.version.startsWith('v14.')) { + return; + } + console.log(`use vitest@^0.32.0 on Node.js ${process.version}`); + const cwd = process.cwd() + execSync('npm i vitest@^0.32.0 @vitest/coverage-v8@^0.32.0', { + cwd, + stdio: [ 'inherit', 'inherit', 'inherit' ], + }); +} + +main(); diff --git a/vite.config.ts b/vite.config.ts index 10a33e3d..188f19ce 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -6,5 +6,10 @@ export default defineConfig({ 'test/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}', ], testTimeout: 60000, + coverage: { + include: [ + 'src', + ], + }, }, });