blob: 0a1258495de15d12689d0eaf29a3fec2dafefdda [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001/* 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
7const path = require('path');
8
9process.env.CHROME_BIN = require('puppeteer').executablePath();
10
11module.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 {
122 test: /\.js$/,
123 loader: 'istanbul-instrumenter-loader',
124 include: path.resolve('static_src/'),
125 exclude: [/\.test.(js|ts|tsx)$/],
126 query: {esModules: true},
127 },
128 {
129 test: /\.css$/i,
130 use: [
131 {loader: 'style-loader', options: {injectType: 'styleTag'}},
132 {
133 loader: 'css-loader',
134 options: {
135 modules: true,
136 importLoaders: 1,
137 },
138 },
139 'postcss-loader',
140 ],
141 },
142 ],
143 },
144 },
145
146
147 // test results reporter to use
148 // possible values: 'dots', 'progress'
149 // available reporters: https://npmjs.org/browse/keyword/karma-reporter
150 reporters: ['mocha', 'chopsui-json'].concat(
151 coverage ? ['coverage'] : []),
152
153
154 // configure coverage reporter
155 coverageReporter: {
156 dir: 'coverage',
157 reporters: [
158 {type: 'lcovonly', subdir: '.'},
159 {type: 'json', subdir: '.', file: 'coverage.json'},
160 {type: 'html'},
161 {type: 'text'},
162 ],
163 },
164
165 chopsUiReporter: {
166 stdout: false,
167 buildNumber: String(new Date().getTime()),
168 outputFile: 'full_results.json',
169 },
170
171 // web server port
172 port: 9876,
173
174
175 // enable / disable colors in the output (reporters and logs)
176 colors: true,
177
178
179 // level of logging
180 // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
181 logLevel: config.LOG_INFO,
182
183
184 // enable / disable watching file and executing tests whenever any file changes
185 autoWatch: true,
186
187
188 // start these browsers
189 // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
190 browsers: isDebug ? ['Chrome_latest'] : ['ChromeHeadless'],
191
192
193 customLaunchers: {
194 Chrome_latest: {
195 base: 'Chrome',
196 version: 'latest',
197 },
198 },
199
200
201 // Continuous Integration mode
202 // if true, Karma captures browsers, runs the tests and exits
203 singleRun: isDebug ? false : true,
204
205 // Concurrency level
206 // how many browser should be started simultaneous
207 concurrency: Infinity,
208 });
209};