Skip to content

Commit 47ac3bc

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

File tree

15 files changed

+806
-1914
lines changed

15 files changed

+806
-1914
lines changed

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 --experimental-test-coverage --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-integration/cjs-project/import.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ const assert = require('node:assert/strict');
44
const { DockerClient } = require('@docker/node-sdk');
55

66
test('CJS module should import correctly', () => {
7-
assert.equal(typeof DockerClient, 'function');
8-
assert.equal(typeof DockerClient.fromDockerConfig, 'function');
7+
assert.strictEqual(typeof DockerClient, 'function');
8+
assert.strictEqual(typeof DockerClient.fromDockerConfig, 'function');
99
});
1010

1111
test('CJS module should import functional client', async () => {
1212
const docker = await DockerClient.fromDockerConfig();
1313
const apiVersion = await docker.systemPing();
14-
assert.ok(apiVersion);
14+
assert.notStrictEqual(apiVersion, null);
1515
console.log(` Docker API version: ${apiVersion}`);
1616
});

test/build.test.ts

Lines changed: 52 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,64 @@
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.notStrictEqual(
45+
imageInspect.RepoTags?.includes(`${testImageName}:${testTag}`),
46+
false,
5147
);
48+
console.log(` Image size: ${imageInspect.Size} bytes`);
49+
} finally {
50+
// Clean up: delete the test image
51+
console.log(' Cleaning up test image...');
52+
try {
53+
await client.imageDelete(`${testImageName}:${testTag}`, {
54+
force: true,
55+
});
56+
console.log(' Test image deleted successfully');
57+
} catch (cleanupError) {
58+
console.log(
59+
` Warning: Failed to delete test image: ${(cleanupError as any)?.message}`,
60+
);
61+
}
5262
}
53-
}
54-
}, 60000); // 60 second timeout
63+
},
64+
);

test/concurrency.test.ts

Lines changed: 52 additions & 42 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.notStrictEqual(results[0], null); // systemPing result
27+
assert.notStrictEqual(results[1], null); // systemInfo result
28+
assert.notStrictEqual(results[2], null); // systemVersion result
29+
assert.notStrictEqual(results[3], null); // containerList result
30+
assert.notStrictEqual(results[4], null); // 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,24 @@ 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.notStrictEqual(
57+
result,
58+
null,
59+
`Request ${index} should return a result`,
60+
);
5261
});
5362

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

5766
// All requests should complete within reasonable time
58-
assert.isTrue(
67+
assert.ok(
5968
totalTime < 15000,
6069
'High concurrency requests should complete within reasonable time',
6170
);
62-
}, 20000);
71+
});
6372

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

6776
// Test different types of concurrent operations
@@ -86,17 +95,18 @@ test('mixed concurrent operations', async () => {
8695

8796
// Verify all requests completed successfully
8897
results.forEach((result, index) => {
89-
assert.isNotNull(
98+
assert.notStrictEqual(
9099
result,
100+
null,
91101
`Mixed operation ${index} should return a result`,
92102
);
93103
});
94104

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

97107
// Should handle mixed operations efficiently
98-
assert.isTrue(
108+
assert.ok(
99109
totalTime < 12000,
100110
'Mixed concurrent operations should complete efficiently',
101111
);
102-
}, 18000);
112+
});

0 commit comments

Comments
 (0)