Skip to content

Commit be2a887

Browse files
committed
fix: get images
1 parent 8e5c1da commit be2a887

File tree

6 files changed

+29
-8
lines changed

6 files changed

+29
-8
lines changed

jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
module.exports = {
33
preset: "ts-jest",
44
testEnvironment: "node",
5+
modulePaths: ["<rootDir>/src/tests"],
56
moduleNameMapper: {
67
"^@/(.*)$": "<rootDir>/src/$1",
78
},

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nerdctl",
3-
"version": "0.0.7",
3+
"version": "0.1.0",
44
"main": "dist/index.js",
55
"types": "dist/index.d.ts",
66
"description": "Node wrapper for nerdctl",

src/tests/container.test.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
1+
import { ChildProcess } from "child_process";
12
import { factory } from "..";
23

34
describe("container", () => {
45
const engine = factory();
56
const IMAGE = "hello-world";
67
const NAME = "hello";
78

8-
test("rm", async () => {
9-
await engine.run(IMAGE, { name: NAME, detach: true });
10-
const result = await engine.rm(NAME, { force: true });
9+
test("run", async () => {
10+
const result = (await engine.run(IMAGE, {
11+
name: NAME,
12+
detach: true,
13+
})) as ChildProcess;
14+
expect(result.exitCode).toBeNull();
15+
});
1116

12-
expect(result.code).toEqual(0);
17+
afterAll(() => {
18+
(async () => {
19+
await engine.rm(IMAGE);
20+
})();
1321
});
1422
});

src/vms/base.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ export default abstract class BaseBackend {
4545
if (flags) {
4646
for (const [key, value] of Object.entries(flags)) {
4747
const flag = `--${paramCase(key)}`;
48+
if (Array.isArray(value)) {
49+
value.forEach((val) => {
50+
flagParams.push(`${flag} ${val}`);
51+
});
52+
}
4853
if (typeof value === "boolean") {
4954
flagParams.push(flag);
5055
}

src/vms/lima.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,16 @@ export default class LimaBackend extends BaseBackend {
8484

8585
return new Promise((resolve, reject) => {
8686
if (!!child.exitCode) reject(null);
87+
88+
const images: ImageResult[] = [];
89+
8790
child.stdout!.on("data", (data) => {
88-
if (!data) reject(null);
89-
resolve(JSON.parse(data));
91+
if (!data) return;
92+
images.push(JSON.parse(data));
93+
});
94+
95+
child.stdout!.on("close", () => {
96+
resolve(images);
9097
});
9198
});
9299
}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
}
1515
},
1616
"include": ["src"],
17-
"exclude": ["node_modules"]
17+
"exclude": ["node_modules", "docs", "src/tests"]
1818
}

0 commit comments

Comments
 (0)