зеркало из https://github.com/microsoft/onnxjs.git
tool: add chromium edge test launcher (#204)
This commit is contained in:
Родитель
89d22d8f02
Коммит
82216b3998
|
@ -2,6 +2,7 @@
|
|||
// Licensed under the MIT license.
|
||||
|
||||
const bundleMode = require('minimist')(process.argv)['bundle-mode'] || 'dev'; // 'dev'|'perf'|undefined;
|
||||
const karmaPlugins = require('minimist')(process.argv)['karma-plugins'] || undefined;
|
||||
const mainFile = bundleMode === 'perf' ? 'test/onnx.perf.js' : 'test/onnx.dev.js';
|
||||
|
||||
// it's a known issue that Safari does not work with "localhost" in BrowserStack:
|
||||
|
@ -30,7 +31,7 @@ function getMachineIpAddress() {
|
|||
return 'localhost';
|
||||
}
|
||||
|
||||
module.exports = function(config) {
|
||||
module.exports = function (config) {
|
||||
config.set({
|
||||
// global config of your BrowserStack account
|
||||
browserStack: {
|
||||
|
@ -41,20 +42,21 @@ module.exports = function(config) {
|
|||
},
|
||||
frameworks: ['mocha'],
|
||||
files: [
|
||||
{pattern: mainFile},
|
||||
{pattern: 'test/testdata-file-cache-*.json', included: false},
|
||||
{pattern: 'test/onnx-worker.js', included: false},
|
||||
{pattern: 'test/data/**/*', included: false, nocache: true},
|
||||
{pattern: 'deps/data/data/test/**/*', included: false, nocache: true},
|
||||
{pattern: 'deps/onnx/onnx/backend/test/data/**/*', included: false, nocache: true},
|
||||
{pattern: 'dist/onnx-wasm.wasm', included: false},
|
||||
{ pattern: mainFile },
|
||||
{ pattern: 'test/testdata-file-cache-*.json', included: false },
|
||||
{ pattern: 'test/onnx-worker.js', included: false },
|
||||
{ pattern: 'test/data/**/*', included: false, nocache: true },
|
||||
{ pattern: 'deps/data/data/test/**/*', included: false, nocache: true },
|
||||
{ pattern: 'deps/onnx/onnx/backend/test/data/**/*', included: false, nocache: true },
|
||||
{ pattern: 'dist/onnx-wasm.wasm', included: false },
|
||||
],
|
||||
proxies: {
|
||||
'/onnx-wasm.wasm': '/base/dist/onnx-wasm.wasm',
|
||||
'/onnx-worker.js': '/base/test/onnx-worker.js',
|
||||
},
|
||||
client: {captureConsole: true, mocha: {expose: ['body'], timeout: 60000}},
|
||||
preprocessors: {mainFile: ['sourcemap']},
|
||||
plugins: karmaPlugins,
|
||||
client: { captureConsole: true, mocha: { expose: ['body'], timeout: 60000 } },
|
||||
preprocessors: { mainFile: ['sourcemap'] },
|
||||
reporters: ['mocha', 'BrowserStack'],
|
||||
browsers: [],
|
||||
captureTimeout: 120000,
|
||||
|
@ -65,8 +67,8 @@ module.exports = function(config) {
|
|||
browserSocketTimeout: 60000,
|
||||
hostname: getMachineIpAddress(),
|
||||
customLaunchers: {
|
||||
ChromeTest: {base: 'Chrome', flags: ['--window-size=1,1']},
|
||||
ChromeDebug: {debug: true, base: 'Chrome', flags: ['--remote-debugging-port=9333']},
|
||||
ChromeTest: { base: 'Chrome', flags: ['--window-size=1,1'] },
|
||||
ChromeDebug: { debug: true, base: 'Chrome', flags: ['--remote-debugging-port=9333'] },
|
||||
//
|
||||
// ==== BrowserStack browsers ====
|
||||
//
|
||||
|
|
|
@ -30,6 +30,12 @@
|
|||
"js-tokens": "^4.0.0"
|
||||
}
|
||||
},
|
||||
"@chiragrupani/karma-chromium-edge-launcher": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@chiragrupani/karma-chromium-edge-launcher/-/karma-chromium-edge-launcher-2.0.0.tgz",
|
||||
"integrity": "sha512-ZSuKymhFJSXRweLOb76jN5oBGR24dL+tplQRYYyEhiXLBnRsbbUChyrlCXVF/V4BaK+o+erfhPhvgX7BzoWk4g==",
|
||||
"dev": true
|
||||
},
|
||||
"@electron/get": {
|
||||
"version": "1.12.2",
|
||||
"resolved": "https://registry.npmjs.org/@electron/get/-/get-1.12.2.tgz",
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
"platform": "^1.3.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@chiragrupani/karma-chromium-edge-launcher": "^2.0.0",
|
||||
"@types/chai": "^4.2.11",
|
||||
"@types/fs-extra": "^9.0.1",
|
||||
"@types/karma": "^5.0.0",
|
||||
|
|
|
@ -6,6 +6,7 @@ import * as fs from 'fs';
|
|||
import * as globby from 'globby';
|
||||
import {default as minimatch} from 'minimatch';
|
||||
import npmlog from 'npmlog';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import stripJsonComments from 'strip-json-comments';
|
||||
import {inspect} from 'util';
|
||||
|
@ -457,29 +458,54 @@ function run(config: Test.Config) {
|
|||
karmaArgs.push('--no-sandbox');
|
||||
}
|
||||
karmaArgs.push(`--bundle-mode=${args.bundleMode}`);
|
||||
// == Special treatment to Microsoft Edge ==
|
||||
//
|
||||
// == Edge's Auto Recovery Feature ==
|
||||
// when Edge starts, if it found itself was terminated forcely last time, it always recovers all previous pages.
|
||||
// this always happen in Karma because `karma-edge-launcher` uses `taskkill` command to kill Edge every time.
|
||||
//
|
||||
// == The Problem ==
|
||||
// every time when a test is completed, it will be added to the recovery page list.
|
||||
// if we run the test 100 times, there will be 100 previous tabs when we launch Edge again.
|
||||
// this run out of resources quickly and fails the futher test.
|
||||
// and it cannot recover by itself because every time it is terminated forcely or crashes.
|
||||
// and the auto recovery feature has no way to disable by configuration/commandline/registry
|
||||
//
|
||||
// == The Solution ==
|
||||
// for Microsoft Edge, we should clean up the previous active page before each run
|
||||
// delete the files stores in the specific folder to clean up the recovery page list.
|
||||
// see also: https://www.laptopmag.com/articles/edge-browser-stop-tab-restore
|
||||
if (browser === 'Edge') {
|
||||
const deleteEdgeActiveRecoveryCommand =
|
||||
// tslint:disable-next-line:max-line-length
|
||||
`del /F /Q %LOCALAPPDATA%\\Packages\\Microsoft.MicrosoftEdge_8wekyb3d8bbwe\\AC\\MicrosoftEdge\\User\\Default\\Recovery\\Active\\*`;
|
||||
npmlog.info('TestRunnerCli.Run', `CMD: ${deleteEdgeActiveRecoveryCommand}`);
|
||||
spawnSync(deleteEdgeActiveRecoveryCommand, {shell: true, stdio: 'inherit'});
|
||||
// There are currently 2 Edge browser launchers:
|
||||
// - karma-edge-launcher: used to launch the old Edge browser
|
||||
// - karma-chromium-edge-launcher: used to launch the new chromium-kernel Edge browser
|
||||
//
|
||||
|
||||
// Those 2 plugins cannot be loaded at the same time, so we need to determine which launchers to use.
|
||||
// - If we use 'karma-edge-launcher', no plugins config need to be set.
|
||||
// - If we use 'karma-chromium-edge-launcher', we need to:
|
||||
// - add plugin "@chiragrupani/karma-chromium-edge-launcher" explicitly, because it does not match the
|
||||
// default plugins config "^karma-.*"
|
||||
// - remove "karma-edge-launcher".
|
||||
|
||||
// check if we have the latest Edge installed:
|
||||
if (os.platform() === 'darwin' ||
|
||||
(os.platform() === 'win32' &&
|
||||
// tslint:disable-next-line:no-require-imports no-submodule-imports
|
||||
require('@chiragrupani/karma-chromium-edge-launcher/dist/Utilities').default.GetEdgeExe('Edge') !== '')) {
|
||||
// use "@chiragrupani/karma-chromium-edge-launcher"
|
||||
karmaArgs.push(
|
||||
'--karma-plugins=@chiragrupani/karma-chromium-edge-launcher',
|
||||
'--karma-plugins=(?!karma-edge-launcher$)karma-*');
|
||||
} else {
|
||||
// use "karma-edge-launcher"
|
||||
|
||||
// == Special treatment to Microsoft Edge ==
|
||||
//
|
||||
// == Edge's Auto Recovery Feature ==
|
||||
// when Edge starts, if it found itself was terminated forcely last time, it always recovers all previous pages.
|
||||
// this always happen in Karma because `karma-edge-launcher` uses `taskkill` command to kill Edge every time.
|
||||
//
|
||||
// == The Problem ==
|
||||
// every time when a test is completed, it will be added to the recovery page list.
|
||||
// if we run the test 100 times, there will be 100 previous tabs when we launch Edge again.
|
||||
// this run out of resources quickly and fails the futher test.
|
||||
// and it cannot recover by itself because every time it is terminated forcely or crashes.
|
||||
// and the auto recovery feature has no way to disable by configuration/commandline/registry
|
||||
//
|
||||
// == The Solution ==
|
||||
// for Microsoft Edge, we should clean up the previous active page before each run
|
||||
// delete the files stores in the specific folder to clean up the recovery page list.
|
||||
// see also: https://www.laptopmag.com/articles/edge-browser-stop-tab-restore
|
||||
const deleteEdgeActiveRecoveryCommand =
|
||||
// tslint:disable-next-line:max-line-length
|
||||
`del /F /Q %LOCALAPPDATA%\\Packages\\Microsoft.MicrosoftEdge_8wekyb3d8bbwe\\AC\\MicrosoftEdge\\User\\Default\\Recovery\\Active\\*`;
|
||||
npmlog.info('TestRunnerCli.Run', `CMD: ${deleteEdgeActiveRecoveryCommand}`);
|
||||
spawnSync(deleteEdgeActiveRecoveryCommand, {shell: true, stdio: 'inherit'});
|
||||
}
|
||||
}
|
||||
npmlog.info('TestRunnerCli.Run', `CMD: ${karmaCommand} ${karmaArgs.join(' ')}`);
|
||||
const karma = spawnSync(karmaCommand, karmaArgs, {shell: true, stdio: 'inherit'});
|
||||
|
|
Загрузка…
Ссылка в новой задаче