xref: /aosp_15_r20/development/tools/winscope/karma.config.ci.js (revision 90c8c64db3049935a07c6143d7fd006e26f8ecca)
1*90c8c64dSAndroid Build Coastguard Worker/*
2*90c8c64dSAndroid Build Coastguard Worker * Copyright (C) 2023 The Android Open Source Project
3*90c8c64dSAndroid Build Coastguard Worker *
4*90c8c64dSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*90c8c64dSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*90c8c64dSAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*90c8c64dSAndroid Build Coastguard Worker *
8*90c8c64dSAndroid Build Coastguard Worker *      http://www.apache.org/licenses/LICENSE-2.0
9*90c8c64dSAndroid Build Coastguard Worker *
10*90c8c64dSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*90c8c64dSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*90c8c64dSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*90c8c64dSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*90c8c64dSAndroid Build Coastguard Worker * limitations under the License.
15*90c8c64dSAndroid Build Coastguard Worker */
16*90c8c64dSAndroid Build Coastguard Worker
17*90c8c64dSAndroid Build Coastguard Workerconst path = require('path');
18*90c8c64dSAndroid Build Coastguard Workerconst configCommon = require('./karma.config.common');
19*90c8c64dSAndroid Build Coastguard Worker
20*90c8c64dSAndroid Build Coastguard Workerconst configCi = (config) => {
21*90c8c64dSAndroid Build Coastguard Worker  config.set({
22*90c8c64dSAndroid Build Coastguard Worker    singleRun: true,
23*90c8c64dSAndroid Build Coastguard Worker    browsers: ['ChromeHeadless'],
24*90c8c64dSAndroid Build Coastguard Worker    plugins: [
25*90c8c64dSAndroid Build Coastguard Worker      'karma-webpack',
26*90c8c64dSAndroid Build Coastguard Worker      'karma-chrome-launcher',
27*90c8c64dSAndroid Build Coastguard Worker      'karma-coverage-istanbul-reporter',
28*90c8c64dSAndroid Build Coastguard Worker      'karma-jasmine',
29*90c8c64dSAndroid Build Coastguard Worker      'karma-sourcemap-loader',
30*90c8c64dSAndroid Build Coastguard Worker    ],
31*90c8c64dSAndroid Build Coastguard Worker    reporters: ['progress', 'coverage-istanbul'],
32*90c8c64dSAndroid Build Coastguard Worker    coverageIstanbulReporter: {
33*90c8c64dSAndroid Build Coastguard Worker      // reports can be any that are listed here: https://github.com/istanbuljs/istanbuljs/tree/73c25ce79f91010d1ff073aa6ff3fd01114f90db/packages/istanbul-reports/lib
34*90c8c64dSAndroid Build Coastguard Worker      reports: ['html', 'lcovonly', 'text-summary'],
35*90c8c64dSAndroid Build Coastguard Worker
36*90c8c64dSAndroid Build Coastguard Worker      // base output directory. If you include %browser% in the path it will be replaced with the karma browser name
37*90c8c64dSAndroid Build Coastguard Worker      dir: path.join(__dirname, 'coverage'),
38*90c8c64dSAndroid Build Coastguard Worker
39*90c8c64dSAndroid Build Coastguard Worker      // if using webpack and pre-loaders, work around webpack breaking the source path
40*90c8c64dSAndroid Build Coastguard Worker      fixWebpackSourcePaths: true,
41*90c8c64dSAndroid Build Coastguard Worker
42*90c8c64dSAndroid Build Coastguard Worker      // Omit files with no statements, no functions and no branches covered from the report
43*90c8c64dSAndroid Build Coastguard Worker      skipFilesWithNoCoverage: true,
44*90c8c64dSAndroid Build Coastguard Worker
45*90c8c64dSAndroid Build Coastguard Worker      // Most reporters accept additional config options. You can pass these through the `report-config` option
46*90c8c64dSAndroid Build Coastguard Worker      'report-config': {
47*90c8c64dSAndroid Build Coastguard Worker        // all options available at: https://github.com/istanbuljs/istanbuljs/blob/73c25ce79f91010d1ff073aa6ff3fd01114f90db/packages/istanbul-reports/lib/html/index.js#L257-L261
48*90c8c64dSAndroid Build Coastguard Worker        html: {
49*90c8c64dSAndroid Build Coastguard Worker          // outputs the report in ./coverage/html
50*90c8c64dSAndroid Build Coastguard Worker          subdir: 'html',
51*90c8c64dSAndroid Build Coastguard Worker        },
52*90c8c64dSAndroid Build Coastguard Worker      },
53*90c8c64dSAndroid Build Coastguard Worker
54*90c8c64dSAndroid Build Coastguard Worker      // enforce percentage thresholds
55*90c8c64dSAndroid Build Coastguard Worker      // anything under these percentages will cause karma to fail with an exit code of 1 if not running in watch mode
56*90c8c64dSAndroid Build Coastguard Worker      thresholds: {
57*90c8c64dSAndroid Build Coastguard Worker        emitWarning: true, // set to `true` to not fail the test command when thresholds are not met
58*90c8c64dSAndroid Build Coastguard Worker        // thresholds for all files
59*90c8c64dSAndroid Build Coastguard Worker        global: {
60*90c8c64dSAndroid Build Coastguard Worker          statements: 100,
61*90c8c64dSAndroid Build Coastguard Worker          lines: 100,
62*90c8c64dSAndroid Build Coastguard Worker          branches: 100,
63*90c8c64dSAndroid Build Coastguard Worker          functions: 100,
64*90c8c64dSAndroid Build Coastguard Worker        },
65*90c8c64dSAndroid Build Coastguard Worker        // thresholds per file
66*90c8c64dSAndroid Build Coastguard Worker        each: {
67*90c8c64dSAndroid Build Coastguard Worker          statements: 50,
68*90c8c64dSAndroid Build Coastguard Worker          lines: 50,
69*90c8c64dSAndroid Build Coastguard Worker          branches: 50,
70*90c8c64dSAndroid Build Coastguard Worker          functions: 50,
71*90c8c64dSAndroid Build Coastguard Worker        },
72*90c8c64dSAndroid Build Coastguard Worker      },
73*90c8c64dSAndroid Build Coastguard Worker    },
74*90c8c64dSAndroid Build Coastguard Worker
75*90c8c64dSAndroid Build Coastguard Worker    verbose: true, // output config used by istanbul for debugging
76*90c8c64dSAndroid Build Coastguard Worker  });
77*90c8c64dSAndroid Build Coastguard Worker};
78*90c8c64dSAndroid Build Coastguard Worker
79*90c8c64dSAndroid Build Coastguard Workermodule.exports = (config) => {
80*90c8c64dSAndroid Build Coastguard Worker  configCommon(config);
81*90c8c64dSAndroid Build Coastguard Worker  configCi(config);
82*90c8c64dSAndroid Build Coastguard Worker};
83