Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(e2e): setup coverage (server) #61

Merged
merged 3 commits into from
Apr 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
/.env.staging.sh
/.env.production.sh
/coverage
*.log
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions app/routes/kill.tsx
Original file line number Diff line number Diff line change
@@ -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 };
};
1 change: 1 addition & 0 deletions logs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.log
Empty file added logs/.keep
Empty file.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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\"",
Expand All @@ -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",
Expand Down
12 changes: 7 additions & 5 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
28 changes: 28 additions & 0 deletions scripts/test-e2e-coverage.sh
Original file line number Diff line number Diff line change
@@ -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"