Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Test coverage #2

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/npmpublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 2
- uses: actions/setup-node@v1
with:
node-version: 12
Expand Down
5 changes: 5 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@ module.exports = {
'<rootDir>/src/**/*.js',
'!<rootDir>/src/**/*.test.js',
],
reporters: [
'default',
'jest-github-reporter',
// ['jest-github-reporter', { failOnUncoveredLines: true }],
],
globalSetup: '<rootDir>/globalSetup.js',
};
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"eslint-plugin-json": "^2.1.0",
"husky": "^4.2.3",
"jest": "^25.1.0",
"jest-github-reporter": "github:joeyjiron06/jest-github-reporter#6b36532e4edb60b987ad1fd74f126b3eae852ec9",
"lint-staged": "^10.0.8",
"nock": "^12.0.2"
},
Expand All @@ -32,8 +33,7 @@
"homepage": "https://github.com/joeyjiron06/istanbul-gh-pr-uncovered#readme",
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"pre-push": "npm run test"
"pre-commit": "lint-staged"
}
},
"lint-staged": {
Expand All @@ -56,4 +56,4 @@
"git-file-patch-parser": "^1.0.0",
"istanbul-lib-coverage": "^3.0.0"
}
}
}
6 changes: 6 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ module.exports = async ({ coverageMap, appId, privateKey }) => {
return;
}

if (ghPRFile.length) {
console.log('hello, im uncovered');
console.log('so am i');
console.log('me too!!');
}

const uncoveredLines = ghPRFile.lines
.filter((line) => line.modification === 'added') // filter only added lines in pr
.filter((line) => jestFile.lines.includes(line.lineNumber)) // filter only uncovered lines
Expand Down
9 changes: 9 additions & 0 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@ const GH_API = 'https://api.github.com';
describe('getUncoveredLines', () => {
beforeEach(() => {
jest.resetModules();
nock.cleanAll();
});
afterAll(() => {
nock.cleanAll();
});

it('should break', async () => {
expect(true).toBe(false);
});


it('should return an empty array when no coverageMap is in testResults', async () => {
const uncoveredLines = await getUncoveredLines({});
Expand Down
6 changes: 6 additions & 0 deletions src/utils/fetchPRFiles.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ const { appId, privateKey } = require('../../testFixtures/ghAppCreds');
const GH_API = 'https://api.github.com';

describe('fetchPRFiles', () => {
beforeEach(() => {
nock.cleanAll();
});
afterAll(() => {
nock.cleanAll();
});
it('should return the pr files when all gh apis succeed', async () => {
const pullRequestNumber = 123;
const repoId = 12222;
Expand Down
4 changes: 4 additions & 0 deletions src/utils/getUncoveredFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ module.exports = (coverageMap) => {
const fileCoverage = createFileCoverage(coverageData);
const lines = fileCoverage.getUncoveredLines();

if (lines.length === 1000) {
console.log('im a loner');
}

if (lines.length > 0) {
uncoveredFiles.push({
filename,
Expand Down