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";

packages/headless-tests/.eslintrc.cjs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module.exports = {
2+
root: true,
3+
env: {
4+
browser: true,
5+
node: true,
6+
es2021: true
7+
},
8+
extends: ["eslint:recommended"],
9+
parserOptions: {
10+
ecmaVersion: 2022,
11+
sourceType: "module"
12+
},
13+
rules: {
14+
// Disable rules that might cause issues with this package
15+
"no-undef": "off"
16+
}
17+
};

packages/headless-tests/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Waku Headless Tests
2+
3+
This package contains a minimal browser application used for testing the Waku SDK in a browser environment. It is used by the browser-tests package to run end-to-end tests on the SDK.
4+
5+
## Usage
6+
7+
### Build the app
8+
9+
```bash
10+
npm run build
11+
```
12+
13+
### Start the app
14+
15+
```bash
16+
npm start
17+
```
18+
19+
This will start a server on port 8080 by default.
20+
21+
## Integration with browser-tests
22+
23+
This package is designed to be used with the browser-tests package to run end-to-end tests on the SDK. It exposes the Waku API via a global object in the browser.
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { API } from "@src/api/shared";
1+
/* eslint-disable */
2+
import { API } from "../browser-tests/src/api/shared.ts";
23

34
runApp().catch((err) => {
45
console.error(err);
@@ -7,9 +8,7 @@ runApp().catch((err) => {
78
async function runApp() {
89
if (typeof window !== "undefined") {
910
// Expose shared API functions for browser communication
10-
// eslint-disable-next-line no-undef
1111
window.wakuAPI = API;
12-
// eslint-disable-next-line no-undef
1312
window.subscriptions = [];
1413
}
1514
}

packages/browser-tests/headless/package.json renamed to packages/headless-tests/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
2-
"name": "headless",
2+
"name": "@waku/headless-tests",
33
"version": "0.1.0",
44
"private": true,
55
"homepage": "/headless",
6+
"type": "module",
67
"devDependencies": {
78
"@babel/core": "^7.24.0",
89
"@babel/preset-env": "^7.24.0",
@@ -20,6 +21,7 @@
2021
"scripts": {
2122
"start": "serve .",
2223
"build": "webpack",
23-
"deploy": "gh-pages -d ."
24+
"deploy": "gh-pages -d .",
25+
"format": "eslint --fix webpack.config.js"
2426
}
2527
}

packages/headless-tests/tsconfig.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2020",
4+
"module": "commonjs",
5+
"allowJs": true,
6+
"checkJs": false,
7+
"esModuleInterop": true,
8+
"skipLibCheck": true,
9+
"forceConsistentCasingInFileNames": true
10+
},
11+
"include": [
12+
"**/*.js"
13+
]
14+
}

packages/browser-tests/headless/webpack.config.js renamed to packages/headless-tests/webpack.config.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
/* eslint-disable @typescript-eslint/no-var-requires */
2-
const path = require("path");
1+
/* eslint-disable */
2+
/**
3+
* This webpack configuration file uses ES Module syntax.
4+
*/
5+
import path from 'path';
6+
import { fileURLToPath } from 'url';
7+
import NodePolyfillPlugin from 'node-polyfill-webpack-plugin';
38

4-
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin");
9+
const __filename = fileURLToPath(import.meta.url);
10+
const __dirname = path.dirname(__filename);
511

6-
module.exports = {
12+
export default {
713
entry: "./index.js",
814
output: {
915
filename: "bundle.js",

0 commit comments

Comments
 (0)