Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
Signed-off-by: Mihovil Ilakovac <mihovil@ilakovac.com>
  • Loading branch information
infomiho committed Nov 28, 2024
0 parents commit 29f0b35
Show file tree
Hide file tree
Showing 33 changed files with 8,140 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .env.client.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

# REACT_APP_SOME_ENV_VAR=123
2 changes: 2 additions & 0 deletions .env.server.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

# SOME_ENV_VAR=123
104 changes: 104 additions & 0 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: e2e tests

on:
push:
branches:
- main
pull_request:
branches:
- main

env:
WASP_TELEMETRY_DISABLE: 1
WASP_VERSION: 0.15.2

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout the repo
uses: actions/checkout@v4

- name: Setup Node.js
id: setup-node
uses: actions/setup-node@v4
with:
node-version: "20"

- name: Docker setup
uses: docker/setup-buildx-action@v3

- name: Install Wasp
run: |
curl -sSL https://get.wasp-lang.dev/installer.sh | sh -s -- -v ${{ env.WASP_VERSION }}
- name: Cache global node modules
uses: actions/cache@v4
with:
path: ~/.npm
key: node-modules-${{ runner.os }}-${{ hashFiles('package-lock.json') }}-${{ hashFiles('e2e-tests/package-lock.json') }}-wasp${{ env.WASP_VERSION }}-node${{ steps.setup-node.outputs.node-version }}
restore-keys: |
node-modules-${{ runner.os }}-
# 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. This step sets mock env vars in order to pass the
# validation steps so the app can run in the CI environment. For env vars that are actually
# used in tests and therefore need real values, we set them in the GitHub secrets settings and
# access them in a step below.
- name: Set required wasp app env vars to mock values
run: |
cp .env.server.example .env.server && cp .env.client.example .env.client
- name: "[e2e-tests] Install Node.js dependencies for Playwright tests"
if: steps.cache-e2e-tests.outputs.cache-hit != 'true'
run: |
cd e2e-tests
npm ci
- name: "[e2e-tests] Store Playwright's Version"
run: |
cd e2e-tests
PLAYWRIGHT_VERSION=$(npm ls @playwright/test | grep @playwright | sed 's/.*@//')
echo "Playwright's Version: $PLAYWRIGHT_VERSION"
echo "PLAYWRIGHT_VERSION=$PLAYWRIGHT_VERSION" >> $GITHUB_ENV
- name: "[e2e-tests] Cache Playwright Browsers for Playwright's Version"
id: cache-playwright-browsers
uses: actions/cache@v4
with:
path: ~/.cache/ms-playwright
key: playwright-browsers-${{ env.PLAYWRIGHT_VERSION }}-${{ runner.os }}

- name: "[e2e-tests] Set up Playwright"
if: steps.cache-playwright-browsers.outputs.cache-hit != 'true'
run: |
cd e2e-tests
npx playwright install --with-deps
- name: "[e2e-tests] Run Playwright tests"
env:
# The e2e tests are testing parts of the app that need certain env vars, so we need to access them here.
# These secretes can be set in your GitHub repo settings, e.g. https://github.com/<account>/<repo>/settings/secrets/actions

# Server-side env vars
# OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}

# Client-side env vars
# REACT_APP_GOOGLE_ANALYTICS_ID: G-H3LSJCK95H

# Test specific env vars
SKIP_EMAIL_VERIFICATION_IN_DEV: true
run: |
cd e2e-tests
npm run e2e:playwright
# UNCOMMENT this if you want to upload the test results so you can download them from the GitHub Actions UI
# - name: "[e2e-tests] Upload Playwright test results"
# - uses: actions/upload-artifact@v4
# if: ${{ !cancelled() }}
# with:
# include-hidden-files: true
# name: playwright-report
# path: ./e2e-tests/test-results
# retention-days: 30
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/.wasp/
/.env.server
/.env.client
/node_modules
.DS_Store
3 changes: 3 additions & 0 deletions .waspignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Ignore editor tmp files
**/*~
**/#*#
1 change: 1 addition & 0 deletions .wasproot
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
File marking the root of Wasp project.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# A Simple ToDo App w/ Typescript & Fullstack Type Saftey ⛑

## Running it locally

1. Make sure you have the latest version of [Wasp](https://wasp-lang.dev) installed by running `curl -sSL https://get.wasp-lang.dev/installer.sh | sh` in your terminal.
2. Run `wasp new <project-name> -t todo-ts` to create a new app using this template.
3. Run `wasp db migrate-dev`
4. Run `wasp start`. This will install all dependencies and start the client and server for you :)
5. Go to `localhost:3000` in your browser (your NodeJS server will be running on port `3001`)
6. Install the Wasp extension for VSCode to get the best DX
7. Check out the docs for more info on wasp's [features](https://wasp-lang.dev/docs/language/features) and step-by-step [guides](https://wasp-lang.dev/docs)
5 changes: 5 additions & 0 deletions e2e-tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/reports/
/test-results/
/.cache/
/node_modules/
prisma/
54 changes: 54 additions & 0 deletions e2e-tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# e2e Tests with Playwright

These are e2e tests that are written using [Playwright](https://playwright.dev/) for this Wasp app.

## Running the tests

### Locally

First, install the test dependencies:

```shell
cd e2e-tests && npm install
```

Then, in the same dir, install Playwright browser binaries:

```shell
npx playwright install
```

Start your Wasp DB and leave it running:

```shell
cd ../ && wasp db start
```

Open another terminal and start the Wasp app with the environment variable set to skip email verification in development mode:

```shell
SKIP_EMAIL_VERIFICATION_IN_DEV=true wasp start
```

NOTE: When using the email auth method a verification link is sent when the user registers, or logged to the console if you're using the default Dummy provider. You must click this link to complete registration. Setting SKIP_EMAIL_VERIFICATION_IN_DEV to "true" skips this verification step, allowing you to automatically log in. This step must be skipped when running tests, otherwise the tests will hang and fail as the verification link is never clicked!

In another terminal, run the local e2e tests:

```shell
cd e2e-tests && npm run local:e2e:start
```

This will start the tests in Playwright's UI mode, which will allow you to see and run the tests in an interactive browser environment.

To exit the local e2e tests, go back to the terminal were you started your tests and press `ctrl + c`.

## CI/CD

Update the app name in the `ci:e2e:cleanup-db` script in the `package.json` file to match the name of your app. This script is used to clean up the database after the tests have run.

> [!IMPORTANT]
> Please make sure to update the `WASP_VERSION` environment variable in the `e2e-tests.yml` file to match the version of Wasp you are using in your project.
In order for these tests to run correctly on GitHub, you need to provide the environment variables mentioned in the `e2e-tests.yml` file within your GitHub repository's "Actions" secrets so that they can be accessed by the tests.

Upon pushing to the repository's main branch, or creating a PR against the main branch, the tests will run in the CI/CD pipeline.
45 changes: 45 additions & 0 deletions e2e-tests/ci-start-app-and-db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* We use this script rather than running `wasp start` normally in the CI due to an error where prisma hangs due to some stdin issue.
* Running it this way gives us more control over that and avoids it hanging. See https://github.com/wasp-lang/wasp/pull/1218#issuecomment-1599098272.
*/

const cp = require("child_process");
const readline = require("linebyline");

function spawn(name, cmd, args, done) {
try {
const spawnOptions = {
detached: false,
};
const proc = cp.spawn(cmd, args, spawnOptions);
console.log(
"\x1b[0m\x1b[33m",
`Starting ${name} with command: ${cmd} ${args.join(" ")}`,
"\x1b[0m"
);

// We close stdin stream on the new process because otherwise the start-app
// process hangs.
// See https://github.com/wasp-lang/wasp/pull/1218#issuecomment-1599098272.
proc.stdin.destroy();

readline(proc.stdout).on("line", (data) => {
console.log(`\x1b[0m\x1b[33m[${name}][out]\x1b[0m ${data}`);
});
readline(proc.stderr).on("line", (data) => {
console.log(`\x1b[0m\x1b[33m[${name}][err]\x1b[0m ${data}`);
});
proc.on("exit", done);
} catch (error) {
console.error(error);
}
}

// Exit if either child fails
const cb = (code) => {
if (code !== 0) {
process.exit(code);
}
};
spawn("app", "npm", ["run", "ci:e2e:start-app"], cb);
spawn("db", "npm", ["run", "ci:e2e:start-db"], cb);
Loading

0 comments on commit 29f0b35

Please sign in to comment.