Skip to content

Commit

Permalink
test(ilc client): fix typescript code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
stas-nc committed Nov 12, 2024
1 parent c94b984 commit b42248b
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 23 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ jobs:
fullCoverageDiff: true
autorun: false
postComment: false
oldCodeCoveragePath: ./dest-client-side-tests-artifacts/coverage/chrome/coverage-summary.json
newCodeCoveragePath: ./src-client-side-tests-artifacts/coverage/chrome/coverage-summary.json
oldCodeCoveragePath: ./dest-client-side-tests-artifacts/coverage/coverage-summary.json
newCodeCoveragePath: ./src-client-side-tests-artifacts/coverage/coverage-summary.json
total_delta: 2
- name: Merge coverage report for registry
run: |
Expand All @@ -338,7 +338,7 @@ jobs:
postComment: false
oldCodeCoveragePath: ./dest-merged-registry-tests-artifacts/coverage/coverage-summary.json
newCodeCoveragePath: ./src-merged-registry-tests-artifacts/coverage/coverage-summary.json
total_delta: 6
total_delta: 2
- name: Compose comment
if: success() || failure()
run: |
Expand Down
11 changes: 11 additions & 0 deletions ilc/build/webpack.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ const config = {
},
};

config.module.rules.push({
test: /\.(js|ts)$/,
/**
* Control coveraage files
*/
exclude: /(node_modules|\.spec\.(js|ts)$|tests\/)/,
loader: '@jsdevtools/coverage-istanbul-loader',
enforce: 'post',
options: { esModules: true },
});

config.resolve.alias['nock'] = false;
config.resolve.alias['timers'] = false;

Expand Down
57 changes: 48 additions & 9 deletions ilc/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ module.exports = function (config) {
const files = config.glob
? [config.glob]
: [
'client/**/*.spec.js',
'common/**/*.spec.js',
'systemjs/**/*.spec.js',
'client/**/*.spec.+(js|ts)',
'common/**/*.spec.+(js|ts)',
'systemjs/**/*.spec.+(js|ts)',
{
pattern: 'systemjs/spec/fixtures/**/*.js',
included: false,
Expand All @@ -41,7 +41,7 @@ module.exports = function (config) {
},
},
customContextFile: './tests/karma.index.html',
frameworks: ['parallel', 'mocha', 'chai', 'sinon'],
frameworks: ['parallel', 'mocha', 'chai', 'sinon', 'webpack'],
plugins: [
'karma-parallel',
'karma-chrome-launcher',
Expand All @@ -50,19 +50,19 @@ module.exports = function (config) {
'karma-chai',
'karma-sinon',

'karma-coverage',
'karma-coverage-istanbul-reporter',
'karma-mocha-reporter',

'karma-webpack',
'karma-sourcemap-loader',
],
files,
preprocessors: {
'client/**/*.spec.js': ['webpack', 'sourcemap'],
'common/**/*.spec.js': ['webpack', 'sourcemap'],
'systemjs/**/*.spec.js': ['webpack', 'sourcemap'],
'client/**/*.spec.+(js|ts)': ['webpack', 'sourcemap'],
'common/**/*.spec.+(js|ts)': ['webpack', 'sourcemap'],
'systemjs/**/*.spec.+(js|ts)': ['webpack', 'sourcemap'],
},
reporters: ['mocha', 'coverage'],
reporters: ['mocha', 'coverage-istanbul'],
mochaReporter: {
showDiff: true,
},
Expand All @@ -85,6 +85,45 @@ module.exports = function (config) {
...nycConfig.watermarks,
},
},
coverageIstanbulReporter: {
// reports can be any that are listed here: https://github.com/istanbuljs/istanbuljs/tree/73c25ce79f91010d1ff073aa6ff3fd01114f90db/packages/istanbul-reports/lib
reports: nycConfig.reporter,

// base output directory. If you include %browser% in the path it will be replaced with the karma browser name
dir: path.join(__dirname, '.karma_output', 'coverage'),

// Combines coverage information from multiple browsers into one report rather than outputting a report
// for each browser.
combineBrowserReports: true,

// if using webpack and pre-loaders, work around webpack breaking the source path
fixWebpackSourcePaths: true,

// Omit files with no statements, no functions and no branches covered from the report
skipFilesWithNoCoverage: true,

// Most reporters accept additional config options. You can pass these through the `report-config` option
'report-config': {
// all options available at: https://github.com/istanbuljs/istanbuljs/blob/73c25ce79f91010d1ff073aa6ff3fd01114f90db/packages/istanbul-reports/lib/html/index.js#L257-L261
html: {
// outputs the report in ./coverage/html
subdir: 'html',
},
},

// enforce percentage thresholds
// anything under these percentages will cause karma to fail with an exit code of 1 if not running in watch mode
thresholds: {
emitWarning: false, // set to `true` to not fail the test command when thresholds are not met
// thresholds for all files
global: getThresholds(),
// thresholds per file
each: getThresholds(),
},
watermarks: {
...nycConfig.watermarks,
},
},
webpack: {
...webpackConfig,
},
Expand Down
142 changes: 132 additions & 10 deletions ilc/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion ilc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/preset-env": "^7.25.4",
"@babel/register": "^7.24.6",
"@jsdevtools/coverage-istanbul-loader": "^3.0.5",
"@types/chai": "^4.3.19",
"@types/config": "^3.3.5",
"@types/mocha": "^10.0.8",
Expand All @@ -74,7 +75,7 @@
"karma": "^6.4.4",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^3.2.0",
"karma-coverage": "^2.2.1",
"karma-coverage-istanbul-reporter": "^3.0.3",
"karma-mocha": "^2.0.1",
"karma-mocha-reporter": "^2.2.5",
"karma-parallel": "^0.3.1",
Expand Down

0 comments on commit b42248b

Please sign in to comment.