Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 1 | /* Copyright 2019 The Chromium Authors. All Rights Reserved. |
| 2 | * |
| 3 | * Use of this source code is governed by a BSD-style |
| 4 | * license that can be found in the LICENSE file. |
| 5 | */ |
| 6 | |
| 7 | const path = require('path'); |
| 8 | |
| 9 | process.env.CHROME_BIN = require('puppeteer').executablePath(); |
| 10 | |
| 11 | module.exports = function(config) { |
| 12 | const isDebug = process.argv.some((arg) => arg === '--debug'); |
| 13 | const coverage = process.argv.some((arg) => arg === '--coverage'); |
| 14 | config.set({ |
| 15 | |
| 16 | // base path that will be used to resolve all patterns (eg. files, exclude) |
| 17 | basePath: '', |
| 18 | |
| 19 | |
| 20 | client: { |
| 21 | mocha: { |
| 22 | reporter: 'html', |
| 23 | ui: 'bdd', |
| 24 | checkLeaks: true, |
| 25 | globals: [ |
| 26 | 'CS_env', |
| 27 | // __tsMonClient probably shouldn't be allowed to |
| 28 | // leak between tests, but locating the current source of these |
| 29 | // leaks has proven quite difficult. |
| 30 | '__tsMonClient', |
| 31 | 'ga', |
| 32 | 'Color', |
| 33 | 'Chart', |
| 34 | // TODO(ehmaldonado): Remove once the old autocomplete code is |
| 35 | // deprecated. |
| 36 | 'TKR_populateAutocomplete', |
| 37 | // All of the below are necessary for loading gapi.js. |
| 38 | 'gapi', |
| 39 | '__gapiLoadPromise', |
| 40 | '___jsl', |
| 41 | 'osapi', |
| 42 | 'gadgets', |
| 43 | 'shindig', |
| 44 | 'googleapis', |
| 45 | 'iframer', |
| 46 | 'ToolbarApi', |
| 47 | 'iframes', |
| 48 | 'IframeBase', |
| 49 | 'Iframe', |
| 50 | 'IframeProxy', |
| 51 | 'IframeWindow', |
| 52 | '__gapi_jstiming__', |
| 53 | ], |
| 54 | timeout: 5000, |
| 55 | }, |
| 56 | }, |
| 57 | |
| 58 | mochaReporter: { |
| 59 | showDiff: true, |
| 60 | }, |
| 61 | |
| 62 | |
| 63 | // frameworks to use |
| 64 | // available frameworks: https://npmjs.org/browse/keyword/karma-adapter |
| 65 | frameworks: ['parallel', 'mocha', 'sinon'], |
| 66 | |
| 67 | |
| 68 | // list of files / patterns to load in the browser |
| 69 | files: [ |
| 70 | 'static_src/test/setup.js', |
| 71 | 'static_src/test/index.js', |
| 72 | ], |
| 73 | |
| 74 | |
| 75 | // list of files / patterns to exclude |
| 76 | exclude: [ |
| 77 | ], |
| 78 | |
| 79 | |
| 80 | // preprocess matching files before serving them to the browser |
| 81 | // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor |
| 82 | preprocessors: { |
| 83 | 'static_src/test/setup.js': ['webpack', 'sourcemap'], |
| 84 | 'static_src/test/index.js': ['webpack', 'sourcemap'], |
| 85 | }, |
| 86 | |
| 87 | plugins: [ |
| 88 | 'karma-chrome-launcher', |
| 89 | 'karma-coverage', |
| 90 | 'karma-mocha', |
| 91 | 'karma-mocha-reporter', |
| 92 | 'karma-parallel', |
| 93 | 'karma-sinon', |
| 94 | 'karma-sourcemap-loader', |
| 95 | 'karma-webpack', |
| 96 | '@chopsui/karma-reporter', |
| 97 | ], |
| 98 | |
| 99 | parallelOptions: { |
| 100 | // Our builder is on a VM with 8 CPUs, so force this |
| 101 | // to run the same number of shards locally too. |
| 102 | // Vary this number to stress test order dependencies. |
| 103 | executors: isDebug ? 1 : 7, // Defaults to cpu-count - 1 |
| 104 | shardStrategy: 'round-robin', |
| 105 | }, |
| 106 | |
| 107 | webpack: { |
| 108 | // webpack configuration |
| 109 | devtool: 'inline-source-map', |
| 110 | mode: 'development', |
| 111 | resolve: { |
| 112 | modules: ['node_modules', 'static_src'], |
| 113 | }, |
| 114 | module: { |
| 115 | rules: [ |
| 116 | { |
| 117 | test: /\.(ts|tsx)$/, |
| 118 | exclude: /node_modules/, |
| 119 | use: ['babel-loader'], |
| 120 | }, |
| 121 | { |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 122 | test: /\.css$/i, |
| 123 | use: [ |
| 124 | {loader: 'style-loader', options: {injectType: 'styleTag'}}, |
| 125 | { |
| 126 | loader: 'css-loader', |
| 127 | options: { |
| 128 | modules: true, |
| 129 | importLoaders: 1, |
| 130 | }, |
| 131 | }, |
| 132 | 'postcss-loader', |
| 133 | ], |
| 134 | }, |
| 135 | ], |
| 136 | }, |
| 137 | }, |
| 138 | |
| 139 | |
| 140 | // test results reporter to use |
| 141 | // possible values: 'dots', 'progress' |
| 142 | // available reporters: https://npmjs.org/browse/keyword/karma-reporter |
| 143 | reporters: ['mocha', 'chopsui-json'].concat( |
| 144 | coverage ? ['coverage'] : []), |
| 145 | |
| 146 | |
| 147 | // configure coverage reporter |
| 148 | coverageReporter: { |
| 149 | dir: 'coverage', |
| 150 | reporters: [ |
| 151 | {type: 'lcovonly', subdir: '.'}, |
| 152 | {type: 'json', subdir: '.', file: 'coverage.json'}, |
| 153 | {type: 'html'}, |
| 154 | {type: 'text'}, |
| 155 | ], |
| 156 | }, |
| 157 | |
| 158 | chopsUiReporter: { |
| 159 | stdout: false, |
| 160 | buildNumber: String(new Date().getTime()), |
| 161 | outputFile: 'full_results.json', |
| 162 | }, |
| 163 | |
| 164 | // web server port |
| 165 | port: 9876, |
| 166 | |
| 167 | |
| 168 | // enable / disable colors in the output (reporters and logs) |
| 169 | colors: true, |
| 170 | |
| 171 | |
| 172 | // level of logging |
| 173 | // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG |
| 174 | logLevel: config.LOG_INFO, |
| 175 | |
| 176 | |
| 177 | // enable / disable watching file and executing tests whenever any file changes |
| 178 | autoWatch: true, |
| 179 | |
| 180 | |
| 181 | // start these browsers |
| 182 | // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher |
| 183 | browsers: isDebug ? ['Chrome_latest'] : ['ChromeHeadless'], |
| 184 | |
| 185 | |
| 186 | customLaunchers: { |
| 187 | Chrome_latest: { |
| 188 | base: 'Chrome', |
| 189 | version: 'latest', |
| 190 | }, |
| 191 | }, |
| 192 | |
| 193 | |
| 194 | // Continuous Integration mode |
| 195 | // if true, Karma captures browsers, runs the tests and exits |
| 196 | singleRun: isDebug ? false : true, |
| 197 | |
| 198 | // Concurrency level |
| 199 | // how many browser should be started simultaneous |
| 200 | concurrency: Infinity, |
| 201 | }); |
| 202 | }; |