onnxruntime/js/web/test/e2e/browser-test-wasm-binary-override.js
Yulong Wang b03c9496aa
[js/web] allow load WebAssembly binary from buffer (#21534)
### Description

This PR adds a new option `ort.env.wasm.wasmBinary`, which allows user
to set to a buffer containing preload .wasm file content.

This PR should resolve the problem from latest discussion in #20876.
2024-07-29 13:39:38 -07:00

22 lines
734 B
JavaScript

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
const documentUrl = document.currentScript.src;
it('Browser E2E testing - WebAssembly backend', async function() {
// preload .wasm file binary
const wasmUrl = new URL('./node_modules/onnxruntime-web/dist/ort-wasm-simd-threaded.wasm', documentUrl).href;
const response = await fetch(wasmUrl);
// make sure the .wasm file is loaded successfully
assert(response.ok);
assert(response.headers.get('Content-Type') === 'application/wasm');
// override wasm binary
const binary = await response.arrayBuffer();
ort.env.wasm.wasmBinary = binary;
await testFunction(ort, {executionProviders: ['wasm']});
});