-
Notifications
You must be signed in to change notification settings - Fork 20
/
parseCoverageThresholds.ts
47 lines (40 loc) · 1.46 KB
/
parseCoverageThresholds.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import path from 'node:path';
import * as core from '@actions/core';
import { promises as fs } from 'fs';
import { Thresholds } from './types/Threshold';
const regex100 = /100"?\s*:\s*true/;
const regexStatements = /statements\s*:\s*(\d+)/;
const regexLines = /lines:\s*(\d+)/;
const regexBranches = /branches\s*:\s*(\d+)/;
const regexFunctions = /functions\s*:\s*(\d+)/;
const parseCoverageThresholds = async (vitestConfigPath: string): Promise<Thresholds> => {
try {
const resolvedViteConfigPath = path.resolve(process.cwd(), vitestConfigPath);
const rawContent = await fs.readFile(resolvedViteConfigPath, 'utf8');
const has100Value = rawContent.match(regex100);
if(has100Value) {
return {
lines: 100,
branches: 100,
functions: 100,
statements: 100,
}
}
const lines = rawContent.match(regexLines);
const branches = rawContent.match(regexBranches);
const functions = rawContent.match(regexFunctions);
const statements = rawContent.match(regexStatements);
return {
lines: lines ? parseInt(lines[1]) : undefined,
branches: branches ? parseInt(branches[1]) : undefined,
functions: functions ? parseInt(functions[1]) : undefined,
statements: statements ? parseInt(statements[1]) : undefined,
}
} catch (err: unknown) {
core.warning(`Could not read vite config file for tresholds due to an error:\n ${err}`);
return {};
}
}
export {
parseCoverageThresholds,
};