diff --git a/js/web/lib/wasm/proxy-wrapper.ts b/js/web/lib/wasm/proxy-wrapper.ts index 12b5b9287a..105f46c43f 100644 --- a/js/web/lib/wasm/proxy-wrapper.ts +++ b/js/web/lib/wasm/proxy-wrapper.ts @@ -79,7 +79,7 @@ const onProxyWorkerMessage = (ev: MessageEvent): void => { } }; -const scriptSrc = isProxy() ? (document?.currentScript as HTMLScriptElement)?.src : undefined; +const scriptSrc = typeof document !== 'undefined' ? (document?.currentScript as HTMLScriptElement)?.src : undefined; export const initWasm = async(): Promise => { if (isProxy()) { diff --git a/js/web/test/e2e/browser-test-wasm-no-threads-proxy.js b/js/web/test/e2e/browser-test-wasm-no-threads-proxy.js new file mode 100644 index 0000000000..d9e4a66d1d --- /dev/null +++ b/js/web/test/e2e/browser-test-wasm-no-threads-proxy.js @@ -0,0 +1,10 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +'use strict'; + +it('Browser E2E testing - WebAssembly backend (no threads, proxy)', async function () { + ort.env.wasm.numThreads = 1; + ort.env.wasm.proxy = true; + await testFunction(ort, { executionProviders: ['wasm'] }); +}); diff --git a/js/web/test/e2e/browser-test-wasm-proxy.js b/js/web/test/e2e/browser-test-wasm-proxy.js new file mode 100644 index 0000000000..eae66a23ec --- /dev/null +++ b/js/web/test/e2e/browser-test-wasm-proxy.js @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +'use strict'; + +it('Browser E2E testing - WebAssembly backend (proxy)', async function () { + ort.env.wasm.proxy = true; + await testFunction(ort, { executionProviders: ['wasm'] }); +}); diff --git a/js/web/test/e2e/karma.conf.js b/js/web/test/e2e/karma.conf.js index 8468fb722b..42ca6e0313 100644 --- a/js/web/test/e2e/karma.conf.js +++ b/js/web/test/e2e/karma.conf.js @@ -19,7 +19,7 @@ module.exports = function (config) { config.set({ frameworks: ['mocha'], files: [ - { pattern: distPrefix + 'ort.js' }, + { pattern: distPrefix + 'ort.min.js' }, { pattern: './common.js' }, { pattern: TEST_MAIN }, { pattern: './node_modules/onnxruntime-web/dist/*.wasm', included: false, nocache: true }, diff --git a/js/web/test/e2e/run.js b/js/web/test/e2e/run.js index 095004d7a3..468d4611c5 100644 --- a/js/web/test/e2e/run.js +++ b/js/web/test/e2e/run.js @@ -86,6 +86,8 @@ async function testAllBrowserCases({ hostInKarma }) { await runKarma({ hostInKarma, main: './browser-test-webgl.js', browser: 'Chrome_default' }); await runKarma({ hostInKarma, main: './browser-test-wasm.js', browser: 'Chrome_default' }); await runKarma({ hostInKarma, main: './browser-test-wasm-no-threads.js', browser: 'Chrome_default' }); + await runKarma({ hostInKarma, main: './browser-test-wasm-proxy.js', browser: 'Chrome_default' }); + await runKarma({ hostInKarma, main: './browser-test-wasm-no-threads-proxy.js', browser: 'Chrome_default' }); await runKarma({ hostInKarma, main: './browser-test-wasm-path-override-filename.js', browser: 'Chrome_default' }); await runKarma({ hostInKarma, main: './browser-test-wasm-path-override-prefix.js', browser: 'Chrome_default' }); } diff --git a/tools/ci_build/github/azure-pipelines/win-wasm-ci-pipeline.yml b/tools/ci_build/github/azure-pipelines/win-wasm-ci-pipeline.yml index aa6ba8afeb..e3c7a09956 100644 --- a/tools/ci_build/github/azure-pipelines/win-wasm-ci-pipeline.yml +++ b/tools/ci_build/github/azure-pipelines/win-wasm-ci-pipeline.yml @@ -217,11 +217,15 @@ jobs: - script: | npm test workingDirectory: '$(Build.SourcesDirectory)\js\web' - displayName: 'Run ort-web tests - unpacked mode' + displayName: 'Run ort-web tests' - script: | npm test -- --webgl-texture-pack-mode -b=webgl workingDirectory: '$(Build.SourcesDirectory)\js\web' - displayName: 'Run ort-web tests - packed mode' + displayName: 'Run ort-web tests - WebGL: packed mode' + - script: | + npm test -- --wasm-enable-proxy -b=wasm + workingDirectory: '$(Build.SourcesDirectory)\js\web' + displayName: 'Run ort-web tests - WebAssembly: proxy' - script: | npm pack workingDirectory: '$(Build.SourcesDirectory)\js\common'