Skip to content
Snippets Groups Projects
Commit 9e640a04 authored by Millicent Billette's avatar Millicent Billette
Browse files

FIX: real coverage

WiP: dead code deletion based on coverage
parent c7653761
No related branches found
No related tags found
No related merge requests found
const fs = require('fs');
const covData = JSON.parse(fs.readFileSync('generated/cov-dead-code-deletion/coverage-final.json', 'utf8'));
const files = Object.keys(covData);
for(const filePath of files){
const fullContent = fs.readFileSync(filePath, 'utf8').split('\n');
const keptContent = [];
const statementMap = covData[filePath].statementMap;
const statementRan = covData[filePath].s;
for(let key of Object.keys(statementMap)){
if(statementRan[key]>0) for(let line = statementMap[key].start.line; line<=statementMap[key].end.line;line++){
keptContent[line-1] = fullContent[line-1];
}
}
const fnMap = covData[filePath].fnMap;
const fnRan = covData[filePath].f;
for(let key of Object.keys(fnMap)){
if(fnRan[key]>0) for(let line = fnMap[key].decl.start.line; line<=fnMap[key].decl.end.line;line++){
keptContent[line-1] = fullContent[line-1];
}
}
fs.writeFileSync(filePath, keptContent.join('\n'));
}
const fs = require('fs');
fs.readdirSync('src/').forEach(fileName => {
const orgContent = fs.readFileSync(`src/${fileName}`, 'utf8');
fs.writeFileSync(`generated/cov-env/${fileName}`, orgContent);
if (!fileName.includes('.test.')) return;
fs.writeFileSync(`generated/npm/${fileName}`, orgContent);
const allJsTest = orgContent.replace(
/import \* as app from '\.\/(crypto)\.mjs';/,
(full, libName) => `import {${libName} as app} from './all.mjs';`);
fs.writeFileSync(`generated/cov-env/all.${fileName}`, allJsTest);
fs.writeFileSync(`generated/npm/all.${fileName}`, allJsTest);
});
fs.writeFileSync(`generated/cov-env/package.json`, fs.readFileSync(`package.json`, 'utf8'));
......@@ -20,18 +20,10 @@
"url": "https://framagit.org/g1/g1lib.js/-/issues"
},
"license": "AGPL-3.0",
"ava": {},
"c8": {
"c8": {
"all": true,
"branches": 0.080,
"lines": 0.080,
"functions": 0.080,
"statements": 0.080,
"report-dir": "../coverage",
"temp-dir": "../nyc_output.temp",
"reporter": [
"text-summary",
"html"
]
}
"report-dir": "../cov-dead-code-deletion",
"temp-dir": "../nyc_output.temp",
"reporter": ["json"]
}
}
......@@ -6,18 +6,21 @@
"clean": "rm -rf generated*",
"build": "run-s build:**",
"build:mk:npm": "mkdirp generated/npm",
"build:mk:cov-env": "mkdirp generated/cov-env",
"build:mk:minfied": "mkdirp generated/minified",
"build:mk:vendors": "mkdirp generated/vendors",
"build:vendors": "node CI/build.js",
"build:npm:all": "rollup src/all.mjs --format esm --file generated/npm/all.mjs",
"build:npm:crypto": "rollup src/crypto.mjs --format esm --file generated/npm/crypto.mjs",
"build:npm:dictionaryBuilder": "rollup src/dictionary-builder.mjs --format esm --file generated/npm/dictionary-builder.mjs",
"packaging": "https://github.com/1000i100/latinize-to-ascii/blob/master/package.json",
"build:npm:min:all": "terser generated/npm/all.mjs -o generated/minified/all.mjs",
"build:npm:cp": "cp npm/* generated/npm/",
"build:npm:cp:readme": "cp README* generated/npm/",
"build:npm:test2npm": "node CI/gen-prod-test.js",
"xbuild:npm:coverageForDeadCodeDeletion": "cd generated/npm/ && c8 ava",
"build:npm:min:all": "terser generated/npm/all.mjs -o generated/minified/all.mjs",
"build:npm:min:crypto": "terser generated/npm/crypto.mjs -o generated/minified/crypto.mjs",
"build:npm:min:dictionaryBuilder": "terser generated/npm/dictionary-builder.mjs -o generated/minified/dictionary-builder.mjs",
"build:npm:cp": "cp npm/* generated/npm/",
"build:npm:cp:readme": "cp README* generated/npm/",
"test": "run-s test:dev",
"test:dev": "run-p test:dev:**",
"test:dev:qualityCheck": "xo",
......@@ -29,8 +32,7 @@
"test:production:duplication": "jscpd ./",
"test:production:complexity": "./node_modules/.bin/es6-plato -r -d generated/maintainability ./src/*",
"test:production:complexity:badgesAndThreshold": "node CI/plato-badges.js",
"test:production:test2npm": "cp src/*.test.mjs generated/npm/",
"test:production:coverage": "cd generated/npm/ && c8 ava",
"test:production:srcCoverage": "cd generated/cov-env/ && c8 ava",
"test:production:testMinified": "cd generated/npm/ && cp -rf ../minified/* ./ && ava",
"test:production:clean": "rm -rf generated/npm/*.test.mjs generated/npm/node_modules"
},
......@@ -56,7 +58,20 @@
"ecma-nacl": "^2.5.0",
"codehawk-cli": "^6.0.3"
},
"ava": {},
"ava": {},
"c8": {
"all": true,
"branches": 0.080,
"lines": 0.080,
"functions": 0.080,
"statements": 0.080,
"report-dir": "../coverage",
"temp-dir": "../nyc_output.temp",
"reporter": [
"text-summary",
"html"
]
},
"xo": {
"rules": {
"curly": 0,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment