Kevin Lubick | f14a3c0 | 2018-08-22 09:35:32 -0400 | [diff] [blame] | 1 | const isDocker = require('is-docker')(); |
Kevin Lubick | 92c9171 | 2018-08-09 10:00:02 -0400 | [diff] [blame] | 2 | |
Kevin Lubick | f14a3c0 | 2018-08-22 09:35:32 -0400 | [diff] [blame] | 3 | module.exports = function(config) { |
| 4 | // Set the default values to be what are needed when testing the |
| 5 | // WebAssembly build locally. |
| 6 | let cfg = { |
Kevin Lubick | 92c9171 | 2018-08-09 10:00:02 -0400 | [diff] [blame] | 7 | // frameworks to use |
| 8 | // available frameworks: https://npmjs.org/browse/keyword/karma-adapter |
| 9 | frameworks: ['jasmine'], |
| 10 | |
Kevin Lubick | 92c9171 | 2018-08-09 10:00:02 -0400 | [diff] [blame] | 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}, |
Kevin Lubick | a0ba612 | 2018-08-15 13:45:28 -0400 | [diff] [blame] | 15 | 'tests/testReporter.js', |
Kevin Lubick | 92c9171 | 2018-08-09 10:00:02 -0400 | [diff] [blame] | 16 | 'npm-wasm/bin/test/pathkit.js', |
Kevin Lubick | d254435 | 2019-03-12 09:20:32 -0400 | [diff] [blame] | 17 | 'tests/pathkitinit.js', |
Kevin Lubick | 92c9171 | 2018-08-09 10:00:02 -0400 | [diff] [blame] | 18 | 'tests/*.spec.js' |
| 19 | ], |
| 20 | |
Kevin Lubick | 97d6d98 | 2018-08-10 15:53:16 -0400 | [diff] [blame] | 21 | proxies: { |
Kevin Lubick | 556350d | 2018-10-12 15:21:17 -0400 | [diff] [blame] | 22 | '/pathkit/': '/base/npm-wasm/bin/test/' |
Kevin Lubick | 97d6d98 | 2018-08-10 15:53:16 -0400 | [diff] [blame] | 23 | }, |
| 24 | |
Kevin Lubick | 92c9171 | 2018-08-09 10:00:02 -0400 | [diff] [blame] | 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 | |
Kevin Lubick | d254435 | 2019-03-12 09:20:32 -0400 | [diff] [blame] | 43 | browserDisconnectTimeout: 20000, |
| 44 | browserNoActivityTimeout: 20000, |
Kevin Lubick | c6c48aa | 2018-08-17 15:00:43 -0400 | [diff] [blame] | 45 | |
Kevin Lubick | 92c9171 | 2018-08-09 10:00:02 -0400 | [diff] [blame] | 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, |
Kevin Lubick | f14a3c0 | 2018-08-22 09:35:32 -0400 | [diff] [blame] | 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 | ], |
| 69 | }, |
| 70 | }; |
| 71 | } |
| 72 | |
| 73 | if (process.env.ASM_JS) { |
| 74 | console.log('asm.js is under test'); |
| 75 | cfg.files = [ |
| 76 | { pattern: 'npm-asmjs/bin/test/pathkit.js.mem', included:false, served:true}, |
| 77 | { pattern: 'tests/*.json', included:false, served:true}, |
| 78 | 'tests/testReporter.js', |
| 79 | 'npm-asmjs/bin/test/pathkit.js', |
Kevin Lubick | d254435 | 2019-03-12 09:20:32 -0400 | [diff] [blame] | 80 | 'tests/pathkitinit.js', |
Kevin Lubick | f14a3c0 | 2018-08-22 09:35:32 -0400 | [diff] [blame] | 81 | 'tests/*.spec.js' |
| 82 | ]; |
| 83 | |
| 84 | cfg.proxies = { |
Kevin Lubick | 556350d | 2018-10-12 15:21:17 -0400 | [diff] [blame] | 85 | '/pathkit/': '/base/npm-asmjs/bin/test/' |
Kevin Lubick | f14a3c0 | 2018-08-22 09:35:32 -0400 | [diff] [blame] | 86 | }; |
| 87 | } else { |
| 88 | console.log('wasm is under test'); |
| 89 | } |
| 90 | |
| 91 | config.set(cfg); |
Kevin Lubick | 92c9171 | 2018-08-09 10:00:02 -0400 | [diff] [blame] | 92 | } |