/
githubmirror
/
webpack
Обзор
Документация
Войти
/
githubmirror
/
webpack
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
test/configCases/html/wasm-script-src/index.js
28 строк
1 KB
Alexander Akait
feat(html): parse web app manifest icons; support twitter:player:stream + legacy SVG hrefs (#21355)
09 июл 2026, 01:34
Не верифицирован
09 июл 2026, 01:34
3d616c6
Код
Авторство
О чём код?
import fs from "fs"; import path from "path"; import { fileURLToPath } from "url"; import page from "./page.html"; const here = path.dirname(fileURLToPath(import.meta.url)); it("should emit a <script type=application/wasm src> as a bundled wasm asset and rewrite its src", () => { expect(typeof page).toBe("string"); expect(page).toMatchSnapshot(); // A `<script type="application/wasm">` is not executable JS, so it is not // bundled as an entry; its `src` is emitted as a hashed wasm asset, like // a wasm module referenced from JS. expect(page).not.toContain('src="./add.wasm"'); const match = page.match( /<script type="application\/wasm" src="([^"]+\.wasm)">/ ); expect(match).not.toBeNull(); const wasmUrl = /** @type {RegExpMatchArray} */ (match)[1]; expect(wasmUrl).toMatch(/^[0-9a-f]+\.wasm$/); // The emitted wasm is byte-identical to the source, so it still instantiates // (synchronous API — the sandbox does not pump promise microtasks). const bytes = fs.readFileSync(path.resolve(here, wasmUrl)); const instance = new WebAssembly.Instance(new WebAssembly.Module(bytes), {}); expect(instance.exports.add(2, 3)).toBe(5); });