mirror of
https://github.com/nick-fields/retry.git
synced 2026-02-09 14:48:02 +00:00
Setup tests (#87)
* test: move timeout tests to their own job to speed things up slightly * test: add comment about timeout tests * test: fix needs in cd job * test: add jest configuration and first test * test: setup codecov to track coverage
This commit is contained in:
13
.config/jest.config.js
Normal file
13
.config/jest.config.js
Normal file
@@ -0,0 +1,13 @@
|
||||
module.exports = {
|
||||
clearMocks: true,
|
||||
moduleFileExtensions: ['js', 'ts'],
|
||||
rootDir: '..',
|
||||
testEnvironment: 'node',
|
||||
testMatch: ['<rootDir>/src/**/*.test.ts'],
|
||||
transform: {
|
||||
'^.+\\.ts$': 'ts-jest',
|
||||
},
|
||||
verbose: true,
|
||||
collectCoverage: true,
|
||||
collectCoverageFrom: ['src/**/*.{js,ts,jsx,tsx}'],
|
||||
};
|
||||
7
.github/codecov.yml
vendored
Normal file
7
.github/codecov.yml
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
# see https://docs.codecov.com/docs/codecovyml-reference
|
||||
codecov:
|
||||
require_ci_to_pass: false
|
||||
comment:
|
||||
layout: 'diff, flags'
|
||||
behavior: default
|
||||
require_changes: true
|
||||
82
.github/workflows/ci_cd.yml
vendored
82
.github/workflows/ci_cd.yml
vendored
@@ -4,10 +4,30 @@ on:
|
||||
|
||||
jobs:
|
||||
# runs on branch pushes only
|
||||
ci:
|
||||
name: Run Tests
|
||||
ci_unuit:
|
||||
name: Run Unit Tests
|
||||
if: startsWith(github.ref, 'refs/heads')
|
||||
runs-on: ubuntu-18.04
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 16
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
- name: Run Unit Tests
|
||||
run: npm test
|
||||
- uses: codecov/codecov-action@v3
|
||||
with:
|
||||
directory: ./coverage/
|
||||
verbose: true
|
||||
|
||||
ci_integration:
|
||||
name: Run Integration Tests
|
||||
if: startsWith(github.ref, 'refs/heads')
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
@@ -220,7 +240,39 @@ jobs:
|
||||
expected: 2
|
||||
actual: ${{ steps.retry_on_error.outputs.exit_code }}
|
||||
|
||||
# timeout tests (takes longer to run so run last)
|
||||
- name: sad-path (wrong shell for OS)
|
||||
id: wrong_shell
|
||||
uses: ./
|
||||
continue-on-error: true
|
||||
with:
|
||||
timeout_minutes: 1
|
||||
max_attempts: 2
|
||||
shell: cmd
|
||||
command: 'dir'
|
||||
- uses: nick-invision/assert-action@v1
|
||||
with:
|
||||
expected: 2
|
||||
actual: ${{ steps.wrong_shell.outputs.total_attempts }}
|
||||
- uses: nick-invision/assert-action@v1
|
||||
with:
|
||||
expected: failure
|
||||
actual: ${{ steps.wrong_shell.outcome }}
|
||||
|
||||
# timeout tests take longer to run so run in parallel
|
||||
ci_integration_timeout:
|
||||
name: Run Integration Timeout Tests
|
||||
if: startsWith(github.ref, 'refs/heads')
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 16
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: sad-path (timeout)
|
||||
id: sad_path_timeout
|
||||
uses: ./
|
||||
@@ -295,24 +347,6 @@ jobs:
|
||||
expected: failure
|
||||
actual: ${{ steps.sad_path_timeout.outcome }}
|
||||
|
||||
- name: sad-path (wrong shell for OS)
|
||||
id: wrong_shell
|
||||
uses: ./
|
||||
continue-on-error: true
|
||||
with:
|
||||
timeout_minutes: 1
|
||||
max_attempts: 2
|
||||
shell: cmd
|
||||
command: 'dir'
|
||||
- uses: nick-invision/assert-action@v1
|
||||
with:
|
||||
expected: 2
|
||||
actual: ${{ steps.wrong_shell.outputs.total_attempts }}
|
||||
- uses: nick-invision/assert-action@v1
|
||||
with:
|
||||
expected: failure
|
||||
actual: ${{ steps.wrong_shell.outcome }}
|
||||
|
||||
ci_windows:
|
||||
name: Run Windows Tests
|
||||
if: startsWith(github.ref, 'refs/heads')
|
||||
@@ -368,9 +402,9 @@ jobs:
|
||||
# runs on push to master only
|
||||
cd:
|
||||
name: Publish Action
|
||||
needs: ci
|
||||
needs: [ci_integration, ci_integration_timeout, ci_windows]
|
||||
if: github.ref == 'refs/heads/master'
|
||||
runs-on: ubuntu-18.04
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
7649
package-lock.json
generated
7649
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
12
package.json
12
package.json
@@ -8,7 +8,8 @@
|
||||
"local": "npm run prepare && node -r dotenv/config ./dist/index.js",
|
||||
"prepare": "ncc build src/index.ts && husky install",
|
||||
"style:base": "prettier --config ./.config/.prettierrc.yml --ignore-path ./.config/.prettierignore --write ",
|
||||
"style": "npm run style:base -- ."
|
||||
"style": "npm run style:base -- .",
|
||||
"test": "jest -c ./.config/jest.config.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -31,6 +32,7 @@
|
||||
"@commitlint/config-conventional": "^16.2.1",
|
||||
"@semantic-release/changelog": "^6.0.1",
|
||||
"@semantic-release/git": "^10.0.1",
|
||||
"@types/jest": "^28.1.6",
|
||||
"@types/milliseconds": "0.0.30",
|
||||
"@types/node": "^16.11.7",
|
||||
"@typescript-eslint/eslint-plugin": "^5.32.0",
|
||||
@@ -40,11 +42,14 @@
|
||||
"eslint": "^8.21.0",
|
||||
"eslint-config-prettier": "^8.5.0",
|
||||
"husky": "^8.0.1",
|
||||
"jest": "^28.1.3",
|
||||
"lint-staged": "^13.0.3",
|
||||
"prettier": "^2.7.1",
|
||||
"semantic-release": "19.0.3",
|
||||
"ts-jest": "^28.0.7",
|
||||
"ts-node": "9.0.0",
|
||||
"typescript": "^4.7.4"
|
||||
"typescript": "^4.7.4",
|
||||
"yaml-lint": "^1.7.0"
|
||||
},
|
||||
"lint-staged": {
|
||||
"**/*.ts": [
|
||||
@@ -53,6 +58,9 @@
|
||||
],
|
||||
"**/*.{md,yaml,yml}": [
|
||||
"npm run style:base --"
|
||||
],
|
||||
"**/*.{yaml,yml}": [
|
||||
"npx yamllint "
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
17
src/util.test.ts
Normal file
17
src/util.test.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import 'jest';
|
||||
import { getHeapStatistics } from 'v8';
|
||||
|
||||
import { wait } from './util';
|
||||
|
||||
// mocks the setTimeout function, see https://jestjs.io/docs/timer-mocks
|
||||
jest.useFakeTimers();
|
||||
jest.spyOn(global, 'setTimeout');
|
||||
|
||||
describe('util', () => {
|
||||
test('wait', async () => {
|
||||
const waitTime = 1000;
|
||||
wait(waitTime);
|
||||
expect(setTimeout).toHaveBeenCalledTimes(1);
|
||||
expect(setTimeout).toHaveBeenLastCalledWith(expect.any(Function), waitTime);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user