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

@ -2,7 +2,7 @@
const babelConfig ={
presets: [
["@babel/preset-typescript", {
}],
}],
],
plugins: [
],

View File

@ -24,15 +24,6 @@
"registry": "https://npm.cerxes.net",
"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": [
"dist",
"!dist/**/*.map",
@ -55,49 +46,64 @@
}
},
"dependencies": {
"@rollup/pluginutils": "^5.0.5",
"magic-string": "^0.30.5",
"@rollup/pluginutils": "^5.1.0",
"magic-string": "^0.30.8",
"parse5": "^7.1.2"
},
"devDependencies": {
"@babel/core": "^7.23.3",
"@babel/plugin-syntax-import-assertions": "^7.23.3",
"@babel/preset-typescript": "^7.23.3",
"@babel/preset-env": "^7.23.6",
"@babel/preset-react": "^7.23.3",
"@babel/core": "^7.24.3",
"@babel/plugin-syntax-import-assertions": "^7.24.1",
"@babel/preset-env": "^7.24.3",
"@babel/preset-react": "^7.24.1",
"@babel/preset-typescript": "^7.24.1",
"@jest/globals": "^29.7.0",
"@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-node-resolve": "^15.2.3",
"@rollup/plugin-replace": "^5.0.5",
"@types/node": "^18.18.12",
"@types/react": "^18.2.0",
"@types/react-dom": "^18.2.0",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.6",
"@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",
"del-cli": "^5.1.0",
"handlebars": "^4.7.8",
"jest": "^29.7.0",
"lint-staged": "^13.3.0",
"mime": "^4.0.1",
"nyc": "^15.1.0",
"postcss": "^8.4.31",
"rollup": "^4.12.0",
"postcss": "^8.4.38",
"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-livereload": "^2.0.5",
"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",
"@jest/globals": "^29.7.0"
"typescript": "^5.4.3"
},
"types": "./types/index.d.ts",
"jest": {
"preset":"ts-jest/presets/default-esm",
"setupFiles": ["./test/setup.js"]
"preset": "ts-jest/presets/default-esm",
"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": "
(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 = ()=>{
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);
await bundle.close();// Make sure live-reload closes itself
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();
});

View File

@ -106,7 +106,9 @@ export async function puppeteerRunTest(opts: Partial<TestOptions>, hostUrl: stri
await cb(page);
}
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
output.html = html || '';