Skip to content

Commit

Permalink
Add Test Suite, Achieve 80% Coverage (#41)
Browse files Browse the repository at this point in the history
## Description Of Change

This PR adds a testing suite to this repository, achieving 80%+ test
coverage of all relevant client files.

While working on the test suite, I ran across an old method on the
client `performWorkflowStep` which was broken. As far as we can tell, no
one uses this method and it doens't fit into the API surface of our
Staking API anymore. So I've gone ahead and removed it. This makes this
PR a breaking change.

I attempted to modify as little actual client code as possible while
making these changes, focusing only on the testing and the appropriate
coverage. Slight alterations were made, where necessary, to achieve
maximal coverage (ex: exporting a method).

As you can see in the image attached in a comment, we've achieved 80%+
on statements and lines. We can still improve coverage for branches and
funcs. But considering we started at 0 across the board, this is a huge
improvement. The coverage image I posted can be regenerated via `npm run
coverage`.

## Testing Procedure

Added dozens of tests and achieved 80%+ test coverage :)
  • Loading branch information
ProfMoo authored Dec 5, 2024
1 parent a5d06f9 commit a96c684
Show file tree
Hide file tree
Showing 20 changed files with 5,333 additions and 360 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: TypeScript Lint
on:
push:
branches:
- master
- main
pull_request:

permissions:
Expand All @@ -17,8 +17,9 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20.x"
node-version: "23.x"
registry-url: "https://registry.npmjs.org"
- run: npm ci
- name: Run npm ci
run: npm ci
- name: Run linter
run: npm run lint
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: "20.x"
node-version: "23.x"
registry-url: "https://registry.npmjs.org"

- name: Publish to NPM
Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: TypeScript Test

on:
push:
branches:
- main
pull_request:

jobs:
test:
name: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "23.x"
registry-url: "https://registry.npmjs.org"
- name: Run npm ci
run: npm ci
- name: Run tests
run: npm run test
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ dist/

node_modules/

# VSCode configuration
.vscode

docs/**/*.json

# code coverage output
coverage
.nyc_output
6 changes: 6 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"require": [
"ts-node/register"
],
"spec": "src/**/*.test.ts"
}
20 changes: 20 additions & 0 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"extends": "@istanbuljs/nyc-config-typescript",
"all": true,
"include": [
"src/**/*.ts"
],
"exclude": [
"src/**/*.test.ts",
"src/**/index.ts",
"node_modules",
"src/gen"
],
"reporter": [
"text",
"html"
],
"check-coverage": true,
"lines": 80,
"statements": 80
}
36 changes: 36 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"markdownlint.config": {
"MD033": false,
},
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
"editor.formatOnType": false,
"files.autoSave": "onFocusChange",
"cSpell.words": [
"automerge",
"holesky",
"nonroutine",
"solana",
"txsigner",
"unstake"
],
"typescript.updateImportsOnFileMove.enabled": "always",
"javascript.updateImportsOnFileMove.enabled": "always",
"vs-code-prettier-eslint.prettierLast": false,
"[javascript]": {
"editor.defaultFormatter": "rvest.vs-code-prettier-eslint"
},
"[json]": {
"editor.defaultFormatter": "vscode.json-language-features"
},
"[jsonc]": {
"editor.defaultFormatter": "vscode.json-language-features"
},
"[typescript]": {
"editor.defaultFormatter": "rvest.vs-code-prettier-eslint"
},
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
},
"files.insertFinalNewline": true,
}
Loading

0 comments on commit a96c684

Please sign in to comment.