Skip to content

Commit

Permalink
feat(yarn coverage) (nomad-xyz#449)
Browse files Browse the repository at this point in the history
Co-authored-by: Imti Majeed <[email protected]>
  • Loading branch information
odyslam and Imti authored Oct 3, 2022
1 parent 207fc89 commit 5cae4fd
Show file tree
Hide file tree
Showing 28 changed files with 65 additions and 42 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ yarn-error.log
dist/
cache/
scripts/accumulator-cli
**/.coverage

.yarn/*
!.yarn/cache
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"snapshot:check": "yarn workspaces foreach -Apvt --include @nomad-xyz/contracts-core --include @nomad-xyz/contracts-bridge run snapshot:check",
"storage-inspect:check": "yarn workspaces foreach -Apvi --include @nomad-xyz/contracts-core --include @nomad-xyz/contracts-bridge --include @nomad-xyz/contracts-router run storage-inspect:check",
"storage-inspect:generate": "yarn workspaces foreach -Apvi --include @nomad-xyz/contracts-core --include @nomad-xyz/contracts-bridge --include @nomad-xyz/contracts-router run storage-inspect:generate",
"test:coverage": "yarn workspaces foreach -Apvi run test:coverage",
"test:integration": "yarn local-environment test:integration",
"test:unit": "yarn workspaces foreach -Apvt --exclude @nomad-xyz/deploy run test:unit"
},
Expand Down
1 change: 0 additions & 1 deletion packages/chain-ops/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
dist/
tsconfig.tsbuildinfo
.nyc_output/
coverage/
4 changes: 1 addition & 3 deletions packages/contracts-bridge/.gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
node_modules/
cache/
artifacts/
coverage/
coverage.json
.env
src.ts/
src/
dist/
foundry_artifacts/
foundry_artifacts/
1 change: 1 addition & 0 deletions packages/contracts-bridge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"test:unit": "FOUNDRY_PROFILE=bridge-ci forge test",
"test:unit:local": "FOUNDRY_PROFILE=bridge forge test",
"test:static-analyze": "rm -rf node_modules && yarn link:node_modules && slither .",
"test:coverage": "../../scripts/coverage-report.sh bridge",
"link:node_modules": "ln -s ../../node_modules",
"snapshot": "forge clean && FOUNDRY_PROFILE=bridge forge snapshot",
"snapshot:check": "forge clean && FOUNDRY_PROFILE=bridge forge snapshot --check",
Expand Down
2 changes: 0 additions & 2 deletions packages/contracts-core/.gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/node_modules
cache/
artifacts/
coverage/
coverage.json
.env
src.ts/
src/
Expand Down
1 change: 1 addition & 0 deletions packages/contracts-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"test:unit": "FOUNDRY_PROFILE=core-ci forge test",
"test:unit:local": "FOUNDRY_PROFILE=core forge test",
"test:static-analyze": "rm -rf node_modules && yarn link:node_modules && slither .",
"test:coverage": "../../scripts/coverage-report.sh core",
"link:node_modules": "ln -s ../../node_modules",
"snapshot": "forge clean && FOUNDRY_PROFILE=core forge snapshot",
"snapshot:check": "forge clean && FOUNDRY_PROFILE=core forge snapshot --check",
Expand Down
4 changes: 1 addition & 3 deletions packages/contracts-router/.gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
node_modules/
cache/
artifacts/
coverage/
coverage.json
.env
src.ts/
src/
dist/
foundry_artifacts/
foundry_artifacts/
1 change: 1 addition & 0 deletions packages/contracts-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"prepublish": "yarn bootstrap && yarn build",
"test:unit": "FOUNDRY_PROFILE=router-ci forge test",
"test:unit-local": "FOUNDRY_PROFILE=router forge test",
"test:coverage": "../../scripts/coverage-report.sh router",
"storage-inspect:check": "../../scripts/storage-inspect.sh check Router XAppConnectionClient",
"storage-inspect:generate": "../../scripts/storage-inspect.sh generate Router XAppConnectionClient"
},
Expand Down
1 change: 0 additions & 1 deletion packages/deploy/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ dist/
lib/
output/
config/config.json
coverage/
3 changes: 1 addition & 2 deletions packages/deploy/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
collectCoverage: true,
coverageDirectory: 'coverage',
coverageDirectory: '.coverage',
verbose: true,
globals: {
'ts-jest': {
Expand Down
2 changes: 1 addition & 1 deletion packages/deploy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"scripts": {
"build": "tsc --build",
"check": "tsc --noEmit",
"coverage": "echo TODO: Fix tests",
"test:coverage": "jest --collectCoverage",
"lint": "eslint --fix ./src",
"prettier": "prettier --write ./src",
"test:unit": "jest"
Expand Down
1 change: 0 additions & 1 deletion packages/local-environment/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.env
output/verification-*
output/config.json
coverage
!output/.gitkeep
17 changes: 5 additions & 12 deletions packages/local-environment/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,22 @@ export default {
clearMocks: true,

// Indicates whether the coverage information should be collected while executing the test
collectCoverage: true,
// collectCoverage: true,

// An array of glob patterns indicating a set of files for which coverage information should be collected
// collectCoverageFrom: undefined,

// The directory where Jest should output its coverage files
coverageDirectory: "coverage",
coverageDirectory: ".coverage",

// An array of regexp pattern strings used to skip coverage collection
coveragePathIgnorePatterns: [
"/node_modules/"
],
coveragePathIgnorePatterns: ["/node_modules/"],

// Indicates which provider should be used to instrument code for coverage
// coverageProvider: "babel",

// A list of reporter names that Jest uses when writing coverage reports
coverageReporters: [
"json",
"text",
"html",
],
coverageReporters: ["json", "text", "html"],

// An object that configures minimum threshold enforcement for coverage results
// coverageThreshold: undefined,
Expand Down Expand Up @@ -136,7 +130,7 @@ export default {
// setupFiles: [],

//A list of paths to modules that run some code to configure or set up the testing framework before each test
setupFilesAfterEnv: ['./jest.setup.ts'],
setupFilesAfterEnv: ["./jest.setup.ts"],

// The number of seconds after which a test is considered as slow and reported as such in the results.
// slowTestThreshold: 5,
Expand Down Expand Up @@ -193,5 +187,4 @@ export default {

// Whether to use watchman for file crawling
// watchman: true,

};
1 change: 1 addition & 0 deletions packages/local-environment/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"build": "tsc --build",
"bootup": "./bootup.sh",
"cleanup": "npm run hardhat_stop && npm run agents_stop && npm run agents_clean",
"test:coverage": "jest --collectCoverage",
"hardhat_stop": "docker ps --filter name=_net -aq | xargs docker rm --force",
"test:unit": "jest unit --detectOpenHandles --ci --forceExit",
"test:integration": "jest int --detectOpenHandles --ci --forceExit",
Expand Down
1 change: 0 additions & 1 deletion packages/multi-provider/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
dist/
tsconfig.tsbuildinfo
.nyc_output/
coverage/
3 changes: 1 addition & 2 deletions packages/multi-provider/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
collectCoverage: true,
coverageDirectory: 'coverage',
coverageDirectory: '.coverage',
verbose: true,
globals: {
'ts-jest': {
Expand Down
2 changes: 1 addition & 1 deletion packages/multi-provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"scripts": {
"build": "tsc --build",
"check": "tsc --noEmit",
"coverage": "echo TODO: Fix tests",
"test:coverage": "jest --collectCoverage",
"lint": "eslint --fix ./src ./tests",
"prettier": "prettier --write ./src ./tests",
"test:unit": "jest"
Expand Down
1 change: 0 additions & 1 deletion packages/sdk-bridge/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
dist/
tsconfig.tsbuildinfo
.nyc_output/
coverage/
3 changes: 1 addition & 2 deletions packages/sdk-bridge/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
collectCoverage: true,
coverageDirectory: 'coverage',
coverageDirectory: '.coverage',
verbose: true,
globals: {
'ts-jest': {
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk-bridge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"scripts": {
"build": "tsc --build",
"check": "tsc --noEmit",
"coverage": "echo TODO: Fix tests",
"test:coverage": "jest --collectCoverage",
"lint": "eslint --fix ./src ./tests",
"prettier": "prettier --write ./src ./tests",
"test:unit": "jest"
Expand Down
1 change: 0 additions & 1 deletion packages/sdk-govern/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
dist/
tsconfig.tsbuildinfo
.nyc_output/
coverage/
config/config.json
config/callBatch.json
3 changes: 1 addition & 2 deletions packages/sdk-govern/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
collectCoverage: true,
coverageDirectory: 'coverage',
coverageDirectory: '.coverage',
verbose: true,
globals: {
'ts-jest': {
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk-govern/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"scripts": {
"build": "tsc --build",
"check": "tsc --noEmit",
"coverage": "echo TODO: Fix tests",
"test:coverage": "jest --collectCoverage",
"lint": "eslint --fix ./src ./tests",
"prettier": "prettier --write ./src ./tests",
"test:unit": "jest"
Expand Down
1 change: 0 additions & 1 deletion packages/sdk/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
dist/
tsconfig.tsbuildinfo
.nyc_output/
coverage/
3 changes: 1 addition & 2 deletions packages/sdk/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
collectCoverage: true,
coverageDirectory: 'coverage',
coverageDirectory: '.coverage',
verbose: true,
globals: {
'ts-jest': {
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"scripts": {
"build": "tsc --build",
"check": "tsc --noEmit",
"coverage": "echo TODO: Fix tests",
"test:coverage": "jest --collectCoverage",
"lint": "eslint --fix ./src ./tests",
"prettier": "prettier --write ./src ./tests",
"test:unit": "jest"
Expand Down
42 changes: 42 additions & 0 deletions scripts/coverage-report.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash

set -e

if [[ $(which genhtml) == "" ]]; then
echo "To generate code coverage, you need to install lcov"
echo "See: https://command-not-found.com/genhtml"
exit 1
fi

if [[ $(which forge) == "" ]]; then
echo "To generate code coverage, you need to install Foundry"
echo "See: https://getfoundry.sh/"
exit 1
fi

if [[ $1 == *"core"* ]]; then
# Need to be to top-level directory of the monorepo
cd $(git rev-parse --show-toplevel)
path="packages/contracts-core/.coverage"
profile=core
elif [[ $1 == *"bridge"* ]]; then
# Need to be to top-level directory of the monorepo
cd $(git rev-parse --show-toplevel)
path="packages/contracts-bridge/.coverage"
profile=bridge
elif [[ $1 == *"router"* ]]; then
# Need to be to top-level directory of the monorepo
cd $(git rev-parse --show-toplevel)
path="packages/contracts-router/.coverage"
profile=router
else
echo "Argument not recognised: '$1'"
echo "Supported packages: core, bridge, router"
echo "Example: sh coverage-report.sh core"
exit 1
fi
FOUNDRY_PROFILE=$profile forge coverage --report lcov
genhtml -o "$path" lcov.info
echo "Report generated at $path"
echo "Open $(readlink -f $path)/index.html"
rm lcov.info

0 comments on commit 5cae4fd

Please sign in to comment.