Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/cuddly-months-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cartesi/cli": patch
---

migrate from vitest to bun:test
8 changes: 4 additions & 4 deletions .github/workflows/cli.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ jobs:
run: bun run build --filter @cartesi/cli

- name: Test
run: bun run test --filter @cartesi/cli
run: bun test apps/cli/

- name: "Report Coverage"
- name: Coverage Report
uses: 70-10/bun-coverage-report-action@6173866ce2a31456a726ff3f4c91f230bd94a9e9 # v1.0.3
if: always()
uses: davelosert/vitest-coverage-report-action@5a78cb16e761204097ad8a39369ea5d0ff7c8a5d # v2.8.0
with:
working-directory: ./apps/cli
lcov-path: coverage/lcov.info
8 changes: 4 additions & 4 deletions apps/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,22 @@
"@types/prompts": "^2.4.9",
"@types/semver": "^7.7.1",
"@types/tmp": "^0.2.6",
"@vitest/coverage-istanbul": "^4.0.17",
"@wagmi/cli": "^2.5.1",
"npm-run-all": "^4.1.5",
"rimraf": "^6.0.1",
"ts-node": "^10.9.2",
"tslib": "^2.8.1",
"typescript": "^5.9.2",
"vitest": "^4.0.17"
"typescript": "^5.9.2"
},
"scripts": {
"build": "run-s clean codegen compile",
"clean": "rimraf dist",
"codegen": "run-p codegen:wagmi",
"codegen:wagmi": "wagmi generate",
"compile": "bun build.ts",
"test": "vitest"
"lint": "biome lint",
"posttest": "bun lint",
"test": "bun test"
},
"engines": {
"node": ">=20.0.0"
Expand Down
Empty file.
173 changes: 88 additions & 85 deletions apps/cli/tests/integration/builder/directory.test.ts
Original file line number Diff line number Diff line change
@@ -1,98 +1,101 @@
import {
afterEach,
beforeAll,
beforeEach,
describe,
expect,
it,
} from "bun:test";
import fs from "fs-extra";
import path from "node:path";
import { describe, expect } from "vitest";
import { build } from "../../../src/builder/directory.js";
import type { DirectoryDriveConfig } from "../../../src/config.js";
import { TEST_SDK } from "../config.js";
import { tmpdirTest } from "./tmpdirTest.js";
import { setupIntegrationTests, TEST_SDK } from "../config.js";
import { cleanupTempDir, createTempDir } from "./tmpdirTest.js";

beforeAll(
async () => {
await setupIntegrationTests();
},
{ timeout: 60000 },
);

describe("when building with the directory builder", () => {
const image = TEST_SDK;
let destination: string;

beforeEach(async () => {
destination = await createTempDir();
});

afterEach(async () => {
await cleanupTempDir(destination);
});

tmpdirTest(
"should fail when the directory doesn't exists",
async ({ tmpdir }) => {
const destination = tmpdir;
const drive: DirectoryDriveConfig = {
builder: "directory",
directory: path.join(__dirname, "data", "invalid"),
extraSize: 0,
format: "ext2",
};
await expect(
build("root", drive, image, destination, false),
).rejects.toThrow("no such file or directory");
},
);
it("should fail when the directory doesn't exists", async () => {
const drive: DirectoryDriveConfig = {
builder: "directory",
directory: path.join(__dirname, "data", "invalid"),
extraSize: 0,
format: "ext2",
};
await expect(
build("root", drive, image, destination, false),
).rejects.toThrow("no such file or directory");
});

tmpdirTest(
"should fail when the directory is empty",
async ({ tmpdir }) => {
const destination = tmpdir;
const directory = path.join(__dirname, "data", "empty");
fs.ensureDirSync(directory);
const drive: DirectoryDriveConfig = {
builder: "directory",
directory,
extraSize: 0,
format: "ext2",
};
await expect(
build("root", drive, image, destination, false),
).rejects.toThrow("too few blocks");
},
);
it("should fail when the directory is empty", async () => {
const directory = path.join(__dirname, "data", "empty");
fs.ensureDirSync(directory);
const drive: DirectoryDriveConfig = {
builder: "directory",
directory,
extraSize: 0,
format: "ext2",
};
await expect(
build("root", drive, image, destination, false),
).rejects.toThrow("too few blocks");
});

tmpdirTest(
"should pass when the directory is empty but extra size is defined",
async ({ tmpdir }) => {
const destination = tmpdir;
const directory = path.join(__dirname, "data", "empty");
fs.ensureDirSync(directory);
const drive: DirectoryDriveConfig = {
builder: "directory",
directory,
extraSize: 1024 * 1024, // 1Mb
format: "ext2",
};
await build("root", drive, image, destination, false);
const filename = path.join(destination, "root.ext2");
const stat = fs.statSync(filename);
expect(stat.size).toEqual(1069056);
},
);
it("should pass when the directory is empty but extra size is defined", async () => {
const directory = path.join(__dirname, "data", "empty");
fs.ensureDirSync(directory);
const drive: DirectoryDriveConfig = {
builder: "directory",
directory,
extraSize: 1024 * 1024, // 1Mb
format: "ext2",
};
await build("root", drive, image, destination, false);
const filename = path.join(destination, "root.ext2");
const stat = fs.statSync(filename);
expect(stat.size).toEqual(1069056);
});

tmpdirTest(
"should pass for a populated directory (ext2)",
async ({ tmpdir }) => {
const destination = tmpdir;
const drive: DirectoryDriveConfig = {
builder: "directory",
directory: path.join(__dirname, "fixtures", "sample1"),
extraSize: 0,
format: "ext2",
};
await build("root", drive, image, destination, false);
const filename = path.join(destination, "root.ext2");
const stat = fs.statSync(filename);
expect(stat.size).toEqual(32768);
},
);
it("should pass for a populated directory (ext2)", async () => {
const drive: DirectoryDriveConfig = {
builder: "directory",
directory: path.join(__dirname, "fixtures", "sample1"),
extraSize: 0,
format: "ext2",
};
await build("root", drive, image, destination, false);
const filename = path.join(destination, "root.ext2");
const stat = fs.statSync(filename);
expect(stat.size).toEqual(32768);
});

tmpdirTest(
"should pass for a populated directory (sqfs)",
async ({ tmpdir }) => {
const destination = tmpdir;
const drive: DirectoryDriveConfig = {
builder: "directory",
directory: path.join(__dirname, "fixtures", "sample1"),
extraSize: 0,
format: "sqfs",
};
await build("root", drive, image, destination, false);
const filename = path.join(destination, "root.sqfs");
const stat = fs.statSync(filename);
expect(stat.size).toEqual(4096);
},
);
it("should pass for a populated directory (sqfs)", async () => {
const drive: DirectoryDriveConfig = {
builder: "directory",
directory: path.join(__dirname, "fixtures", "sample1"),
extraSize: 0,
format: "sqfs",
};
await build("root", drive, image, destination, false);
const filename = path.join(destination, "root.sqfs");
const stat = fs.statSync(filename);
expect(stat.size).toEqual(4096);
});
});
80 changes: 45 additions & 35 deletions apps/cli/tests/integration/builder/docker.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,38 @@
import {
afterEach,
beforeAll,
beforeEach,
describe,
expect,
it,
} from "bun:test";
import fs from "fs-extra";
import path from "node:path";
import { beforeEach } from "node:test";
import { describe, expect } from "vitest";
import { build } from "../../../src/builder/docker.js";
import type { DockerDriveConfig } from "../../../src/config.js";
import { TEST_SDK } from "../config.js";
import { tmpdirTest } from "./tmpdirTest.js";
import { setupIntegrationTests, TEST_SDK } from "../config.js";
import { cleanupTempDir, createTempDir } from "./tmpdirTest.js";

beforeAll(
async () => {
await setupIntegrationTests();
},
{ timeout: 60000 },
);

describe("when building with the docker builder", () => {
const image = TEST_SDK;
let destination: string;

beforeEach(async () => {
destination = await createTempDir();
});

beforeEach(({ name }) => {
fs.mkdirpSync(path.join(__dirname, "output", name));
afterEach(async () => {
await cleanupTempDir(destination);
});

tmpdirTest("should fail without correct context", async ({ tmpdir }) => {
const destination = tmpdir;
it("should fail without correct context", async () => {
const drive: DockerDriveConfig = {
buildArgs: [],
builder: "docker",
Expand All @@ -32,8 +49,7 @@ describe("when building with the docker builder", () => {
).rejects.toThrow("exit code 1");
});

tmpdirTest("should fail a non-riscv image", async ({ tmpdir }) => {
const destination = tmpdir;
it("should fail a non-riscv image", async () => {
const drive: DockerDriveConfig = {
buildArgs: [],
builder: "docker",
Expand All @@ -50,30 +66,25 @@ describe("when building with the docker builder", () => {
).rejects.toThrow(/no match for platform in manifest/);
});

tmpdirTest(
"should build an ext2 drive with a target definition",
async ({ tmpdir }) => {
const destination = tmpdir;
const drive: DockerDriveConfig = {
buildArgs: [],
builder: "docker",
context: path.join(__dirname, "fixtures"),
dockerfile: path.join(__dirname, "fixtures", "Dockerfile"),
extraSize: 0,
format: "ext2",
tags: [],
image: undefined,
target: "test",
};
await build("root", drive, image, destination, false);
const filename = path.join(destination, "root.ext2");
const stat = fs.statSync(filename);
expect(stat.size).toEqual(93716480);
},
);
it("should build an ext2 drive with a target definition", async () => {
const drive: DockerDriveConfig = {
buildArgs: [],
builder: "docker",
context: path.join(__dirname, "fixtures"),
dockerfile: path.join(__dirname, "fixtures", "Dockerfile"),
extraSize: 0,
format: "ext2",
tags: [],
image: undefined,
target: "test",
};
await build("root", drive, image, destination, false);
const filename = path.join(destination, "root.ext2");
const stat = fs.statSync(filename);
expect(stat.size).toEqual(93716480);
});

tmpdirTest("should build an ext2 drive", async ({ tmpdir }) => {
const destination = tmpdir;
it("should build an ext2 drive", async () => {
const drive: DockerDriveConfig = {
buildArgs: [],
builder: "docker",
Expand All @@ -91,8 +102,7 @@ describe("when building with the docker builder", () => {
expect(stat.size).toEqual(93716480);
});

tmpdirTest.skip("should build a sqfs drive", async ({ tmpdir }) => {
const destination = tmpdir;
it.skip("should build a sqfs drive", async () => {
const drive: DockerDriveConfig = {
buildArgs: [],
builder: "docker",
Expand Down
Loading
Loading