Skip to content

Commit

Permalink
enhance(cypress): add code coverage for apps/backend-docker code thro…
Browse files Browse the repository at this point in the history
…ugh cypress (#4001)

Co-authored-by: sjschlapbach <julius.schlapbach@gmx.net>
Co-authored-by: Julius Schlapbach <80708107+sjschlapbach@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 2, 2024
1 parent b2d7343 commit df55ff1
Show file tree
Hide file tree
Showing 16 changed files with 130 additions and 81 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/cypress-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,12 @@ jobs:
DATABASE_URL: postgres://klicker:klicker@localhost:5432/klicker
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_ENV: production

- name: Archive code coverage results
uses: actions/upload-artifact@v3
with:
name: code-coverage
path: cypress/coverage

- name: Coveralls
uses: coverallsapp/github-action@v2
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@ We welcome any contributions to the KlickerUZH project. Before considering any c
The KlickerUZH and all of its subprojects are licensed under the [AGPLv3](https://www.gnu.org/licenses/agpl-3.0.de.html).

[![klicker-uzh](https://img.shields.io/endpoint?url=https://cloud.cypress.io/badge/simple/y436dx/v3&style=for-the-badge&logo=cypress)](https://cloud.cypress.io/projects/y436dx/runs)
[![Coverage Status](https://coveralls.io/repos/github/uzh-bf/klicker-uzh/badge.svg?branch=v3)](https://coveralls.io/github/uzh-bf/klicker-uzh?branch=v3.1-dev)
3 changes: 2 additions & 1 deletion apps/backend-docker/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
.DS_Store
node_modules
src/client
dist
dist/
instrumented/

src/prisma/ERD.svg
src/graphql
Expand Down
4 changes: 4 additions & 0 deletions apps/backend-docker/.nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "@istanbuljs/nyc-config-typescript",
"all": true
}
13 changes: 8 additions & 5 deletions apps/backend-docker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"ws": "8.13.0"
},
"devDependencies": {
"@cypress/code-coverage": "3.12.1",
"@cypress/code-coverage": "3.12.16",
"@istanbuljs/nyc-config-typescript": "1.0.2",
"@tsconfig/node18": "^2.0.0",
"@tsconfig/node20": "^20.1.2",
"@tsconfig/recommended": "^1.0.2",
Expand All @@ -61,13 +62,16 @@
"npm-run-all": "4.1.5",
"nyc": "15.1.0",
"prisma": "5.3.1",
"source-map-support": "0.5.21",
"ts-node": "10.9.1",
"tsup": "7.2.0",
"typescript": "5.2.2"
},
"scripts": {
"build": "cross-env NODE_ENV=production tsup",
"build:test": "pnpm run build",
"build": "cross-env NODE_ENV=production pnpm run build:ts",
"build:ts": "tsup",
"build:test": "run-s build:instrument build:ts",
"build:instrument": "nyc instrument --compact=false src instrumented",
"check": "tsc --noEmit",
"dev": "npm-run-all --parallel dev:build dev:run",
"dev:build": "tsup --watch",
Expand All @@ -76,8 +80,7 @@
"format": "prettier --write .",
"format:check": "prettier --check .",
"start": "node -r dotenv/config dist/index.js",
"--start:test": "nyc --silent npm start",
"start:test": "pnpm start",
"start:test": "nyc --silent node -r dotenv/config dist/index.js",
"exec:prod": "doppler run --config prd -- bun run"
},
"engines": {
Expand Down
4 changes: 3 additions & 1 deletion apps/backend-docker/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ function prepareApp({ prisma, redisExec, pubSub, cache, emitter }: any) {
if (global.__coverage__) {
try {
require('@cypress/code-coverage/middleware/express')(app)
} catch (e) {}
} catch (e) {
console.error(e)
}
}

app.use(
Expand Down
4 changes: 3 additions & 1 deletion apps/backend-docker/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"extends": "@tsconfig/node20/tsconfig.json",
"include": ["src", "scripts"],
"compilerOptions": {},
"compilerOptions": {
"sourceMap": true
},
"ts-node": {
"transpileOnly": true,
"moduleTypes": {
Expand Down
5 changes: 4 additions & 1 deletion apps/backend-docker/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { defineConfig } from 'tsup'

export default defineConfig({
entry: ['src/index.ts'],
entry:
process.env.NODE_ENV === 'test'
? ['instrumented/index.ts']
: ['src/index.ts'],
format: 'esm',
clean: true,
target: 'node20',
Expand Down
23 changes: 8 additions & 15 deletions cypress/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,19 @@ export default defineConfig({
STUDENT_USERNAME: 'testuser1',
STUDENT_PASSWORD: 'abcd',

// codeCoverage: {
// expectBackendCoverageOnly: true,
// url: 'http://127.0.0.1:3000/__coverage__',
// },
codeCoverage: {
expectBackendCoverageOnly: true,
url: 'http://127.0.0.1:3000/__coverage__',
},
},

e2e: {
experimentalStudio: true,
// // includeShadowDom: true,
// setupNodeEvents(on, config) {
// require('@cypress/code-coverage/task')(on, config)
// /* on("task", {
// async "db:seed"() {
// // seed database with test data
// const { data } = await axios.post(`${testDataApiEndpoint}/seed`);
// return data;
// },
// }); */
// return config
// },
setupNodeEvents(on, config) {
require('@cypress/code-coverage/task')(on, config)
return config
},
},

retries: {
Expand Down
6 changes: 3 additions & 3 deletions cypress/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"private": true,
"name": "@klicker-uzh/cypress",
"devDependencies": {
"@cypress/code-coverage": "3.12.1",
"@cypress/code-coverage": "3.12.16",
"@testing-library/cypress": "10.0.1",
"@types/jsonwebtoken": "^8.0.0",
"@types/node": "^18.17.4",
"cypress": "13.6.0",
"@types/node": "^20.10.6",
"cypress": "13.6.2",
"jsonwebtoken": "8.5.1",
"typescript": "5.2.2"
},
Expand Down
3 changes: 2 additions & 1 deletion packages/graphql/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
.DS_Store
node_modules
src/prisma/client
dist
dist/
instrumented/
hive.json
4 changes: 4 additions & 0 deletions packages/graphql/.nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "@istanbuljs/nyc-config-typescript",
"all": true
}
10 changes: 7 additions & 3 deletions packages/graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@graphql-codegen/typescript-resolvers": "4.0.1",
"@graphql-tools/utils": "10.0.6",
"@graphql-typed-document-node/core": "3.2.0",
"@istanbuljs/nyc-config-typescript": "1.0.2",
"@parcel/watcher": "2.2.0",
"@size-limit/preset-small-lib": "8.2.4",
"@tsconfig/node18": "^2.0.1",
Expand All @@ -64,9 +65,11 @@
"ioredis": "5.3.2",
"jest": "29.5.0",
"npm-run-all": "4.1.5",
"nyc": "15.1.0",
"prettier": "2.8.8",
"prettier-plugin-organize-imports": "3.2.3",
"size-limit": "8.2.4",
"source-map-support": "0.5.21",
"ts-node": "10.9.1",
"ts-node-dev": "2.0.0",
"tsup": "7.2.0",
Expand All @@ -75,9 +78,10 @@
},
"scripts": {
"analyze": "size-limit --why",
"build": "run-s generate build:ts",
"build:ts": "cross-env NODE_ENV=production tsup --dts",
"build:test": "pnpm run build",
"build": "cross-env NODE_ENV=production run-s generate build:ts",
"build:ts": "tsup --dts",
"build:test": "run-s build:instrument build",
"build:instrument": "nyc instrument --compact=false src instrumented",
"check": "tsc --noEmit",
"dev": "npm-run-all --parallel dev:graphql dev:ts",
"dev:graphql": "doppler run --config dev -- graphql-codegen --config codegen.ts --watch 'src/**.graphql' --watch 'src/**.ts'",
Expand Down
3 changes: 2 additions & 1 deletion packages/graphql/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"extends": "@tsconfig/node18/tsconfig.json",
"include": ["src", "src/types/app.ts"],
"compilerOptions": {
"baseUrl": "."
"baseUrl": ".",
"sourceMap": true
},
"ts-node": {
"transpileOnly": true
Expand Down
5 changes: 4 additions & 1 deletion packages/graphql/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { defineConfig } from 'tsup'

export default defineConfig({
entry: ['src/index.ts', 'src/ops.ts', 'src/util.ts'],
entry:
process.env.NODE_ENV === 'test'
? ['instrumented/index.ts', 'instrumented/ops.ts', 'instrumented/util.ts']
: ['src/index.ts', 'src/ops.ts', 'src/util.ts'],
clean: false,
dts: true,
publicDir: 'src/public',
Expand Down
Loading

0 comments on commit df55ff1

Please sign in to comment.