Skip to content
Draft
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ src/**/*.d.ts
test/fixtures/ts-esm/*.js
.eslintcache
.idea/
.vitest/
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/
1,306 changes: 640 additions & 666 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,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.7aaf0908b976917d9dd32a3a6c8e740ad2cb151d
vitest: 5.0.1
vite-plus: 0.0.0-commit.7aaf0908b976917d9dd32a3a6c8e740ad2cb151d
'@vitest/coverage-v8': 5.0.1
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 { test, describe } 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();
});
});
11 changes: 5 additions & 6 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@
import { defineConfig } from 'vite-plus';

export default defineConfig({
pack: {
entry: ['src/index.ts'],
format: 'esm',
dts: true,
sourcemap: true,
},
pack: { deps: { resolveDepSubpath: true }, entry: ['src/index.ts'], format: 'esm', dts: true, sourcemap: true },
staged: {
'*': 'vp check --fix',
},
Expand Down Expand Up @@ -162,6 +157,10 @@ export default defineConfig({
},
// plugins: [codspeedPlugin()],
test: {
// Vitest v4 compatibility: preserve mock call history.
// Remove after tests no longer rely on calls from setup or earlier tests.
// https://vitest.dev/guide/migration/#clearmocks-is-enabled-by-default
clearMocks: false,
include: ['test/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
setupFiles: ['./test/setup.ts'],
testTimeout: 60000,
Expand Down
Loading