Skip to content

Commit fa08c1c

Browse files
committed
initial commit
1 parent 0472d57 commit fa08c1c

10 files changed

Lines changed: 6064 additions & 0 deletions

File tree

.circleci/config.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
version: 2.1
2+
orbs:
3+
codecov: codecov/codecov@3
4+
5+
jobs:
6+
build:
7+
docker:
8+
- image: cimg/node:current
9+
steps:
10+
- checkout
11+
- run:
12+
name: Install dependencies
13+
command: npm install
14+
- run:
15+
name: Run tests and collect coverage
16+
command: npm run test
17+
- codecov/upload
18+
19+
workflow:
20+
version: 2.1
21+
build-test:
22+
jobs:
23+
- build

.github/dependabot.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: npm
4+
directory: "/"
5+
schedule:
6+
interval: daily
7+
open-pull-requests-limit: 10

.github/workflows/ci.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Workflow for Codecov example-javascript
2+
on: [push, pull_request]
3+
jobs:
4+
run:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- name: Checkout
8+
uses: actions/checkout@v2
9+
- name: Set up Node 18
10+
uses: actions/setup-node@v3
11+
with:
12+
node-version: 18
13+
- name: Install dependencies
14+
run: npm install
15+
- name: Run tests and collect coverage
16+
run: npm run test
17+
- name: Upload coverage to Codecov
18+
uses: codecov/codecov-action@v3

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
coverage/

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# [Codecov](https://codecov.io) Python Example
2+
[![codecov](https://codecov.io/github/codecov/example-javascript/branch/master/graph/badge.svg?token=tkq655ROg3)](https://codecov.io/github/codecov/example-javascript)
3+
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fcodecov%2Fexample-javascript.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fcodecov%2Fexample-javascript?ref=badge_shield)
4+
5+
This example repository shows how Codecov can be integrated with a simple javascript project. It uses **GitHub Actions** and **CircleCI** as CI/CD providers and **jest** as the coverage provider.
6+
7+
For more information, please see the links below.
8+
9+
## Links
10+
- [Quick Start](https://docs.codecov.com/docs/quick-start)
11+
- [GitHub Tutorial](https://docs.codecov.com/docs/github-tutorial)
12+
- [Community Boards](https://community.codecov.io)
13+
- [Support](https://codecov.io/support)
14+
- [Documentation](https://docs.codecov.io)
15+
16+
17+
## License
18+
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fcodecov%2Fexample-javascript.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fcodecov%2Fexample-javascript?ref=badge_large)

app/calculator.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const add = (x, y) => x + y;
2+
const subtract = (x, y) => x - y;
3+
const multiply = (x, y) => x * y;
4+
const divide = (x, y) => {
5+
if (y === 0) {
6+
return "Cannot divide by 0";
7+
}
8+
return x * 1.0 / y;
9+
}
10+
11+
module.exports = { add, subtract, multiply, divide };

app/calculator.test.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const {
2+
add,
3+
subtract,
4+
multiply,
5+
divide,
6+
} = require('./calculator');
7+
8+
test('add function', () => {
9+
expect(add(1, 2)).toBe(3);
10+
expect(add(1.0, 2.0)).toBe(3.0);
11+
expect(add(0, 2.0)).toBe(2.0);
12+
expect(add(2.0, 0)).toBe(2.0);
13+
expect(add(-4, 2.0)).toBe(-2.0);
14+
});
15+
16+
test('subtract function', () => {
17+
expect(subtract(1, 2)).toBe(-1.0);
18+
expect(subtract(2, 1)).toBe(1.0);
19+
expect(subtract(1.0, 2.0)).toBe(-1.0);
20+
expect(subtract(0, 2.0)).toBe(-2.0);
21+
expect(subtract(2.0, 0)).toBe(2.0);
22+
expect(subtract(-4, 2.0)).toBe(-6.0);
23+
});
24+
25+
test('multiply function', () => {
26+
expect(multiply(1, 2)).toBe(2.0);
27+
expect(multiply(1.0, 2.0)).toBe(2.0);
28+
expect(multiply(0, 2.0)).toBe(0.0);
29+
expect(multiply(2.0, 0)).toBe(0.0);
30+
expect(multiply(-4, 2.0)).toBe(-8.0);
31+
});
32+
33+
test('divide function', () => {
34+
expect(divide(1, 2)).toBe(0.5);
35+
expect(divide(1.0, 2.0)).toBe(0.5);
36+
expect(divide(0, 2.0)).toBe(0);
37+
expect(divide(-4, 2.0)).toBe(-2.0);
38+
// expect(divide(2.0, 0)).toBe('Cannot divide by 0');
39+
});

jest.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
collectCoverage: true,
3+
coverageReporters: ['text', 'cobertura'],
4+
}

0 commit comments

Comments
 (0)