From 7ef0fdc9ec0a63810f6557d24b38a8bfb12e6a3b Mon Sep 17 00:00:00 2001 From: Kevin Scott <151596+thekevinscott@users.noreply.github.com> Date: Sat, 14 Oct 2023 16:44:20 -0400 Subject: [PATCH] Add bundling step for clientside (#1224) * Add bundling step for clientside --- internals/bundlers/package.json | 4 +- package.json | 7 +- pnpm-lock.yaml | 333 ++++++++++++++---- scripts/test.ts | 1 + test/integration/clientside/tests/builds.mts | 139 ++++---- test/integration/clientside/tests/cdn.mts | 15 +- test/integration/clientside/tests/image.mts | 152 ++++---- test/integration/clientside/tests/model.mts | 47 ++- test/integration/clientside/tests/speed.mts | 8 +- test/integration/clientside/tests/upscale.mts | 142 ++++---- 10 files changed, 558 insertions(+), 290 deletions(-) diff --git a/internals/bundlers/package.json b/internals/bundlers/package.json index 1b4fd53c5..a372a7c04 100644 --- a/internals/bundlers/package.json +++ b/internals/bundlers/package.json @@ -16,7 +16,9 @@ "dependencies": { "@internals/common": "workspace:*", "@internals/http-server": "workspace:*", - "fs-extra": "latest" + "fs-extra": "latest", + "html-webpack-plugin": "^5.5.3", + "webpack": "^5.88.2" }, "scripts": { "run-bundle": "wireit", diff --git a/package.json b/package.json index 9ced92536..6e99f81e6 100644 --- a/package.json +++ b/package.json @@ -102,7 +102,6 @@ "fs-extra": "11.1.1", "glob": "^10.3.3", "heapdump": "0.3.15", - "html-webpack-plugin": "5.5.3", "inquirer": "9.2.10", "jest": "29.6.3", "jest-canvas-mock": "2.5.2", @@ -130,7 +129,6 @@ "upscaler": "workspace:*", "vite": "4.4.9", "vitest": "^0.34.5", - "webpack": "5.88.2", "yargs": "17.7.2" }, "engines": { @@ -333,7 +331,10 @@ "./internals/test-runner:build", "./packages/upscalerjs:build:browser", "build:models:esm", - "build:models:umd" + "build:models:umd", + "bundle:esbuild", + "bundle:webpack", + "bundle:umd" ] }, "test:integration:serverside": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7dbb38698..ffb07f9fa 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -170,9 +170,6 @@ importers: heapdump: specifier: 0.3.15 version: 0.3.15 - html-webpack-plugin: - specifier: 5.5.3 - version: 5.5.3(webpack@5.88.2) inquirer: specifier: 9.2.10 version: 9.2.10 @@ -254,9 +251,6 @@ importers: vitest: specifier: ^0.34.5 version: 0.34.5(jsdom@22.1.0) - webpack: - specifier: 5.88.2 - version: 5.88.2(esbuild@0.19.2)(uglify-js@3.17.4) yargs: specifier: 17.7.2 version: 17.7.2 @@ -575,6 +569,12 @@ importers: fs-extra: specifier: latest version: 11.1.1 + html-webpack-plugin: + specifier: ^5.5.3 + version: 5.5.3(webpack@5.88.2) + webpack: + specifier: ^5.88.2 + version: 5.88.2(esbuild@0.19.2)(uglify-js@3.17.4) devDependencies: '@types/ejs': specifier: ^3.1.2 @@ -1070,6 +1070,52 @@ importers: specifier: 2.6.1 version: 2.6.1 + tmp/bundlers/webpack: + dependencies: + '@tensorflow/tfjs': + specifier: 4.8.0 + version: 4.8.0(seedrandom@3.0.5) + '@upscalerjs/default-model': + specifier: workspace:* + version: link:../../../models/default-model + '@upscalerjs/esrgan-legacy': + specifier: workspace:* + version: link:../../../models/esrgan-legacy + '@upscalerjs/esrgan-medium': + specifier: workspace:* + version: link:../../../models/esrgan-medium + '@upscalerjs/esrgan-slim': + specifier: workspace:* + version: link:../../../models/esrgan-slim + '@upscalerjs/esrgan-thick': + specifier: workspace:* + version: link:../../../models/esrgan-thick + '@upscalerjs/pixel-upsampler': + specifier: workspace:* + version: link:../../../models/pixel-upsampler + upscaler: + specifier: workspace:* + version: link:../../../packages/upscalerjs + devDependencies: + '@babel/plugin-transform-modules-commonjs': + specifier: latest + version: 7.23.0(@babel/core@7.22.10) + '@babel/preset-env': + specifier: latest + version: 7.23.2(@babel/core@7.22.10) + '@babel/preset-typescript': + specifier: latest + version: 7.23.2(@babel/core@7.22.10) + html-webpack-plugin: + specifier: 5.5.3 + version: 5.5.3(webpack@5.88.2) + seedrandom: + specifier: 3.0.5 + version: 3.0.5 + webpack: + specifier: 5.88.2 + version: 5.88.2(esbuild@0.19.2)(uglify-js@3.17.4) + packages: /@aashutoshrathi/word-wrap@1.2.6: @@ -1258,14 +1304,21 @@ packages: '@babel/highlight': 7.22.10 chalk: 2.4.2 - /@babel/compat-data@7.22.20: - resolution: {integrity: sha512-BQYjKbpXjoXwFW5jGqiizJQQT/aC7pFm9Ok1OWssonuguICi264lbgMzRp2ZMmRSlfkX6DsWDDcsrctK8Rwfiw==} + /@babel/code-frame@7.22.13: + resolution: {integrity: sha512-XktuhWlJ5g+3TJXc5upd9Ks1HutSArik6jf2eAjYFyIOf4ej3RN+184cZbzDvbPnuTJIUhPKKJE3cIsYTiAT3w==} engines: {node: '>=6.9.0'} + dependencies: + '@babel/highlight': 7.22.20 + chalk: 2.4.2 /@babel/compat-data@7.22.9: resolution: {integrity: sha512-5UamI7xkUcJ3i9qVDS+KFDEK8/7oJ55/sJMB1Ge7IEapr7KfdfV/HErR+koZwOfd+SgtFKOKRhRakdg++DcJpQ==} engines: {node: '>=6.9.0'} + /@babel/compat-data@7.23.2: + resolution: {integrity: sha512-0S9TQMmDHlqAZ2ITT95irXKfxN9bncq8ZCoJhun3nHL/lLUxd2NKBJYoNGWH7S0hz6fRQwWlAWn/ILM0C70KZQ==} + engines: {node: '>=6.9.0'} + /@babel/core@7.12.9: resolution: {integrity: sha512-gTXYh3M5wb7FRXQy+FErKFAv90BnlOuNn1QkCK2lREoPAjrQCO49+HVSrFoe5uakFAF5eenS75KbO2vQiLrTMQ==} engines: {node: '>=6.9.0'} @@ -1275,7 +1328,7 @@ packages: '@babel/helper-module-transforms': 7.23.0(@babel/core@7.12.9) '@babel/helpers': 7.22.10 '@babel/parser': 7.22.10 - '@babel/template': 7.22.5 + '@babel/template': 7.22.15 '@babel/traverse': 7.22.10 '@babel/types': 7.23.0 convert-source-map: 1.9.0 @@ -1354,9 +1407,9 @@ packages: resolution: {integrity: sha512-y6EEzULok0Qvz8yyLkCvVX+02ic+By2UdOhylwUOvOn9dvYc9mKICJuuU1n1XBI02YWsNsnrY1kc6DVbjcXbtw==} engines: {node: '>=6.9.0'} dependencies: - '@babel/compat-data': 7.22.20 + '@babel/compat-data': 7.23.2 '@babel/helper-validator-option': 7.22.15 - browserslist: 4.21.9 + browserslist: 4.22.1 lru-cache: 5.1.1 semver: 6.3.1 @@ -1411,7 +1464,7 @@ packages: '@babel/core': ^7.4.0-0 dependencies: '@babel/core': 7.22.10 - '@babel/helper-compilation-targets': 7.22.10 + '@babel/helper-compilation-targets': 7.22.15 '@babel/helper-plugin-utils': 7.22.5 debug: 4.3.4(supports-color@8.1.1) lodash.debounce: 4.0.8 @@ -1426,7 +1479,22 @@ packages: '@babel/core': ^7.4.0 || ^8.0.0-0 <8.0.0 dependencies: '@babel/core': 7.22.10 - '@babel/helper-compilation-targets': 7.22.10 + '@babel/helper-compilation-targets': 7.22.15 + '@babel/helper-plugin-utils': 7.22.5 + debug: 4.3.4(supports-color@8.1.1) + lodash.debounce: 4.0.8 + resolve: 1.22.4 + transitivePeerDependencies: + - supports-color + dev: true + + /@babel/helper-define-polyfill-provider@0.4.3(@babel/core@7.22.10): + resolution: {integrity: sha512-WBrLmuPP47n7PNwsZ57pqam6G/RGo1vw/87b0Blc53tZNGZ4x7YvZ6HgQe2vo1W/FR20OgjeZuGXzudPiXHFug==} + peerDependencies: + '@babel/core': ^7.4.0 || ^8.0.0-0 <8.0.0 + dependencies: + '@babel/core': 7.22.10 + '@babel/helper-compilation-targets': 7.22.15 '@babel/helper-plugin-utils': 7.22.5 debug: 4.3.4(supports-color@8.1.1) lodash.debounce: 4.0.8 @@ -1447,7 +1515,7 @@ packages: resolution: {integrity: sha512-wtHSq6jMRE3uF2otvfuD3DIvVhOsSNshQl0Qrd7qC9oQJzHvOL4qQXlQn2916+CXGywIjpGuIkoyZRRxHPiNQQ==} engines: {node: '>=6.9.0'} dependencies: - '@babel/template': 7.22.5 + '@babel/template': 7.22.15 '@babel/types': 7.23.0 /@babel/helper-hoist-variables@7.22.5: @@ -1519,6 +1587,17 @@ packages: resolution: {integrity: sha512-uLls06UVKgFG9QD4OeFYLEGteMIAa5kpTPcFL28yuCIIzsf6ZyKZMllKVOCZFhiZ5ptnwX4mtKdWCBE/uT4amg==} engines: {node: '>=6.9.0'} + /@babel/helper-remap-async-to-generator@7.22.20(@babel/core@7.22.10): + resolution: {integrity: sha512-pBGyV4uBqOns+0UvhsTO8qgl8hO89PmiDYv+/COyp1aeMcmfrfruz+/nCMFiYyFF/Knn0yfrC85ZzNFjembFTw==} + engines: {node: '>=6.9.0'} + peerDependencies: + '@babel/core': ^7.0.0 + dependencies: + '@babel/core': 7.22.10 + '@babel/helper-annotate-as-pure': 7.22.5 + '@babel/helper-environment-visitor': 7.22.20 + '@babel/helper-wrap-function': 7.22.20 + /@babel/helper-remap-async-to-generator@7.22.9(@babel/core@7.22.10): resolution: {integrity: sha512-8WWC4oR4Px+tr+Fp0X3RHDVfINGpF3ad1HIbrc8A77epiR6eMMc6jsgozkzT2uDiOOdoS9cLIQ+XD2XvI2WSmQ==} engines: {node: '>=6.9.0'} @@ -1580,6 +1659,14 @@ packages: engines: {node: '>=6.9.0'} dev: true + /@babel/helper-wrap-function@7.22.20: + resolution: {integrity: sha512-pms/UwkOpnQe/PDAEdV/d7dVCoBbB+R4FvYoHGZz+4VPcg7RtYy2KP7S2lbuWM6FCSgob5wshfGESbC/hzNXZw==} + engines: {node: '>=6.9.0'} + dependencies: + '@babel/helper-function-name': 7.22.5 + '@babel/template': 7.22.15 + '@babel/types': 7.23.0 + /@babel/helper-wrap-function@7.22.9: resolution: {integrity: sha512-sZ+QzfauuUEfxSEjKFmi3qDSHgLsTPK/pEpoD/qonZKOtTPTLbf59oabPQ4rKekt9lFcj/hTZaOhWwFYrgjk+Q==} engines: {node: '>=6.9.0'} @@ -1606,12 +1693,26 @@ packages: chalk: 2.4.2 js-tokens: 4.0.0 + /@babel/highlight@7.22.20: + resolution: {integrity: sha512-dkdMCN3py0+ksCgYmGG8jKeGA/8Tk+gJwSYYlFGxG5lmhfKNoAy004YpLxpS1W2J8m/EK2Ew+yOs9pVRwO89mg==} + engines: {node: '>=6.9.0'} + dependencies: + '@babel/helper-validator-identifier': 7.22.20 + chalk: 2.4.2 + js-tokens: 4.0.0 + /@babel/parser@7.22.10: resolution: {integrity: sha512-lNbdGsQb9ekfsnjFGhEiF4hfFqGgfOP3H3d27re3n+CGhNuTSUEQdfWk556sTLNTloczcdM5TYF2LhzmDQKyvQ==} engines: {node: '>=6.0.0'} dependencies: '@babel/types': 7.22.10 + /@babel/parser@7.23.0: + resolution: {integrity: sha512-vvPKKdMemU85V9WE/l5wZEmImpCtLqbnTvqDS2U1fJ96KrxoW7KrXhNsNCblQlg8Ck4b85yxdTyelsMUgFUXiw==} + engines: {node: '>=6.0.0'} + dependencies: + '@babel/types': 7.23.0 + /@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression@7.22.15(@babel/core@7.22.10): resolution: {integrity: sha512-FB9iYlz7rURmRJyXRKEnalYPPdn87H5no108cyuQQyMwlpJ2SJtpIUBI27kdTin956pz+LPypkPVPUTlxOmrsg==} engines: {node: '>=6.9.0'} @@ -1673,7 +1774,7 @@ packages: '@babel/core': 7.12.9 '@babel/helper-plugin-utils': 7.22.5 '@babel/plugin-syntax-object-rest-spread': 7.8.3(@babel/core@7.12.9) - '@babel/plugin-transform-parameters': 7.22.5(@babel/core@7.12.9) + '@babel/plugin-transform-parameters': 7.22.15(@babel/core@7.12.9) /@babel/plugin-proposal-private-property-in-object@7.21.0-placeholder-for-preset-env.2(@babel/core@7.22.10): resolution: {integrity: sha512-SOSkfJDddaM7mak6cPEpswyTRnuRltl429hMraQEglW+OkovnCzsiszTmsrlY//qLFjCpQDFRvjdm2wA5pPm9w==} @@ -1899,8 +2000,8 @@ packages: '@babel/plugin-syntax-async-generators': 7.8.4(@babel/core@7.22.10) dev: true - /@babel/plugin-transform-async-generator-functions@7.22.15(@babel/core@7.22.10): - resolution: {integrity: sha512-jBm1Es25Y+tVoTi5rfd5t1KLmL8ogLKpXszboWOTTtGFGz2RKnQe2yn7HbZ+kb/B8N0FVSGQo874NSlOU1T4+w==} + /@babel/plugin-transform-async-generator-functions@7.23.2(@babel/core@7.22.10): + resolution: {integrity: sha512-BBYVGxbDVHfoeXbOwcagAkOQAm9NxoTdMGfTqghu1GrvadSaw6iW3Je6IcL5PNOw8VwjxqBECXy50/iCQSY/lQ==} engines: {node: '>=6.9.0'} peerDependencies: '@babel/core': ^7.0.0-0 @@ -1908,7 +2009,7 @@ packages: '@babel/core': 7.22.10 '@babel/helper-environment-visitor': 7.22.20 '@babel/helper-plugin-utils': 7.22.5 - '@babel/helper-remap-async-to-generator': 7.22.9(@babel/core@7.22.10) + '@babel/helper-remap-async-to-generator': 7.22.20(@babel/core@7.22.10) '@babel/plugin-syntax-async-generators': 7.8.4(@babel/core@7.22.10) /@babel/plugin-transform-async-to-generator@7.22.5(@babel/core@7.22.10): @@ -2217,6 +2318,17 @@ packages: '@babel/core': 7.22.10 '@babel/helper-module-transforms': 7.23.0(@babel/core@7.22.10) '@babel/helper-plugin-utils': 7.22.5 + dev: true + + /@babel/plugin-transform-modules-amd@7.23.0(@babel/core@7.22.10): + resolution: {integrity: sha512-xWT5gefv2HGSm4QHtgc1sYPbseOyf+FFDo2JbpE25GWl5BqTGO9IMwTYJRoIdjsF85GE+VegHxSCUt5EvoYTAw==} + engines: {node: '>=6.9.0'} + peerDependencies: + '@babel/core': ^7.0.0-0 + dependencies: + '@babel/core': 7.22.10 + '@babel/helper-module-transforms': 7.23.0(@babel/core@7.22.10) + '@babel/helper-plugin-utils': 7.22.5 /@babel/plugin-transform-modules-commonjs@7.22.5(@babel/core@7.22.10): resolution: {integrity: sha512-B4pzOXj+ONRmuaQTg05b3y/4DuFz3WcCNAXPLb2Q0GT0TrGKGxNKV4jwsXts+StaM0LQczZbOpj8o1DLPDJIiA==} @@ -2228,6 +2340,7 @@ packages: '@babel/helper-module-transforms': 7.23.0(@babel/core@7.22.10) '@babel/helper-plugin-utils': 7.22.5 '@babel/helper-simple-access': 7.22.5 + dev: true /@babel/plugin-transform-modules-commonjs@7.23.0(@babel/core@7.22.10): resolution: {integrity: sha512-32Xzss14/UVc7k9g775yMIvkVK8xwKE0DPdP5JTapr3+Z9w4tzeOuLNY6BXDQR6BdnzIlXnCGAzsk/ICHBLVWQ==} @@ -2342,7 +2455,7 @@ packages: peerDependencies: '@babel/core': ^7.0.0-0 dependencies: - '@babel/compat-data': 7.22.20 + '@babel/compat-data': 7.23.2 '@babel/core': 7.22.10 '@babel/helper-compilation-targets': 7.22.15 '@babel/helper-plugin-utils': 7.22.5 @@ -2417,22 +2530,22 @@ packages: '@babel/helper-skip-transparent-expression-wrappers': 7.22.5 '@babel/plugin-syntax-optional-chaining': 7.8.3(@babel/core@7.22.10) - /@babel/plugin-transform-parameters@7.22.15(@babel/core@7.22.10): + /@babel/plugin-transform-parameters@7.22.15(@babel/core@7.12.9): resolution: {integrity: sha512-hjk7qKIqhyzhhUvRT683TYQOFa/4cQKwQy7ALvTpODswN40MljzNDa0YldevS6tGbxwaEKVn502JmY0dP7qEtQ==} engines: {node: '>=6.9.0'} peerDependencies: '@babel/core': ^7.0.0-0 dependencies: - '@babel/core': 7.22.10 + '@babel/core': 7.12.9 '@babel/helper-plugin-utils': 7.22.5 - /@babel/plugin-transform-parameters@7.22.5(@babel/core@7.12.9): - resolution: {integrity: sha512-AVkFUBurORBREOmHRKo06FjHYgjrabpdqRSwq6+C7R5iTCZOsM4QbcB27St0a4U6fffyAOqh3s/qEfybAhfivg==} + /@babel/plugin-transform-parameters@7.22.15(@babel/core@7.22.10): + resolution: {integrity: sha512-hjk7qKIqhyzhhUvRT683TYQOFa/4cQKwQy7ALvTpODswN40MljzNDa0YldevS6tGbxwaEKVn502JmY0dP7qEtQ==} engines: {node: '>=6.9.0'} peerDependencies: '@babel/core': ^7.0.0-0 dependencies: - '@babel/core': 7.12.9 + '@babel/core': 7.22.10 '@babel/helper-plugin-utils': 7.22.5 /@babel/plugin-transform-parameters@7.22.5(@babel/core@7.22.10): @@ -2762,13 +2875,13 @@ packages: - supports-color dev: true - /@babel/preset-env@7.22.20(@babel/core@7.22.10): - resolution: {integrity: sha512-11MY04gGC4kSzlPHRfvVkNAZhUxOvm7DCJ37hPDnUENwe06npjIRAfInEMTGSb4LZK5ZgDFkv5hw0lGebHeTyg==} + /@babel/preset-env@7.23.2(@babel/core@7.22.10): + resolution: {integrity: sha512-BW3gsuDD+rvHL2VO2SjAUNTBe5YrjsTiDyqamPDWY723na3/yPQ65X5oQkFVJZ0o50/2d+svm1rkPoJeR1KxVQ==} engines: {node: '>=6.9.0'} peerDependencies: '@babel/core': ^7.0.0-0 dependencies: - '@babel/compat-data': 7.22.20 + '@babel/compat-data': 7.23.2 '@babel/core': 7.22.10 '@babel/helper-compilation-targets': 7.22.15 '@babel/helper-plugin-utils': 7.22.5 @@ -2795,7 +2908,7 @@ packages: '@babel/plugin-syntax-top-level-await': 7.14.5(@babel/core@7.22.10) '@babel/plugin-syntax-unicode-sets-regex': 7.18.6(@babel/core@7.22.10) '@babel/plugin-transform-arrow-functions': 7.22.5(@babel/core@7.22.10) - '@babel/plugin-transform-async-generator-functions': 7.22.15(@babel/core@7.22.10) + '@babel/plugin-transform-async-generator-functions': 7.23.2(@babel/core@7.22.10) '@babel/plugin-transform-async-to-generator': 7.22.5(@babel/core@7.22.10) '@babel/plugin-transform-block-scoped-functions': 7.22.5(@babel/core@7.22.10) '@babel/plugin-transform-block-scoping': 7.23.0(@babel/core@7.22.10) @@ -2815,7 +2928,7 @@ packages: '@babel/plugin-transform-literals': 7.22.5(@babel/core@7.22.10) '@babel/plugin-transform-logical-assignment-operators': 7.22.11(@babel/core@7.22.10) '@babel/plugin-transform-member-expression-literals': 7.22.5(@babel/core@7.22.10) - '@babel/plugin-transform-modules-amd': 7.22.5(@babel/core@7.22.10) + '@babel/plugin-transform-modules-amd': 7.23.0(@babel/core@7.22.10) '@babel/plugin-transform-modules-commonjs': 7.23.0(@babel/core@7.22.10) '@babel/plugin-transform-modules-systemjs': 7.23.0(@babel/core@7.22.10) '@babel/plugin-transform-modules-umd': 7.22.5(@babel/core@7.22.10) @@ -2844,10 +2957,10 @@ packages: '@babel/plugin-transform-unicode-sets-regex': 7.22.5(@babel/core@7.22.10) '@babel/preset-modules': 0.1.6-no-external-plugins(@babel/core@7.22.10) '@babel/types': 7.23.0 - babel-plugin-polyfill-corejs2: 0.4.5(@babel/core@7.22.10) - babel-plugin-polyfill-corejs3: 0.8.3(@babel/core@7.22.10) - babel-plugin-polyfill-regenerator: 0.5.2(@babel/core@7.22.10) - core-js-compat: 3.31.1 + babel-plugin-polyfill-corejs2: 0.4.6(@babel/core@7.22.10) + babel-plugin-polyfill-corejs3: 0.8.5(@babel/core@7.22.10) + babel-plugin-polyfill-regenerator: 0.5.3(@babel/core@7.22.10) + core-js-compat: 3.33.0 semver: 6.3.1 transitivePeerDependencies: - supports-color @@ -2888,6 +3001,20 @@ packages: '@babel/plugin-syntax-jsx': 7.22.5(@babel/core@7.22.10) '@babel/plugin-transform-modules-commonjs': 7.22.5(@babel/core@7.22.10) '@babel/plugin-transform-typescript': 7.22.15(@babel/core@7.22.10) + dev: true + + /@babel/preset-typescript@7.23.2(@babel/core@7.22.10): + resolution: {integrity: sha512-u4UJc1XsS1GhIGteM8rnGiIvf9rJpiVgMEeCnwlLA7WJPC+jcXWJAGxYmeqs5hOZD8BbAfnV5ezBOxQbb4OUxA==} + engines: {node: '>=6.9.0'} + peerDependencies: + '@babel/core': ^7.0.0-0 + dependencies: + '@babel/core': 7.22.10 + '@babel/helper-plugin-utils': 7.22.5 + '@babel/helper-validator-option': 7.22.15 + '@babel/plugin-syntax-jsx': 7.22.5(@babel/core@7.22.10) + '@babel/plugin-transform-modules-commonjs': 7.23.0(@babel/core@7.22.10) + '@babel/plugin-transform-typescript': 7.22.15(@babel/core@7.22.10) /@babel/regjsgen@0.8.0: resolution: {integrity: sha512-x/rqGMdzj+fWZvCOYForTghzbtqPDZ5gPwaoNGHdgDfF2QA/XZbCBp4Moo5scrkAMPhB7z26XM/AaHuIJdgauA==} @@ -2911,6 +3038,14 @@ packages: dependencies: regenerator-runtime: 0.13.11 + /@babel/template@7.22.15: + resolution: {integrity: sha512-QPErUVm4uyJa60rkI73qneDacvdvzxshT3kksGqlGWYdOTIUOwJ7RDUL8sGqslY1uXWSL6xMFKEXDS3ox2uF0w==} + engines: {node: '>=6.9.0'} + dependencies: + '@babel/code-frame': 7.22.13 + '@babel/parser': 7.23.0 + '@babel/types': 7.23.0 + /@babel/template@7.22.5: resolution: {integrity: sha512-X7yV7eiwAxdj9k94NEylvbVHLiVG1nvzCV2EAowhxLTwODV1jl9UzZ48leOC0sH7OnuHrIkllaBgneUykIcZaw==} engines: {node: '>=6.9.0'} @@ -3086,9 +3221,9 @@ packages: '@babel/generator': 7.20.7 '@babel/plugin-syntax-dynamic-import': 7.8.3(@babel/core@7.22.10) '@babel/plugin-transform-runtime': 7.18.10(@babel/core@7.22.10) - '@babel/preset-env': 7.22.20(@babel/core@7.22.10) + '@babel/preset-env': 7.23.2(@babel/core@7.22.10) '@babel/preset-react': 7.18.6(@babel/core@7.22.10) - '@babel/preset-typescript': 7.22.5(@babel/core@7.22.10) + '@babel/preset-typescript': 7.23.2(@babel/core@7.22.10) '@babel/runtime': 7.18.9 '@babel/runtime-corejs3': 7.18.9 '@babel/traverse': 7.20.12 @@ -4941,6 +5076,7 @@ packages: /@jridgewell/sourcemap-codec@1.4.14: resolution: {integrity: sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw==} + dev: true /@jridgewell/sourcemap-codec@1.4.15: resolution: {integrity: sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==} @@ -4950,6 +5086,7 @@ packages: dependencies: '@jridgewell/resolve-uri': 3.1.0 '@jridgewell/sourcemap-codec': 1.4.14 + dev: true /@jridgewell/trace-mapping@0.3.19: resolution: {integrity: sha512-kf37QtfW+Hwx/buWGMPcR60iF9ziHa6r/CZJIHbmcm4+0qrXiVdxegAH0F6yddEVQ7zdkjcGCgCzUu+BcbhQxw==} @@ -5382,9 +5519,9 @@ packages: dependencies: '@babel/core': 7.22.10 '@babel/plugin-transform-react-constant-elements': 7.17.12(@babel/core@7.22.10) - '@babel/preset-env': 7.22.20(@babel/core@7.22.10) + '@babel/preset-env': 7.23.2(@babel/core@7.22.10) '@babel/preset-react': 7.18.6(@babel/core@7.22.10) - '@babel/preset-typescript': 7.22.5(@babel/core@7.22.10) + '@babel/preset-typescript': 7.23.2(@babel/core@7.22.10) '@svgr/core': 6.3.1 '@svgr/plugin-jsx': 6.3.1(@svgr/core@6.3.1) '@svgr/plugin-svgo': 6.3.1(@svgr/core@6.3.1) @@ -5508,6 +5645,7 @@ packages: /@tensorflow/tfjs@4.8.0(seedrandom@3.0.5): resolution: {integrity: sha512-aKyYPFk5/aABtz+ETzvow8QBQxq0QgBCf3yQ7I33JkNbrIjlmEJmcfwbbbpLs5bg0BiOcNn2gYGbZHZ4AZuMQQ==} + hasBin: true dependencies: '@tensorflow/tfjs-backend-cpu': 4.8.0(@tensorflow/tfjs-core@4.8.0) '@tensorflow/tfjs-backend-webgl': 4.8.0(@tensorflow/tfjs-core@4.8.0) @@ -6623,6 +6761,7 @@ packages: /acorn@8.10.0: resolution: {integrity: sha512-F0SAmZ8iUtS//m8DmCTA0jlh6TDKkHQyK6xc6V4KDTyZKA9dnvX9/3sRTVQrWm79glUAZbnmmNcdYwUIHWVybw==} engines: {node: '>=0.4.0'} + hasBin: true /address@1.2.0: resolution: {integrity: sha512-tNEZYz5G/zYunxFm7sfhAxkXEuLj3K6BKwv6ZURlsF6yiUQ65z0Q2wZW9L5cPUl9ocofGvXOdFYbFHp0+6MOig==} @@ -6979,7 +7118,7 @@ packages: peerDependencies: postcss: ^8.1.0 dependencies: - browserslist: 4.21.9 + browserslist: 4.22.1 caniuse-lite: 1.0.30001509 fraction.js: 4.2.0 normalize-range: 0.1.2 @@ -7107,7 +7246,7 @@ packages: resolution: {integrity: sha512-ESAc/RJvGTFEzRwOTT4+lNDk/GNHMkKbNzsvT0qKRfDyyYTskxB5rnU2njIDYVxXCBHHEI1c0YwHob3WaYujOg==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} dependencies: - '@babel/template': 7.22.5 + '@babel/template': 7.22.15 '@babel/types': 7.23.0 '@types/babel__core': 7.20.1 '@types/babel__traverse': 7.20.1 @@ -7118,7 +7257,7 @@ packages: peerDependencies: '@babel/core': ^7.0.0-0 dependencies: - '@babel/compat-data': 7.22.9 + '@babel/compat-data': 7.23.2 '@babel/core': 7.22.10 '@babel/helper-define-polyfill-provider': 0.3.2(@babel/core@7.22.10) semver: 6.3.1 @@ -7136,6 +7275,19 @@ packages: semver: 6.3.1 transitivePeerDependencies: - supports-color + dev: true + + /babel-plugin-polyfill-corejs2@0.4.6(@babel/core@7.22.10): + resolution: {integrity: sha512-jhHiWVZIlnPbEUKSSNb9YoWcQGdlTLq7z1GHL4AjFxaoOUMuuEVJ+Y4pAaQUGOGk93YsVCKPbqbfw3m0SM6H8Q==} + peerDependencies: + '@babel/core': ^7.4.0 || ^8.0.0-0 <8.0.0 + dependencies: + '@babel/compat-data': 7.23.2 + '@babel/core': 7.22.10 + '@babel/helper-define-polyfill-provider': 0.4.3(@babel/core@7.22.10) + semver: 6.3.1 + transitivePeerDependencies: + - supports-color /babel-plugin-polyfill-corejs3@0.5.3(@babel/core@7.22.10): resolution: {integrity: sha512-zKsXDh0XjnrUEW0mxIHLfjBfnXSMr5Q/goMe/fxpQnLm07mcOZiIZHBNWCMx60HmdvjxfXcalac0tfFg0wqxyw==} @@ -7144,7 +7296,7 @@ packages: dependencies: '@babel/core': 7.22.10 '@babel/helper-define-polyfill-provider': 0.3.2(@babel/core@7.22.10) - core-js-compat: 3.31.1 + core-js-compat: 3.33.0 transitivePeerDependencies: - supports-color @@ -7158,6 +7310,18 @@ packages: core-js-compat: 3.31.1 transitivePeerDependencies: - supports-color + dev: true + + /babel-plugin-polyfill-corejs3@0.8.5(@babel/core@7.22.10): + resolution: {integrity: sha512-Q6CdATeAvbScWPNLB8lzSO7fgUVBkQt6zLgNlfyeCr/EQaEQR+bWiBYYPYAFyE528BMjRhL+1QBMOI4jc/c5TA==} + peerDependencies: + '@babel/core': ^7.4.0 || ^8.0.0-0 <8.0.0 + dependencies: + '@babel/core': 7.22.10 + '@babel/helper-define-polyfill-provider': 0.4.3(@babel/core@7.22.10) + core-js-compat: 3.33.0 + transitivePeerDependencies: + - supports-color /babel-plugin-polyfill-regenerator@0.4.0(@babel/core@7.22.10): resolution: {integrity: sha512-RW1cnryiADFeHmfLS+WW/G431p1PsW5qdRdz0SDRi7TKcUgc7Oh/uXkT7MZ/+tGsT1BkczEAmD5XjUyJ5SWDTw==} @@ -7178,6 +7342,17 @@ packages: '@babel/helper-define-polyfill-provider': 0.4.2(@babel/core@7.22.10) transitivePeerDependencies: - supports-color + dev: true + + /babel-plugin-polyfill-regenerator@0.5.3(@babel/core@7.22.10): + resolution: {integrity: sha512-8sHeDOmXC8csczMrYEOf0UTNa4yE2SxV5JGeT/LP1n0OYVDUUFPxG9vdk2AlDlIit4t+Kf0xCtpgXPBwnn/9pw==} + peerDependencies: + '@babel/core': ^7.4.0 || ^8.0.0-0 <8.0.0 + dependencies: + '@babel/core': 7.22.10 + '@babel/helper-define-polyfill-provider': 0.4.3(@babel/core@7.22.10) + transitivePeerDependencies: + - supports-color /babel-plugin-transform-inline-environment-variables@0.4.4: resolution: {integrity: sha512-bJILBtn5a11SmtR2j/3mBOjX4K3weC6cq+NNZ7hG22wCAqpc3qtj/iN7dSe9HDiS46lgp1nHsQgeYrea/RUe+g==} @@ -7458,10 +7633,19 @@ packages: resolution: {integrity: sha512-M0MFoZzbUrRU4KNfCrDLnvyE7gub+peetoTid3TBIqtunaDJyXlwhakT+/VkvSXcfIzFfK/nkCs4nmyTmxdNSg==} engines: {node: ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7} dependencies: - caniuse-lite: 1.0.30001509 - electron-to-chromium: 1.4.461 + caniuse-lite: 1.0.30001549 + electron-to-chromium: 1.4.554 node-releases: 2.0.13 - update-browserslist-db: 1.0.11(browserslist@4.21.9) + update-browserslist-db: 1.0.13(browserslist@4.21.9) + + /browserslist@4.22.1: + resolution: {integrity: sha512-FEVc202+2iuClEhZhrWy6ZiAcRLvNMyYcxZ8raemul1DYVOVdFsbqckWLdsixQZCpJlwe77Z3UTalE7jsjnKfQ==} + engines: {node: ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7} + dependencies: + caniuse-lite: 1.0.30001549 + electron-to-chromium: 1.4.554 + node-releases: 2.0.13 + update-browserslist-db: 1.0.13(browserslist@4.22.1) /bs-logger@0.2.6: resolution: {integrity: sha512-pd8DCoxmbgc7hyPKOvxtqNcjYoOsABPQdcCUjGp3d42VR2CX1ORhk2A87oqqu5R1kk+76nsxZupkmyd+MVtCog==} @@ -7656,14 +7840,17 @@ packages: /caniuse-api@3.0.0: resolution: {integrity: sha512-bsTwuIg/BZZK/vreVTYYbSWoe2F+71P7K5QGEX+pT250DZbfU1MQ5prOKpPR+LL6uWKK3KMwMCAS74QB3Um1uw==} dependencies: - browserslist: 4.21.9 - caniuse-lite: 1.0.30001509 + browserslist: 4.22.1 + caniuse-lite: 1.0.30001549 lodash.memoize: 4.1.2 lodash.uniq: 4.5.0 /caniuse-lite@1.0.30001509: resolution: {integrity: sha512-2uDDk+TRiTX5hMcUYT/7CSyzMZxjfGu0vAUjS2g0LSD8UoXOv0LtpH4LxGMemsiPq6LCVIUjNwVM0erkOkGCDA==} + /caniuse-lite@1.0.30001549: + resolution: {integrity: sha512-qRp48dPYSCYaP+KurZLhDYdVE+yEyht/3NlmcJgVQ2VMGt6JL36ndQ/7rgspdZsJuxDPFIo/OzBT2+GmIJ53BA==} + /capnp-ts@0.7.0: resolution: {integrity: sha512-XKxXAC3HVPv7r674zP0VC3RTXz+/JKhfyw94ljvF80yynK6VkTnqE3jMuN8b3dUVmmc43TjyxjW4KTsmB3c86g==} dependencies: @@ -8276,6 +8463,12 @@ packages: resolution: {integrity: sha512-wIDWd2s5/5aJSdpOJHfSibxNODxoGoWOBHt8JSPB41NOE94M7kuTPZCYLOlTtuoXTsBPKobpJ6T+y0SSy5L9SA==} dependencies: browserslist: 4.21.9 + dev: true + + /core-js-compat@3.33.0: + resolution: {integrity: sha512-0w4LcLXsVEuNkIqwjjf9rjCoPhK8uqA4tMRh4Ge26vfLtUutshn+aRJU21I9LCJlh2QQHfisNToLjw1XEJLTWw==} + dependencies: + browserslist: 4.22.1 /core-js-pure@3.23.1: resolution: {integrity: sha512-3qNgf6TqI3U1uhuSYRzJZGfFd4T+YlbyVPl+jgRiKjdZopvG4keZQwWZDAWpu1UH9nCgTpUzIV3GFawC7cJsqg==} @@ -8458,7 +8651,7 @@ packages: postcss-modules-scope: 3.0.0(postcss@8.4.17) postcss-modules-values: 4.0.0(postcss@8.4.17) postcss-value-parser: 4.2.0 - semver: 7.3.8 + semver: 7.5.4 webpack: 5.88.2(esbuild@0.19.2)(uglify-js@3.17.4) /css-minimizer-webpack-plugin@4.0.0(clean-css@5.3.0)(esbuild@0.19.2)(webpack@5.88.2): @@ -9168,8 +9361,8 @@ packages: jake: 10.8.7 dev: false - /electron-to-chromium@1.4.461: - resolution: {integrity: sha512-1JkvV2sgEGTDXjdsaQCeSwYYuhLRphRpc+g6EHTFELJXEiznLt3/0pZ9JuAOQ5p2rI3YxKTbivtvajirIfhrEQ==} + /electron-to-chromium@1.4.554: + resolution: {integrity: sha512-Q0umzPJjfBrrj8unkONTgbKQXzXRrH7sVV7D9ea2yBV3Oaogz991yhbpfvo2LMNkJItmruXTEzVpP9cp7vaIiQ==} /elliptic@6.5.4: resolution: {integrity: sha512-iLhC6ULemrljPZb+QutR5TQGB+pdW6KGD5RSegS+8sorOZT+rdQFbsQFJgvN3eRqNALqJer4oQ16YvJHlU8hzQ==} @@ -10799,6 +10992,7 @@ packages: /html-minifier-terser@6.1.0: resolution: {integrity: sha512-YXxSlJBZTP7RS3tWnQw74ooKa6L9b9i9QYXY21eUEvhZ3u9XLfv6OnFsQq6RxkhHygsaUMvYsZRV5rU/OVNZxw==} engines: {node: '>=12'} + hasBin: true dependencies: camel-case: 4.1.2 clean-css: 5.3.0 @@ -14058,7 +14252,7 @@ packages: peerDependencies: postcss: ^8.2.15 dependencies: - browserslist: 4.21.9 + browserslist: 4.22.1 caniuse-api: 3.0.0 colord: 2.9.2 postcss: 8.4.17 @@ -14070,7 +14264,7 @@ packages: peerDependencies: postcss: ^8.2.15 dependencies: - browserslist: 4.21.9 + browserslist: 4.22.1 postcss: 8.4.17 postcss-value-parser: 4.2.0 @@ -14125,7 +14319,7 @@ packages: cosmiconfig: 7.1.0 klona: 2.0.5 postcss: 8.4.17 - semver: 7.3.8 + semver: 7.5.4 webpack: 5.88.2(esbuild@0.19.2)(uglify-js@3.17.4) /postcss-merge-idents@5.1.1(postcss@8.4.17): @@ -14154,7 +14348,7 @@ packages: peerDependencies: postcss: ^8.2.15 dependencies: - browserslist: 4.21.9 + browserslist: 4.22.1 caniuse-api: 3.0.0 cssnano-utils: 3.1.0(postcss@8.4.17) postcss: 8.4.17 @@ -14186,7 +14380,7 @@ packages: peerDependencies: postcss: ^8.2.15 dependencies: - browserslist: 4.21.9 + browserslist: 4.22.1 cssnano-utils: 3.1.0(postcss@8.4.17) postcss: 8.4.17 postcss-value-parser: 4.2.0 @@ -14296,7 +14490,7 @@ packages: peerDependencies: postcss: ^8.2.15 dependencies: - browserslist: 4.21.9 + browserslist: 4.22.1 postcss: 8.4.17 postcss-value-parser: 4.2.0 @@ -14344,7 +14538,7 @@ packages: peerDependencies: postcss: ^8.2.15 dependencies: - browserslist: 4.21.9 + browserslist: 4.22.1 caniuse-api: 3.0.0 postcss: 8.4.17 @@ -14785,7 +14979,7 @@ packages: dependencies: '@babel/code-frame': 7.22.10 address: 1.2.0 - browserslist: 4.21.9 + browserslist: 4.22.1 chalk: 4.1.2 cross-spawn: 7.0.3 detect-port-alt: 1.1.6 @@ -16321,7 +16515,7 @@ packages: peerDependencies: postcss: ^8.2.15 dependencies: - browserslist: 4.21.9 + browserslist: 4.22.1 postcss: 8.4.17 postcss-selector-parser: 6.0.10 @@ -16535,7 +16729,7 @@ packages: uglify-js: optional: true dependencies: - '@jridgewell/trace-mapping': 0.3.18 + '@jridgewell/trace-mapping': 0.3.19 esbuild: 0.19.2 jest-worker: 27.5.1 schema-utils: 3.3.0 @@ -16547,6 +16741,7 @@ packages: /terser@5.19.0: resolution: {integrity: sha512-JpcpGOQLOXm2jsomozdMDpd5f8ZHh1rR48OFgWUH3QsyZcfPgv2qDCYbcDEAYNd4OZRj2bWYKpwdll/udZCk/Q==} engines: {node: '>=10'} + hasBin: true dependencies: '@jridgewell/source-map': 0.3.5 acorn: 8.10.0 @@ -17199,8 +17394,9 @@ packages: resolution: {integrity: sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==} engines: {node: '>= 0.8'} - /update-browserslist-db@1.0.11(browserslist@4.21.9): - resolution: {integrity: sha512-dCwEFf0/oT85M1fHBg4F0jtLwJrutGoHSQXCh7u4o2t1drG+c0a9Flnqww6XUKSfQMPpJBRjU8d4RXB09qtvaA==} + /update-browserslist-db@1.0.13(browserslist@4.21.9): + resolution: {integrity: sha512-xebP81SNcPuNpPP3uzeW1NYXxI3rxyJzF3pD6sH4jE7o/IX+WtSpwnVU+qIsDPyk0d3hmFQ7mjqc6AtV604hbg==} + hasBin: true peerDependencies: browserslist: '>= 4.21.0' dependencies: @@ -17208,6 +17404,16 @@ packages: escalade: 3.1.1 picocolors: 1.0.0 + /update-browserslist-db@1.0.13(browserslist@4.22.1): + resolution: {integrity: sha512-xebP81SNcPuNpPP3uzeW1NYXxI3rxyJzF3pD6sH4jE7o/IX+WtSpwnVU+qIsDPyk0d3hmFQ7mjqc6AtV604hbg==} + hasBin: true + peerDependencies: + browserslist: '>= 4.21.0' + dependencies: + browserslist: 4.22.1 + escalade: 3.1.1 + picocolors: 1.0.0 + /update-check@1.5.4: resolution: {integrity: sha512-5YHsflzHP4t1G+8WGPlvKbJEbAJGCgw+Em+dGR1KmBUbr1J36SJBqlHLjR7oob7sco5hWHGQVcr9B2poIVDDTQ==} dependencies: @@ -17249,7 +17455,7 @@ packages: is-yarn-global: 0.3.0 latest-version: 5.1.0 pupa: 2.1.1 - semver: 7.3.8 + semver: 7.5.4 semver-diff: 3.1.1 xdg-basedir: 4.0.0 @@ -17892,6 +18098,7 @@ packages: /webpack@5.88.2(esbuild@0.19.2)(uglify-js@3.17.4): resolution: {integrity: sha512-JmcgNZ1iKj+aiR0OvTYtWQqJwq37Pf683dY9bVORwVbUrDhLhdn/PlO2sHsFHPkj7sHNQF3JwaAkp49V+Sq1tQ==} engines: {node: '>=10.13.0'} + hasBin: true peerDependencies: webpack-cli: '*' peerDependenciesMeta: @@ -17905,7 +18112,7 @@ packages: '@webassemblyjs/wasm-parser': 1.11.6 acorn: 8.10.0 acorn-import-assertions: 1.9.0(acorn@8.10.0) - browserslist: 4.21.9 + browserslist: 4.22.1 chrome-trace-event: 1.0.3 enhanced-resolve: 5.15.0 es-module-lexer: 1.3.0 diff --git a/scripts/test.ts b/scripts/test.ts index 59ef97147..d138f98c3 100644 --- a/scripts/test.ts +++ b/scripts/test.ts @@ -125,6 +125,7 @@ const test = async (platform: Platform | Platform[], runner: Runner, kind: Kind, || kind === 'memory' || kind === 'model' || (platform === 'node' && kind === 'integration') + || (platform === 'browser' && kind === 'integration') )) { const dependencies = await getDependencies(platform, runner, kind, ...positionalArgs); const durations: number[] = []; diff --git a/test/integration/clientside/tests/builds.mts b/test/integration/clientside/tests/builds.mts index fcdd4580b..6c6f666cc 100644 --- a/test/integration/clientside/tests/builds.mts +++ b/test/integration/clientside/tests/builds.mts @@ -2,89 +2,100 @@ * Tests that different build outputs all function correctly */ import { checkImage } from '../../../lib/utils/checkImage.js'; -import { DIST as UMD_DIST, mockCDN as umdMockCDN } from '../../../lib/umd/prepare.js'; -import { DIST as WEBPACK_DIST, mockCDN as webpackMockCDN } from '../../../lib/esm-webpack/prepare.js'; import path from 'path'; import * as tf from '@tensorflow/tfjs'; import Upscaler, { ModelDefinition } from 'upscaler'; -import { BrowserTestRunner, MockCDN } from '../../utils/BrowserTestRunner.js'; -import { MODELS_DIR } from '../../../../scripts/package-scripts/utils/constants.js'; +import { MODELS_DIR } from '@internals/common/constants'; +import { ClientsideTestRunner } from '@internals/test-runner/clientside'; const PIXEL_UPSAMPLER_DIR = path.resolve(MODELS_DIR, 'pixel-upsampler/test/__fixtures__'); -describe('Build Integration Tests', () => { - const testRunner = new BrowserTestRunner({ - showWarnings: true, - }); +const ROOT_BUNDLER_OUTPUT_DIR = process.env.ROOT_BUNDLER_OUTPUT_DIR; +if (typeof ROOT_BUNDLER_OUTPUT_DIR !== 'string') { + throw new Error('ROOT_BUNDLER_OUTPUT_DIR not defined in env'); +} +const UMD_DIST_FOLDER = path.resolve(ROOT_BUNDLER_OUTPUT_DIR, 'umd/dist') +const WEBPACK_DIST_FOLDER = path.resolve(ROOT_BUNDLER_OUTPUT_DIR, 'webpack/dist') - beforeAll(async () => { - await testRunner.startBrowser(); - }); +describe('Build Integration Tests', () => { + describe('umd', () => { + const testRunner = new ClientsideTestRunner({ + mock: true, + dist: UMD_DIST_FOLDER, + }) - beforeEach(async () => { - await testRunner.createNewPage(); - }); + beforeAll(async () => { + await testRunner.beforeAll(); + }); - afterAll(async () => { - await testRunner.closeBrowser(); - }); + beforeEach(async () => { + await testRunner.beforeEach(); + }); - afterEach(async function afterEach() { - await testRunner.afterEach(async () => { - await testRunner.stopServer(); + afterAll(async () => { + await testRunner.afterAll(); }); - }, 5000); - const start = async (dist: string, mockCDN: MockCDN, pageTitle: string | null = null) => { - testRunner.mockCDN = mockCDN; - await testRunner.startServer(dist); - await testRunner.navigateToServer(pageTitle); - return { page: testRunner.page } ; - } + afterEach(async function afterEach() { + await testRunner.afterEach(); + }, 5000); - it("upscales using a UMD build via a script tag", async () => { - const { page } = await start(UMD_DIST, umdMockCDN); - const result = await page.evaluate(() => { - const Upscaler = window['Upscaler']; - const upscaler = new Upscaler({ - model: { - path: '/models/pixel-upsampler/models/x4/x4.json', - scale: 4, - modelType: 'layers', - }, - }); - return upscaler.execute(window['fixtures']['pixel-upsampler']); + it("upscales using a UMD build with a specified model", async () => { + const page = testRunner.page; + const fixturePath = `${await testRunner.getFixturesServerURL()}/pixel-upsampler/test/__fixtures__/fixture.png`; + const modelScriptPath = `${await testRunner.getFixturesServerURL()}/pixel-upsampler/dist/umd/x4.min.js`; + const result = await page.evaluate(async ({ modelScriptPath, fixturePath }) => { + const Upscaler = window['Upscaler']; + await window['loadScript'](modelScriptPath); + const pixelUpsampler = window['PixelUpsampler4x']; + const upscaler = new Upscaler({ + model: pixelUpsampler, + }); + return upscaler.execute(fixturePath); + }, { modelScriptPath, fixturePath }); + checkImage(result, path.resolve(PIXEL_UPSAMPLER_DIR, "x4/result.png"), 'diff.png'); }); - checkImage(result, path.resolve(PIXEL_UPSAMPLER_DIR, "x4/result.png"), 'diff.png'); }); - it("upscales using a UMD build with a specified model", async () => { - const { page } = await start(UMD_DIST, umdMockCDN); - const result = await page.evaluate(() => { - const Upscaler = window['Upscaler']; - const pixelUpsampler = window['PixelUpsampler4x']; - const upscaler = new Upscaler({ - model: pixelUpsampler, - }); - return upscaler.execute(window['fixtures']['pixel-upsampler']); + describe('webpack', () => { + const testRunner = new ClientsideTestRunner({ + mock: true, + dist: WEBPACK_DIST_FOLDER, + }) + + beforeAll(async () => { + await testRunner.beforeAll(); }); - checkImage(result, path.resolve(PIXEL_UPSAMPLER_DIR, "x4/result.png"), 'diff.png'); - }); - it("upscales using an ESM build using Webpack", async () => { - const { page } = await start(WEBPACK_DIST, webpackMockCDN, '| Loaded'); - const result = await page.evaluate(() => { - const Upscaler = window['Upscaler']; - const upscaler = new Upscaler({ - model: { - path: '/models/pixel-upsampler/models/x4/x4.json', - scale: 4, - modelType: 'layers', - }, - }); - return upscaler.execute(window['fixtures']['pixel-upsampler']); + beforeEach(async () => { + await testRunner.beforeEach(); + }); + + afterAll(async () => { + await testRunner.afterAll(); + }); + + afterEach(async function afterEach() { + await testRunner.afterEach(); + }, 5000); + + it("upscales using an ESM build using Webpack", async () => { + const page = testRunner.page; + const fixturePath = `${await testRunner.getFixturesServerURL()}/pixel-upsampler/test/__fixtures__/fixture.png`; + const modelPath = `${await testRunner.getFixturesServerURL()}/pixel-upsampler/models/x4/x4.json`; + const result = await page.evaluate(({ modelPath, fixturePath }) => { + const Upscaler = window['Upscaler']; + const upscaler = new Upscaler({ + model: { + path: modelPath, + scale: 4, + modelType: 'layers', + }, + }); + return upscaler.execute(fixturePath); + }, { modelPath, fixturePath }); + checkImage(result, path.resolve(PIXEL_UPSAMPLER_DIR, "x4/result.png"), 'diff.png'); }); - checkImage(result, path.resolve(PIXEL_UPSAMPLER_DIR, "x4/result.png"), 'diff.png'); }); }); diff --git a/test/integration/clientside/tests/cdn.mts b/test/integration/clientside/tests/cdn.mts index 54dc64d5e..07f69e784 100644 --- a/test/integration/clientside/tests/cdn.mts +++ b/test/integration/clientside/tests/cdn.mts @@ -1,7 +1,7 @@ /**** * Tests that loading models via CDN works */ -import { ESBUILD_DIST as ESBUILD_DIST } from '../../../lib/esm-esbuild/prepare.js'; +import path from 'path'; import Upscaler, { ModelDefinition } from 'upscaler'; import type tf from '@tensorflow/tfjs'; import type { Page } from 'puppeteer'; @@ -16,9 +16,16 @@ const CDNS = [ // TODO: Figure out how to import this from upscaler const LOAD_MODEL_ERROR_MESSAGE = (modelPath: string) => `Could not resolve URL ${modelPath}`; +const ROOT_BUNDLER_OUTPUT_DIR = process.env.ROOT_BUNDLER_OUTPUT_DIR; +if (typeof ROOT_BUNDLER_OUTPUT_DIR !== 'string') { + throw new Error('ROOT_BUNDLER_OUTPUT_DIR not defined in env'); +} +const ESBUILD_DIST = path.resolve(ROOT_BUNDLER_OUTPUT_DIR, 'esbuild/dist') + describe('CDN Integration Tests', () => { const testRunner = new ClientsideTestRunner({ dist: ESBUILD_DIST, + log: false, }); const page = (): Page => { testRunner.page.setRequestInterception(true); @@ -44,8 +51,12 @@ describe('CDN Integration Tests', () => { const evaluateUpscaler = async (page: Page) => { try { await page.evaluate(() => { + const model = window['@upscalerjs/pixel-upsampler/x4']; + if (!model) { + throw new Error('Model not found'); + } const upscaler = new window['Upscaler']({ - model: window['pixel-upsampler']['x4'], + model, }); return upscaler.getModel(); }); diff --git a/test/integration/clientside/tests/image.mts b/test/integration/clientside/tests/image.mts index 36c4fee43..70760ba28 100644 --- a/test/integration/clientside/tests/image.mts +++ b/test/integration/clientside/tests/image.mts @@ -2,7 +2,6 @@ * Tests that different supported image formats all upscale correctly. */ import { checkImage } from '../../../lib/utils/checkImage.js'; -import { ESBUILD_DIST } from '../../../lib/esm-esbuild/prepare.js'; import { describe, it, expect } from 'vitest'; import * as tf from '@tensorflow/tfjs'; import Upscaler from 'upscaler'; @@ -16,6 +15,12 @@ const PIXEL_UPSAMPLER_DIR = path.resolve(MODELS_DIR, 'pixel-upsampler/test/__fix const flowerPixels = JSON.parse(fs.readFileSync(path.resolve(PIXEL_UPSAMPLER_DIR, 'flower-small-tensor.json'), 'utf-8')); +const ROOT_BUNDLER_OUTPUT_DIR = process.env.ROOT_BUNDLER_OUTPUT_DIR; +if (typeof ROOT_BUNDLER_OUTPUT_DIR !== 'string') { + throw new Error('ROOT_BUNDLER_OUTPUT_DIR not defined in env'); +} +const ESBUILD_DIST = path.resolve(ROOT_BUNDLER_OUTPUT_DIR, 'esbuild/dist') + describe('Image Format Integration Tests', () => { const testRunner = new ClientsideTestRunner({ mock: true, @@ -41,110 +46,117 @@ describe('Image Format Integration Tests', () => { describe('Image formats', () => { it("upscales an imported local image path", async () => { - const result = await page().evaluate(() => { + const fixturePath = `${await testRunner.getFixturesServerURL()}/pixel-upsampler/test/__fixtures__/fixture.png`; + const result = await page().evaluate(({ fixturePath }) => { + const model = window['@upscalerjs/pixel-upsampler/x4']; + if (!model) { + throw new Error('No model found') + } const upscaler = new window['Upscaler']({ - model: { - path: '/models/pixel-upsampler/models/x4/x4.json', - scale: 4, - modelType: 'layers', - }, + model, }); - return upscaler.execute(window['fixtures']['pixel-upsampler']); - }); + return upscaler.execute(fixturePath); + }, { fixturePath, }); checkImage(result, path.resolve(PIXEL_UPSAMPLER_DIR, "x4/result.png"), 'diff.png'); }); it("upscales an HTML Image", async () => { - const result = await page().evaluate(() => new Promise(resolve => { + const fixturePath = `${await testRunner.getFixturesServerURL()}/pixel-upsampler/test/__fixtures__/fixture.png`; + const result = await page().evaluate(async ({ fixturePath, }) => new Promise(resolve => { + const model = window['@upscalerjs/pixel-upsampler/x4']; + if (!model) { + throw new Error('No model found') + } const upscaler = new window['Upscaler']({ - model: { - path: '/models/pixel-upsampler/models/x4/x4.json', - scale: 4, - modelType: 'layers', - }, + model, }); const img = new Image(); - img.src = window['fixtures']['pixel-upsampler']; + img.src = fixturePath; + img.crossOrigin = 'anonymous'; img.onload = function () { upscaler.execute(img).then(resolve); } - }), []); + }), { fixturePath, }); checkImage(result, path.resolve(PIXEL_UPSAMPLER_DIR, "x4/result.png"), 'diff.png'); }); it("upscales an HTML Image from the page", async () => { - const result = await page().evaluate(() => new Promise(resolve => { + const fixturePath = `${await testRunner.getFixturesServerURL()}/pixel-upsampler/test/__fixtures__/fixture.png`; + const result = await page().evaluate(({ fixturePath }) => new Promise(resolve => { + const model = window['@upscalerjs/pixel-upsampler/x4']; + if (!model) { + throw new Error('No model found') + } const upscaler = new window['Upscaler']({ - model: { - path: '/models/pixel-upsampler/models/x4/x4.json', - scale: 4, - modelType: 'layers', - }, + model, }); const img = document.createElement('img'); img.id = 'img'; - img.src = window['fixtures']['pixel-upsampler']; + img.src = fixturePath; + img.crossOrigin = 'anonymous'; document.body.append(img); img.onload = () => { upscaler.execute(document.getElementById('img')).then(resolve); } - })); + }), { fixturePath }); checkImage(result, path.resolve(PIXEL_UPSAMPLER_DIR, "x4/result.png"), 'diff.png'); }); it("upscales a tensor from an HTML image", async () => { - const result = await page().evaluate(() => new Promise(resolve => { + const fixturePath = `${await testRunner.getFixturesServerURL()}/pixel-upsampler/test/__fixtures__/fixture.png`; + const result = await page().evaluate(({ fixturePath }) => new Promise(resolve => { + const model = window['@upscalerjs/pixel-upsampler/x4']; + if (!model) { + throw new Error('No model found') + } const upscaler = new window['Upscaler']({ - model: { - path: '/models/pixel-upsampler/models/x4/x4.json', - scale: 4, - modelType: 'layers', - }, + model, }); const img = new Image(); - img.src = window['fixtures']['pixel-upsampler']; + img.src = fixturePath; img.crossOrigin = 'anonymous'; img.onload = function () { const tensor = window['tf'].browser.fromPixels(img); upscaler.execute(tensor).then(resolve); } - })); + }), { fixturePath, }); checkImage(result, path.resolve(PIXEL_UPSAMPLER_DIR, "x4/result.png"), 'diff.png'); }); it("upscales a tensor from a Uint8Array", async () => { - const result = await page().evaluate((pixels) => new Promise(resolve => { + const result = await page().evaluate(({ pixels }) => new Promise(resolve => { + const model = window['@upscalerjs/pixel-upsampler/x4']; + if (!model) { + throw new Error('No model found') + } const upscaler = new window['Upscaler']({ - model: { - path: '/models/pixel-upsampler/models/x4/x4.json', - scale: 4, - modelType: 'layers', - }, + model, }); const bytes = new Uint8Array(pixels); const tensor = window['tf'].tensor(bytes).reshape([16, 16, 3]) as tf.Tensor3D; upscaler.execute(tensor).then(resolve); - }), flowerPixels); + }), { pixels: flowerPixels }); checkImage(result, path.resolve(PIXEL_UPSAMPLER_DIR, "x4/result.png"), 'diff.png'); }); it("upscales a rank 4 tensor", async () => { - const result = await page().evaluate(() => new Promise(resolve => { + const fixturePath = `${await testRunner.getFixturesServerURL()}/pixel-upsampler/test/__fixtures__/fixture.png`; + const result = await page().evaluate(({ fixturePath }) => new Promise(resolve => { + const model = window['@upscalerjs/pixel-upsampler/x4']; + if (!model) { + throw new Error('No model found') + } const upscaler = new window['Upscaler']({ - model: { - path: '/models/pixel-upsampler/models/x4/x4.json', - scale: 4, - modelType: 'layers', - }, + model, }); const img = new Image(); - img.src = window['fixtures']['pixel-upsampler']; + img.src = fixturePath; img.crossOrigin = 'anonymous'; img.onload = function () { const tensor = window['tf'].browser.fromPixels(img).expandDims(0); upscaler.execute(tensor).then(resolve); } - })); + }), { fixturePath }); checkImage(result, path.resolve(PIXEL_UPSAMPLER_DIR, "x4/result.png"), 'diff.png'); }); @@ -152,12 +164,12 @@ describe('Image Format Integration Tests', () => { const data = fs.readFileSync(path.resolve(PIXEL_UPSAMPLER_DIR, 'flower-small.png')).toString('base64'); const originalImage = `data:image/png;base64,${data}`; const result = await page().evaluate(src => { + const model = window['@upscalerjs/pixel-upsampler/x4']; + if (!model) { + throw new Error('No model found') + } const upscaler = new window['Upscaler']({ - model: { - path: '/models/pixel-upsampler/models/x4/x4.json', - scale: 4, - modelType: 'layers', - }, + model, }); return upscaler.execute(src); }, originalImage); @@ -167,15 +179,16 @@ describe('Image Format Integration Tests', () => { describe('Patch sizes', () => { it("throws if given an invalid patch size and padding", async () => { - const errMessage = await page().evaluate(() => new Promise((resolve, reject) => { + const fixturePath = `${await testRunner.getFixturesServerURL()}/pixel-upsampler/test/__fixtures__/fixture.png`; + const errMessage = await page().evaluate(({ fixturePath }) => new Promise((resolve, reject) => { + const model = window['@upscalerjs/pixel-upsampler/x4']; + if (!model) { + throw new Error('No model found') + } const upscaler = new window['Upscaler']({ - model: { - path: '/models/pixel-upsampler/models/x4/x4.json', - scale: 4, - modelType: 'layers', - }, + model, }); - return upscaler.execute(window['fixtures']['pixel-upsampler'], { + return upscaler.execute(fixturePath, { patchSize: 4, padding: 2, }).then(() => { @@ -183,25 +196,26 @@ describe('Image Format Integration Tests', () => { }).catch((err: Error) => { return resolve(err.message); }); - })); + }), { fixturePath }); expect(errMessage).toEqual('Invalid patch size and padding: 4 and 2. Patch size must be greater than padding * 2.'); }); it("upscales an imported local image path with patch sizes", async () => { - const result = await page().evaluate(() => { + const fixturePath = `${await testRunner.getFixturesServerURL()}/pixel-upsampler/test/__fixtures__/fixture.png`; + const result = await page().evaluate(({ fixturePath }) => { + const model = window['@upscalerjs/pixel-upsampler/x4']; + if (!model) { + throw new Error('No model found') + } const upscaler = new window['Upscaler']({ - model: { - path: '/models/pixel-upsampler/models/x4/x4.json', - scale: 4, - modelType: 'layers', - }, + model, }); - return upscaler.execute(window['fixtures']['pixel-upsampler'], { + return upscaler.execute(fixturePath, { patchSize: 6, padding: 2, }); - }); + }, { fixturePath }); checkImage(result, path.resolve(PIXEL_UPSAMPLER_DIR, "x4/result.png"), 'diff.png'); }); }); diff --git a/test/integration/clientside/tests/model.mts b/test/integration/clientside/tests/model.mts index 9ad5cdfce..ba178ba34 100644 --- a/test/integration/clientside/tests/model.mts +++ b/test/integration/clientside/tests/model.mts @@ -2,7 +2,6 @@ * Tests that different approaches to loading a model all load correctly */ import { checkImage } from '../../../lib/utils/checkImage.js'; -import { ESBUILD_DIST , mockCDN as esbuildMockCDN } from '../../../lib/esm-esbuild/prepare.js'; import Upscaler, { ModelDefinition } from 'upscaler'; import * as tf from '@tensorflow/tfjs'; import type { Tensor3D, } from '@tensorflow/tfjs'; @@ -14,6 +13,12 @@ import { ClientsideTestRunner } from '@internals/test-runner/clientside'; const PIXEL_UPSAMPLER_DIR = path.resolve(MODELS_DIR, 'pixel-upsampler/test/__fixtures__'); const DEFAULT_MODEL_DIR = path.resolve(MODELS_DIR, 'default-model/test/__fixtures__'); +const ROOT_BUNDLER_OUTPUT_DIR = process.env.ROOT_BUNDLER_OUTPUT_DIR; +if (typeof ROOT_BUNDLER_OUTPUT_DIR !== 'string') { + throw new Error('ROOT_BUNDLER_OUTPUT_DIR not defined in env'); +} +const ESBUILD_DIST = path.resolve(ROOT_BUNDLER_OUTPUT_DIR, 'esbuild/dist') + describe('Model Loading Integration Tests', () => { const testRunner = new ClientsideTestRunner({ name: 'esm', @@ -39,50 +44,54 @@ describe('Model Loading Integration Tests', () => { }); it("loads the default model", async () => { - const wait = (ms: number) => new Promise(resolve => setTimeout(resolve, ms)); - await wait(15000); - const result = await page().evaluate(() => { + const fixturePath = `${await testRunner.getFixturesServerURL()}/pixel-upsampler/test/__fixtures__/fixture.png`; + const result = await page().evaluate(({ fixturePath }) => { const upscaler = new window['Upscaler'](); - return upscaler.execute(window['fixtures']['default-model']); - }); + return upscaler.execute(fixturePath); + }, { fixturePath }); checkImage(result, path.resolve(DEFAULT_MODEL_DIR, "result.png"), 'diff.png'); }); it("can import a specific model", async () => { - const result = await page().evaluate(() => { + const fixturePath = `${await testRunner.getFixturesServerURL()}/pixel-upsampler/test/__fixtures__/fixture.png`; + const result = await page().evaluate(({ fixturePath }) => { const upscaler = new window['Upscaler']({ - model: window['pixel-upsampler']['x4'], + model: window['@upscalerjs/pixel-upsampler/x4'], }); - return upscaler.execute(window['fixtures']['pixel-upsampler']); - }); + return upscaler.execute(fixturePath); + }, { fixturePath }); checkImage(result, path.resolve(PIXEL_UPSAMPLER_DIR, "x4/result.png"), 'diff.png'); }); it("loads a locally exposed model via implied HTTP", async () => { - const result = await page().evaluate(() => { + const modelPath = `${await testRunner.getFixturesServerURL()}/pixel-upsampler/models/x4/x4.json`; + const fixturePath = `${await testRunner.getFixturesServerURL()}/pixel-upsampler/test/__fixtures__/fixture.png`; + const result = await page().evaluate(({ modelPath, fixturePath }) => { const upscaler = new window['Upscaler']({ model: { - path: '/models/pixel-upsampler/models/x4/x4.json', + path: modelPath, scale: 4, modelType: 'layers', }, }); - return upscaler.execute(window['fixtures']['pixel-upsampler']); - }); + return upscaler.execute(fixturePath); + }, { modelPath, fixturePath }); checkImage(result, path.resolve(PIXEL_UPSAMPLER_DIR, "x4/result.png"), 'diff.png'); }); it("loads a locally exposed model via absolute HTTP", async () => { - const result = await page().evaluate(() => { + const modelPath = `${await testRunner.getFixturesServerURL()}/pixel-upsampler/models/x4/x4.json`; + const fixturePath = `${await testRunner.getFixturesServerURL()}/pixel-upsampler/test/__fixtures__/fixture.png`; + const result = await page().evaluate(({ modelPath, fixturePath }) => { const upscaler = new window['Upscaler']({ model: { - path: `${window.location.origin}/models/pixel-upsampler/models/x4/x4.json`, + path: modelPath, scale: 4, modelType: 'layers', }, }); - return upscaler.execute(window['fixtures']['pixel-upsampler']); - }); + return upscaler.execute(fixturePath); + }, { modelPath, fixturePath }); checkImage(result, path.resolve(PIXEL_UPSAMPLER_DIR, "x4/result.png"), 'diff.png'); }); @@ -91,7 +100,7 @@ describe('Model Loading Integration Tests', () => { const predictedPixels: number[] = await page().evaluate(async (startingPixels) => { const tensor = window['tf'].tensor(startingPixels).reshape([2,2,3]) as Tensor3D; const upscaler = new window['Upscaler']({ - model: window['pixel-upsampler']['x2'], + model: window['@upscalerjs/pixel-upsampler/x2'], }); const loadImage = (src: string): Promise => new Promise(resolve => { const img = new Image(); diff --git a/test/integration/clientside/tests/speed.mts b/test/integration/clientside/tests/speed.mts index 8388ce1e6..b0eae6430 100644 --- a/test/integration/clientside/tests/speed.mts +++ b/test/integration/clientside/tests/speed.mts @@ -1,8 +1,8 @@ /**** * Tests that different approaches to loading a model all load correctly */ -import { ESBUILD_DIST as ESBUILD_DIST, mockCDN as esbuildMockCDN } from '../../../lib/esm-esbuild/prepare.js'; import Upscaler, { ModelDefinition } from 'upscaler'; +import path from 'path'; import * as tf from '@tensorflow/tfjs'; import type { Page } from 'puppeteer'; import { ClientsideTestRunner } from '@internals/test-runner/clientside'; @@ -11,6 +11,12 @@ const LOWER_THRESHOLD = 40; // in milliseconds const UPPER_THRESHOLD = 20; // in milliseconds const DATE_AT_WHICH_SPEED_TESTS_TAKE_EFFECT = new Date('December 1, 2023 00:00:00'); +const ROOT_BUNDLER_OUTPUT_DIR = process.env.ROOT_BUNDLER_OUTPUT_DIR; +if (typeof ROOT_BUNDLER_OUTPUT_DIR !== 'string') { + throw new Error('ROOT_BUNDLER_OUTPUT_DIR not defined in env'); +} +const ESBUILD_DIST = path.resolve(ROOT_BUNDLER_OUTPUT_DIR, 'esbuild/dist') + describe('Speed Integration Tests', () => { const testRunner = new ClientsideTestRunner({ name: 'esm', diff --git a/test/integration/clientside/tests/upscale.mts b/test/integration/clientside/tests/upscale.mts index 521b2edc8..6a566bbc3 100644 --- a/test/integration/clientside/tests/upscale.mts +++ b/test/integration/clientside/tests/upscale.mts @@ -2,7 +2,6 @@ * Tests that different supported image formats all upscale correctly. */ import { checkImage } from '../../../lib/utils/checkImage.js'; -import { ESBUILD_DIST, mockCDN as esbuildMockCDN } from '../../../lib/esm-esbuild/prepare.js'; import * as tf from '@tensorflow/tfjs'; import Upscaler from 'upscaler'; import path from 'path'; @@ -12,6 +11,12 @@ import { ClientsideTestRunner } from '@internals/test-runner/clientside'; const PIXEL_UPSAMPLER_DIR = path.resolve(MODELS_DIR, 'pixel-upsampler/test/__fixtures__'); +const ROOT_BUNDLER_OUTPUT_DIR = process.env.ROOT_BUNDLER_OUTPUT_DIR; +if (typeof ROOT_BUNDLER_OUTPUT_DIR !== 'string') { + throw new Error('ROOT_BUNDLER_OUTPUT_DIR not defined in env'); +} +const ESBUILD_DIST = path.resolve(ROOT_BUNDLER_OUTPUT_DIR, 'esbuild/dist') + describe('Upscale Integration Tests', () => { const testRunner = new ClientsideTestRunner({ mock: true, @@ -36,30 +41,32 @@ describe('Upscale Integration Tests', () => { }); it("upscales an imported local image path", async () => { - const result = await page().evaluate(() => { + const fixturePath = `${await testRunner.getFixturesServerURL()}/pixel-upsampler/test/__fixtures__/fixture.png`; + const result = await page().evaluate(({ fixturePath, }) => { + const model = window["@upscalerjs/pixel-upsampler/x4"]; + if (!model) { + throw new Error('No model found'); + } const upscaler = new window['Upscaler']({ - model: { - path: '/models/pixel-upsampler/models/x4/x4.json', - scale: 4, - modelType: 'layers', - }, + model, }); - return upscaler.execute(window['fixtures']['pixel-upsampler']); - }); + return upscaler.execute(fixturePath); + }, { fixturePath }); checkImage(result, path.resolve(PIXEL_UPSAMPLER_DIR, "x4/result.png"), 'diff.png'); }); describe('Cancel', () => { it("cancels an inflight upscale request", async () => { - const errMessage = await page().evaluate(() => new Promise(resolve => { + const fixturePath = `${await testRunner.getFixturesServerURL()}/pixel-upsampler/test/__fixtures__/fixture.png`; + const errMessage = await page().evaluate(({ fixturePath, }) => new Promise(resolve => { const abortController = new AbortController(); const patchSize = 7; + const model = window["@upscalerjs/pixel-upsampler/x4"]; + if (!model) { + throw new Error('No model found'); + } const upscaler = new window['Upscaler']({ - model: { - path: '/models/pixel-upsampler/models/x4/x4.json', - scale: 4, - modelType: 'layers', - }, + model, warmupSizes: [{ patchSize, }] @@ -69,7 +76,7 @@ describe('Upscale Integration Tests', () => { let startTime = new Date().getTime(); window['durations'] = []; - upscaler.execute(window['fixtures']['pixel-upsampler'], { + upscaler.execute(fixturePath, { patchSize, padding: 2, output: 'base64', @@ -89,7 +96,7 @@ describe('Upscale Integration Tests', () => { }).catch((err: Error) => { return resolve(err.message); }); - })); + }), { fixturePath }); expect(errMessage).toEqual('The upscale request received an abort signal'); const [progressRates, called] = await page().evaluate((): Promise<[number[], boolean]> => new Promise(resolve => { const durations = window['durations'].slice(1); // skip the first entry, it's usually slower than the others @@ -107,14 +114,15 @@ describe('Upscale Integration Tests', () => { }); it("cancels all inflight upscale requests", async () => { - const errMessage = await page().evaluate(() => new Promise(resolve => { + const fixturePath = `${await testRunner.getFixturesServerURL()}/pixel-upsampler/test/__fixtures__/fixture.png`; + const errMessage = await page().evaluate(({ fixturePath }) => new Promise(resolve => { const patchSize = 7; + const model = window["@upscalerjs/pixel-upsampler/x4"]; + if (!model) { + throw new Error('No model found'); + } const upscaler = new window['Upscaler']({ - model: { - path: '/models/pixel-upsampler/models/x4/x4.json', - scale: 4, - modelType: 'layers', - }, + model, warmupSizes: [{ patchSize, }] @@ -140,14 +148,14 @@ describe('Upscale Integration Tests', () => { }, }; Array(3).fill('').forEach(() => { - upscaler.execute(window['fixtures']['pixel-upsampler'], options).then(() => { + upscaler.execute(fixturePath, options).then(() => { window['called'] = true; resolve('this should not be called'); }).catch((err: Error) => { return resolve(err.message); }); }) - })); + }), { fixturePath, }); expect(errMessage).toEqual('The upscale request received an abort signal'); const [progressRates, called] = await page().evaluate((): Promise<[number[], boolean]> => new Promise(resolve => { const durations = window['durations'].slice(1); // skip the first entry, it's usually slower than the others @@ -167,14 +175,15 @@ describe('Upscale Integration Tests', () => { }); it("can cancel all inflight upscale requests and then make a new request successfully", async () => { - const errMessage = await page().evaluate(() => new Promise(resolve => { + const fixturePath = `${await testRunner.getFixturesServerURL()}/pixel-upsampler/test/__fixtures__/fixture.png`; + const errMessage = await page().evaluate(({ fixturePath }) => new Promise(resolve => { const patchSize = 7; + const model = window["@upscalerjs/pixel-upsampler/x4"]; + if (!model) { + throw new Error('No model found'); + } window['upscaler'] = new window['Upscaler']({ - model: { - path: '/models/pixel-upsampler/models/x4/x4.json', - scale: 4, - modelType: 'layers', - }, + model, warmupSizes: [{ patchSize, }] @@ -190,34 +199,35 @@ describe('Upscale Integration Tests', () => { } }, }; - window['upscaler'].execute(window['fixtures']['pixel-upsampler'], options).then(() => { + upscaler.execute(fixturePath, options).then(() => { window['called'] = true; resolve('this should not be called'); }).catch((err: Error) => { return resolve(err.message); }); - })); + }), { fixturePath }); expect(errMessage).toEqual('The upscale request received an abort signal'); - const result = await page().evaluate(() => { - return window['upscaler'].execute(window['fixtures']['pixel-upsampler']); - }); + const result = await page().evaluate((fixturePath) => { + return window['upscaler'].execute(fixturePath); + }, fixturePath); checkImage(result, path.resolve(PIXEL_UPSAMPLER_DIR, "x4/result.png"), 'diff.png'); }); }); describe('Progress Method', () => { it("calls back to progress the correct number of times", async () => { - const progressRates = await page().evaluate(() => new Promise(resolve => { + const fixturePath = `${await testRunner.getFixturesServerURL()}/pixel-upsampler/test/__fixtures__/fixture.png`; + const progressRates = await page().evaluate(({ fixturePath }) => new Promise(resolve => { + const model = window["@upscalerjs/pixel-upsampler/x4"]; + if (!model) { + throw new Error('No model found'); + } const upscaler = new window['Upscaler']({ - model: { - path: '/models/pixel-upsampler/models/x4/x4.json', - scale: 4, - modelType: 'layers', - }, + model, }); const progressRates: Array = []; - upscaler.execute(window['fixtures']['pixel-upsampler'], { + upscaler.execute(fixturePath, { patchSize: 10, padding: 2, output: 'base64', @@ -227,29 +237,30 @@ describe('Upscale Integration Tests', () => { }).then(() => { resolve(progressRates); }); - })); + }), { fixturePath }); expect(progressRates).toEqual([.25, .5, .75, 1]); }); it("calls back to progress with a base64", async () => { - const [rate, slice] = await page().evaluate((): Promise<[number, string]> => new Promise(resolve => { + const fixturePath = `${await testRunner.getFixturesServerURL()}/pixel-upsampler/test/__fixtures__/fixture.png`; + const [rate, slice] = await page().evaluate(({ fixturePath }): Promise<[number, string]> => new Promise(resolve => { + const model = window["@upscalerjs/pixel-upsampler/x4"]; + if (!model) { + throw new Error('No model found'); + } const upscaler = new window['Upscaler']({ - model: { - path: '/models/pixel-upsampler/models/x4/x4.json', - scale: 4, - modelType: 'layers', - }, + model, }); const progress: MultiArgStringProgress = (rate, slice) => { resolve([rate, slice]); }; - upscaler.execute(window['fixtures']['pixel-upsampler'], { + upscaler.execute(fixturePath, { patchSize: 14, padding: 2, output: 'base64', progress, }); - })); + }), { fixturePath, }); expect(typeof rate).toEqual('number'); checkImage(slice, path.resolve(PIXEL_UPSAMPLER_DIR, "x4/slice-patchsize-12-padding-2.png"), 'diff.png'); }); @@ -294,19 +305,16 @@ describe('Upscale Integration Tests', () => { ])( "calls back to progress with a tensor | patch size: %i | padding: %i", async (patchSize, padding, expectation,) => { - const updates = await page().evaluate(({ patchSize, padding }): Promise<[number, number[]][]> => new Promise(resolve => { + const fixturePath = `${await testRunner.getFixturesServerURL()}/pixel-upsampler/test/__fixtures__/fixture.png`; + const updates = await page().evaluate(({ fixturePath, patchSize, padding }): Promise<[number, number[]][]> => new Promise(resolve => { const upscaler = new window['Upscaler']({ - model: { - path: '/models/pixel-upsampler/models/x2/x2.json', - scale: 2, - modelType: 'layers', - }, + model: window['PixelUpsampler2x'], }); const updates: [number, number[]][] = []; const progress: MultiArgTensorProgress = (rate, slice) => { updates.push([rate, slice.shape]) }; - upscaler.execute(window['fixtures']['pixel-upsampler'], { + upscaler.execute(fixturePath, { patchSize, padding, output: 'tensor', @@ -314,31 +322,29 @@ describe('Upscale Integration Tests', () => { }).then(() => { resolve(updates); }); - }), { patchSize, padding }); + }), { fixturePath, patchSize, padding }); expect(updates).toEqual(expectation); }); it("calls back to progress with a row and col", async () => { - const progressRates = await page().evaluate((): Promise> => new Promise(resolve => { + const fixturePath = `${await testRunner.getFixturesServerURL()}/pixel-upsampler/test/__fixtures__/fixture.png`; + const progressRates = await page().evaluate(({ fixturePath }): Promise> => new Promise(resolve => { const upscaler = new window['Upscaler']({ - model: { - path: '/models/pixel-upsampler/models/x2/x2.json', - scale: 2, - modelType: 'layers', - }, + model: window['PixelUpsampler2x'], }); const progressRates: Array<[number, number]> = []; const progress: MultiArgStringProgress = (rate, slice, { row, col }) => { progressRates.push([row, col]); }; - upscaler.execute(window['fixtures']['pixel-upsampler'], { + upscaler.execute(fixturePath, { patchSize: 8, padding: 0, progress, }).then(() => { resolve(progressRates) }); - })); + }), { fixturePath }); + expect(progressRates).toEqual([ [0, 0], [0, 1],