Skip to content

Commit

Permalink
refactor(api): extract TMDB mock server to a separate app
Browse files Browse the repository at this point in the history
This is used for e2e tests.

Related to #83
  • Loading branch information
JoosepAlviste committed Jan 11, 2024
1 parent a426389 commit 77fdbfb
Show file tree
Hide file tree
Showing 15 changed files with 106 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.nx/cache
.env
node_modules
dist
1 change: 0 additions & 1 deletion apps/api/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
dist
coverage
1 change: 0 additions & 1 deletion apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"start:jobs": "NODE_ENV=development tsx watch --clear-screen=false src/mainJobs.ts",
"start:jobs:prod": "NODE_ENV=production node dist/src/mainJobs.js",
"start:prod": "NODE_ENV=production node dist/src/main.js",
"start:tmdb": "tsx watch src/test/mockTMDBServer.ts",
"test": "dotenv -e ../../.env.test vitest run",
"test:coverage": "dotenv -e ../../.env.test vitest run -- --coverage",
"test:watch": "dotenv -e ../../.env.test vitest",
Expand Down
5 changes: 3 additions & 2 deletions apps/e2e/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ export default defineConfig({
reuseExistingServer: !process.env.CI,
},
{
command: '(cd ../.. && pnpm exec nx start:tmdb @serieslist/api)',
url: `http://localhost:4002`,
command:
'(cd ../.. && pnpm exec nx start:e2e @serieslist/tmdb-mock-server)',
url: config.tmdb.url,
timeout: 20 * 1000,
reuseExistingServer: !process.env.CI,
},
Expand Down
6 changes: 5 additions & 1 deletion apps/e2e/project.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"name": "@serieslist/e2e",
"implicitDependencies": ["@serieslist/api", "@serieslist/webapp"]
"implicitDependencies": [
"@serieslist/api",
"@serieslist/webapp",
"@serieslist/tmdb-mock-server"
]
}
3 changes: 3 additions & 0 deletions apps/e2e/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ export const config = {
api: {
url: process.env.VITE_API_URL!,
},
tmdb: {
url: process.env.TMDB_URL!,
},
}
12 changes: 12 additions & 0 deletions apps/tmdbMockServer/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "@serieslist/eslint-config-base",
"root": true,
"overrides": [
{
"files": ["src/main.ts"],
"rules": {
"@typescript-eslint/no-non-null-assertion": "off"
}
}
]
}
1 change: 1 addition & 0 deletions apps/tmdbMockServer/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"@serieslist/prettier-config"
8 changes: 8 additions & 0 deletions apps/tmdbMockServer/bin/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { buildEsbuild } from '@serieslist/esbuild'

import pkg from '../package.json'

await buildEsbuild({
packageJson: pkg,
entryPoints: ['src/main.ts'],
})
26 changes: 26 additions & 0 deletions apps/tmdbMockServer/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "@serieslist/tmdb-mock-server",
"version": "1.0.0",
"type": "module",
"scripts": {
"build": "rimraf dist && NODE_ENV=production tsx bin/build.ts",
"lint": "eslint src",
"tsc": "tsc --noEmit",
"start:e2e": "NODE_ENV=production node dist/main.js"
},
"devDependencies": {
"@serieslist/esbuild": "workspace:*",
"@serieslist/eslint-config-base": "workspace:*",
"@serieslist/prettier-config": "workspace:*",
"@serieslist/typescript-config-base": "workspace:*",
"rimraf": "^4.4.0",
"tsx": "^4.7.0",
"typescript": "^5.3.3"
},
"dependencies": {
"@serieslist/logger": "workspace:*",
"@serieslist/tmdb": "workspace:*",
"fastify": "^4.18.0",
"just-omit": "^2.2.0"
}
}
6 changes: 6 additions & 0 deletions apps/tmdbMockServer/src/lib/createArrayOfLength.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* Create an array with the given length, filled with `null`s.
*/
export const createArrayOfLength = (length: number) =>
/* eslint-disable-next-line prefer-spread*/
Array.apply(null, Array(length))
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
import fastify from 'fastify'
import omit from 'just-omit'

import { createArrayOfLength } from '#/lib/createArrayOfLength'
import { createArrayOfLength } from './lib/createArrayOfLength'

const app = fastify({
logger: true,
Expand Down
3 changes: 3 additions & 0 deletions apps/tmdbMockServer/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@serieslist/typescript-config-base"
}
2 changes: 0 additions & 2 deletions apps/webapp/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
node_modules/
dist/
coverage
37 changes: 37 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 77fdbfb

Please sign in to comment.