nodejs: add tests to library (#7694)

* nodejs: add tests to library

* new tests

* remove message splitting

* fix race

* docs

* replace extract-zip with yauzl that it wraps (high severity issue)

* fix ci tests

* skip server tests on macos and win unless SMP_SERVER is set

* fix win test

* fix win test

---------

Co-authored-by: Evgeny @ SimpleX Chat <259188159+evgeny-simplex@users.noreply.github.com>
This commit is contained in:
EvgenyandEvgeny @ SimpleX Chat authored and GitHub committed 2026-10-19 19:49:44 +01:00
1 parent ba9269a3ad
commit 46b2cf9f85
73 files changed
+957 -265

No files matched your search

@@ -17,8 +17,18 @@ describe("Core tests", () => {
}, 300000);
const tmpDir = "./tests/tmp";
const dbPath = path.join(tmpDir, "simplex_v1");
const templateDir = "./tests/template";
const templateDbPath = path.join(templateDir, "simplex_v1");
beforeEach(() => fs.mkdirSync(tmpDir, {recursive: true}));
beforeAll(async () => {
fs.mkdirSync(templateDir, {recursive: true});
await stopAndClose(await core.chatMigrateInit(templateDbPath, "key", core.MigrationConfirmation.YesUp));
}, 30000);
afterAll(() => fs.rmSync(templateDir, {recursive: true, force: true}));
beforeEach(() => {
fs.mkdirSync(tmpDir, {recursive: true});
copyTemplateDb(dbPath);
});
afterEach(() => fs.rmSync(tmpDir, {recursive: true, force: true}));
async function stopAndClose(ctrl: bigint): Promise<void> {
@@ -26,6 +36,10 @@ describe("Core tests", () => {
await core.chatCloseStore(ctrl);
}
function copyTemplateDb(dbFilePrefix: string): void {
for (const suffix of ["_chat.db", "_agent.db"]) fs.copyFileSync(templateDbPath + suffix, dbFilePrefix + suffix);
}
it("should initialize chat controller", async () => {
const ctrl = await core.chatMigrateInit(dbPath, "key", core.MigrationConfirmation.YesUp);
expect(typeof ctrl).toBe("bigint");
@@ -132,7 +146,7 @@ describe("Core tests", () => {
it("should not block the libuv pool while receiving", async () => {
const ctrl = await core.chatMigrateInit(dbPath, "key", core.MigrationConfirmation.YesUp);
const receives = [1, 2, 3, 4].map(() => core.chatRecvMsgWait(ctrl, 2_000_000));
const receives = [1, 2, 3, 4].map(() => core.chatRecvMsgWait(ctrl, 500_000));
const start = Date.now();
await fs.promises.stat(tmpDir);
expect(Date.now() - start).toBeLessThan(200);
@@ -159,8 +173,10 @@ describe("Core tests", () => {
}, 30000);
it("should receive on two controllers concurrently", async () => {
const ctrlA = await core.chatMigrateInit(path.join(tmpDir, "simplex_a"), "key", core.MigrationConfirmation.YesUp);
const ctrlB = await core.chatMigrateInit(path.join(tmpDir, "simplex_b"), "key", core.MigrationConfirmation.YesUp);
const dbPathB = path.join(tmpDir, "simplex_b");
copyTemplateDb(dbPathB);
const ctrlA = await core.chatMigrateInit(dbPath, "key", core.MigrationConfirmation.YesUp);
const ctrlB = await core.chatMigrateInit(dbPathB, "key", core.MigrationConfirmation.YesUp);
const start = Date.now();
await expect(Promise.all([core.chatRecvMsgWait(ctrlA, 1_000_000), core.chatRecvMsgWait(ctrlB, 1_000_000)]))
.resolves.toEqual([undefined, undefined]);
@@ -235,7 +251,7 @@ describe("Core tests", () => {
}, 35000);
it("should let the process exit while a receiver is idle", () => {
const childDbPath = path.resolve(tmpDir, "simplex_child");
const childDbPath = path.resolve(dbPath);
const script = `
const simplex = require("./build/Release/simplex.node");
simplex.load(${JSON.stringify(libPath)});