Something went wrong. Try again.
Monorepo for the nibling.run platform
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778// Unmodified esbuild-wasm (demo/apps/esbuild, pinned by its lockfile). NODE is what real// Node v24.16 printed for `node build.cjs` in that directory: the sync API through a// worker thread and receiveMessageOnPort, the async API through its service child.import { test, expect } from "@playwright/test";import type { Kernel } from "../src/host/index";
declare global { interface Window { __runtime?: Kernel }}
const NODE = [ "version 0.28.2", "transformSync:", "const n = 1;", "export default n != null ? n : 2;", "buildSync:", "<stdout> 130", "// src/greet.js", "var greet = (name) => `Hello, ${name}!`;", "", "// src/main.ts", 'var ada = { name: "Ada" };', "console.log(greet(ada.name));", 'syntax error 1 "Unexpected \\";\\"" 6', "transform:", "var __defProp = Object.defineProperty;", "var __getOwnPropDesc = Object.getOwnPropertyDescriptor;", "var __getOwnPropNames = Object.getOwnPropertyNames;", "var __hasOwnProp = Object.prototype.hasOwnProperty;", "var __export = (target, all) => {", " for (var name in all)", " __defProp(target, name, { get: all[name], enumerable: true });", "};", "var __copyProps = (to, from, except, desc) => {", ' if (from && typeof from === "object" || typeof from === "function") {', " for (let key of __getOwnPropNames(from))", " if (!__hasOwnProp.call(to, key) && key !== except)", " __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });", " }", " return to;", "};", 'var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);', "var stdin_exports = {};", "__export(stdin_exports, {", " f: () => f", "});", "module.exports = __toCommonJS(stdin_exports);", "const f = (a) => {", " var _a;", " return (_a = a == null ? void 0 : a.b) != null ? _a : `x${a}`;", "};", "build:", '"use strict";var app=(()=>{var e=o=>`Hello, ${o}!`;var n={name:"Ada"};console.log(e(n.name));})();', "inputs src/greet.js src/main.ts", "",].join("\n");
test("esbuild-wasm's sync and async APIs print what Node printed", async ({ page }) => { test.setTimeout(90_000); await page.goto("/demo/fixture.html"); await page.waitForFunction(() => window.__runtime !== undefined, undefined, { timeout: 20_000 }); const out = await page.evaluate(async () => { const runtime = window.__runtime!; runtime.mountSnapshot(await (await fetch("/dist/fixtures/esbuild.snap")).arrayBuffer()); const proc = runtime.exec("/app/build.cjs"); void proc.stdin.getWriter().close(); const dec = new TextDecoder(); let stdout = ""; let stderr = ""; await Promise.all([ proc.stdout.pipeTo(new WritableStream({ write(c) { stdout += dec.decode(c); } })), proc.stderr.pipeTo(new WritableStream({ write(c) { stderr += dec.decode(c); } })), ]); return { code: await proc.exited, stdout, stderr }; }); expect(out).toEqual({ code: 0, stdout: NODE, stderr: "" });});