Add test coverage config and badges
Configured Jest for improved test coverage reporting and threshold enforcement. Updated README with project time and test coverage badges. Added scripts to fix coverage report paths and generate badges. Updated dependencies to include necessary tools for coverage reporting. Bumped package version to 0.0.9.
This commit is contained in:
46
scripts/fix-coverage-paths.cjs
Normal file
46
scripts/fix-coverage-paths.cjs
Normal file
@@ -0,0 +1,46 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const coverageDir = path.join(__dirname, '..', '.locale', 'coverage');
|
||||
const typedocUrl = 'https://pxammaxp.github.io/TSinjex/';
|
||||
|
||||
const getAllFiles = (dir, files = []) => {
|
||||
fs.readdirSync(dir).forEach(file => {
|
||||
const fullPath = path.join(dir, file);
|
||||
if (fs.statSync(fullPath).isDirectory()) {
|
||||
getAllFiles(fullPath, files);
|
||||
} else {
|
||||
files.push(fullPath);
|
||||
}
|
||||
});
|
||||
return files;
|
||||
};
|
||||
|
||||
// Alle HTML-Dateien im coverage-Ordner finden
|
||||
const htmlFiles = getAllFiles(coverageDir).filter(file => file.endsWith('.html'));
|
||||
|
||||
// Alle HTML-Dateien bearbeiten
|
||||
htmlFiles.forEach(filePath => {
|
||||
fs.readFile(filePath, 'utf8', (err, data) => {
|
||||
if (err) {
|
||||
console.error(`Error reading file ${filePath}:`, err);
|
||||
return;
|
||||
}
|
||||
|
||||
// Relative Pfade anpassen
|
||||
let fixedData = data.replace(/(src|href)="(?!\.)/g, '$1="./');
|
||||
|
||||
// Link zur TypeDoc-Dokumentation hinzufügen
|
||||
const linkHtml = `<div style="position: fixed; bottom: 10px; right: 10px;"><a href="${typedocUrl}">Zur TypeDoc-Dokumentation</a></div>`;
|
||||
fixedData = fixedData.replace('</body>', `${linkHtml}</body>`);
|
||||
|
||||
fs.writeFile(filePath, fixedData, 'utf8', (err) => {
|
||||
if (err) {
|
||||
console.error(`Error writing file ${filePath}:`, err);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`Fixed paths and added link in ${filePath}`);
|
||||
});
|
||||
});
|
||||
});
|
55
scripts/generate-badge.cjs
Normal file
55
scripts/generate-badge.cjs
Normal file
@@ -0,0 +1,55 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { exec } = require('child_process');
|
||||
const axios = require('axios');
|
||||
|
||||
// Step 1: Create README.md in the coverage directory
|
||||
const coverageReadmePath = path.join(__dirname, '..', '.locale', 'coverage', 'README.md');
|
||||
const readmeContent = `
|
||||

|
||||

|
||||

|
||||

|
||||
`;
|
||||
|
||||
fs.writeFileSync(coverageReadmePath, readmeContent, 'utf8');
|
||||
|
||||
// Step 2: Execute the istanbul-badges-readme tool
|
||||
exec('npx istanbul-badges-readme --coverageDir=./.locale/coverage --readmeDir=./.locale/coverage', (err, stdout, stderr) => {
|
||||
if (err) {
|
||||
console.error(`Error executing istanbul-badges-readme: ${stderr}`);
|
||||
return;
|
||||
}
|
||||
console.log('Badges generated successfully.');
|
||||
|
||||
// Step 3: Extract the badge links from README.md
|
||||
const updatedReadmeContent = fs.readFileSync(coverageReadmePath, 'utf8');
|
||||
const badgeLines = updatedReadmeContent.split('\n').filter(line => line.includes('https://img.shields.io'));
|
||||
|
||||
// Ensure the target directory exists
|
||||
const badgesDir = path.join(__dirname, '..', '.locale', 'coverage', 'badges');
|
||||
if (!fs.existsSync(badgesDir)) {
|
||||
fs.mkdirSync(badgesDir, { recursive: true });
|
||||
}
|
||||
|
||||
// Badge types and their order
|
||||
const badgeTypes = ['statements', 'branches', 'functions', 'lines'];
|
||||
|
||||
// Save the badge images
|
||||
badgeLines.forEach(async (line, index) => {
|
||||
const match = line.match(/\((https:\/\/img\.shields\.io\/badge\/[^)]+)\)/);
|
||||
if (match) {
|
||||
const url = match[1];
|
||||
const response = await axios.get(url, { responseType: 'arraybuffer' });
|
||||
const buffer = Buffer.from(response.data, 'binary');
|
||||
const fileName = `badge-${badgeTypes[index]}.svg`;
|
||||
const filePath = path.join(badgesDir, fileName);
|
||||
fs.writeFileSync(filePath, buffer);
|
||||
console.log(`Saved ${fileName}`);
|
||||
}
|
||||
});
|
||||
|
||||
// Step 4: Delete the README.md file
|
||||
fs.unlinkSync(coverageReadmePath);
|
||||
console.log('README.md file deleted.');
|
||||
});
|
Reference in New Issue
Block a user