feat: whyrating - initial project from turbostarter boilerplate
This commit is contained in:
28
tooling/vitest/package.json
Normal file
28
tooling/vitest/package.json
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "@turbostarter/vitest-config",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"exports": {
|
||||
"./base": "./src/base.js"
|
||||
},
|
||||
"scripts": {
|
||||
"clean": "git clean -xdf .cache .turbo coverage node_modules",
|
||||
"test:coverage": "nyc report -t coverage/merged --report-dir coverage/report --reporter=html --exclude-after-remap false",
|
||||
"test:coverage:collect": "pnpm dlx tsx ./src/scripts/collect-json-outputs.ts",
|
||||
"test:coverage:merge": "nyc merge coverage/raw coverage/merged/merged-coverage.json",
|
||||
"test:coverage:view": "open coverage/report/index.html"
|
||||
},
|
||||
"dependencies": {
|
||||
"vitest": "catalog:"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@turbostarter/tsconfig": "workspace:*",
|
||||
"@vitest/coverage-v8": "catalog:",
|
||||
"@vitest/ui": "4.0.14",
|
||||
"glob": "11.0.1",
|
||||
"jsdom": "26.0.0",
|
||||
"nyc": "17.1.0",
|
||||
"typescript": "catalog:"
|
||||
}
|
||||
}
|
||||
19
tooling/vitest/src/base.js
Normal file
19
tooling/vitest/src/base.js
Normal file
@@ -0,0 +1,19 @@
|
||||
import { defineConfig } from "vitest/config";
|
||||
|
||||
export default defineConfig({
|
||||
test: {
|
||||
globals: true,
|
||||
coverage: {
|
||||
enabled: true,
|
||||
provider: "v8",
|
||||
reporter: [
|
||||
[
|
||||
"json",
|
||||
{
|
||||
file: `../coverage.json`,
|
||||
},
|
||||
],
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
73
tooling/vitest/src/scripts/collect-json-outputs.ts
Normal file
73
tooling/vitest/src/scripts/collect-json-outputs.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
import fs from "fs/promises";
|
||||
import path from "path";
|
||||
import { glob } from "glob";
|
||||
|
||||
async function collectCoverageFiles() {
|
||||
try {
|
||||
// Define the patterns to search
|
||||
const patterns = ["../../apps/*", "../../packages/*"];
|
||||
|
||||
// Define the destination directory (you can change this as needed)
|
||||
const destinationDir = path.join(process.cwd(), "coverage/raw");
|
||||
|
||||
// Create the destination directory if it doesn't exist
|
||||
await fs.mkdir(destinationDir, { recursive: true });
|
||||
|
||||
// Arrays to collect all directories and directories with coverage.json
|
||||
const allDirectories = [];
|
||||
const directoriesWithCoverage = [];
|
||||
|
||||
// Process each pattern
|
||||
for (const pattern of patterns) {
|
||||
// Find all paths matching the pattern
|
||||
const matches = await glob(pattern);
|
||||
|
||||
// Filter to only include directories
|
||||
for (const match of matches) {
|
||||
const stats = await fs.stat(match);
|
||||
|
||||
if (stats.isDirectory()) {
|
||||
allDirectories.push(match);
|
||||
const coverageFilePath = path.join(match, "coverage.json");
|
||||
|
||||
// Check if coverage.json exists in this directory
|
||||
try {
|
||||
await fs.access(coverageFilePath);
|
||||
|
||||
// File exists, add to list of directories with coverage
|
||||
directoriesWithCoverage.push(match);
|
||||
|
||||
// Copy it to the destination with a unique name
|
||||
const directoryName = path.basename(match);
|
||||
const destinationFile = path.join(
|
||||
destinationDir,
|
||||
`${directoryName}.json`
|
||||
);
|
||||
|
||||
await fs.copyFile(coverageFilePath, destinationFile);
|
||||
} catch (err) {
|
||||
// File doesn't exist in this directory, skip
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create clean patterns for display (without any "../" prefixes)
|
||||
const replaceDotPatterns = (str: string) => str.replace(/\.\.\//g, "");
|
||||
|
||||
if (directoriesWithCoverage.length > 0) {
|
||||
console.log(
|
||||
`Found coverage.json in: ${directoriesWithCoverage
|
||||
.map(replaceDotPatterns)
|
||||
.join(", ")}`
|
||||
);
|
||||
}
|
||||
|
||||
console.log(`Coverage collected into: ${path.join(process.cwd())}`);
|
||||
} catch (error) {
|
||||
console.error("Error collecting coverage files:", error);
|
||||
}
|
||||
}
|
||||
|
||||
// Run the function
|
||||
collectCoverageFiles();
|
||||
6
tooling/vitest/tsconfig.json
Normal file
6
tooling/vitest/tsconfig.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"extends": "@turbostarter/tsconfig/internal.json",
|
||||
"compilerOptions": {},
|
||||
"include": ["*.ts", "src/**/*"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
22
tooling/vitest/turbo.json
Normal file
22
tooling/vitest/turbo.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"extends": ["//"],
|
||||
"tasks": {
|
||||
"test:coverage:collect": {
|
||||
"cache": false
|
||||
},
|
||||
"test:coverage:merge": {
|
||||
"dependsOn": ["test:coverage:collect"],
|
||||
"inputs": ["coverage/raw/**"],
|
||||
"outputs": ["coverage/merged/**"]
|
||||
},
|
||||
"test:coverage": {
|
||||
"dependsOn": ["test:coverage:merge"],
|
||||
"inputs": ["coverage/merge"],
|
||||
"outputs": ["coverage/report/**"]
|
||||
},
|
||||
"test:coverage:view": {
|
||||
"dependsOn": ["test:coverage"],
|
||||
"cache": false
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user