Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: use vitest@3 #570

Merged
merged 4 commits into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
[![Test coverage][codecov-image]][codecov-url]
[![Known Vulnerabilities][snyk-image]][snyk-url]
[![npm download][download-image]][download-url]
[![Node.js Version](https://img.shields.io/node/v/urllib.svg?style=flat)](https://nodejs.org/en/download/)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://makeapullrequest.com)
![CodeRabbit Pull Request Reviews](https://img.shields.io/coderabbit/prs/github/node-modules/urllib)

[npm-image]: https://img.shields.io/npm/v/urllib.svg?style=flat-square
[npm-url]: https://npmjs.org/package/urllib
Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
"test-tsc:cjs": "cd test/fixtures/ts && rm -rf node_modules && npm link ../../.. && npm run build",
"test-tsc:cjs:es2021": "cd test/fixtures/ts-cjs-es2021 && rm -rf node_modules && npm link ../../.. && npm run build",
"test-tsc:esm": "cd test/fixtures/ts-esm && rm -rf node_modules && npm link ../../.. && npm run build",
"test": "npm run lint && vitest run",
"test": "npm run lint -- --fix && vitest run",
"test-keepalive": "cross-env TEST_KEEPALIVE_COUNT=50 vitest run --test-timeout 180000 keep-alive-header.test.ts",
"test-node16": "node examples/httpclient.cjs && node examples/search_github.cjs && node examples/timing.cjs",
"cov": "vitest run --coverage",
"cov": "cross-env NODE_OPTIONS='--require ./test/patch-structuredClone.cjs' vitest run --coverage",
"ci": "npm run lint && npm run cov && npm run prepublishOnly && npm pack && attw --pack",
"clean": "rm -rf dist",
"prepublishOnly": "npm run build"
Expand All @@ -54,7 +54,7 @@
"ylru": "^2.0.0"
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.17.0",
"@arethetypeswrong/cli": "^0.17.3",
"@eggjs/tsconfig": "^1.3.3",
"@tsconfig/node18": "^18.2.1",
"@tsconfig/strictest": "^2.0.2",
Expand All @@ -65,7 +65,8 @@
"@types/qs": "^6.9.7",
"@types/selfsigned": "^2.0.1",
"@types/tar-stream": "^2.2.2",
"@vitest/coverage-v8": "^2.0.0",
"@ungap/structured-clone": "^1.2.1",
"@vitest/coverage-v8": "^3.0.2",
"busboy": "^1.6.0",
"cross-env": "^7.0.3",
"eslint": "8",
Expand All @@ -77,7 +78,7 @@
"tshy": "^3.0.0",
"tshy-after": "^1.0.0",
"typescript": "^5.0.4",
"vitest": "^2.0.0"
"vitest": "^3.0.2"
},
"engines": {
"node": ">= 18.19.0"
Expand Down
12 changes: 6 additions & 6 deletions test/HttpClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import selfsigned from 'selfsigned';
import { HttpClient, RawResponseWithMeta, getGlobalDispatcher } from '../src/index.js';
import { startServer } from './fixtures/server.js';

const pems = selfsigned.generate();

if (process.env.ENABLE_PERF) {
const obs = new PerformanceObserver(items => {
items.getEntries().forEach(item => {
Expand Down Expand Up @@ -118,10 +120,9 @@ describe('HttpClient.test.ts', () => {
});

it.skipIf(process.version.startsWith('v16.'))('should not exit after other side closed error', async () => {
const pem = selfsigned.generate();
const server = createSecureServer({
key: pem.private,
cert: pem.cert,
key: pems.private,
cert: pems.cert,
});

let count = 0;
Expand Down Expand Up @@ -176,10 +177,9 @@ describe('HttpClient.test.ts', () => {
});

it('should auto redirect work', async () => {
const pem = selfsigned.generate();
const server = createSecureServer({
key: pem.private,
cert: pem.cert,
key: pems.private,
cert: pems.cert,
});

let count = 0;
Expand Down
8 changes: 5 additions & 3 deletions test/options.timeout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { describe, it, beforeAll, afterAll } from 'vitest';
import urllib, { HttpClientRequestTimeoutError, HttpClient } from '../src/index.js';
import { startServer } from './fixtures/server.js';

const pems = selfsigned.generate();

describe('options.timeout.test.ts', () => {
let close: any;
let _url: string;
Expand Down Expand Up @@ -46,10 +48,10 @@ describe('options.timeout.test.ts', () => {
rejectUnauthorized: false,
},
});
const pem = selfsigned.generate();

const server = createSecureServer({
key: pem.private,
cert: pem.cert,
key: pems.private,
cert: pems.cert,
});

server.on('stream', () => {
Expand Down
7 changes: 7 additions & 0 deletions test/patch-structuredClone.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const structuredClone = require('@ungap/structured-clone').default;

// vitest require structuredClone
if (!('structuredClone' in globalThis)) {
globalThis.structuredClone = structuredClone;
// console.debug('patched structuredClone for Node.js %s', process.version);
}
2 changes: 1 addition & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default defineConfig({
},
pool: 'threads',
setupFiles: [
'test/setup.ts'
'test/setup.ts',
],
},
});
Loading