Specify files and add testing

This commit is contained in:
Thomas Hu
2020-07-09 23:05:11 -04:00
parent f3570723ef
commit 89692c91b7
12 changed files with 6117 additions and 230 deletions

View File

@@ -1,14 +1,19 @@
name: Example workflow for Codecov name: Workflow for Codecov Action
on: [push, pull_request] on: [push, pull_request]
jobs: jobs:
run: run:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@master - name: Checkout
uses: actions/checkout@master
- name: Install dependencies
run: npm install
- name: Run tests and collect coverage
run: yarn run test-all
- name: Upload coverage to Codecov - name: Upload coverage to Codecov
uses: ./ uses: ./
with: with:
#commenting out token because tokenless uploads are now supported files: ./coverage/calculator/coverage-final.json,./coverage/index/coverage-final.json
#token: ${{secrets.CODECOV_TOKEN}} file: ./coverage/coverage-final.json
flags: unittest flags: unittest
name: codecov-1 name: codecov-1

View File

@@ -71,6 +71,7 @@ jobs:
with: with:
token: ${{ secrets.CODECOV_TOKEN }} token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.xml file: ./coverage.xml
files: ./coverage1.xml,./coverage2.xml
flags: unittests flags: unittests
env_vars: OS,PYTHON env_vars: OS,PYTHON
name: codecov-umbrella name: codecov-umbrella

View File

@@ -11,6 +11,9 @@ inputs:
file: file:
description: 'Path to coverage file to upload' description: 'Path to coverage file to upload'
required: false required: false
files:
description: 'Comma-separated list of files to upload'
required: false
flags: flags:
description: 'Flag upload to group coverage metrics (e.g. unittests | integration | ui,chrome)' description: 'Flag upload to group coverage metrics (e.g. unittests | integration | ui,chrome)'
required: false required: false

1376
dist/index.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -9,6 +9,7 @@ try {
const token = core.getInput("token"); const token = core.getInput("token");
const flags = core.getInput("flags"); const flags = core.getInput("flags");
const file = core.getInput("file"); const file = core.getInput("file");
const files = core.getInput("files");
const env_vars = core.getInput("env_vars"); const env_vars = core.getInput("env_vars");
fail_ci = core.getInput("fail_ci_if_error").toLowerCase(); fail_ci = core.getInput("fail_ci_if_error").toLowerCase();
@@ -83,6 +84,14 @@ try {
); );
} }
if (files) {
files.split(',').forEach(f => {
execArgs.push(
"-f", `${f}`
);
});
}
execArgs.push( execArgs.push(
"-n", `${name}`, "-n", `${name}`,
"-F", `${flags}` "-F", `${flags}`

4
jest.config.js Normal file
View File

@@ -0,0 +1,4 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
}

4873
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,10 +1,13 @@
{ {
"name": "codecov-action", "name": "codecov-action",
"version": "1.0.10", "version": "1.0.11",
"description": "Upload coverage reports to Codecov from GitHub Actions", "description": "Upload coverage reports to Codecov from GitHub Actions",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "jest --coverage",
"test-calculator": "jest --testPathPattern=src/calculator/ --coverage --coverageDirectory=coverage/calculator",
"test-index": "jest --testPathPattern=src/index --coverage --coverageDirectory=coverage/index",
"test-all": "yarn run test && yarn run test-calculator && yarn run test-index",
"build": "ncc build index.js" "build": "ncc build index.js"
}, },
"repository": { "repository": {
@@ -21,10 +24,16 @@
"dependencies": { "dependencies": {
"@actions/core": "^1.2.0", "@actions/core": "^1.2.0",
"@actions/exec": "^1.0.1", "@actions/exec": "^1.0.1",
"@types/jest": "^26.0.4",
"@zeit/ncc": "^0.22.3", "@zeit/ncc": "^0.22.3",
"fs": "0.0.1-security", "fs": "0.0.1-security",
"jest": "^26.1.0",
"jest-junit": "^10.0.0",
"request": "^2.88.0", "request": "^2.88.0",
"requestretry": "^4.1.1" "requestretry": "^4.1.1",
"ts-jest": "^26.1.1",
"typescript": "^3.9.6",
"yarn": "^1.22.4"
}, },
"devDependencies": {} "devDependencies": {}
} }

View File

@@ -0,0 +1,11 @@
import Calculator from './calculator'
test('adds 2 + 3 to equal 5', () => {
const calc = new Calculator()
expect(calc.add(2, 3)).toBe(5);
});
test('subtracts 2 - 3 to equal -1', () => {
const calc = new Calculator()
expect(calc.subtract(2, 3)).toBe(-1);
});

View File

@@ -0,0 +1,10 @@
export default class Calculator {
add(x : number, y : number) : number {
return x + y;
}
subtract(x: number, y: number) : number {
return x - y;
}
}

11
src/index/index.test.ts Normal file
View File

@@ -0,0 +1,11 @@
import Index from "./index";
test('test uncovered if', () => {
const indexObj = new Index();
expect(indexObj.uncovered_if()).toEqual(false);
});
test('fully covered', () => {
const indexObj = new Index();
expect(indexObj.fully_covered()).toEqual(true);
});

21
src/index/index.ts Normal file
View File

@@ -0,0 +1,21 @@
export default class Index {
//This function is tested and part of it is uncovered
uncovered_if = (a = true) => {
if (a == true) {
return false
} else {
return true
}
}
//This function will be fully covered
fully_covered = () => {
return true
}
//This function will not be tested by unit tests
uncovered = () => {
return true
}
}