Skip to content

Commit

Permalink
Fix vite bundling of worker
Browse files Browse the repository at this point in the history
  • Loading branch information
siefkenj committed Jul 5, 2024
1 parent 3b30c97 commit c479a86
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/doenetml-prototype/test/wasm-tests.test.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ describe("wasm tests", () => {
describe("run_wasm_tests", async () => {
const worker = await workerWithSource("<p>test</p>");
const allTests = await worker._getTests();
if (!allTests) {
throw new Error("No tests found in wasm");
}

for (const testName of allTests) {
it(testName, async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ export type Action = ActionsEnum & { componentIdx: number };

type Flags = Record<string, unknown>;

// Due to vite issue https://github.com/vitejs/vite/issues/17570 (related: https://github.com/vitejs/vite/issues/12611 )
// vite assumes that globalThis.document is defined and relies on it when creating a WebWorker URL. Since it is not defined
// in a worker itself, we define it here to prevent the error.
// 2024-07-05
if (typeof globalThis !== "undefined" && !globalThis.document) {
const url = new URL(
typeof location !== "undefined" ? location.href : "http://localhost",
);
const baseUrl = url.protocol + "//" + url.host + url.pathname;
// @ts-ignore
globalThis.document = {
URL: baseUrl,
baseURI: baseUrl,
};
}
export class CoreWorker {
doenetCore?: PublicDoenetMLCore;
wasm_initialized = false;
Expand Down

0 comments on commit c479a86

Please sign in to comment.