Compare commits
1 commit
0.x
...
feat/diff-
| Author | SHA1 | Date | |
|---|---|---|---|
| 4f7cf162a0 |
5 changed files with 895 additions and 989 deletions
30
.github/workflows/ci.yml
vendored
30
.github/workflows/ci.yml
vendored
|
|
@ -5,16 +5,13 @@ on:
|
|||
pull_request: { branches: ["0.x"] }
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
name: Lint
|
||||
test:
|
||||
name: Test
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Install yarn
|
||||
run: npm i -g yarn
|
||||
|
||||
- name: Set up Node
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
|
|
@ -30,28 +27,5 @@ jobs:
|
|||
- name: Type Check
|
||||
run: yarn build
|
||||
|
||||
test:
|
||||
name: Test Node ${{ matrix.node-versions }}
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
node-version: [16, 18, 20]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Install yarn
|
||||
run: npm i -g yarn
|
||||
|
||||
- name: Set up Node
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
cache: yarn
|
||||
|
||||
- name: Install dependencies
|
||||
run: yarn install
|
||||
|
||||
- name: Test
|
||||
run: yarn test --coverage
|
||||
|
|
|
|||
24
package.json
24
package.json
|
|
@ -31,17 +31,17 @@
|
|||
"yargs": "^17.6.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^29.5.4",
|
||||
"@types/node": "^20.5.0",
|
||||
"@typescript-eslint/eslint-plugin": "^6.4.1",
|
||||
"@typescript-eslint/parser": "^6.4.1",
|
||||
"eslint": "^8.56.0",
|
||||
"eslint-config-prettier": "^9.1.0",
|
||||
"eslint-plugin-prettier": "^5.1.3",
|
||||
"jest": "^29.6.4",
|
||||
"prettier": "^3.0.2",
|
||||
"ts-jest": "^29.1.1",
|
||||
"@types/jest": "^29.4.0",
|
||||
"@types/node": "^18.13.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.51.0",
|
||||
"@typescript-eslint/parser": "^5.51.0",
|
||||
"eslint": "^8.33.0",
|
||||
"eslint-config-prettier": "^8.6.0",
|
||||
"eslint-plugin-prettier": "^4.2.1",
|
||||
"jest": "^29.4.2",
|
||||
"prettier": "^2.8.4",
|
||||
"ts-jest": "^29.0.5",
|
||||
"ts-node": "^10.9.1",
|
||||
"typescript": "^5.1.6"
|
||||
"typescript": "^5.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
45
src/index.ts
45
src/index.ts
|
|
@ -48,40 +48,6 @@ export const validate = async (argv: Argv) => {
|
|||
}
|
||||
};
|
||||
|
||||
async function isGitRepo() {
|
||||
const isGit = await exec(`git rev-parse --is-inside-work-tree`);
|
||||
return isGit.code === 0;
|
||||
}
|
||||
|
||||
async function isSaplingRepo() {
|
||||
const isSapling = await exec(`sl root`);
|
||||
return isSapling.code === 0;
|
||||
}
|
||||
|
||||
async function getDiff(): Promise<string | undefined> {
|
||||
if (await isGitRepo()) {
|
||||
const diffText = await exec(`git diff origin/HEAD...HEAD`);
|
||||
if (diffText.code > 0) {
|
||||
error("Error loading the diff\n\n" + diffText.stderr);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return diffText.stdout;
|
||||
}
|
||||
|
||||
if (await isSaplingRepo()) {
|
||||
const diffText = await exec(`sl diff -g -r '. % public()'`);
|
||||
if (diffText.code > 0) {
|
||||
error("Error loading the diff\n\n" + diffText.stderr);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return diffText.stdout;
|
||||
}
|
||||
|
||||
error("Unable to get a diff no repo was found\n");
|
||||
}
|
||||
|
||||
export const run = async (argv = process.argv) => {
|
||||
const parsed: Argv = await yargs(hideBin(argv)).options(options).argv;
|
||||
const validationError = await validate(parsed);
|
||||
|
|
@ -96,13 +62,12 @@ export const run = async (argv = process.argv) => {
|
|||
return lcovDiff(baseCoverage, compareCoverage);
|
||||
}
|
||||
|
||||
const diffText = await getDiff();
|
||||
if (!diffText) {
|
||||
return;
|
||||
const diffText = await exec(`git diff origin/HEAD...HEAD`);
|
||||
if (diffText.code > 0) {
|
||||
return error("Error loading the diff\n\n" + diffText.stderr);
|
||||
}
|
||||
|
||||
const diff = parseDiff.default(diffText);
|
||||
const diff = parseDiff.default(diffText.stdout);
|
||||
|
||||
const { percentage } = report(diff, baseCoverage);
|
||||
process.exit(percentage > 90 ? 0 : 1);
|
||||
report(diff, baseCoverage);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
const getCoverageForFile = (file: any, coverage: any) => {
|
||||
for (const cov of coverage) {
|
||||
const report: { [k: number]: number } = {};
|
||||
if (cov.file.replace("./", "") === file.to) {
|
||||
if (cov.file === file.to) {
|
||||
for (const detail of cov.lines.details) {
|
||||
report[detail.line] = detail.hit;
|
||||
}
|
||||
|
|
@ -35,7 +35,7 @@ interface Diff {
|
|||
}
|
||||
|
||||
export const printReport = (diff: Diff[], coverage: any) => {
|
||||
const report = { total: 0, covered: 0, percentage: 0 };
|
||||
const report = { total: 0, covered: 0 };
|
||||
|
||||
for (const file of diff) {
|
||||
const fileCoverage = getCoverageForFile(file, coverage);
|
||||
|
|
@ -77,13 +77,13 @@ export const printReport = (diff: Diff[], coverage: any) => {
|
|||
}
|
||||
}
|
||||
|
||||
report.percentage = (report.covered / report.total) * 100;
|
||||
const color = report.percentage > 90 ? "\x1b[32m" : "\x1b[31m";
|
||||
const percentage = (report.covered / report.total) * 100;
|
||||
const color = percentage > 90 ? "\x1b[32m" : "\x1b[31m";
|
||||
|
||||
console.log("");
|
||||
console.log("Total Lines: ", report.total.toString());
|
||||
console.log("Lines Covered: ", report.covered.toString());
|
||||
console.log("Coverage Percentage", color, report.percentage.toString() + "%", "\x1b[0m");
|
||||
console.log("Coverage Percentage", color, percentage.toString() + "%", "\x1b[0m");
|
||||
|
||||
return report;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue