diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2e91e57e7c..c0b2bb1d55 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -76,7 +76,7 @@ jobs: - run: pnpm run install-with-patch -- --frozen-lockfile - run: npx playwright install --with-deps - run: make docker/up db/reset/test - - run: npm run test-e2e + - run: npm run test-e2e:coverage test-migrations: runs-on: ubuntu-20.04 diff --git a/.gitignore b/.gitignore index c066f15c48..ac2a2f54c3 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,3 @@ /.env.staging.sh /.env.production.sh /coverage -*.log diff --git a/README.md b/README.md index 31495a0fd6..97849d2866 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ npm run test:coverage # view result e.g. via `xdg-open coverage/index.html` # testing (playwright) npx playwright install npm run test-e2e +npm run test-e2e:coverage # migration on production npm run knex:production -- migrate:status diff --git a/app/routes/kill.tsx b/app/routes/kill.tsx new file mode 100644 index 0000000000..3cd11f279b --- /dev/null +++ b/app/routes/kill.tsx @@ -0,0 +1,10 @@ +import { LoaderFunction } from "@remix-run/server-runtime"; + +export const loader: LoaderFunction = async () => { + if (process.env.NODE_ENV === "production") { + return { success: false }; + } + console.log("🔥🔥🔥 process.exit(0) 🔥🔥🔥"); + setTimeout(() => process.exit(0)); + return { success: true }; +}; diff --git a/logs/.gitignore b/logs/.gitignore new file mode 100644 index 0000000000..397b4a7624 --- /dev/null +++ b/logs/.gitignore @@ -0,0 +1 @@ +*.log diff --git a/logs/.keep b/logs/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/package.json b/package.json index 5c1618e318..5981f8eee0 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "dev:all": "npm run dev:prepare && concurrently -k 'npm:dev' 'npm:tsc:dev' 'npm:tailwind:dev' 'npm:vite' -c 'bgBlue.bold,bgYellow.bold,bgMagenta.bold,bgGreen.bold'", "copy-assets": "bash scripts/copy-assets.sh", "remix:dev": "remix dev", + "remix:dev:coverage": "c8 -r text -r html --all --src app --exclude build --exclude packages --exclude-after-remap node_modules/.bin/remix dev", "tsc": "tsc", "tsc:dev": "tsc --noEmit --watch --preserveWatchOutput", "tailwind": "tailwindcss -o \"./build/tailwind/${NODE_ENV:-development}/index.css\"", @@ -29,6 +30,7 @@ "test-e2e": "NODE_ENV=test playwright test", "test-e2e:debug": "NODE_ENV=test PWDEBUG=1 playwright test", "test-e2e:headed": "NODE_ENV=test E2E_HEADED=1 playwright test", + "test-e2e:coverage": "bash scripts/test-e2e-coverage.sh", "netlify:build": "bash scripts/netlify.sh", "netlify:build:deploy": "npm run netlify:build && netlify deploy --prod", "cli": "node --require esbuild-register app/misc/cli.ts", diff --git a/playwright.config.ts b/playwright.config.ts index 453f7b1b61..01142c9e99 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -18,11 +18,13 @@ const config: PlaywrightTestConfig = { }, }, ], - webServer: { - command: "npm run dev:prepare && PORT=3001 npm run remix:dev", - port: 3001, - reuseExistingServer: true, - }, + webServer: process.env.E2E_NO_SERVER + ? undefined + : { + command: "npm run dev:prepare && PORT=3001 npm run remix:dev", + port: 3001, + reuseExistingServer: true, + }, }; export default config; diff --git a/scripts/test-e2e-coverage.sh b/scripts/test-e2e-coverage.sh new file mode 100644 index 0000000000..9b3b49d64c --- /dev/null +++ b/scripts/test-e2e-coverage.sh @@ -0,0 +1,28 @@ +#!/bin/bash +set -eux -o pipefail + +export NODE_ENV=test +export PORT=3001 +export E2E_NO_SERVER=1 + +log_file=logs/remix-coverage.log + +# run remix server with c8 +npm run dev:prepare +npm run remix:dev:coverage >> "$log_file" 2>&1 & +coverage_pid="$!" + +# wait server +docker run --rm --network=host jwilder/dockerize:0.6.1 -wait tcp://localhost:3001 + +# run e2e test +playwright test "${@}" + +# kill remix server +curl "http://localhost:$PORT/kill" + +# wait for c8 to create coverage +wait "$coverage_pid" + +# print logs +cat "$log_file"