Skip to content

Commit 365833c

Browse files
committed
fix: restructure headless browser app to its own folder
1 parent cffbef3 commit 365833c

22 files changed

+823
-83
lines changed

.eslintrc.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@
55
"project": ["./tsconfig.json"]
66
},
77
"env": { "es6": true },
8-
"ignorePatterns": ["node_modules", "build", "coverage", "proto"],
8+
"ignorePatterns": [
9+
"node_modules",
10+
"build",
11+
"coverage",
12+
"proto",
13+
"**/webpack.config.js",
14+
"packages/headless-tests/**/*.js",
15+
"packages/headless-tests/**/*.ts"
16+
],
917
"plugins": ["import", "eslint-comments", "functional"],
1018
"extends": [
1119
"eslint:recommended",

.github/workflows/ci.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ jobs:
2929
with:
3030
node-version: ${{ env.NODE_JS }}
3131
- uses: ./.github/actions/npm
32-
- name: Install headless dependencies
33-
run: cd packages/browser-tests/headless && npm install
32+
- name: Install headless-tests dependencies
33+
run: cd packages/headless-tests && npm install
3434
- run: npm run build
3535
- run: npm run check
3636
- run: npm run doc
@@ -45,8 +45,8 @@ jobs:
4545
with:
4646
node-version: ${{ env.NODE_JS }}
4747
- uses: ./.github/actions/npm
48-
- name: Install headless dependencies
49-
run: cd packages/browser-tests/headless && npm install
48+
- name: Install headless-tests dependencies
49+
run: cd packages/headless-tests && npm install
5050
- name: Generate protobuf code
5151
run: |
5252
npm run proto
@@ -72,8 +72,8 @@ jobs:
7272
with:
7373
node-version: ${{ env.NODE_JS }}
7474
- uses: ./.github/actions/npm
75-
- name: Install headless dependencies
76-
run: cd packages/browser-tests/headless && npm install
75+
- name: Install headless-tests dependencies
76+
run: cd packages/headless-tests && npm install
7777
- run: npm run build:esm
7878
- run: npm run test:browser
7979

.github/workflows/playwright.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ jobs:
2929

3030
- uses: ./.github/actions/npm
3131

32-
- name: Install headless dependencies
33-
run: cd packages/browser-tests/headless && npm install
32+
- name: Install headless-tests dependencies
33+
run: cd packages/headless-tests && npm install
3434

3535
- name: Build browser test environment
3636
run: npm run build --workspace=@waku/browser-tests

package-lock.json

Lines changed: 715 additions & 50 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"packages/rln",
1818
"packages/tests",
1919
"packages/browser-tests",
20+
"packages/headless-tests",
2021
"packages/build-utils",
2122
"packages/react-native-polyfills"
2223
],

packages/browser-tests/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This project provides a system for testing the Waku SDK in a browser environment
66

77
The system consists of:
88

9-
1. **Headless Web App**: A simple web application that loads the Waku SDK and exposes shared API functions.
9+
1. **Headless Web App**: A simple web application (in the `@waku/headless-tests` package) that loads the Waku SDK and exposes shared API functions.
1010
2. **Express Server**: A server that communicates with the headless app using Playwright.
1111
3. **Shared API**: TypeScript functions shared between the server and web app.
1212

@@ -19,9 +19,9 @@ The system consists of:
1919
npm install
2020

2121
# Install headless app dependencies
22-
cd headless
22+
cd ../headless-tests
2323
npm install
24-
cd ..
24+
cd ../browser-tests
2525
```
2626

2727
2. Build the application:

packages/browser-tests/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
"type": "module",
66
"scripts": {
77
"start": "npm run start:server",
8-
"start:serve": "npx serve -p 8080 --no-port-switching ./headless -s",
8+
"start:serve": "cd ../headless-tests && npx serve -p 8080 --no-port-switching . -s",
99
"test": "npx playwright test",
10-
"build:headless": "cd headless && npm run build",
10+
"build:headless": "cd ../headless-tests && npm run build",
1111
"build:server": "tsc -p tsconfig.json",
1212
"build": "run-s build:*",
1313
"start:server": "node ./dist/server.js"
@@ -16,6 +16,7 @@
1616
"@types/cors": "^2.8.15",
1717
"@types/express": "^4.17.21",
1818
"@types/node": "^20.10.0",
19+
"@waku/headless-tests": "*",
1920
"axios": "^1.8.4",
2021
"dotenv-flow": "^0.4.0",
2122
"npm-run-all": "^4.1.5",

packages/browser-tests/playwright.config.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1+
// For dynamic import of dotenv-flow
2+
import { defineConfig, devices } from "@playwright/test";
3+
14
// Only load dotenv-flow in non-CI environments
25
if (!process.env.CI) {
3-
require("dotenv-flow/config");
6+
// Need to use .js extension for ES modules
7+
// eslint-disable-next-line import/extensions
8+
await import("dotenv-flow/config.js");
49
}
510

6-
import { defineConfig, devices } from "@playwright/test";
7-
8-
const EXAMPLE_PORT = process.env.EXAMPLE_PORT;
11+
const EXAMPLE_PORT = process.env.EXAMPLE_PORT || "8080";
912
// web-chat specific thingy
10-
const EXAMPLE_TEMPLATE = process.env.EXAMPLE_TEMPLATE;
13+
const EXAMPLE_TEMPLATE = process.env.EXAMPLE_TEMPLATE || "";
1114
const BASE_URL = `http://127.0.0.1:${EXAMPLE_PORT}/${EXAMPLE_TEMPLATE}`;
1215

1316
/**
@@ -77,7 +80,7 @@ export default defineConfig({
7780
url: BASE_URL,
7881
stdout: "pipe",
7982
stderr: "pipe",
80-
command: "npm start",
83+
command: "npm run start:serve",
8184
reuseExistingServer: !process.env.CI,
8285
timeout: 5 * 60 * 1000 // five minutes for bootstrapping an example
8386
}

packages/browser-tests/src/server.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ const messageQueue: MessageQueue = {};
6363

6464
// Start the headless app server on port 8080
6565
async function startHeadlessServer(): Promise<void> {
66-
return new Promise<void>((resolve, reject) => {
66+
return new Promise((resolve, reject) => {
6767
try {
6868
console.log("Starting headless app server...");
6969
headlessServerProcess = exec(
70-
`serve ${join(__dirname, "../headless")} -p 8080 -s`,
70+
`serve ${join(__dirname, "../../headless-tests")} -p 8080 -s`,
7171
(error, stdout, stderr) => {
7272
if (error) {
7373
console.error(`Error starting serve: ${error}`);
@@ -82,8 +82,7 @@ async function startHeadlessServer(): Promise<void> {
8282
setTimeout(resolve, 2000);
8383
} catch (error) {
8484
console.error("Failed to start headless server:", error);
85-
// Resolve anyway, we'll handle the missing server gracefully
86-
resolve();
85+
reject(error);
8786
}
8887
});
8988
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
declare module "dotenv-flow/config";
2+
declare module "dotenv-flow/config.js";

0 commit comments

Comments
 (0)