edgespec
Version:
Write Winter-CG compatible routes with filesystem routing and tons of features
75 lines (72 loc) • 2.45 kB
JavaScript
import { devServer } from '../../chunk-325RCKH4.js';
import '../../chunk-TZHMALR4.js';
import '../../chunk-PRZQE4JB.js';
import '../../chunk-BA3OE4WS.js';
import '../../chunk-LSPDGEVE.js';
import '../../chunk-CE43QKKO.js';
import { loadConfig } from '../../chunk-TMYKADNK.js';
import '../../chunk-5WRI5ZAA.js';
import { once } from 'events';
var Worker = class {
constructor(initialData) {
this.initialData = initialData;
this.startBundlerPromise = this.startBundler();
}
async handleTestWorker(testWorker) {
let workerRpcCallback;
const channel = {
post: (data) => testWorker.publish(data),
on: (data) => {
workerRpcCallback = data;
}
};
const messageHandlerAbortController = new AbortController();
const messageHandlerPromise = Promise.race([
once(messageHandlerAbortController.signal, "abort"),
(async () => {
let didAddChannel = false;
for await (const msg of testWorker.subscribe()) {
if (!didAddChannel) {
const bundler = await this.startBundlerPromise;
bundler.birpc.updateChannels((channels) => channels.push(channel));
didAddChannel = true;
}
workerRpcCallback(msg.data);
if (messageHandlerAbortController.signal.aborted) {
break;
}
}
})()
]);
testWorker.teardown(async () => {
const bundler = await this.startBundlerPromise;
bundler.birpc.updateChannels(
(channels) => channels.filter((c) => c !== channel)
);
messageHandlerAbortController.abort();
await messageHandlerPromise;
});
}
async startBundler() {
const config = await loadConfig(this.initialData.rootDirectory);
return devServer.headless.startBundler({
config
});
}
};
// src/testing/ava/worker-wrapper.ts
var needsToNegotiateProtocol = (arg) => {
return typeof arg.negotiateProtocol === "function";
};
var workerWrapper = async (arg) => {
const protocol = needsToNegotiateProtocol(arg) ? arg.negotiateProtocol(["ava-4"]).ready() : arg;
const { initialData } = protocol;
const worker = new Worker(initialData);
for await (const testWorker of protocol.testWorkers()) {
void worker.handleTestWorker(testWorker);
}
};
var worker_wrapper_default = workerWrapper;
export { worker_wrapper_default as default };
//# sourceMappingURL=worker-wrapper.js.map
//# sourceMappingURL=worker-wrapper.js.map