This is a sample typescript project with basic configuration for Farport Software.
It uses 2 basic packages for all Farport projects:
- A quick way to scaffold a Typescript project with test
- Propose a structure with directory such as
coreanddto - Make sure to leverage type safety provided by Typescript with strict config (see
tsconfig.json) - Ensure that typescript code is clear of error and formatted correctly (via
yarn lint)
Assuming that you are creating a new start-proj project, do the following:
mkdir start-proj
cd start-proj
curl -L https://github.com/fp8/start-typescript/archive/refs/tags/0.2.0.tar.gz | tar -xv --strip=1The structure of the project should be usable as is. The use of start.ts encapsulate all the complexity
related to project startup.
Some changes needed:
- Ensure that
etc/local/config.yamlanddto/config.dtocontains configuration - Add the actual helpers
Make sure to update your package.json with:
- Update the
.nameto your project name - Ensure that
.licenseis updated to your desired license
The alias @proj is created to point to ./src directory. This allow you to avoid use of relative reference
in your code. Use of @proj is specially import in tests as test:dist task will switch to use ./dist so
the compiled version of code is tested. This is done at the end of the build task.
The reference to @proj is removed in the ./dist via the build:alias task.
To run this sample app, simple do:
yarn startBy detail, as no FP8_ENV environment variable is not used, the config under etc/local is used. To try with another config, try:
FP8_ENV=utest yarn startWhen creating a test, make sure to follow the path defined in src and try your best to mirror the project structure under test. If you have a src/core/helpers.ts, it is therefore expected to have a corresponding test under test/core/helpers.spec.ts.
The test in the project must focus sorely on unit testing. The end-to-end testing is expected to be written in a separate project using Playwright.
By default, the test is run in parellel to speed up the testing and show all failures in the end. To run test during dev, you would simple run:
yarn testTo run a single test suite, do:
yarn test helpers.spec.tsTo run test with coverage, do:
yarn test --coverageWhen number of test increases, it can be difficult to see where the failure happens. You can run:
yarn test:debugIn this case, the test will be run in sequence and it will stop upon first failure. You can further filter this to a single test suit:
yarn test:debug helpers.spec.tsA unit test config is created under etc/utest as all test are configured to use FP8_ENV=utest (see package.json). It is expected that unit test are created for the entire project and achieving at least 90% of coverage. In case there is a line that you wish to skip from the coverage as it doesn't make sense to test it, you can skip that line from coverage by prefix the line in question with:
// istanbul ignore next @preserve