mirror of
https://github.com/bcanseco/github-contribution-graph-action.git
synced 2025-10-09 13:41:58 +03:00
test: add basic spec and ci for jest
This commit is contained in:
15
.github/workflows/tests.yml
vendored
Normal file
15
.github/workflows/tests.yml
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
name: tests
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
tests:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
- run: npm ci
|
||||
- run: npm test
|
||||
@@ -11,6 +11,10 @@
|
||||
<img src="https://github.com/bcanseco/github-contribution-graph-action/workflows/build/badge.svg">
|
||||
</a>
|
||||
|
||||
<a href="https://github.com/bcanseco/github-contribution-graph-action/actions?query=workflow%3Atests">
|
||||
<img src="https://github.com/bcanseco/github-contribution-graph-action/workflows/tests/badge.svg">
|
||||
</a>
|
||||
|
||||
<a href="https://github.com/bcanseco/github-contribution-graph-action/actions?query=workflow%3Aaudit">
|
||||
<img src="https://github.com/bcanseco/github-contribution-graph-action/workflows/audit/badge.svg">
|
||||
</a>
|
||||
|
||||
4688
package-lock.json
generated
4688
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -2,7 +2,8 @@
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"start": "node --experimental-top-level-await --experimental-specifier-resolution=node -r dotenv-safe/config src"
|
||||
"start": "node --experimental-top-level-await --experimental-specifier-resolution=node -r dotenv-safe/config src",
|
||||
"test": "node --experimental-vm-modules node_modules/jest/bin/jest"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14.3.0"
|
||||
@@ -11,5 +12,9 @@
|
||||
"date-fns": "^2.14.0",
|
||||
"dotenv-safe": "^8.2.0",
|
||||
"simple-git": "^2.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^25.2.3",
|
||||
"jest": "^26.0.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,4 +13,4 @@ export const getRandomInt = (min, max) => {
|
||||
}
|
||||
|
||||
return Math.floor(Math.random() * (max - min + 1)) + min;
|
||||
}
|
||||
};
|
||||
|
||||
24
src/random/index.spec.js
Normal file
24
src/random/index.spec.js
Normal file
@@ -0,0 +1,24 @@
|
||||
import {getRandomInt} from '.';
|
||||
|
||||
it('should disallow negative values', () => {
|
||||
expect(() => getRandomInt(-5, 1)).toThrow();
|
||||
expect(() => getRandomInt(-5, -1)).toThrow();
|
||||
expect(() => getRandomInt(1, -5)).toThrow();
|
||||
});
|
||||
|
||||
it('should disallow min greater than max', () => {
|
||||
expect(() => getRandomInt(1, 2)).not.toThrow();
|
||||
expect(() => getRandomInt(1, 1)).not.toThrow();
|
||||
expect(() => getRandomInt(1, 0)).toThrow();
|
||||
expect(() => getRandomInt(0, 0)).not.toThrow();
|
||||
});
|
||||
|
||||
it('should work with numeric strings', () => {
|
||||
expect(() => getRandomInt(1, 5)).not.toThrow();
|
||||
expect(() => getRandomInt('1', '5')).not.toThrow();
|
||||
});
|
||||
|
||||
it('should be inclusive on min and max', () => {
|
||||
expect(getRandomInt(0, 0)).toEqual(0);
|
||||
expect(getRandomInt(1, 1)).toEqual(1);
|
||||
});
|
||||
Reference in New Issue
Block a user