Skip to content

Commit

Permalink
Setup tests (#87)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nick-fields authored Aug 3, 2022
1 parent 0f986c4 commit a25f198
Show file tree
Hide file tree
Showing 6 changed files with 15,393 additions and 7,719 deletions.
13 changes: 13 additions & 0 deletions .config/jest.config.js
Original file line number Diff line number Diff line change
@@ -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 changes: 7 additions & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
@@ -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 changes: 58 additions & 24 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: ./
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit a25f198

Please sign in to comment.