From 1be6a9e6c9cccf19782db11ad8d2689580a4832e Mon Sep 17 00:00:00 2001 From: Bartlomiej Obecny Date: Fri, 1 Nov 2019 21:11:25 +0100 Subject: [PATCH] chore: fixing coverage for karma using istanbul (#466) --- api/karma.base.js | 7 ++++++- api/karma.webpack.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 api/karma.webpack.js diff --git a/api/karma.base.js b/api/karma.base.js index 9b8869fc07..088ac3f987 100644 --- a/api/karma.base.js +++ b/api/karma.base.js @@ -19,7 +19,12 @@ module.exports = { hostname: 'localhost', browsers: ['ChromeHeadless'], frameworks: ['mocha'], - reporters: ['spec'], + coverageIstanbulReporter: { + reports: ['json'], + dir: '.nyc_output', + fixWebpackSourcePaths: true + }, + reporters: ['spec', 'coverage-istanbul'], files: ['test/index-webpack.ts'], preprocessors: { 'test/index-webpack.ts': ['webpack'] }, webpackMiddleware: { noInfo: true } diff --git a/api/karma.webpack.js b/api/karma.webpack.js new file mode 100644 index 0000000000..d62d6292c5 --- /dev/null +++ b/api/karma.webpack.js @@ -0,0 +1,43 @@ +/*! + * Copyright 2019, OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +const webpackNodePolyfills = require('./webpack.node-polyfills.js'); + +// This is the webpack configuration for browser Karma tests with coverage. +module.exports = { + mode: 'development', + target: 'web', + output: { filename: 'bundle.js' }, + resolve: { extensions: ['.ts', '.js'] }, + devtool: 'inline-source-map', + module: { + rules: [ + { test: /\.ts$/, use: 'ts-loader' }, + { + enforce: 'post', + exclude: /(node_modules|\.test\.[tj]sx?$)/, + test: /\.ts$/, + use: { + loader: 'istanbul-instrumenter-loader', + options: { esModules: true } + } + }, + // This setting configures Node polyfills for the browser that will be + // added to the webpack bundle for Karma tests. + { parser: { node: webpackNodePolyfills } } + ] + } +};