Skip to content

Commit 2d94e28

Browse files
vincangerZeko369infomihoMartinsos
authored
Playwright tests & CI (wasp-lang#69)
* get tests started * Create opensaas-ci.yml * move github workflows * modify ci scripts * install linebyline * Update package.json * install wait-port * Update package.json * add conditional webserver when in CI env * test tagging action * Update retag-commit.yml * remove unused workflow * add .env file and test stripe webhook * Update e2e-tests.yml * Update e2e-tests.yml * Update e2e-tests.yml * Update e2e-tests.yml * test demo app * Update e2e-tests.yml * update github action versions * disable wasp telemetry * Cleanup running (wasp-lang#72) * improve tests * Update ci-start-app.js * remove npm scripts * Update e2e-tests.yml * Update ci-start-app-with-scripts.js * Update ci-start-app-with-scripts.js * rename test folder * Update e2e-tests.yml * Update e2e-tests.yml * export prisma client from server * Update e2e-tests.yml * Update e2e-tests.yml * Update e2e-tests.yml * Update e2e-tests.yml * Update package-lock.json * install linebyline * add npm scripts * Update package.json * Update paidUserTests.spec.ts * update flaky test * update tsconfig * Update e2e-tests.yml * Update e2e-tests.yml * pin node version to github action * Update e2e-tests.yml * fix retag and clean up * add notes on tag action * Update retag-commit.yml * pr changes part 1 * pr changes part 2 * Setup tests with local Prisma (wasp-lang#86) Signed-off-by: Mihovil Ilakovac <[email protected]> * pr changes part 3 * add db naming script * Update package.json * Update package.json * Update package.json * spawn prisma process * Update package.json * move db setup * Update package.json * Update package.json * Update package.json * Update setupDatabaseName.sh * Update package.json * use same process for local and CI testing * Update package.json * wait for app for prisma setup * Update package.json * changes made with martin * stripe clie * Update e2e-tests.yml * Update e2e-tests.yml * update start stripe cli * try again * start testing stripe payments * stripe payment works * fix base url issue & cleanup * Update playwright.config.ts * Update package.json * Update package-lock.json * Update main.wasp * Update utils.ts * Update e2e-tests.yml * Update utils.ts * Update utils.ts * Update e2e-tests.yml * Update actions.ts * Update actions.ts * Update actions.ts * Update actions.ts * Update stripeUtils.ts * Update e2e-tests.yml * catch stripe checkout error * remove console.logs * fix comments, add err catches * fix cache and cache keys * Update .github/workflows/e2e-tests.yml Co-authored-by: Martin Šošić <[email protected]> * Update .github/workflows/e2e-tests.yml Co-authored-by: Martin Šošić <[email protected]> * Update .github/workflows/e2e-tests.yml Co-authored-by: Martin Šošić <[email protected]> * Update .github/workflows/e2e-tests.yml Co-authored-by: Martin Šošić <[email protected]> * Update e2e-tests/playwright.config.ts Co-authored-by: Martin Šošić <[email protected]> * Improve CI caching and other stuff * fix cache key, npm scripts, error handling * Update e2e-tests.yml * Update README.md * add template versioning info --------- Signed-off-by: Mihovil Ilakovac <[email protected]> Co-authored-by: Fran Zekan <[email protected]> Co-authored-by: Mihovil Ilakovac <[email protected]> Co-authored-by: Martin Šošić <[email protected]>
1 parent 8fa8f24 commit 2d94e28

20 files changed

+5099
-4892
lines changed

.github/workflows/e2e-tests.yml

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
name: e2e tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
env:
12+
WASP_TELEMETRY_DISABLE: 1
13+
WASP_VERSION: 0.13.2
14+
15+
jobs:
16+
test:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout the repo
21+
uses: actions/checkout@v4
22+
23+
- name: Setup Node.js
24+
id: setup-node
25+
uses: actions/setup-node@v4
26+
with:
27+
node-version: '20'
28+
29+
- name: Install Wasp
30+
run: curl -sSL https://get.wasp-lang.dev/installer.sh | sh -s -- -v ${{ env.WASP_VERSION }}
31+
32+
- name: Docker setup
33+
uses: docker/setup-buildx-action@v3
34+
35+
# In order for the app to run in the dev mode we need to set the required env vars even if they aren't actually used by the app.
36+
# This step sets mock env vars in order to pass the validation steps so the app can run
37+
# in the CI environment. For env vars that are actually used in tests and therefore need real values, we set them in
38+
# the GitHub secrets settings and access them in a step below.
39+
- name: Set required wasp app env vars to mock values
40+
run: |
41+
cd app
42+
cp .env.server.example .env.server
43+
44+
- name: Cache global node modules
45+
uses: actions/cache@v4
46+
with:
47+
path: ~/.npm
48+
key: node-modules-${{ runner.os }}-${{ hashFiles('app/package-lock.json') }}-${{ hashFiles('e2e-tests/package-lock.json') }}-wasp${{ env.WASP_VERSION }}-node${{ steps.setup-node.outputs.node-version }}
49+
restore-keys: |
50+
node-modules-${{ runner.os }}-
51+
52+
- name: Install Node.js dependencies for Playwright tests
53+
if: steps.cache-e2e-tests.outputs.cache-hit != 'true'
54+
run: |
55+
cd e2e-tests
56+
npm ci
57+
58+
- name: Store Playwright's Version
59+
run: |
60+
cd e2e-tests
61+
PLAYWRIGHT_VERSION=$(npm ls @playwright/test | grep @playwright | sed 's/.*@//')
62+
echo "Playwright's Version: $PLAYWRIGHT_VERSION"
63+
echo "PLAYWRIGHT_VERSION=$PLAYWRIGHT_VERSION" >> $GITHUB_ENV
64+
65+
- name: Cache Playwright Browsers for Playwright's Version
66+
id: cache-playwright-browsers
67+
uses: actions/cache@v4
68+
with:
69+
path: ~/.cache/ms-playwright
70+
key: playwright-browsers-${{ env.PLAYWRIGHT_VERSION }}-${{ runner.os }}
71+
72+
- name: Set up Playwright
73+
if: steps.cache-playwright-browsers.outputs.cache-hit != 'true'
74+
run: |
75+
cd e2e-tests
76+
npx playwright install --with-deps
77+
78+
- name: Install Stripe CLI
79+
run: |
80+
curl -s https://packages.stripe.dev/api/security/keypair/stripe-cli-gpg/public | gpg --dearmor | sudo tee /usr/share/keyrings/stripe.gpg
81+
echo "deb [signed-by=/usr/share/keyrings/stripe.gpg] https://packages.stripe.dev/stripe-cli-debian-local stable main" | sudo tee -a /etc/apt/sources.list.d/stripe.list
82+
sudo apt update
83+
sudo apt install stripe
84+
85+
# For Stripe webhooks to work in development, we need to run the Stripe CLI to listen for webhook events.
86+
# The Stripe CLI will receive the webhook events from Stripe test payments and
87+
# forward them to our local server so that we can test the payment flow in our e2e tests.
88+
- name: Run Stripe CLI to listen for webhooks
89+
env:
90+
STRIPE_DEVICE_NAME: ${{ secrets.STRIPE_DEVICE_NAME }}
91+
run: |
92+
stripe listen --api-key ${{ secrets.STRIPE_KEY }} --forward-to localhost:3001/stripe-webhook &
93+
94+
- name: Run Playwright tests
95+
env:
96+
# The e2e tests are testing parts of the app that need certain env vars, so we need to access them here.
97+
# These secretes can be set in your GitHub repo settings, e.g. https://github.com/<account>/<repo>/settings/secrets/actions
98+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
99+
STRIPE_KEY: ${{ secrets.STRIPE_KEY }}
100+
STRIPE_WEBHOOK_SECRET: ${{ secrets.STRIPE_WEBHOOK_SECRET }}
101+
HOBBY_SUBSCRIPTION_PRICE_ID: ${{ secrets.HOBBY_SUBSCRIPTION_PRICE_ID }}
102+
PRO_SUBSCRIPTION_PRICE_ID: ${{ secrets.PRO_SUBSCRIPTION_PRICE_ID }}
103+
CREDITS_PRICE_ID: ${{ secrets.CREDITS_PRICE_ID }}
104+
SKIP_EMAIL_VERIFICATION_IN_DEV: true
105+
run: |
106+
cd e2e-tests
107+
npm run e2e:playwright

.github/workflows/retag-commit.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Retag Commit
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
retag:
10+
runs-on: ubuntu-latest
11+
env:
12+
TAG_NAME: wasp-v0.13-template
13+
steps:
14+
- name: Checkout Code
15+
uses: actions/checkout@v4
16+
17+
- name: Configure Git
18+
run: |
19+
git config user.email "github-actions[bot]@users.noreply.github.com"
20+
git config user.name "github-actions[bot]"
21+
22+
- name: Delete Old Tag
23+
run: |
24+
git tag -d ${{ env.TAG_NAME }} || true
25+
git push origin :refs/tags/${{ env.TAG_NAME }} || true
26+
27+
- name: Add New Tag
28+
run: |
29+
git tag ${{ env.TAG_NAME }}
30+
git push origin ${{ env.TAG_NAME }}

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
*/.wasp/
22
*/.env.server
33
*/.env.client
4-
*/.DS_Store
54
*/node_modules
65
*/migrations
6+
*/.DS_Store
77
.DS_Store

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ Contributing is simple:
3838
3. Create a new feature branch for your work. See [above](#the-default-template-vs-the-deployed-site--docs) for which branch to base your feature branch off of.
3939
4. Create a pull request.
4040
5. Make a "Da Boi" meme while you wait for us to review your PR.
41-
6. If you don't know who "Da Boi" is, head back to the [Wasp Discord](https://discord.gg/aCamt5wCpS) and find out :)
41+
6. If you don't know who "Da Boi" is, head back to the [Wasp Discord](https://discord.gg/aCamt5wCpS) and find out :)

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ The template itself is built on top of some very powerful tools and frameworks,
2828
- 📧 [SendGrid](https://sendgrid.com), [MailGun](https://mailgun.com), or SMTP - for email sending
2929
- 💅 [TailwindCSS](https://tailwindcss.com) - for styling
3030
- 🧑‍💼 [TailAdmin](https://tailadmin.com/) - admin dashboard & components for TailwindCSS
31+
- 🧪 [Playwright](https://playwright.dev) - end-to-end tests with Playwright
3132

3233
Because we're using Wasp as the full-stack framework, we can leverage a lot of its features to build our SaaS in record time, including:
3334

@@ -62,7 +63,17 @@ For everything you need to know about getting started and using this template, c
6263

6364
We've documented everything in great detail, including installation instructions, pulling updates to the template, guides for integrating services, SEO, deployment, and more. 🚀
6465

66+
6567
## Changes & Contributions
68+
69+
### Template Versioning
70+
71+
Whenever a user starts a new Open SaaS project with `wasp new -t saas`, Wasp looks for a specific tag on the repo, and pulls the project at the commit associated with that tag. In the case of Open SaaS, the tag is `wasp-v{{version}}-template`, where `{{version}}` is the current version of Wasp, e.g. `wasp-v0.13-template`.
72+
73+
For simplicity, we automatically re-apply the tag to the most recent commit on the `main` branch via the `.github/workflows/retag-commit.yml` workflow. This way, users always get the latest version of the template when they start a new project via `wasp new -t saas`.d
74+
75+
### Contributing
76+
6677
Note that we've tried to get as many of the core features of a SaaS app into this template as possible, but there still might be some missing features or functionality.
6778

6879
We could always use some help tying up loose ends, so consider [contributing](https://github.com/wasp-lang/open-saas/blob/main/CONTRIBUTING.md)!

app/.env.server.example

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ GOOGLE_CLIENT_SECRET=GOC...
2121

2222
# get your sendgrid api key at https://app.sendgrid.com/settings/api_keys
2323
SENDGRID_API_KEY=test...
24-
# if not explicitly set to true, emails will be logged to console but not actually sent during development
25-
SEND_EMAILS_IN_DEVELOPMENT=false
24+
# Skips the email verification flow in development every time you sign up a new user.
25+
SKIP_EMAIL_VERIFICATION_IN_DEV=true
2626

2727
# (OPTIONAL) get your openai api key at https://platform.openai.com/account
2828
OPENAI_API_KEY=sk-k...

app/main.wasp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
app OpenSaaS {
22
wasp: {
3-
version: "^0.13.0"
3+
version: "^0.13.2"
44
},
55
title: "My Open SaaS App",
66
head: [

0 commit comments

Comments
 (0)