Skip to content

Commit

Permalink
[js/web] a bugfix and add tests for wasm proxy worker (#9048)
Browse files Browse the repository at this point in the history
* [js/web] add tests for wasm proxy worker

* fix script src override
  • Loading branch information
fs-eire authored and wangyems committed Sep 14, 2021
1 parent a68b4b3 commit dc68ee1
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 4 deletions.
2 changes: 1 addition & 1 deletion js/web/lib/wasm/proxy-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const onProxyWorkerMessage = (ev: MessageEvent<OrtWasmMessage>): 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<void> => {
if (isProxy()) {
Expand Down
10 changes: 10 additions & 0 deletions js/web/test/e2e/browser-test-wasm-no-threads-proxy.js
Original file line number Diff line number Diff line change
@@ -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'] });
});
9 changes: 9 additions & 0 deletions js/web/test/e2e/browser-test-wasm-proxy.js
Original file line number Diff line number Diff line change
@@ -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'] });
});
2 changes: 1 addition & 1 deletion js/web/test/e2e/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
2 changes: 2 additions & 0 deletions js/web/test/e2e/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit dc68ee1

Please sign in to comment.