chore: calculate code coverage

This commit is contained in:
Miel Truyen 2024-03-23 22:20:11 +01:00
parent c4878caef3
commit 4cb8daf908
6 changed files with 1137 additions and 1156 deletions

View File

@ -24,15 +24,6 @@
"registry": "https://npm.cerxes.net", "registry": "https://npm.cerxes.net",
"access": "public" "access": "public"
}, },
"scripts": {
"build": "rollup -c",
"prerelease": "pnpm build",
"ci:coverage": "nyc pnpm test && nyc report --reporter=text-lcov > coverage.lcov",
"ci:lint": "pnpm build && pnpm lint-staged",
"ci:test": "pnpm test -- --verbose",
"test": "NODE_OPTIONS='--experimental-vm-modules' jest",
"save-test": "NODE_OPTIONS='--experimental-vm-modules' jest -u"
},
"files": [ "files": [
"dist", "dist",
"!dist/**/*.map", "!dist/**/*.map",
@ -55,49 +46,64 @@
} }
}, },
"dependencies": { "dependencies": {
"@rollup/pluginutils": "^5.0.5", "@rollup/pluginutils": "^5.1.0",
"magic-string": "^0.30.5", "magic-string": "^0.30.8",
"parse5": "^7.1.2" "parse5": "^7.1.2"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.23.3", "@babel/core": "^7.24.3",
"@babel/plugin-syntax-import-assertions": "^7.23.3", "@babel/plugin-syntax-import-assertions": "^7.24.1",
"@babel/preset-typescript": "^7.23.3", "@babel/preset-env": "^7.24.3",
"@babel/preset-env": "^7.23.6", "@babel/preset-react": "^7.24.1",
"@babel/preset-react": "^7.23.3", "@babel/preset-typescript": "^7.24.1",
"@jest/globals": "^29.7.0",
"@rollup/plugin-babel": "^6.0.4", "@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-typescript": "^11.1.5",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-url": "^8.0.2",
"@rollup/plugin-commonjs": "^25.0.7", "@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-replace": "^5.0.5", "@rollup/plugin-replace": "^5.0.5",
"@types/node": "^18.18.12", "@rollup/plugin-terser": "^0.4.4",
"@types/react": "^18.2.0", "@rollup/plugin-typescript": "^11.1.6",
"@types/react-dom": "^18.2.0", "@rollup/plugin-url": "^8.0.2",
"@types/jest": "^29.5.12",
"@types/node": "^18.19.26",
"@types/react": "^18.2.69",
"@types/react-dom": "^18.2.22",
"chalk": "^5.3.0", "chalk": "^5.3.0",
"del-cli": "^5.1.0", "del-cli": "^5.1.0",
"handlebars": "^4.7.8", "handlebars": "^4.7.8",
"jest": "^29.7.0",
"lint-staged": "^13.3.0", "lint-staged": "^13.3.0",
"mime": "^4.0.1",
"nyc": "^15.1.0", "nyc": "^15.1.0",
"postcss": "^8.4.31", "postcss": "^8.4.38",
"rollup": "^4.12.0", "puppeteer": "^21.11.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"rollup": "^4.13.0",
"rollup-plugin-delete": "^2.0.0", "rollup-plugin-delete": "^2.0.0",
"rollup-plugin-livereload": "^2.0.5", "rollup-plugin-livereload": "^2.0.5",
"rollup-plugin-postcss": "^4.0.2", "rollup-plugin-postcss": "^4.0.2",
"typescript": "^5.3.2",
"puppeteer": "^21.5.2",
"mime": "^4.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"jest": "^29.7.0",
"@types/jest": "^29.5.12",
"ts-jest": "^29.1.2", "ts-jest": "^29.1.2",
"@jest/globals": "^29.7.0" "typescript": "^5.4.3"
}, },
"types": "./types/index.d.ts", "types": "./types/index.d.ts",
"jest": { "jest": {
"preset": "ts-jest/presets/default-esm", "preset": "ts-jest/presets/default-esm",
"setupFiles": ["./test/setup.js"] "setupFiles": [
"./test/setup.js"
],
"collectCoverage": true,
"coveragePathIgnorePatterns": [
"test/*"
]
},
"scripts": {
"build": "rollup -c",
"prerelease": "pnpm build",
"ci:coverage": "nyc pnpm test && nyc report --reporter=text-lcov > coverage.lcov",
"ci:lint": "pnpm build && pnpm lint-staged",
"ci:test": "pnpm test -- --verbose",
"test": "NODE_OPTIONS='--experimental-vm-modules' jest",
"save-test": "NODE_OPTIONS='--experimental-vm-modules' jest -u"
} }
} }

2203
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -4,7 +4,7 @@ exports[`live-reload 1`] = `
[ [
{ {
"code": " "code": "
(function(l, r) { if (!l || l.getElementById('livereloadscript')) return; r = l.createElement('script'); r.async = 1; r.src = '//' + (self.location.host || 'localhost').split(':')[0] + ':35729/livereload.js?snipver=1'; r.id = 'livereloadscript'; l.getElementsByTagName('head')[0].appendChild(r) })(self.document); (function(l, r) { if (!l || l.getElementById('livereloadscript')) return; r = l.createElement('script'); r.async = 1; r.src = '//' + (self.location.host || 'localhost').split(':')[0] + ':<port>/livereload.js?snipver=1'; r.id = 'livereloadscript'; l.getElementsByTagName('head')[0].appendChild(r) })(self.document);
const test = ()=>{ const test = ()=>{
return \`I'm "annoying" \${"in case we need to test \\\`string\\\` escaping."}. Hence this files \\'tries\\' to include all allowed forms of 'it'\`; return \`I'm "annoying" \${"in case we need to test \\\`string\\\` escaping."}. Hence this files \\'tries\\' to include all allowed forms of 'it'\`;
}; };

View File

@ -26,6 +26,12 @@ test('live-reload', async () => {
const code = await getCode(bundle); const code = await getCode(bundle);
await bundle.close();// Make sure live-reload closes itself await bundle.close();// Make sure live-reload closes itself
debugPrintOutput('live-reload',code); debugPrintOutput('live-reload',code);
const portRE = /:[0-9]+\/livereload\.js/gi;
for(const file of code){
if(file.code && portRE.test(file.code)){
file.code = file.code.replaceAll(portRE,":<port>/livereload.js"); // remove any references to a port
}
}
expect(code).toMatchSnapshot(); expect(code).toMatchSnapshot();
}); });

View File

@ -106,7 +106,9 @@ export async function puppeteerRunTest(opts: Partial<TestOptions>, hostUrl: stri
await cb(page); await cb(page);
} }
const htmlHandle = await page.$('html'); const htmlHandle = await page.$('html');
const html = await page.evaluate(html => html?.outerHTML ?? html?.innerHTML, htmlHandle); const html = await page.evaluate( // potentially trips up Jest's code coverage, hence the istanbul ignore
/* istanbul ignore next */html => html?.outerHTML ?? html?.innerHTML, htmlHandle
);
// Add the final html // Add the final html
output.html = html || ''; output.html = html || '';