Skip to content
Closed
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
17 changes: 6 additions & 11 deletions .github/workflows/codspeed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,15 @@ jobs:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7

- name: Install pnpm
uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86 # v6

- name: Set up Node.js
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7
- name: Setup Vite+
uses: voidzero-dev/setup-vp@9fd26ff49f9b5e6276c2b493da4454ad4527f7f4 # main
with:
node-version: '22'
cache: 'pnpm'

- name: Install dependencies
run: pnpm install --frozen-lockfile
node-version: '^24.11.0'
cache: true
sfw: false

- name: Run benchmarks
uses: CodSpeedHQ/action@v5
with:
mode: simulation
run: pnpm vitest bench --run
run: vp run bench
10 changes: 5 additions & 5 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ jobs:
- name: Setup Vite+
uses: voidzero-dev/setup-vp@9fd26ff49f9b5e6276c2b493da4454ad4527f7f4 # main
with:
node-version: '24'
node-version: '^24.11.0'
cache: true
sfw: true
sfw: false

- name: Check
run: vp run check
Expand All @@ -34,14 +34,14 @@ jobs:
run: vp run typecheck

- name: Run build check
run: vp run build
run: vp run build:test

test:
strategy:
fail-fast: false
matrix:
os: ['ubuntu-latest', 'macos-latest', 'windows-latest']
node: ['22', '24', '26']
node: ['^22.19.0', '^24.11.0', '^26.0.0']

name: Test (${{ matrix.os }}, ${{ matrix.node }})
runs-on: ${{ matrix.os }}
Expand All @@ -62,7 +62,7 @@ jobs:
with:
node-version: ${{ matrix.node }}
cache: true
sfw: true
sfw: false

- name: Run tests
run: vp run ci
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pkg.pr.new.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
with:
node-version: 22
cache: true
sfw: true
sfw: false

- name: Build
run: vp run build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ jobs:
# Node 24 bundles npm >= 11.5.1, required for OIDC trusted publishing.
node-version: '24'
cache: true
sfw: true
sfw: false

- name: Determine npm dist-tag
id: dist-tag
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ test/fixtures/ts-esm/*.js
.eslintcache
.tshy*
.idea/
.vitest/
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
24.21.0
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# vite-plus preview build registry bridge (auto-added by vp)
registry=https://registry-bridge.viteplus.dev/
9 changes: 9 additions & 0 deletions .vite-plus/migrations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"version": 1,
"vitest5": {
".": {
"sourceVersion": "4.1.11",
"configless": false
}
}
}
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@
"build:mts:test": "cd test/mts && rm -rf node_modules && npm link ../.. && tsc",
"build:test": "vp run build && vp run build:cjs:test && vp run build:esm:test && vp run build:mts:test && vp run test-tsc",
"test-tsc": "vp run test-tsc:cjs:es2021 && vp run test-tsc:cjs && vp run test-tsc:esm",
"test-tsc:cjs": "cd test/fixtures/ts && rm -rf node_modules && npm link ../../.. && vp run build",
"test-tsc:cjs:es2021": "cd test/fixtures/ts-cjs-es2021 && rm -rf node_modules && npm link ../../.. && vp run build",
"test-tsc:esm": "cd test/fixtures/ts-esm && rm -rf node_modules && npm link ../../.. && vp run build",
"test-tsc:cjs": "cd test/fixtures/ts && rm -rf node_modules && npm link ../../.. && tsc && node hello.js",
"test-tsc:cjs:es2021": "cd test/fixtures/ts-cjs-es2021 && rm -rf node_modules && npm link ../../.. && tsc && node hello.js",
"test-tsc:esm": "cd test/fixtures/ts-esm && rm -rf node_modules && npm link ../../.. && tsc && node hello.js",
"test": "vp run check && vp test run --reporter=dot",
"bench": "vp test bench",
"bench": "cross-env TEST_BENCHMARK=1 vp test run test/urllib.bench.ts",
"test-keepalive": "cross-env TEST_KEEPALIVE_COUNT=50 vp test run --reporter=dot --test-timeout 180000 keep-alive-header.test.ts",
"cov": "vp test run --reporter=dot --coverage",
"ci": "vp run cov && vp run prepublishOnly && npm pack && attw --pack",
Expand Down
1,111 changes: 538 additions & 573 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ minimumReleaseAgeExclude:
- vite-plus
- '@vitest/*'
- undici
- vitest@5.0.1
overrides:
vite@*: 'catalog:'
vitest@*: 'catalog:'
Expand All @@ -14,7 +15,7 @@ peerDependencyRules:
vite: '*'
vitest: '*'
catalog:
vite: npm:@voidzero-dev/vite-plus-core@0.3.2
vitest: 4.1.11
vite-plus: 0.3.2
'@vitest/coverage-v8': 4.1.11
vite: npm:@voidzero-dev/vite-plus-core@0.0.0-commit.26a6dfe55eadd10931a3f7c38d30a900292ffeed
vitest: 5.0.1
vite-plus: 0.0.0-commit.26a6dfe55eadd10931a3f7c38d30a900292ffeed
'@vitest/coverage-v8': 5.0.1
8 changes: 2 additions & 6 deletions test/fixtures/ts-cjs-es2021/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
"compilerOptions": {
"strict": true,
"target": "ES2021",
"module": "CommonJS",
"moduleResolution": "Node",
"baseUrl": "./",
"paths": {
"urllib": ["../../.."]
}
"module": "Node16",
"moduleResolution": "Node16"
}
}
6 changes: 1 addition & 5 deletions test/fixtures/ts-esm/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
"strict": true,
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"baseUrl": "./",
"paths": {
"urllib": ["../../.."]
}
"moduleResolution": "NodeNext"
}
}
8 changes: 2 additions & 6 deletions test/fixtures/ts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
"compilerOptions": {
"strict": true,
"target": "ES2022",
"module": "CommonJS",
"moduleResolution": "Node",
"baseUrl": "./",
"paths": {
"urllib": ["../../.."]
}
"module": "Node16",
"moduleResolution": "Node16"
}
}
3 changes: 1 addition & 2 deletions test/mts/src/index.mts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// @ts-expect-error ignore type error
import { request, IncomingHttpHeaders } from 'urllib';
const responseObj = await request('test');

type IsAny<T, Y, N> = 0 extends 1 & T ? Y : N;
(x: IsAny<number, true, never>) => x; // never
(x: IsAny<any, true, never>) => x; // true

(x: IsAny<typeof responseObj, true, never>) => x; // true
(x: IsAny<typeof responseObj, true, never>) => x; // never
console.log(responseObj.headers as IncomingHttpHeaders);
78 changes: 48 additions & 30 deletions test/urllib.bench.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
import { bench, describe } from 'vite-plus/test';
import { describe, test } from 'vite-plus/test';

import { HttpClient } from '../src/index.js';
import { parseJSON, digestAuthHeader, globalId, performanceTime } from '../src/utils.js';

describe('HttpClient Benchmarks', () => {
bench('create HttpClient instance', () => {
new HttpClient();
test('create HttpClient instance', async ({ bench }) => {
await bench('create HttpClient instance', () => {
new HttpClient();
}).run();
});

bench('create HttpClient with defaultArgs', () => {
new HttpClient({
defaultArgs: {
timeout: 30000,
headers: {
'x-custom-header': 'benchmark',
test('create HttpClient with defaultArgs', async ({ bench }) => {
await bench('create HttpClient with defaultArgs', () => {
new HttpClient({
defaultArgs: {
timeout: 30000,
headers: {
'x-custom-header': 'benchmark',
},
},
},
});
});
}).run();
});

bench('create HttpClient with connect options', () => {
new HttpClient({
connect: {
timeout: 10000,
rejectUnauthorized: true,
},
});
test('create HttpClient with connect options', async ({ bench }) => {
await bench('create HttpClient with connect options', () => {
new HttpClient({
connect: {
timeout: 10000,
rejectUnauthorized: true,
},
});
}).run();
});
});

Expand All @@ -35,30 +41,42 @@ describe('Utility Functions Benchmarks', () => {
items: Array.from({ length: 100 }, (_, i) => ({ id: i, name: `item-${i}` })),
});

bench('parseJSON - small object', () => {
parseJSON(jsonString);
test('parseJSON - small object', async ({ bench }) => {
await bench('parseJSON - small object', () => {
parseJSON(jsonString);
}).run();
});

bench('parseJSON - large array', () => {
parseJSON(largeJsonString);
test('parseJSON - large array', async ({ bench }) => {
await bench('parseJSON - large array', () => {
parseJSON(largeJsonString);
}).run();
});

bench('parseJSON with fixJSONCtlChars', () => {
parseJSON(jsonString, true);
test('parseJSON with fixJSONCtlChars', async ({ bench }) => {
await bench('parseJSON with fixJSONCtlChars', () => {
parseJSON(jsonString, true);
}).run();
});

const wwwAuthenticate =
'Digest realm="testrealm@host.com", qop="auth,auth-int", nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", opaque="5ccc069c403ebaf9f0171e9517f40e41"';

bench('digestAuthHeader', () => {
digestAuthHeader('GET', '/api/resource', wwwAuthenticate, 'user:password');
test('digestAuthHeader', async ({ bench }) => {
await bench('digestAuthHeader', () => {
digestAuthHeader('GET', '/api/resource', wwwAuthenticate, 'user:password');
}).run();
});

bench('globalId', () => {
globalId('benchmark');
test('globalId', async ({ bench }) => {
await bench('globalId', () => {
globalId('benchmark');
}).run();
});

bench('performanceTime', () => {
performanceTime(performance.now() - 100);
test('performanceTime', async ({ bench }) => {
await bench('performanceTime', () => {
performanceTime(performance.now() - 100);
}).run();
});
});
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
// verbatimModuleSyntax is incompatible with multi-dialect builds
// "verbatimModuleSyntax": true
},
"exclude": ["test/fixtures/ts*", "*.config.ts"]
"exclude": ["test/fixtures/ts*", "test/mts", "*.config.ts"]
}
6 changes: 5 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,17 @@ export default defineConfig({
'arrow-body-style': 'allow',
'prefer-destructuring': 'allow',
},
ignorePatterns: ['test/fixtures/ts*'],
ignorePatterns: ['test/fixtures/ts*', 'test/mts'],
},
// plugins: [codspeedPlugin()],
test: {
clearMocks: false,
include: ['test/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
setupFiles: ['./test/setup.ts'],
testTimeout: 60000,
benchmark: {
enabled: process.env.TEST_BENCHMARK === '1',
},
coverage: {
include: ['src'],
},
Expand Down
Loading