blob: 0d84576bfb71c635ece9028d372e49973817222c [file] [log] [blame]
Kevin Lubickf14a3c02018-08-22 09:35:32 -04001const isDocker = require('is-docker')();
Kevin Lubick92c91712018-08-09 10:00:02 -04002
Kevin Lubickf14a3c02018-08-22 09:35:32 -04003module.exports = function(config) {
4 // Set the default values to be what are needed when testing the
5 // WebAssembly build locally.
6 let cfg = {
Kevin Lubick92c91712018-08-09 10:00:02 -04007 // frameworks to use
8 // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
9 frameworks: ['jasmine'],
10
Kevin Lubick92c91712018-08-09 10:00:02 -040011 // list of files / patterns to load in the browser
12 files: [
Kevin Lubickcedcaee2022-02-03 13:25:13 -050013 { pattern: 'build/wasm/pathkit.wasm', included:false, served:true},
Kevin Lubick92c91712018-08-09 10:00:02 -040014 { pattern: 'tests/*.json', included:false, served:true},
Kevin Lubicka0ba6122018-08-15 13:45:28 -040015 'tests/testReporter.js',
Kevin Lubickcedcaee2022-02-03 13:25:13 -050016 'build/wasm/pathkit.js',
Kevin Lubickd2544352019-03-12 09:20:32 -040017 'tests/pathkitinit.js',
Kevin Lubick92c91712018-08-09 10:00:02 -040018 'tests/*.spec.js'
19 ],
20
Kevin Lubick97d6d982018-08-10 15:53:16 -040021 proxies: {
Kevin Lubickcedcaee2022-02-03 13:25:13 -050022 '/pathkit/': '/base/build/wasm/'
Kevin Lubick97d6d982018-08-10 15:53:16 -040023 },
24
Kevin Lubick92c91712018-08-09 10:00:02 -040025 // test results reporter to use
26 // possible values: 'dots', 'progress'
27 // available reporters: https://npmjs.org/browse/keyword/karma-reporter
28 reporters: ['progress'],
29
30 // web server port
31 port: 4444,
32
33 // enable / disable colors in the output (reporters and logs)
34 colors: true,
35
36 // level of logging
37 // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
38 logLevel: config.LOG_INFO,
39
40 // enable / disable watching file and executing tests whenever any file changes
41 autoWatch: true,
42
Kevin Lubickd2544352019-03-12 09:20:32 -040043 browserDisconnectTimeout: 20000,
44 browserNoActivityTimeout: 20000,
Kevin Lubickc6c48aa2018-08-17 15:00:43 -040045
Kevin Lubick92c91712018-08-09 10:00:02 -040046 // start these browsers
47 browsers: ['Chrome'],
48
49 // Continuous Integration mode
50 // if true, Karma captures browsers, runs the tests and exits
51 singleRun: false,
52
53 // Concurrency level
54 // how many browser should be started simultaneous
55 concurrency: Infinity,
Kevin Lubickf14a3c02018-08-22 09:35:32 -040056 };
57
58 if (isDocker) {
59 // See https://hackernoon.com/running-karma-tests-with-headless-chrome-inside-docker-ae4aceb06ed3
60 cfg.browsers = ['ChromeHeadlessNoSandbox'],
61 cfg.customLaunchers = {
62 ChromeHeadlessNoSandbox: {
Kevin Lubick9c2b7cf2019-11-21 12:49:16 -050063 base: 'ChromeHeadless',
64 flags: [
Kevin Lubickf14a3c02018-08-22 09:35:32 -040065 // Without this flag, we see an error:
66 // Failed to move to new namespace: PID namespaces supported, Network namespace supported, but failed: errno = Operation not permitted
Kevin Lubick9c2b7cf2019-11-21 12:49:16 -050067 '--no-sandbox',
68 // may help tests be less flaky
69 // https://peter.sh/experiments/chromium-command-line-switches/#browser-test
70 '--browser-test',
71 // This can also help avoid crashes/timeouts:
72 // https://github.com/GoogleChrome/puppeteer/issues/1834
73 '--disable-dev-shm-usage',
74 ],
Kevin Lubickf14a3c02018-08-22 09:35:32 -040075 },
76 };
77 }
78
79 if (process.env.ASM_JS) {
80 console.log('asm.js is under test');
81 cfg.files = [
Kevin Lubickcedcaee2022-02-03 13:25:13 -050082 { pattern: 'build/asmjs/pathkit.js.mem', included:false, served:true},
Kevin Lubickf14a3c02018-08-22 09:35:32 -040083 { pattern: 'tests/*.json', included:false, served:true},
84 'tests/testReporter.js',
Kevin Lubickcedcaee2022-02-03 13:25:13 -050085 'build/asmjs/pathkit.js',
Kevin Lubickd2544352019-03-12 09:20:32 -040086 'tests/pathkitinit.js',
Kevin Lubickf14a3c02018-08-22 09:35:32 -040087 'tests/*.spec.js'
88 ];
89
90 cfg.proxies = {
Kevin Lubickcedcaee2022-02-03 13:25:13 -050091 '/pathkit/': '/base/build/asmjs/'
Kevin Lubickf14a3c02018-08-22 09:35:32 -040092 };
93 } else {
94 console.log('wasm is under test');
95 }
96
97 config.set(cfg);
Kevin Lubick92c91712018-08-09 10:00:02 -040098}