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
49 changes: 25 additions & 24 deletions api/node/__test__/eventloop.spec.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@

// Test that the Slint event loop processes libuv's events.

import test from "ava";
import { test, expect, afterEach } from "vitest";
import * as http from "node:http";

import { runEventLoop, quitEventLoop, private_api } from "../dist/index.js";

test.serial("merged event loops with timer", async (t) => {
afterEach(() => {
quitEventLoop();
});

test.sequential("merged event loops with timer", async () => {
let invoked = false;

await runEventLoop(() => {
Expand All @@ -17,10 +21,10 @@ test.serial("merged event loops with timer", async (t) => {
quitEventLoop();
}, 2);
});
t.true(invoked);
expect(invoked).toBe(true);
});

test.serial("merged event loops with networking", async (t) => {
test.sequential("merged event loops with networking", async () => {
const listener = (request, result) => {
result.writeHead(200);
result.end("Hello World");
Expand Down Expand Up @@ -48,32 +52,29 @@ test.serial("merged event loops with networking", async (t) => {
});
});

t.is(received_response, "Hello World");
expect(received_response).toBe("Hello World");
});

test.serial(
"quit event loop on last window closed with callback",
async (t) => {
const compiler = new private_api.ComponentCompiler();
const definition = compiler.buildFromSource(
`
test.sequential("quit event loop on last window closed with callback", async () => {
const compiler = new private_api.ComponentCompiler();
const definition = compiler.buildFromSource(
`

export component App inherits Window {
width: 300px;
height: 300px;
}`,
"",
);
t.not(definition.App, null);
"",
);
expect(definition.App).not.toBeNull();

const instance = definition.App!.create() as any;
t.not(instance, null);
const instance = definition.App!.create() as any;
expect(instance).not.toBeNull();

instance.window().show();
await runEventLoop(() => {
setTimeout(() => {
instance.window().hide();
}, 2);
});
},
);
instance.window().show();
await runEventLoop(() => {
setTimeout(() => {
instance.window().hide();
}, 2);
});
});
34 changes: 34 additions & 0 deletions api/node/__test__/helpers/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright © SixtyFPS GmbH <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0

import { hook } from "capture-console";

export function captureAsyncStderr() {
const chunks: string[] = [];

const streams = new Set<NodeJS.WritableStream>();
streams.add(process.stderr);

const consoleStderr = (globalThis.console as any)?._stderr;
if (consoleStderr && consoleStderr !== process.stderr) {
streams.add(consoleStderr);
}

const unhooks = Array.from(streams).map((stream) =>
hook(stream, { quiet: true }, (chunk) => {
chunks.push(chunk);
}),
);

return {
output() {
return chunks.join("");
},
restore() {
while (unhooks.length) {
const unhook = unhooks.pop();
unhook && unhook();
}
},
};
}
Loading
Loading