Skip to content

Commit

Permalink
es test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
akosyakov committed Apr 13, 2024
1 parent 1e0fcda commit 62cd2ea
Show file tree
Hide file tree
Showing 19 changed files with 577 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ components/supervisor/frontend/lib/
src-gen/
css-gen/
node_modules/
coverage/
.nyc_output/
yarn-error.log
lerna-debug.log
**/telepresence.log
Expand Down
1 change: 1 addition & 0 deletions components/gitpod-db/BUILD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ packages:
deps:
- :dbtest
- components/gitpod-protocol:lib
- dev/mochaw:lib
config:
packaging: library
yarnLock: ${coreYarnLockBase}/yarn.lock
Expand Down
3 changes: 2 additions & 1 deletion components/gitpod-db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"test": "yarn db-test",
"watch": "leeway exec --package .:lib --transitive-dependencies --filter-type yarn --components --parallel -- tsc -w --preserveWatchOutput",
"db-test": "r(){ . $(leeway run components/gitpod-db:db-test-env); yarn db-test-run; };r",
"db-test-run": "mocha '**/*.spec.db.ts' --exclude './node_modules/**' --exit",
"db-test-run": "mochaw db",
"wait-for-db": "node ./lib/wait-for-db.js",
"typeorm": "typeorm -f lib/typeorm/ormconfig",
"migrate-migrations": "node ./lib/migrate-migrations.js",
Expand Down Expand Up @@ -47,6 +47,7 @@
"prom-client": "^14.2.0"
},
"devDependencies": {
"@gitpod/mochaw": "0.1.5",
"@testdeck/mocha": "^0.3.3",
"@types/chai": "^4.2.2",
"@types/mocha": "^10.0.1",
Expand Down
2 changes: 2 additions & 0 deletions components/gitpod-protocol/BUILD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ packages:
- .eslintrc
- mocha.opts
- package.json
deps:
- dev/mochaw:lib
config:
packaging: library
yarnLock: ${coreYarnLockBase}/yarn.lock
Expand Down
3 changes: 2 additions & 1 deletion components/gitpod-protocol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"src"
],
"devDependencies": {
"@gitpod/mochaw": "0.1.5",
"@grpc/grpc-js": "1.9.1",
"@testdeck/mocha": "^0.3.3",
"@types/analytics-node": "^3.1.9",
Expand Down Expand Up @@ -41,7 +42,7 @@
"build:clean": "yarn clean && yarn lint && yarn build",
"lint": "yarn eslint src/*.ts src/**/*.ts",
"lint:fix": "yarn eslint src/*.ts src/**/*.ts --fix",
"test": "mocha './**/*.spec.js' --exclude './node_modules/**' --exit",
"test": "mochaw",
"test:leeway": "yarn build && yarn test",
"test-debug": "mocha --inspect-brk './**/*.spec.js' --exclude './node_modules/**' --exit",
"watch": "leeway exec --package .:lib --transitive-dependencies --filter-type yarn --components --parallel -- tsc -w --preserveWatchOutput"
Expand Down
1 change: 1 addition & 0 deletions components/public-api/typescript-common/BUILD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ packages:
deps:
- components/gitpod-protocol:lib
- components/public-api/typescript:lib
- dev/mochaw:lib
config:
packaging: library
commands:
Expand Down
5 changes: 3 additions & 2 deletions components/public-api/typescript-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"build": "yarn run build:cjs && yarn run build:esm",
"build:cjs": "tsc",
"build:esm": "tsc --module es2015 --outDir ./lib/esm",
"test": "mocha './**/*.spec.js' --exclude './node_modules/**' --exclude './lib/esm/**' --exit",
"test:forceUpdate": "mocha './**/*.spec.js' --exclude './node_modules/**' --exclude './lib/esm/**' --exit -force -update && yarn format:fixtures",
"test": "mochaw",
"test:forceUpdate": "mochaw -force -update && yarn format:fixtures",
"test:leeway": "yarn build && yarn test",
"format:fixtures": "git ls-files -- 'fixtures/*' | xargs pre-commit run end-of-file-fixer --files > /dev/null || exit 0",
"watch": "leeway exec --package .:lib --transitive-dependencies --filter-type yarn --components --parallel -- tsc -w --preserveWatchOutput"
Expand All @@ -29,6 +29,7 @@
"@gitpod/public-api": "0.1.5"
},
"devDependencies": {
"@gitpod/mochaw": "0.1.5",
"@types/chai-subset": "^1.3.3",
"@types/glob": "^8.1.0",
"@types/mocha": "^10.0.1",
Expand Down
1 change: 1 addition & 0 deletions components/server/BUILD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ packages:
- components/gitpod-db:dbtest-init
- components/spicedb:lib
- components/spicedb/typescript:lib
- dev/mochaw:lib
config:
packaging: offline-mirror
yarnLock: ${coreYarnLockBase}/yarn.lock
Expand Down
5 changes: 3 additions & 2 deletions components/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"purge": "yarn clean && yarn clean:node && yarn run rimraf yarn.lock",
"test:leeway": "yarn build && yarn test",
"test": "yarn test:unit && yarn test:db",
"test:unit": "mocha './**/*.spec.js' --exclude './node_modules/**' --exit",
"test:db": "cleanup() { echo 'Cleanup started'; yarn stop-services; }; trap cleanup EXIT; . $(leeway run components/gitpod-db:db-test-env) && yarn start-services && mocha './**/*.spec.db.js' --exclude './node_modules/**' --exit",
"test:unit": "mochaw",
"test:db": "cleanup() { echo 'Cleanup started'; yarn stop-services; }; trap cleanup EXIT; . $(leeway run components/gitpod-db:db-test-env) && yarn start-services && mochaw db",
"start-services": "yarn start-testdb && yarn start-redis && yarn start-spicedb",
"stop-services": "yarn stop-redis && yarn stop-spicedb",
"start-testdb": "leeway run components/gitpod-db:init-testdb",
Expand Down Expand Up @@ -110,6 +110,7 @@
"ws": "^7.4.6"
},
"devDependencies": {
"@gitpod/mochaw": "0.1.5",
"@testdeck/mocha": "^0.3.3",
"@types/assert": "^1.5.6",
"@types/base-64": "^1.0.0",
Expand Down
1 change: 1 addition & 0 deletions components/ws-manager-api/typescript/BUILD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ packages:
deps:
- components/content-service-api/typescript:lib
- components/gitpod-protocol:lib
- dev/mochaw:lib
srcs:
- "src/*.ts"
- "src/*.js"
Expand Down
3 changes: 2 additions & 1 deletion components/ws-manager-api/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"scripts": {
"build": "mkdir -p lib && cp -f src/*.js src/*d.ts lib && tsc",
"watch": "leeway exec --package .:lib --transitive-dependencies --filter-type yarn --components --parallel -- tsc -w --preserveWatchOutput",
"test": "mocha './**/*.spec.ts' --exclude './node_modules/**' --exit",
"test": "mochaw",
"test:brk": "yarn test --inspect-brk"
},
"mocha": {
Expand All @@ -33,6 +33,7 @@
"opentracing": "^0.14.4"
},
"devDependencies": {
"@gitpod/mochaw": "0.1.5",
"@testdeck/mocha": "^0.3.3",
"@types/chai": "^4.1.2",
"@types/google-protobuf": "^3.15.5",
Expand Down
1 change: 1 addition & 0 deletions components/ws-manager-bridge/BUILD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ packages:
- components/ws-daemon-api/typescript:lib
- components/ws-manager-api/typescript:lib
- components/ws-manager-bridge-api/typescript:lib
- dev/mochaw:lib
config:
packaging: offline-mirror
yarnLock: ${coreYarnLockBase}/yarn.lock
Expand Down
3 changes: 2 additions & 1 deletion components/ws-manager-bridge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "UNLICENSED",
"scripts": {
"start": "node ./dist/index.js",
"test": "mocha './**/*.spec.ts' --exclude './node_modules/**' --exit",
"test": "mochaw",
"lint": "yarn eslint src/*.ts src/**/*.ts",
"lint:fix": "yarn eslint src/*.ts src/**/*.ts --fix",
"build": "yarn lint && npx tsc",
Expand Down Expand Up @@ -46,6 +46,7 @@
"reflect-metadata": "^0.1.13"
},
"devDependencies": {
"@gitpod/mochaw": "0.1.5",
"@testdeck/mocha": "^0.3.3",
"@types/chai": "^4.2.21",
"@types/express": "^4.17.13",
Expand Down
10 changes: 10 additions & 0 deletions dev/mochaw/BUILD.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
packages:
- name: lib
type: yarn
srcs:
- mochaw.sh
- package.json
config:
packaging: library
yarnLock: ${coreYarnLockBase}/yarn.lock
dontTest: true
35 changes: 35 additions & 0 deletions dev/mochaw/mochaw.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
# Copyright (c) 2024 Gitpod GmbH. All rights reserved.
# Licensed under the GNU Affero General Public License (AGPL).
# See License.AGPL.txt in the project root for license information.


COMPONENT_DIR="$(pwd)"

# unit or db
TEST_SUITE=${1:-unit}

FILE_PATTERN="**/*.spec.js"
if [ "$TEST_SUITE" = "db" ]; then
FILE_PATTERN="**/*.spec.db.js"
fi

# Exclude the first argument and pass the rest to mocha
shift 1

if [ "$COVERAGE" = "true" ]; then
nyc --cwd=/workspace/gitpod \
--all \
--report-dir="$COMPONENT_DIR/coverage/$TEST_SUITE" \
--include="components/*/{src,lib,dist}/**/*.{ts,js}" \
--include="components/public-api/typescript-common/src/**/*.ts" \
--exclude="components/**/*.spec.{ts,js}" \
--exclude="components/**/*.spec.db.{ts,js}" \
--exclude="components/*/src/test/**" \
--exclude="components/dashboard/**" \
--exclude="components/supervisor/frontend/**" \
--reporter=json \
mocha "$COMPONENT_DIR/$FILE_PATTERN" --exclude "$COMPONENT_DIR/node_modules/**" --exclude "$COMPONENT_DIR/lib/esm/**" --exit "$@"
else
mocha "$COMPONENT_DIR/$FILE_PATTERN" --exclude "$COMPONENT_DIR/node_modules/**" --exclude "$COMPONENT_DIR/lib/esm/**" --exit "$@"
fi
17 changes: 17 additions & 0 deletions dev/mochaw/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "@gitpod/mochaw",
"version": "0.1.5",
"license": "UNLICENSED",
"files": [
"mochaw.sh"
],
"bin": {
"mochaw": "mochaw.sh"
},
"scripts": {
"build": "echo 'nothing to build'"
},
"dependencies": {
"nyc": "^15.1.0"
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"workspaces": {
"packages": [
"dev/mochaw",
"components/*",
"components/*/typescript",
"components/*/typescript-*",
Expand Down
45 changes: 45 additions & 0 deletions scripts/es-coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

export COVERAGE=true

yarn --cwd=/workspace/gitpod install
rm -rf coverage

# gitpod-protocol
rm -rf /workspace/gitpod/components/gitpod-protocol/coverage
yarn --cwd=/workspace/gitpod/components/gitpod-protocol run test:leeway
yarn nyc merge --cwd=/workspace/gitpod components/gitpod-protocol/coverage/unit coverage/gitpod-protocol-unit.json

# gitpod-db
rm -rf /workspace/gitpod/components/gitpod-db/coverage
yarn --cwd=/workspace/gitpod/components/gitpod-db run build
yarn --cwd=/workspace/gitpod/components/gitpod-db run test
yarn nyc merge --cwd=/workspace/gitpod components/gitpod-db/coverage/db coverage/gitpod-db-db.json

# public-api-common
rm -rf /workspace/gitpod/components/public-api/typescript-common/coverage
yarn --cwd=/workspace/gitpod/components/public-api/typescript-common run test:leeway
yarn nyc merge --cwd=/workspace/gitpod components/public-api/typescript-common/coverage/unit coverage/public-api-common-unit.json

# server
rm -rf /workspace/gitpod/components/server/coverage
yarn --cwd=/workspace/gitpod/components/server run build
yarn --cwd=/workspace/gitpod/components/server run test
yarn nyc merge --cwd=/workspace/gitpod components/server/coverage/unit coverage/server-unit.json
yarn nyc merge --cwd=/workspace/gitpod components/server/coverage/db coverage/server-db.json

# ws-manager-api
rm -rf /workspace/gitpod/components/ws-manager-api/typescript/coverage
yarn --cwd=/workspace/gitpod/components/ws-manager-api/typescript run build
yarn --cwd=/workspace/gitpod/components/ws-manager-api/typescript run test
yarn nyc merge --cwd=/workspace/gitpod components/ws-manager-api/typescript/coverage/unit coverage/ws-manager-api-unit.json

# ws-manager-bridge
rm -rf /workspace/gitpod/components/ws-manager-bridge/coverage
yarn --cwd=/workspace/gitpod/components/ws-manager-bridge run build
yarn --cwd=/workspace/gitpod/components/ws-manager-bridge run test
yarn nyc merge --cwd=/workspace/gitpod components/ws-manager-bridge/coverage/unit coverage/ws-manager-bridge-unit.json

# final
yarn nyc merge --cwd=/workspace/gitpod coverage coverage/final-coverage.json
yarn nyc report --cwd=/workspace/gitpod --reporter=lcov --reporter=text-summary --temp-dir=coverage

0 comments on commit 62cd2ea

Please sign in to comment.