Skip to content

Commit 9335c92

Browse files
committed
prefer node:test
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
1 parent 57f4662 commit 9335c92

14 files changed

Lines changed: 762 additions & 1893 deletions

package-lock.json

Lines changed: 27 additions & 1215 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"scripts": {
4141
"generate": "openapi-generator-cli generate -i swagger.yaml -c openapi-config.yaml -o lib && npm run format.types",
4242
"build": "npm run generate && tsdown",
43-
"test": "vitest run --coverage",
43+
"test": "node --import tsx --test 'test/**/*.test.ts'",
4444
"typecheck": "tsc --noEmit",
4545
"lint": "oxlint --type-aware",
4646
"format": "prettier --write .",
@@ -57,13 +57,12 @@
5757
"@types/node": "^24.5.2",
5858
"@types/ssh2": "^1.15.5",
5959
"@types/tar-stream": "^3.1.4",
60-
"@vitest/coverage-v8": "^3.2.4",
6160
"oxlint": "^1.16.0",
6261
"oxlint-tsgolint": "^0.2.0",
6362
"prettier": "^3.6.2",
6463
"tsdown": "^0.15.6",
65-
"typescript": "^5.9.2",
66-
"vitest": "^3.2.4"
64+
"tsx": "^4.20.6",
65+
"typescript": "^5.9.2"
6766
},
6867
"engines": {
6968
"node": "^18.0.0 || ^20.0.0 || >=22.0.0"

test/build.test.ts

Lines changed: 51 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,63 @@
1-
import { expect, test } from 'vitest';
1+
import { test } from 'node:test';
2+
import assert from 'node:assert/strict';
23
import { DockerClient } from '../lib/docker-client.js';
34
import { pack as createTarPack } from 'tar-stream';
45
import { Readable } from 'node:stream';
56

6-
test('imageBuild: build image from Dockerfile with tar-stream context', async () => {
7-
const client = await DockerClient.fromDockerConfig();
8-
const testImageName = 'test-build-image';
9-
const testTag = 'latest';
7+
test(
8+
'imageBuild: build image from Dockerfile with tar-stream context',
9+
{ timeout: 60000 },
10+
async () => {
11+
const client = await DockerClient.fromDockerConfig();
12+
const testImageName = 'test-build-image';
13+
const testTag = 'latest';
1014

11-
try {
12-
const pack = createTarPack();
13-
pack.entry(
14-
{ name: 'Dockerfile' },
15-
`FROM scratch
15+
try {
16+
const pack = createTarPack();
17+
pack.entry(
18+
{ name: 'Dockerfile' },
19+
`FROM scratch
1620
COPY test.txt /test.txt
1721
`,
18-
);
19-
pack.entry({ name: 'test.txt' }, 'Hello from Docker build test!');
20-
pack.finalize();
22+
);
23+
pack.entry({ name: 'test.txt' }, 'Hello from Docker build test!');
24+
pack.finalize();
2125

22-
const builtImage = await client
23-
.imageBuild(
24-
Readable.toWeb(pack, { strategy: { highWaterMark: 16384 } }),
25-
{
26-
tag: `${testImageName}:${testTag}`,
27-
rm: true,
28-
forcerm: true,
29-
},
30-
)
31-
.wait();
26+
const builtImage = await client
27+
.imageBuild(
28+
Readable.toWeb(pack, {
29+
strategy: { highWaterMark: 16384 },
30+
}),
31+
{
32+
tag: `${testImageName}:${testTag}`,
33+
rm: true,
34+
forcerm: true,
35+
},
36+
)
37+
.wait();
3238

33-
// Inspect the built builtImage to confirm it was created successfully
34-
console.log(` Inspecting built image ${builtImage}`);
35-
const imageInspect = await client.imageInspect(builtImage || '');
36-
console.log(' Image found! Build was successful.');
39+
// Inspect the built builtImage to confirm it was created successfully
40+
console.log(` Inspecting built image ${builtImage}`);
41+
const imageInspect = await client.imageInspect(builtImage || '');
42+
console.log(' Image found! Build was successful.');
3743

38-
expect(imageInspect.RepoTags).toContain(`${testImageName}:${testTag}`);
39-
console.log(` Image size: ${imageInspect.Size} bytes`);
40-
} finally {
41-
// Clean up: delete the test image
42-
console.log(' Cleaning up test image...');
43-
try {
44-
await client.imageDelete(`${testImageName}:${testTag}`, {
45-
force: true,
46-
});
47-
console.log(' Test image deleted successfully');
48-
} catch (cleanupError) {
49-
console.log(
50-
` Warning: Failed to delete test image: ${(cleanupError as any)?.message}`,
44+
assert.ok(
45+
imageInspect.RepoTags?.includes(`${testImageName}:${testTag}`),
5146
);
47+
console.log(` Image size: ${imageInspect.Size} bytes`);
48+
} finally {
49+
// Clean up: delete the test image
50+
console.log(' Cleaning up test image...');
51+
try {
52+
await client.imageDelete(`${testImageName}:${testTag}`, {
53+
force: true,
54+
});
55+
console.log(' Test image deleted successfully');
56+
} catch (cleanupError) {
57+
console.log(
58+
` Warning: Failed to delete test image: ${(cleanupError as any)?.message}`,
59+
);
60+
}
5261
}
53-
}
54-
}, 60000); // 60 second timeout
62+
},
63+
);

test/concurrency.test.ts

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,46 @@
1-
import { assert, test } from 'vitest';
1+
import { test } from 'node:test';
2+
import assert from 'node:assert/strict';
23
import { DockerClient } from '../lib/docker-client.js';
34

4-
test('concurrent requests should execute in parallel', async () => {
5-
const client = await DockerClient.fromDockerConfig();
6-
const startTime = Date.now();
7-
8-
// Make 5 concurrent API calls
9-
const promises = [
10-
client.systemPing(),
11-
client.systemInfo(),
12-
client.systemVersion(),
13-
client.containerList({ all: true }),
14-
client.imageList(),
15-
];
16-
17-
// Execute all requests concurrently
18-
const results = await Promise.all(promises);
19-
const totalTime = Date.now() - startTime;
20-
21-
// Verify all requests completed successfully
22-
assert.isNotNull(results[0]); // systemPing result
23-
assert.isNotNull(results[1]); // systemInfo result
24-
assert.isNotNull(results[2]); // systemVersion result
25-
assert.isNotNull(results[3]); // containerList result
26-
assert.isNotNull(results[4]); // imageList result
27-
28-
console.log(` Completed 5 concurrent requests in ${totalTime}ms`);
29-
30-
// Concurrent requests should be faster than sequential ones
31-
// This is a rough check - concurrent should typically be < 80% of sequential time
32-
assert.isTrue(
33-
totalTime < 10000,
34-
'Concurrent requests should complete within reasonable time',
35-
);
36-
}, 15000);
5+
test(
6+
'concurrent requests should execute in parallel',
7+
{ timeout: 15000 },
8+
async () => {
9+
const client = await DockerClient.fromDockerConfig();
10+
const startTime = Date.now();
11+
12+
// Make 5 concurrent API calls
13+
const promises = [
14+
client.systemPing(),
15+
client.systemInfo(),
16+
client.systemVersion(),
17+
client.containerList({ all: true }),
18+
client.imageList(),
19+
];
20+
21+
// Execute all requests concurrently
22+
const results = await Promise.all(promises);
23+
const totalTime = Date.now() - startTime;
24+
25+
// Verify all requests completed successfully
26+
assert.ok(results[0]); // systemPing result
27+
assert.ok(results[1]); // systemInfo result
28+
assert.ok(results[2]); // systemVersion result
29+
assert.ok(results[3]); // containerList result
30+
assert.ok(results[4]); // imageList result
31+
32+
console.log(` Completed 5 concurrent requests in ${totalTime}ms`);
33+
34+
// Concurrent requests should be faster than sequential ones
35+
// This is a rough check - concurrent should typically be < 80% of sequential time
36+
assert.ok(
37+
totalTime < 10000,
38+
'Concurrent requests should complete within reasonable time',
39+
);
40+
},
41+
);
3742

38-
test('high concurrency stress test', async () => {
43+
test('high concurrency stress test', { timeout: 20000 }, async () => {
3944
const client = await DockerClient.fromDockerConfig();
4045
const startTime = Date.now();
4146

@@ -48,20 +53,20 @@ test('high concurrency stress test', async () => {
4853

4954
// Verify all requests completed successfully
5055
results.forEach((result, index) => {
51-
assert.isNotNull(result, `Request ${index} should return a result`);
56+
assert.ok(result, `Request ${index} should return a result`);
5257
});
5358

5459
console.log(` Completed 20 concurrent ping requests in ${totalTime}ms`);
5560
console.log(` Average time per request: ${(totalTime / 20).toFixed(1)}ms`);
5661

5762
// All requests should complete within reasonable time
58-
assert.isTrue(
63+
assert.ok(
5964
totalTime < 15000,
6065
'High concurrency requests should complete within reasonable time',
6166
);
62-
}, 20000);
67+
});
6368

64-
test('mixed concurrent operations', async () => {
69+
test('mixed concurrent operations', { timeout: 18000 }, async () => {
6570
const client = await DockerClient.fromDockerConfig();
6671

6772
// Test different types of concurrent operations
@@ -86,17 +91,14 @@ test('mixed concurrent operations', async () => {
8691

8792
// Verify all requests completed successfully
8893
results.forEach((result, index) => {
89-
assert.isNotNull(
90-
result,
91-
`Mixed operation ${index} should return a result`,
92-
);
94+
assert.ok(result, `Mixed operation ${index} should return a result`);
9395
});
9496

9597
console.log(` Completed 10 mixed concurrent operations in ${totalTime}ms`);
9698

9799
// Should handle mixed operations efficiently
98-
assert.isTrue(
100+
assert.ok(
99101
totalTime < 12000,
100102
'Mixed concurrent operations should complete efficiently',
101103
);
102-
}, 18000);
104+
});

0 commit comments

Comments
 (0)