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-wasm/bin/test/pathkit.wasm', included:false, served:true},
14      { pattern: 'tests/*.json', included:false, served:true},
15      'tests/testReporter.js',
16      'npm-wasm/bin/test/pathkit.js',
17      'tests/pathkitinit.js',
18      'tests/*.spec.js'
19    ],
20
21    proxies: {
22      '/pathkit/': '/base/npm-wasm/bin/test/'
23    },
24
25    // 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
43    browserDisconnectTimeout: 20000,
44    browserNoActivityTimeout: 20000,
45
46    // 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,
56  };
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: {
63          base: 'ChromeHeadless',
64          flags: [
65            // 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
67            '--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          ],
75        },
76    };
77  }
78
79  if (process.env.ASM_JS) {
80    console.log('asm.js is under test');
81    cfg.files = [
82      { pattern: 'npm-asmjs/bin/test/pathkit.js.mem', included:false, served:true},
83      { pattern: 'tests/*.json', included:false, served:true},
84      'tests/testReporter.js',
85      'npm-asmjs/bin/test/pathkit.js',
86      'tests/pathkitinit.js',
87      'tests/*.spec.js'
88    ];
89
90    cfg.proxies = {
91      '/pathkit/': '/base/npm-asmjs/bin/test/'
92    };
93  } else {
94    console.log('wasm is under test');
95  }
96
97  config.set(cfg);
98}
99