Skip to content

Commit 3a54d4b

Browse files
authored
Update GH Actions (#14)
* add unittest step * use nvmrc for `node-version` * init playwright * fix playwright action issue * update artifact path * headless only * remove playwright * init mock server * explain how to run playwright tests
1 parent b9920c7 commit 3a54d4b

File tree

14 files changed

+555
-31
lines changed

14 files changed

+555
-31
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ DISCORD_CLIENT_SECRET=""
2020

2121
# OAuth Mock
2222
OAUTH_MOCK_ENABLED=false
23-
#OAUTH_MOCK_ENDPOINT="http://localhost"
23+
OAUTH_MOCK_ENDPOINT="http://localhost:8080"

.github/workflows/ci.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,14 @@ jobs:
5555

5656
- name: Typecheck
5757
run: pnpm typecheck
58+
59+
unittest:
60+
runs-on: ubuntu-latest
61+
steps:
62+
- uses: actions/checkout@v4
63+
64+
- name: Setup
65+
uses: ./tooling/github/setup
66+
67+
- name: Unittest
68+
run: pnpm test

README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ This project is a monorepo based on turborepo.
4141
├── apps
4242
│ └── frontend - Contains the logic for the site
4343
├── packages
44-
│ ├── auth - Based on lucia-auth.com / same as we have at itaps monorepo
44+
│ ├── auth - Based on lucia-auth.com
4545
│ ├── db - Contains all the database related stuff ( prisma schema, migrations, seeds etc. )
4646
│ ├── helpers - Helper functions 🤷‍♂️
4747
│ ├── locales - contains the translations for the `frontend` app
@@ -85,11 +85,26 @@ This project is a monorepo based on turborepo.
8585
## Todos
8686

8787
- [ ] Add unit tests
88-
- [ ] Add more docs ( like how to activate/use mock users )
8988
- [ ] Integrate https://github.com/sadmann7/shadcn-table to have an example
9089
- [ ] Maybe: Adding a RBAC solution ( maybe via casl? )
9190
- [ ] Add a contribution guide
9291

92+
## Running playwright tests
93+
94+
We have prepared some simple testcases to test the authentication in the nextjs app.
95+
96+
To make it runable inside a CI or locally, we're using an [oauth mock server](https://github.com/axa-group/oauth2-mock-server) to make it easier to run the tests and ensuring everything works as expected without having to add some magic to bypass the tests.
97+
98+
With this, we automatically test the authentication flow.
99+
100+
By running `pnpm dev`, the oauth mock server will start, too.
101+
102+
You only have to set `OAUTH_MOCK_ENABLED` to `true` in your `.env` file.
103+
104+
Last step is to open a new terminal tab and run `pnpm test:e2e:nextjs` to start the playwright tests.
105+
106+
You can find the complete playwright configuration in `tooling/playwright`.
107+
93108
## Credits
94109

95110
Without the amazing work of the [T3 OSS Community](https://github.com/t3-oss), this project wouldn't exists.

apps/mock-server/eslint.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import baseConfig, { restrictEnvAccess } from "@acme/eslint-config/base"
2+
3+
/** @type {import('typescript-eslint').Config} */
4+
export default [...baseConfig]

apps/mock-server/package.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "mock-server",
3+
"version": "2.0.0",
4+
"private": true,
5+
"type": "module",
6+
"scripts": {
7+
"clean": "git clean -xdf .cache .turbo dist node_modules .next",
8+
"clean:cache": "git clean -xdf .cache",
9+
"dev": "tsx --watch src/server.ts",
10+
"format": "prettier --check . --ignore-path ../../.gitignore",
11+
"lint": "eslint .",
12+
"typecheck": "tsc --noEmit"
13+
},
14+
"prettier": "@acme/prettier-config",
15+
"dependencies": {
16+
"@acme/logging": "workspace:*",
17+
"oauth2-mock-server": "7.2.0"
18+
},
19+
"devDependencies": {
20+
"@acme/eslint-config": "workspace:*",
21+
"@acme/prettier-config": "workspace:*",
22+
"@acme/tailwind-config": "workspace:*",
23+
"@acme/tsconfig": "workspace:*",
24+
"@types/node": "22.10.2",
25+
"eslint": "9.17.0",
26+
"prettier": "3.4.2",
27+
"tsx": "4.19.2",
28+
"typescript": "5.7.2"
29+
}
30+
}

apps/mock-server/src/server.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { OAuth2Server } from "oauth2-mock-server"
2+
3+
import { createLogger } from "@acme/logging"
4+
5+
const logger = createLogger("console")
6+
const server = new OAuth2Server()
7+
await server.issuer.keys.generate("RS256")
8+
9+
await server.start(8080, "localhost")
10+
logger.info("Issuer URL:", server.issuer.url) // -> http://localhost:8080

apps/mock-server/tsconfig.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"extends": "@acme/tsconfig/base.json",
3+
"compilerOptions": {
4+
"lib": ["es2022", "dom", "dom.iterable"],
5+
"jsx": "preserve",
6+
"typeRoots": ["types"],
7+
"baseUrl": ".",
8+
"paths": {
9+
"~/*": ["./src/*"]
10+
},
11+
12+
"module": "esnext"
13+
},
14+
"include": [".", "dist/types/**/*.ts", "types"],
15+
"exclude": ["node_modules"]
16+
}

apps/nextjs/playwright.config.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import playwrightConfig from "@acme/playwright"
22

3-
const baseUrl = process.env.APPLICATION_URL
4-
? `${process.env.APPLICATION_URL}`
5-
: process.env.LOCAL_HTTPS
6-
? "https://localhost:3000"
7-
: "http://localhost:3000"
3+
const baseUrl = process.env.APPLICATION_URL ?? "http://localhost:3000"
84

95
export default playwrightConfig({
106
basePath: "/",

apps/nextjs/tests/a11y/initial.test.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@
3232
"test": "vitest --project=unit",
3333
"test:ui": "vitest --ui",
3434
"prune": "turbo prune --docker",
35-
"prepare_test": "turbo run build --filter @acme/* --filter !./apps/*",
3635
"turbo": "turbo",
37-
"test:e2e:frontend": "pnpm -F frontend test:e2e",
36+
"test:e2e:nextjs": "pnpm -F nextjs test:e2e",
3837
"playwright:init": "pnpm -F playwright test:init"
3938
},
4039
"devDependencies": {

0 commit comments

Comments
 (0)