|
| 1 | +// Karma configuration |
| 2 | +process.env.CHROME_BIN = require('puppeteer').executablePath() |
| 3 | +const path = require('path') |
| 4 | +const webpack = require('webpack') |
| 5 | + |
| 6 | +const REPO = process.env.BUILD_REPOSITORY_NAME |
| 7 | +const ISSUE = |
| 8 | + process.env.SYSTEM_PULLREQUEST_PULLREQUESTNUMBER || |
| 9 | + process.env.SYSTEM_PULLREQUEST_PULLREQUESTID |
| 10 | +const COMMIT = process.env.BUILD_SOURCEVERSION |
| 11 | + |
| 12 | +module.exports = function (config) { |
| 13 | + const options = { |
| 14 | + // start these browsers |
| 15 | + // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher |
| 16 | + browsers: [], |
| 17 | + // base path that will be used to resolve all patterns (eg. files, exclude) |
| 18 | + basePath: '', |
| 19 | + // frameworks to use |
| 20 | + // available frameworks: https://npmjs.org/browse/keyword/karma-adapter |
| 21 | + frameworks: ['jasmine'], |
| 22 | + // list of files / patterns to load in the browser |
| 23 | + files: [ |
| 24 | + 'src/**/*.spec.js' |
| 25 | + ], |
| 26 | + // list of files to exclude |
| 27 | + // exclude: [ |
| 28 | + // '**/node_modules/**', |
| 29 | + // ], |
| 30 | + // preprocess matching files before serving them to the browser |
| 31 | + // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor |
| 32 | + preprocessors: { |
| 33 | + 'src/**/*.spec.js': ['webpack'] |
| 34 | + }, |
| 35 | + // web server port |
| 36 | + port: 9876, |
| 37 | + // enable / disable colors in the output (reporters and logs) |
| 38 | + colors: true, |
| 39 | + // Increase timeouts since some actions take quite a while. |
| 40 | + browserNoActivityTimeout: 4 * 60 * 1000, // default 10000 |
| 41 | + // https://support.saucelabs.com/hc/en-us/articles/225104707-Karma-Tests-Disconnect-Particularly-When-Running-Tests-on-Safari |
| 42 | + browserDisconnectTimeout: 10000, // default 2000 |
| 43 | + browserDisconnectTolerance: 0, // default 0 |
| 44 | + captureTimeout: 4 * 60 * 1000, // default 60000 |
| 45 | + // SauceLabs browsers |
| 46 | + customLaunchers: { |
| 47 | + XXXsl_chrome: { |
| 48 | + base: 'SauceLabs', |
| 49 | + browserName: 'chrome', |
| 50 | + extendedDebugging: true |
| 51 | + }, |
| 52 | + sl_firefox: { |
| 53 | + base: 'SauceLabs', |
| 54 | + browserName: 'firefox' |
| 55 | + }, |
| 56 | + sl_edge: { |
| 57 | + base: 'SauceLabs', |
| 58 | + browserName: 'MicrosoftEdge' |
| 59 | + }, |
| 60 | + sl_safari: { |
| 61 | + base: 'SauceLabs', |
| 62 | + browserName: 'safari' |
| 63 | + }, |
| 64 | + sl_ios_safari: { |
| 65 | + base: 'SauceLabs', |
| 66 | + deviceName: 'iPhone X Simulator', |
| 67 | + platformName: 'iOS', |
| 68 | + platformVersion: '11.2', |
| 69 | + browserName: 'Safari', |
| 70 | + appiumVersion: '1.7.2' |
| 71 | + }, |
| 72 | + sl_android_chrome: { |
| 73 | + base: 'SauceLabs', |
| 74 | + deviceName: 'Android GoogleAPI Emulator', |
| 75 | + platformName: 'Android', |
| 76 | + platformVersion: '7.1', |
| 77 | + browserName: 'Chrome', |
| 78 | + appiumVersion: '1.7.2' |
| 79 | + }, |
| 80 | + FirefoxHeadless: { |
| 81 | + base: 'Firefox', |
| 82 | + flags: ['-headless'] |
| 83 | + }, |
| 84 | + ChromeHeadlessNoSandbox: { |
| 85 | + base: 'ChromeHeadless', |
| 86 | + flags: ['--no-sandbox'] |
| 87 | + } |
| 88 | + }, |
| 89 | + sauceLabs: { |
| 90 | + // Since tags aren't being sent correctly, I'm going to stick the branch name in here. |
| 91 | + testName: `${REPO} / ${ISSUE} / ${COMMIT}`, |
| 92 | + // Note: I added the Date.now() bit so that when I can click "Restart" on a Travis job, |
| 93 | + // Sauce Labs does not simply append new test results to the old set that failed, which |
| 94 | + // convinces karma that it failed again and always. |
| 95 | + build: process.env.BUILD_BUILDID + '-' + Date.now(), |
| 96 | + // Note: it does not appear that tags are being sent correctly. |
| 97 | + tags: [ISSUE], |
| 98 | + recordScreenshots: false, |
| 99 | + recordVideo: false, |
| 100 | + public: 'public restricted' |
| 101 | + }, |
| 102 | + concurrency: 5, |
| 103 | + // Continuous Integration mode |
| 104 | + // if true, Karma captures browsers, runs the tests and exits |
| 105 | + singleRun: true, |
| 106 | + // test results reporter to use |
| 107 | + // available reporters: https://npmjs.org/browse/keyword/karma-reporter |
| 108 | + reporters: ['verbose', 'junit'], |
| 109 | + junitReporter: { |
| 110 | + outputDir: './junit' |
| 111 | + }, |
| 112 | + webpack: { |
| 113 | + mode: 'development', |
| 114 | + devtool: 'inline-source-map', |
| 115 | + }, |
| 116 | + plugins: [ |
| 117 | + 'karma-chrome-launcher', |
| 118 | + 'karma-edge-launcher', |
| 119 | + 'karma-safari-launcher', |
| 120 | + 'karma-firefox-launcher', |
| 121 | + 'karma-jasmine', |
| 122 | + 'karma-junit-reporter', |
| 123 | + 'karma-sauce-launcher', |
| 124 | + 'karma-verbose-reporter', |
| 125 | + 'karma-webpack', |
| 126 | + ] |
| 127 | + } |
| 128 | + |
| 129 | + if (!process.env.SAUCE_USERNAME) { |
| 130 | + console.log( |
| 131 | + 'Skipping SauceLabs tests because SAUCE_USERNAME environment variable is not set.' |
| 132 | + ) |
| 133 | + } else if (!process.env.SAUCE_ACCESS_KEY) { |
| 134 | + console.log( |
| 135 | + 'Skipping SauceLabs tests because SAUCE_ACCESS_KEY environment variable is not set.' |
| 136 | + ) |
| 137 | + } else { |
| 138 | + options.reporters.push('saucelabs') |
| 139 | + } |
| 140 | + |
| 141 | + if (process.env.TEST_BROWSERS) { |
| 142 | + options.browsers = process.env.TEST_BROWSERS.split(',') |
| 143 | + } else { |
| 144 | + options.browsers.push('ChromeHeadlessNoSandbox') |
| 145 | + options.browsers.push('FirefoxHeadless') |
| 146 | + options.browsers.push('Edge') |
| 147 | + } |
| 148 | + |
| 149 | + console.log('running with browsers:', options.browsers) |
| 150 | + |
| 151 | + if (!process.env.CI) { |
| 152 | + // Continuous Integration mode |
| 153 | + // if true, Karma captures browsers, runs the tests and exits |
| 154 | + options.singleRun = false |
| 155 | + // enable / disable watching file and executing tests whenever any file changes |
| 156 | + options.autoWatch = true |
| 157 | + } |
| 158 | + |
| 159 | + config.set(options) |
| 160 | +} |
0 commit comments