[js/web] a bugfix and add tests for wasm proxy worker (#9048)

* [js/web] add tests for wasm proxy worker

* fix script src override
This commit is contained in:
Yulong Wang 2021-09-14 10:38:58 -07:00 committed by GitHub
parent e574be4a53
commit be80698698
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 29 additions and 4 deletions

View file

@ -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()) {

View file

@ -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'] });
});

View file

@ -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'] });
});

View file

@ -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 },

View file

@ -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' });
}

View file

@ -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'