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