1cb93a386Sopenharmony_ciconst isDocker = require('is-docker')(); 2cb93a386Sopenharmony_ci 3cb93a386Sopenharmony_cimodule.exports = function(config) { 4cb93a386Sopenharmony_ci // Set the default values to be what are needed when testing the 5cb93a386Sopenharmony_ci // WebAssembly build locally. 6cb93a386Sopenharmony_ci let cfg = { 7cb93a386Sopenharmony_ci // frameworks to use 8cb93a386Sopenharmony_ci // available frameworks: https://npmjs.org/browse/keyword/karma-adapter 9cb93a386Sopenharmony_ci frameworks: ['jasmine'], 10cb93a386Sopenharmony_ci 11cb93a386Sopenharmony_ci // list of files / patterns to load in the browser 12cb93a386Sopenharmony_ci files: [ 13cb93a386Sopenharmony_ci { pattern: 'npm_build/bin/canvaskit.wasm', included:false, served:true}, 14cb93a386Sopenharmony_ci { pattern: 'tests/assets/*', included:false, served:true}, 15cb93a386Sopenharmony_ci 'tests/testReporter.js', 16cb93a386Sopenharmony_ci 'npm_build/bin/canvaskit.js', 17cb93a386Sopenharmony_ci 'tests/canvaskitinit.js', 18cb93a386Sopenharmony_ci 'tests/util.js', 19cb93a386Sopenharmony_ci 'tests/*.spec.js' 20cb93a386Sopenharmony_ci ], 21cb93a386Sopenharmony_ci 22cb93a386Sopenharmony_ci proxies: { 23cb93a386Sopenharmony_ci '/assets/': '/base/tests/assets/', 24cb93a386Sopenharmony_ci '/npm_build/': '/base/npm_build/bin/', 25cb93a386Sopenharmony_ci }, 26cb93a386Sopenharmony_ci 27cb93a386Sopenharmony_ci // test results reporter to use 28cb93a386Sopenharmony_ci // possible values: 'dots', 'progress' 29cb93a386Sopenharmony_ci // available reporters: https://npmjs.org/browse/keyword/karma-reporter 30cb93a386Sopenharmony_ci reporters: ['progress'], 31cb93a386Sopenharmony_ci 32cb93a386Sopenharmony_ci // web server port 33cb93a386Sopenharmony_ci port: 4444, 34cb93a386Sopenharmony_ci 35cb93a386Sopenharmony_ci // enable / disable colors in the output (reporters and logs) 36cb93a386Sopenharmony_ci colors: true, 37cb93a386Sopenharmony_ci 38cb93a386Sopenharmony_ci // level of logging 39cb93a386Sopenharmony_ci // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG 40cb93a386Sopenharmony_ci logLevel: config.LOG_INFO, 41cb93a386Sopenharmony_ci 42cb93a386Sopenharmony_ci // enable / disable watching file and executing tests whenever any file changes 43cb93a386Sopenharmony_ci autoWatch: true, 44cb93a386Sopenharmony_ci 45cb93a386Sopenharmony_ci browserDisconnectTimeout: 20000, 46cb93a386Sopenharmony_ci browserNoActivityTimeout: 20000, 47cb93a386Sopenharmony_ci 48cb93a386Sopenharmony_ci // start these browsers 49cb93a386Sopenharmony_ci browsers: ['Chrome'], 50cb93a386Sopenharmony_ci 51cb93a386Sopenharmony_ci // Continuous Integration mode 52cb93a386Sopenharmony_ci // if true, Karma captures browsers, runs the tests and exits 53cb93a386Sopenharmony_ci singleRun: false, 54cb93a386Sopenharmony_ci 55cb93a386Sopenharmony_ci // Concurrency level 56cb93a386Sopenharmony_ci // how many browser should be started simultaneous 57cb93a386Sopenharmony_ci concurrency: Infinity, 58cb93a386Sopenharmony_ci }; 59cb93a386Sopenharmony_ci 60cb93a386Sopenharmony_ci if (isDocker || config.headless) { 61cb93a386Sopenharmony_ci // See https://hackernoon.com/running-karma-tests-with-headless-chrome-inside-docker-ae4aceb06ed3 62cb93a386Sopenharmony_ci cfg.browsers = ['ChromeHeadlessNoSandbox'], 63cb93a386Sopenharmony_ci cfg.customLaunchers = { 64cb93a386Sopenharmony_ci ChromeHeadlessNoSandbox: { 65cb93a386Sopenharmony_ci base: 'ChromeHeadless', 66cb93a386Sopenharmony_ci flags: [ 67cb93a386Sopenharmony_ci // Without this flag, we see an error: 68cb93a386Sopenharmony_ci // Failed to move to new namespace: PID namespaces supported, Network namespace supported, but failed: errno = Operation not permitted 69cb93a386Sopenharmony_ci '--no-sandbox', 70cb93a386Sopenharmony_ci // may help tests be less flaky 71cb93a386Sopenharmony_ci // https://peter.sh/experiments/chromium-command-line-switches/#browser-test 72cb93a386Sopenharmony_ci '--browser-test', 73cb93a386Sopenharmony_ci // This can also help avoid crashes/timeouts: 74cb93a386Sopenharmony_ci // https://github.com/GoogleChrome/puppeteer/issues/1834 75cb93a386Sopenharmony_ci '--disable-dev-shm-usage', 76cb93a386Sopenharmony_ci ], 77cb93a386Sopenharmony_ci }, 78cb93a386Sopenharmony_ci }; 79cb93a386Sopenharmony_ci } else { 80cb93a386Sopenharmony_ci // Extra options that should only be applied locally 81cb93a386Sopenharmony_ci 82cb93a386Sopenharmony_ci // Measure test coverage and write output to coverage/ directory 83cb93a386Sopenharmony_ci cfg.reporters.push('coverage'); 84cb93a386Sopenharmony_ci cfg.preprocessors = { 85cb93a386Sopenharmony_ci // Measure test coverage of these source files 86cb93a386Sopenharmony_ci // Since this file is a combination of our code, and emscripten's glue, 87cb93a386Sopenharmony_ci // we'll never see 100% coverage, but this lets us measure improvements. 88cb93a386Sopenharmony_ci 'canvaskit/bin/canvaskit.js': ['coverage'], 89cb93a386Sopenharmony_ci }; 90cb93a386Sopenharmony_ci } 91cb93a386Sopenharmony_ci 92cb93a386Sopenharmony_ci config.set(cfg); 93cb93a386Sopenharmony_ci} 94