Pendle SDK Rewrite
Development Guideline
Last update: 1 Dec 2021 By An Tran
My approach to TDD:
For a small library, in my opinion there should be two to three test levels:
- Unit test: for each and every function or class
- Module level integration tests: test the main exports of a given module (subfolders of the src folder).
- This is optional if the library is small enough.
- End-to-end tests (or acceptance tests): test the main export of the whole library.
- This level tests the behaviour of the SDK toward library consumers.
Structure
- The src folder is for writing the source code, unit tests and module level integration tests.
- The src/index.ts file is the main export point of the library.
- The test folder is for writing end-to-end tests
- Those tests will test what the SDK user will use.
- Note that those test must only import from the src/index.ts file, because this is the only place that user can reliably import anything from our library.
Commands
Along with the npm commands provided by tsdx, I have created several extra commands for development:
lint
: this command is overrided, because tsdx doesn't provide a stable eslint configuration. May update later.commitlint
: run the commitlint. Included in the commit-msg hook, so you don't need to use this.format
: format the codebase with prettier.test:{unit,e2e}
: run the respective test scope. If we choose the unit
scope, we will run the unit tests and integration tests, which resides in the src folder.test:{unit,e2e}:cov
: run a coverage test on the chosen test scope.test:{unit,e2e}:watch
: re-run the test suite on changes detected.test:{unit,e2e}:debug
: debug run the chosen test scope.test:all
: run all test scopes.test:all:cov
: run a coverage test on all test scope.
Recommended workflow:
- Reformat your code oftenly. You can run
yarn format
after a while, or set up the prettier
plugin on your text editor/IDE. - Lint your code oftenly. You can run
yarn lint
after a while, or set up the eslint
plugin on your text editor/IDE, which will show you lint errors. - Test your code as often as you can, or keep the test watch on.
- Ensure your code pass the
test:all:cov
test before pushing. This test ensures that your code is fully tested with 80% coverage. - Write your commit message in commitlint convention.