Skip to content

Commit 932feea

Browse files
authored
Add e2e tests to starter templates (#2868)
1 parent 3e27de1 commit 932feea

File tree

17 files changed

+947
-2
lines changed

17 files changed

+947
-2
lines changed

waspc/packages/wasp-config/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"moduleDetection": "force",
1010
"isolatedModules": true,
1111

12-
// linting
1312
"strict": true,
1413
"noUncheckedIndexedAccess": true,
1514
"noImplicitOverride": true,
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dist
2+
test-results
3+
playwright-report

waspc/starters-e2e-tests/README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Wasp starters E2E tests
2+
3+
This project provides automated headless end-to-end testing for Wasp starter templates using Playwright.
4+
5+
## Overview
6+
7+
The test suite automatically (for each starter):
8+
9+
1. Sets up the test environment in a temporary directory
10+
2. Creates a new Wasp projects from the starter template
11+
3. Configures the Wasp project for headless E2E testing
12+
4. Runs the Wasp project in both development and build
13+
5. Validates the project functionality using Playwright
14+
15+
## Installation
16+
17+
```bash
18+
npm install
19+
```
20+
21+
## Usage
22+
23+
### Run tests with production Wasp CLI
24+
25+
```bash
26+
npm run test
27+
```
28+
29+
This uses the `wasp` command.
30+
31+
### Run tests with development Wasp CLI
32+
33+
```bash
34+
npm run test:dev
35+
```
36+
37+
This uses the `wasp-cli` command (typically used for development builds).
38+
39+
### Run tests with custom Wasp CLI command
40+
41+
```bash
42+
npm run build
43+
npm run start -- --wasp-cli-command custom-command-here
44+
```
45+
46+
## Project tests structure
47+
48+
```
49+
├── tests/
50+
│ ├── health-check.spec.ts # Basic health check tests run for every starter
51+
│ └── starter/ # Starter-specific test files
52+
```
53+
54+
## License
55+
56+
MIT

waspc/starters-e2e-tests/package-lock.json

Lines changed: 195 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "starters-e2e-tests",
3+
"version": "1.0.0",
4+
"type": "module",
5+
"license": "MIT",
6+
"scripts": {
7+
"build": "tsc",
8+
"start": "node ./dist/src/main.js",
9+
"test": "npm run build && DEBUG=pw:webserver npm run start -- --wasp-cli-command wasp",
10+
"test:dev": "npm run build && DEBUG=pw:webserver npm run start -- --wasp-cli-command wasp-cli"
11+
},
12+
"dependencies": {
13+
"@commander-js/extra-typings": "^14.0.0",
14+
"@playwright/test": "1.51.1",
15+
"@wasp.sh/wasp-app-runner": "^0.0.7",
16+
"commander": "^14.0.0",
17+
"zx": "^8.8.0"
18+
},
19+
"devDependencies": {
20+
"@types/node": "^24.0.1"
21+
}
22+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { defineConfig, devices } from "@playwright/test";
2+
3+
/**
4+
* See https://playwright.dev/docs/test-configuration.
5+
*/
6+
export default defineConfig({
7+
testDir: "./tests",
8+
/* Run tests in files in parallel */
9+
fullyParallel: true,
10+
/* Fail the build on CI if you accidentally left test.only in the source code. */
11+
forbidOnly: !!process.env.CI,
12+
/* Retry on CI only */
13+
retries: process.env.CI ? 2 : 0,
14+
/* Opt out of parallel tests on CI. */
15+
workers: process.env.CI ? 1 : undefined,
16+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
17+
reporter: "list",
18+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
19+
use: {
20+
/* Base URL to use in actions like `await page.goto('/')`. */
21+
baseURL: "http://localhost:3000",
22+
23+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
24+
trace: "on-first-retry",
25+
26+
/* If you want to debug what's happening in the browser during the tests, set this to false. */
27+
headless: true,
28+
},
29+
30+
/* Configure projects for major browsers */
31+
projects: [
32+
{
33+
name: "chromium",
34+
use: { ...devices["Desktop Chrome"] },
35+
},
36+
// {
37+
// name: "firefox",
38+
// use: { ...devices["Desktop Firefox"] },
39+
// },
40+
// {
41+
// name: "webkit",
42+
// use: { ...devices["Desktop Safari"] },
43+
// },
44+
],
45+
46+
/* Run your local dev server before starting the tests */
47+
webServer: {
48+
command: `run-wasp-app ${process.env.WASP_RUN_MODE} --path-to-app=${process.env.WASP_APP_PATH} --wasp-cli-cmd=${process.env.WASP_CLI_CMD}`,
49+
// Wait for the backend to start
50+
url: "http://localhost:3001",
51+
reuseExistingServer: false,
52+
timeout: 240 * 1000,
53+
gracefulShutdown: { signal: "SIGTERM", timeout: 2000 },
54+
},
55+
});
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { program } from "@commander-js/extra-typings";
2+
import packageJson from "../package.json" with { type: "json" };
3+
4+
export type WaspCliCommand = string;
5+
6+
interface StartersE2ETestsArgs {
7+
waspCliCommand: WaspCliCommand;
8+
}
9+
10+
export function parseArgs(args: string[]): StartersE2ETestsArgs {
11+
const command = program
12+
.name("starters-e2e-tests")
13+
.description(
14+
"Run end-to-end tests for Wasp starter templates (except `ai`)",
15+
)
16+
.version(packageJson.version)
17+
.requiredOption(
18+
"--wasp-cli-command <command>",
19+
"Path or command name for the Wasp CLI executable to test against",
20+
)
21+
.parse(args);
22+
23+
return command.opts();
24+
}

0 commit comments

Comments
 (0)