Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fixing coverage for karma using istanbul #466

Merged
merged 2 commits into from
Nov 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion karma.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
13 changes: 11 additions & 2 deletions ...opentelemetry-core/webpack/test.config.js → karma.webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* limitations under the License.
*/

const webpackNodePolyfills = require('../../../webpack.node-polyfills.js');
const webpackNodePolyfills = require('./webpack.node-polyfills.js');

// This is the webpack configuration for browser Karma tests.
// This is the webpack configuration for browser Karma tests with coverage.
module.exports = {
mode: 'development',
target: 'web',
Expand All @@ -26,6 +26,15 @@ module.exports = {
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 } }
Expand Down
4 changes: 2 additions & 2 deletions packages/opentelemetry-core/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
* limitations under the License.
*/

const webpackConfig = require('./webpack/test.config.js');
const karmaWebpackConfig = require('../../karma.webpack');
const karmaBaseConfig = require('../../karma.base');

module.exports = (config) => {
config.set(Object.assign({}, karmaBaseConfig, {
webpack: webpackConfig
webpack: karmaWebpackConfig
}))
};
13 changes: 8 additions & 5 deletions packages/opentelemetry-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
"repository": "open-telemetry/opentelemetry-js",
"scripts": {
"test": "nyc ts-mocha -p tsconfig.json test/**/*.ts",
"test:browser": "karma start --single-run",
"test:browser": "nyc karma start --single-run",
"tdd": "yarn tdd:node",
"tdd:node": "yarn test -- --watch-extensions ts --watch",
"tdd:browser": "karma start",
"codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../",
"codecov:browser": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../",
"clean": "rimraf build/*",
"check": "gts check",
"compile": "tsc -p .",
Expand Down Expand Up @@ -53,20 +54,22 @@
"@types/webpack-env": "1.13.9",
"codecov": "^3.1.0",
"gts": "^1.0.0",
"karma": "^4.1.0",
"istanbul-instrumenter-loader": "^3.0.1",
"karma": "^4.4.1",
"karma-chrome-launcher": "^3.1.0",
"karma-coverage-istanbul-reporter": "^2.1.0",
"karma-mocha": "^1.3.0",
"karma-spec-reporter": "^0.0.32",
"karma-webpack": "^4.0.2",
"mocha": "^6.1.0",
"nyc": "^14.1.1",
"rimraf": "^3.0.0",
"sinon": "^7.3.2",
"sinon": "^7.5.0",
"tslint-consistent-codestyle" : "^1.16.0",
"tslint-microsoft-contrib": "^6.2.0",
"ts-loader": "^6.0.4",
"ts-mocha": "^6.0.0",
"ts-node": "^8.0.0",
"tslint-consistent-codestyle": "^1.15.1",
"tslint-microsoft-contrib": "^6.2.0",
"typescript": "^3.6.3",
"webpack": "^4.35.2"
},
Expand Down
3 changes: 3 additions & 0 deletions packages/opentelemetry-core/test/index-webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@
// all modules ending in "test" from the current folder and all its subfolders.
const testsContext = require.context('.', true, /test$/);
testsContext.keys().forEach(testsContext);

const srcContext = require.context('.', true, /src$/);
srcContext.keys().forEach(srcContext);
4 changes: 2 additions & 2 deletions packages/opentelemetry-plugin-document-load/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
* limitations under the License.
*/

const webpackConfig = require('./webpack/test.config.js');
const karmaWebpackConfig = require('../../karma.webpack');
const karmaBaseConfig = require('../../karma.base');

module.exports = (config) => {
config.set(Object.assign({}, karmaBaseConfig, {
webpack: webpackConfig
webpack: karmaWebpackConfig
}))
};
10 changes: 6 additions & 4 deletions packages/opentelemetry-plugin-document-load/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,18 @@
"access": "public"
},
"devDependencies": {
"@babel/core": "^7.6.0",
"@types/mocha": "^5.2.5",
"@types/node": "^12.6.8",
"@types/webpack-env": "1.13.9",
"@types/sinon": "^7.0.13",
"@babel/core": "^7.6.0",
"@types/webpack-env": "1.13.9",
"babel-loader": "^8.0.6",
"codecov": "^3.1.0",
"gts": "^1.0.0",
"karma": "^4.1.0",
"karma-chrome-launcher": "^2.2.0",
"istanbul-instrumenter-loader": "^3.0.1",
"karma": "^4.4.1",
"karma-chrome-launcher": "^3.1.0",
"karma-coverage-istanbul-reporter": "^2.1.0",
"karma-mocha": "^1.3.0",
"karma-spec-reporter": "^0.0.32",
"karma-webpack": "^4.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@
// all modules ending in "test" from the current folder and all its subfolders.
const testsContext = require.context('.', true, /test$/);
testsContext.keys().forEach(testsContext);

const srcContext = require.context('.', true, /src$/);
srcContext.keys().forEach(srcContext);
34 changes: 0 additions & 34 deletions packages/opentelemetry-plugin-document-load/webpack/test.config.js

This file was deleted.

4 changes: 2 additions & 2 deletions packages/opentelemetry-tracing/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
* limitations under the License.
*/

const webpackConfig = require('./webpack/test.config.js');
const karmaWebpackConfig = require('../../karma.webpack');
const karmaBaseConfig = require('../../karma.base');

module.exports = (config) => {
config.set(Object.assign({}, karmaBaseConfig, {
webpack: webpackConfig
webpack: karmaWebpackConfig
}))
};
10 changes: 6 additions & 4 deletions packages/opentelemetry-tracing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"prepare": "npm run compile",
"tdd": "yarn test -- --watch-extensions ts --watch",
"test": "nyc ts-mocha -p tsconfig.json 'test/**/*.ts' --exclude 'test/index-webpack.ts'",
"test:browser": "karma start --single-run",
"test:browser": "nyc karma start --single-run",
"watch": "tsc -w"
},
"keywords": [
Expand Down Expand Up @@ -51,16 +51,18 @@
"@types/webpack-env": "1.13.9",
"codecov": "^3.1.0",
"gts": "^1.0.0",
"karma": "^4.1.0",
"karma-chrome-launcher": "^2.2.0",
"istanbul-instrumenter-loader": "^3.0.1",
"karma": "^4.4.1",
"karma-chrome-launcher": "^3.1.0",
"karma-coverage-istanbul-reporter": "^2.1.0",
"karma-mocha": "^1.3.0",
"karma-spec-reporter": "^0.0.32",
"karma-webpack": "^4.0.2",
"mocha": "^6.1.0",
"nyc": "^14.1.1",
"rimraf": "^3.0.0",
"sinon": "^7.5.0",
"tslint-consistent-codestyle": "^1.15.1",
"tslint-consistent-codestyle" : "^1.16.0",
"tslint-microsoft-contrib": "^6.2.0",
"ts-loader": "^6.0.4",
"ts-mocha": "^6.0.0",
Expand Down
3 changes: 3 additions & 0 deletions packages/opentelemetry-tracing/test/index-webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@
// all modules ending in "test" from the current folder and all its subfolders.
const testsContext = require.context('.', true, /test$/);
testsContext.keys().forEach(testsContext);

const srcContext = require.context('.', true, /src$/);
srcContext.keys().forEach(srcContext);
34 changes: 0 additions & 34 deletions packages/opentelemetry-tracing/webpack/test.config.js

This file was deleted.

4 changes: 2 additions & 2 deletions packages/opentelemetry-web/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
* limitations under the License.
*/

const webpackConfig = require('./webpack/test.config.js');
const karmaWebpackConfig = require('../../karma.webpack');
const karmaBaseConfig = require('../../karma.base');

module.exports = (config) => {
config.set(Object.assign({}, karmaBaseConfig, {
webpack: webpackConfig
webpack: karmaWebpackConfig
}))
};
10 changes: 6 additions & 4 deletions packages/opentelemetry-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,18 @@
"access": "public"
},
"devDependencies": {
"@babel/core": "^7.6.0",
"@types/mocha": "^5.2.5",
"@types/node": "^12.6.8",
"@types/webpack-env": "1.13.9",
"@types/sinon": "^7.0.13",
"@babel/core": "^7.6.0",
"@types/webpack-env": "1.13.9",
"babel-loader": "^8.0.6",
"codecov": "^3.1.0",
"gts": "^1.0.0",
"karma": "^4.1.0",
"karma-chrome-launcher": "^2.2.0",
"istanbul-instrumenter-loader": "^3.0.1",
"karma": "^4.4.1",
"karma-chrome-launcher": "^3.1.0",
"karma-coverage-istanbul-reporter": "^2.1.0",
"karma-mocha": "^1.3.0",
"karma-spec-reporter": "^0.0.32",
"karma-webpack": "^4.0.2",
Expand Down
3 changes: 3 additions & 0 deletions packages/opentelemetry-web/test/index-webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@
// all modules ending in "test" from the current folder and all its subfolders.
const testsContext = require.context('.', true, /test$/);
testsContext.keys().forEach(testsContext);

const srcContext = require.context('.', true, /src$/);
srcContext.keys().forEach(srcContext);
34 changes: 0 additions & 34 deletions packages/opentelemetry-web/webpack/test.config.js

This file was deleted.