27 lines
2.2 KiB
JavaScript
27 lines
2.2 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import path from "node:path";
|
|
import { Worker } from "node:worker_threads";
|
|
import { pathToFileURL } from "node:url";
|
|
|
|
const root = path.resolve(path.dirname(new URL(import.meta.url).pathname), "..");
|
|
const facadePath = path.resolve(process.argv[2]);
|
|
const build = path.resolve(process.argv[3]);
|
|
const facade = await import(pathToFileURL(facadePath));
|
|
const envelopePath = path.join(path.dirname(facadePath), "facade-envelope.js");
|
|
const envelope = await import(pathToFileURL(envelopePath));
|
|
const worker = new Worker(new URL("./start-facade-smoke-worker.mjs", import.meta.url), { workerData: { facadePath, envelopePath, build } });
|
|
const pending = new Map(); const events = [];
|
|
worker.on("message", (message) => { events.push(message.kind === "ready" ? "ready" : `${message.kind}:${message.requestId}`); if (message.requestId && pending.has(message.requestId)) { pending.get(message.requestId)(message); pending.delete(message.requestId); } });
|
|
const wait = (id) => new Promise((resolve) => pending.set(id, resolve));
|
|
const ready = await new Promise((resolve) => worker.once("message", resolve));
|
|
assert.equal(ready.kind, "ready");
|
|
const send = (request) => { const response = wait(request.requestId); worker.postMessage(request); return response; };
|
|
const success = await send(facade.createStartRequest("str-act-e-success"));
|
|
const bad = await send(facade.createStartRequest("str-act-e-error", { ...facade.START_FIXTURE, sourceEntry: "src/Mod/Start/App/Missing.cpp" }));
|
|
const duplicate = await send(facade.createStartRequest("str-act-e-success"));
|
|
const cancel = facade.createStartRequest("str-act-e-cancel"); const cancelledPromise = send(cancel); worker.postMessage(envelope.createCancel("str-act-e-cancel-message", cancel.requestId)); const cancelled = await cancelledPromise;
|
|
const after = await send(facade.createStartRequest("str-act-e-after"));
|
|
await worker.terminate();
|
|
assert.equal(success.kind, "result"); assert.equal(success.result.moduleAvailable, true); assert.equal(bad.error.code, "revision_mismatch"); assert.equal(duplicate.error.code, "duplicate_request"); assert.equal(cancelled.error.code, "cancelled"); assert.deepEqual(after.result, success.result);
|
|
console.log(JSON.stringify({ result: "pass", events, responses: 5 }));
|