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