Skip to content
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/node_modules
/.nyc_output
/coverage
/coverage/*
!/coverage/coverage-summary.json
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# pacman-js

![Code Coverage](https://img.shields.io/badge/coverage-100%25-brightgreen.svg)
[![Code Coverage](https://img.shields.io/badge/coverage-100%25-brightgreen.svg)](https://github.com/bward2/pacman-js/blob/master/coverage/coverage-summary.json)
[![Code Style](https://img.shields.io/badge/code%20style-airbnb-brightgreen.svg)](https://github.com/airbnb/javascript)

Pacman clone made with Javascript, HTML, and CSS.
Expand Down
22 changes: 22 additions & 0 deletions coverage/coverage-summary.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"statements": {
"covered": 1116,
"total": 1116,
"pct": 100
},
"branches": {
"covered": 451,
"total": 451,
"pct": 100
},
"functions": {
"covered": 214,
"total": 214,
"pct": 100
},
"lines": {
"covered": 1115,
"total": 1115,
"pct": 100
}
}
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
{
"name": "pacman-js",
"author": "Brent Ward",
"nyc": {
"include": [
"app/scripts/**/*.js"
],
"all": true
},
"scripts": {
"test": "nyc --reporter=html --reporter=text --check-coverage --lines 100 --functions 100 --branches 100 mocha app/tests",
"test": "nyc --reporter=html --reporter=text --reporter=json --check-coverage --lines 100 --functions 100 --branches 100 mocha app/tests",
"posttest": "node scripts/coverage-summary.js",
"lint": "eslint .",
"update": "ncu -i --format group",
"serve": "node ./node_modules/http-server/bin/http-server",
Expand Down
43 changes: 43 additions & 0 deletions scripts/coverage-summary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* eslint-disable no-console */
const fs = require('fs');
const path = require('path');

const htmlPath = path.join(__dirname, '..', 'coverage', 'index.html');
const outputPath = path.join(__dirname, '..', 'coverage', 'coverage-summary.json');

if (!fs.existsSync(htmlPath)) {
console.error('coverage/index.html not found');
process.exit(1);
}

const html = fs.readFileSync(htmlPath, 'utf8');

const metrics = ['Statements', 'Branches', 'Functions', 'Lines'];
const summary = {};

metrics.forEach((metric) => {
const regex = new RegExp(
`<span class="quiet">${metric}<\\/span>[\\s\\S]*?<span class='fraction'>(\\d+)\\/(\\d+)<\\/span>`,
'i',
);

const match = html.match(regex);

if (!match) {
console.warn(`Could not find ${metric} in coverage HTML`);
return;
}

const covered = Number(match[1]);
const total = Number(match[2]);

summary[metric.toLowerCase()] = {
covered,
total,
pct: total === 0 ? 100 : Math.round((covered / total) * 100),
};
});

fs.writeFileSync(outputPath, JSON.stringify(summary, null, 2));

console.log('✅ Report summary ready at coverage/coverage-summary.json!');