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