onnxruntime/js/web/test/e2e/run-data.js
Yulong Wang 0627a6cb93
[js/web] fix package export for bundlers (#23257)
### Description
<!-- Describe your changes. -->

This PR tries to fix #22615. (see detailed description in the issue)

A perfect solution would be too difficult to make, because there are a
huge number of combinations of usage scenarios, including combinations
of development framework, bundler, dev/prod mode, and so on.

This PR is using the following approach:
- Introduce a new type of end to end test: export test. This type of
tests are complete web apps that use popular web development frameworks,
and the tests are using puppeteer to run the apps and check if the apps
can run without error.
  - added one nextjs based web app and one vite based web app.
- In the test, perform the following test steps:
  - `npm install` for packages built locally
- `npm run dev` to start dev server and use puppeteer to launch the
browser to test
- `npm run build && npm run start` to test prod build and use puppeteer
to launch the browser to test
- Make changes to ort-web, including:
- special handling on Webpack's behavior of rewriting `import.meta.url`
to a `file://` string
  - revise build definitions
  - fix wasm URL for proxy, if used in a bundled build
2025-01-09 11:01:00 -08:00

86 lines
5 KiB
JavaScript

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
const NODEJS_TEST_CASES = [
'./node-test-main-no-threads.js',
'./node-test-main.js',
'./node-test-main.mjs',
'./node-test-wasm-path-override-filename.js',
'./node-test-wasm-path-override-prefix.js',
];
// [test_for_same_origin, test_for_cross_origin, main_js, ort_main_js, [test_args]]
const BROWSER_TEST_CASES = [
// IIFE
[true, true, './browser-test-webgl.js', 'ort.all.min.js'], // webgl
[true, true, './browser-test-webgl.js', 'ort.webgl.min.js'], // webgl
[true, true, './browser-test-wasm.js', 'ort.wasm.min.js'], // wasm, ort.wasm
[true, true, './browser-test-wasm-multi-session-create.js', 'ort.min.js'], // wasm, multi-session create
[true, true, './browser-test-wasm.js', 'ort.min.js', ['num_threads=1']], // wasm, 1 thread
[true, true, './browser-test-wasm.js', 'ort.min.js', ['num_threads=2']], // wasm, 2 threads
[true, true, './browser-test-wasm.js', 'ort.min.js', ['num_threads=2', 'proxy=1']], // wasm, 2 threads, proxy
[true, true, './browser-test-wasm.js', 'ort.min.js', ['num_threads=1', 'proxy=1']], // wasm, 1 thread, proxy
// ort.min.mjs
[true, true, './browser-test-webgl.js', 'ort.webgl.min.mjs'], // webgl
[true, true, './browser-test-wasm.js', 'ort.min.mjs', ['num_threads=1']], // wasm, 1 thread
[true, true, './browser-test-wasm.js', 'ort.min.mjs', ['num_threads=2']], // wasm, 2 threads
[true, true, './browser-test-wasm.js', 'ort.min.mjs', ['num_threads=2', 'proxy=1']], // wasm, 2 threads, proxy
[true, true, './browser-test-wasm.js', 'ort.min.mjs', ['num_threads=1', 'proxy=1']], // wasm, 1 thread, proxy
// ort.bundle.min.mjs
[true, true, './browser-test-wasm.js', 'ort.bundle.min.mjs', ['num_threads=1']], // 1 thread
[true, true, './browser-test-wasm.js', 'ort.bundle.min.mjs', ['num_threads=2']], // 2 threads
[true, true, './browser-test-wasm.js', 'ort.bundle.min.mjs', ['num_threads=2', 'proxy=1']], // 2 threads, proxy
[true, true, './browser-test-wasm.js', 'ort.bundle.min.mjs', ['num_threads=1', 'proxy=1']], // 1 thread, proxy
// wasm binary override:
[true, false, './browser-test-wasm-binary-override.js', 'ort.min.js'],
// path override:
// wasm, path override filenames for both mjs and wasm, same origin
[true, false, './browser-test-wasm-path-override-filename-jsep.js', 'ort.min.js', ['port=9876', 'files=mjs,wasm']],
[true, false, './browser-test-wasm-path-override-filename.js', 'ort.wasm.min.js', ['port=9876', 'files=mjs,wasm']],
// wasm, path override filenames for both mjs and wasm, cross origin
[false, true, './browser-test-wasm-path-override-filename-jsep.js', 'ort.min.js', ['port=8081', 'files=mjs,wasm']],
[false, true, './browser-test-wasm-path-override-filename.js', 'ort.wasm.min.js', ['port=8081', 'files=mjs,wasm']],
// wasm, path override filename for wasm, same origin
[true, false, './browser-test-wasm-path-override-filename-jsep.js', 'ort.min.js', ['port=9876', 'files=wasm']],
[true, false, './browser-test-wasm-path-override-filename.js', 'ort.wasm.min.js', ['port=9876', 'files=wasm']],
// wasm, path override filename for wasm, cross origin
[false, true, './browser-test-wasm-path-override-filename-jsep.js', 'ort.min.js', ['port=8081', 'files=wasm']],
[false, true, './browser-test-wasm-path-override-filename.js', 'ort.wasm.min.js', ['port=8081', 'files=wasm']],
// wasm, path override filename for mjs, same origin
[true, false, './browser-test-wasm-path-override-filename-jsep.js', 'ort.min.js', ['port=9876', 'files=mjs']],
[true, false, './browser-test-wasm-path-override-filename.js', 'ort.wasm.min.js', ['port=9876', 'files=mjs']],
// wasm, path override filename for mjs, cross origin
[false, true, './browser-test-wasm-path-override-filename-jsep.js', 'ort.min.js', ['port=8081', 'files=mjs']],
[false, true, './browser-test-wasm-path-override-filename.js', 'ort.wasm.min.js', ['port=8081', 'files=mjs']],
// wasm, path override prefix, same origin
[true, false, './browser-test-wasm-path-override-prefix.js', 'ort.min.js', ['port=9876']],
[true, false, './browser-test-wasm-path-override-prefix.js', 'ort.wasm.min.js', ['port=9876']],
// wasm, path override prefix, cross origin
[false, true, './browser-test-wasm-path-override-prefix.js', 'ort.min.js', ['port=8081']],
[false, true, './browser-test-wasm-path-override-prefix.js', 'ort.wasm.min.js', ['port=8081']],
[true, true, './browser-test-wasm-image-tensor-image.js', 'ort.min.js'], // pre-post-process
[true, true, './browser-test-webgpu-external-data.js', 'ort.webgpu.min.js'], // external data
];
// [bundle_path, format]
const BUNDLER_TEST_CASES = [
['./dist/webpack_esm_js/ort-test-e2e.bundle.mjs', 'esm'],
['./dist/webpack_umd_js/ort-test-e2e.bundle.js', 'iife'],
['./dist/rollup_esm_js/ort-test-e2e.bundle.mjs', 'esm'],
['./dist/rollup_umd_js/ort-test-e2e.bundle.js', 'iife'],
['./dist/parcel_esm_js/main.js', 'esm'],
['./dist/parcel_umd_js/main.js', 'iife'],
];
module.exports = {
NODEJS_TEST_CASES,
BROWSER_TEST_CASES,
BUNDLER_TEST_CASES,
};