INTO-CPS-Association / DTaaS

:factory: :left_right_arrow: :busts_in_silhouette: Digital Twin as a Service
https://into-cps-association.github.io/DTaaS/
Other
116 stars 57 forks source link

[BUG]Consolidate test coverage of react client #1059

Closed prasadtalasila closed 1 week ago

prasadtalasila commented 1 week ago

Describe the bug

The testing of client/ code is fragmented over four yarn commands. Thus a complete overview of test coverage is not available for client

To Reproduce

Steps to reproduce the behavior:

  1. Go to client
  2. Run any of the following commands
    yarn test:unit
    yarn test:int
    yarn test:preview:unit
    yarn test:preview:int

    Each of them produces coverage reports and places them in coverage/ directory. The existing contents of coverage/ directory get overwritten.

Expected behavior

These yarn commands produce a consolidated code coverage report even if they are run separately.

Solution

The solution is to run them separately. Save the test reports into a dedicated directory and then consolidate the reports into a single report. It is possible using the following commands.

yarn test:unit
mv coverage coverage-unit
yarn test:int
mv coverage coverage-int
yarn test:preview:unit
mv coverage coverage-preview-unit
yarn test:preview:int
mv coverage coverage-preview-int

# finally
npx istanbul-combine -d coverage-combined -r lcov -r json -r text coverage-unit/coverage-final.json coverage-int/coverage-final.json coverage-preview-unit/coverage-final.json coverage-preview-int/coverage-final.json

Additional Context

It would be nice to set the target directory for each of the yarn test:* commands so that the move commands themselves can be discarded.

This consolidation needs to happen both at developer computer and Github Actions.

prasadtalasila commented 1 week ago

@VanessaScherma The following modifications to client/package.json shall simplify the coverage data collection.

    "test:coverage:int-unit": "npx istanbul-combine -d coverage/all -r lcov -r json -r text coverage/unit/coverage-final.json coverage/int/coverage-final.json coverage/preview/unit/coverage-final.json coverage/preview/int/coverage-final.json",
    "test:int": "jest -c ./jest.config.json jest --coverage --coverageDirectory=coverage/int ../test/integration --setupFilesAfterEnv ./test/integration/jest.setup.ts",
    "test:unit": "jest -c ./jest.config.json --coverageDirectory=coverage/unit ../test/unit --setupFilesAfterEnv ./test/unit/jest.setup.ts",
    "test:preview:int": "jest -c ./jest.config.json --coverageDirectory=coverage/preview/int ../test/preview/integration --setupFilesAfterEnv ./test/preview/integration/jest.setup.ts",
    "test:preview:unit": "jest -c ./jest.config.json --coverageDirectory=coverage/preview/unit ../test/preview/unit --setupFilesAfterEnv ./test/preview/unit/jest.setup.ts"
prasadtalasila commented 1 week ago

In addition, with the suggested modifications, there is no need to modify client/eslint.config.mjs file.

prasadtalasila commented 1 week ago

This is completed in PR #1005