blob: 83306fa081284c99630dc65dcd20afadbc00eb7d [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
Copybara854996b2021-09-07 19:36:02 +00007process.env.CHROME_BIN = require('puppeteer').executablePath();
8
9module.exports = function(config) {
10 const isDebug = process.argv.some((arg) => arg === '--debug');
11 const coverage = process.argv.some((arg) => arg === '--coverage');
12 config.set({
13
14 // base path that will be used to resolve all patterns (eg. files, exclude)
15 basePath: '',
16
17
18 client: {
19 mocha: {
20 reporter: 'html',
21 ui: 'bdd',
22 checkLeaks: true,
23 globals: [
Adrià Vilanova Martínezde942802022-07-15 14:06:55 +020024 // Used for submitting Issue Wizard Feedback.
25 'userfeedback',
Copybara854996b2021-09-07 19:36:02 +000026 '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
Adrià Vilanova Martínezde942802022-07-15 14:06:55 +020065 frameworks: ['mocha', 'sinon', 'webpack'],
Copybara854996b2021-09-07 19:36:02 +000066
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',
Copybara854996b2021-09-07 19:36:02 +000092 'karma-sinon',
93 'karma-sourcemap-loader',
94 'karma-webpack',
95 '@chopsui/karma-reporter',
96 ],
97
Copybara854996b2021-09-07 19:36:02 +000098 webpack: {
99 // webpack configuration
100 devtool: 'inline-source-map',
101 mode: 'development',
102 resolve: {
103 modules: ['node_modules', 'static_src'],
104 },
105 module: {
106 rules: [
107 {
108 test: /\.(ts|tsx)$/,
109 exclude: /node_modules/,
110 use: ['babel-loader'],
111 },
112 {
Copybara854996b2021-09-07 19:36:02 +0000113 test: /\.css$/i,
114 use: [
115 {loader: 'style-loader', options: {injectType: 'styleTag'}},
116 {
117 loader: 'css-loader',
118 options: {
119 modules: true,
120 importLoaders: 1,
121 },
122 },
123 'postcss-loader',
124 ],
125 },
126 ],
127 },
128 },
129
130
131 // test results reporter to use
132 // possible values: 'dots', 'progress'
133 // available reporters: https://npmjs.org/browse/keyword/karma-reporter
134 reporters: ['mocha', 'chopsui-json'].concat(
135 coverage ? ['coverage'] : []),
136
137
138 // configure coverage reporter
139 coverageReporter: {
140 dir: 'coverage',
141 reporters: [
142 {type: 'lcovonly', subdir: '.'},
143 {type: 'json', subdir: '.', file: 'coverage.json'},
144 {type: 'html'},
145 {type: 'text'},
146 ],
147 },
148
149 chopsUiReporter: {
150 stdout: false,
151 buildNumber: String(new Date().getTime()),
152 outputFile: 'full_results.json',
153 },
154
155 // web server port
156 port: 9876,
157
158
159 // enable / disable colors in the output (reporters and logs)
160 colors: true,
161
162
163 // level of logging
164 // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
165 logLevel: config.LOG_INFO,
166
167
168 // enable / disable watching file and executing tests whenever any file changes
169 autoWatch: true,
170
171
172 // start these browsers
173 // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
174 browsers: isDebug ? ['Chrome_latest'] : ['ChromeHeadless'],
175
176
177 customLaunchers: {
178 Chrome_latest: {
179 base: 'Chrome',
180 version: 'latest',
181 },
182 },
183
184
185 // Continuous Integration mode
186 // if true, Karma captures browsers, runs the tests and exits
187 singleRun: isDebug ? false : true,
188
189 // Concurrency level
190 // how many browser should be started simultaneous
191 concurrency: Infinity,
192 });
193};