Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
artifacts.dat
docs.json
tests/app

integration-tests/websocket/app
4 changes: 3 additions & 1 deletion gren.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
"HttpServer",
"HttpServer.Response",
"WebSocketServer",
"WebSocketServer.Connection"
"WebSocketServer.Connection",
"WebSocketClient",
"WebSocketClient.Connection"
],
"gren-version": "0.6.0 <= v < 0.7.0",
"dependencies": {
Expand Down
5 changes: 5 additions & 0 deletions integration-tests/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,8 @@ echo -e "Running websocket tests...\n\n"
pushd websocket
make test || exit 1
popd

echo -e "Running websocket-client tests...\n\n"
pushd websocket-client
make test || exit 1
popd
3 changes: 2 additions & 1 deletion integration-tests/websocket/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.gren/
app
server-app
client-tests-app
node_modules/
/test-results/
/playwright-report/
Expand Down
14 changes: 9 additions & 5 deletions integration-tests/websocket/Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
app: Makefile gren.json src/Main.gren
gren make --optimize Main --output=app
server-app: Makefile gren.json src/Server.gren
gren make --optimize Server --output=server-app

client-tests-app: Makefile gren.json src/ClientTests.gren
gren make --optimize ClientTests --output=client-tests-app

.PHONY: test
test: app node_modules
npm test
test: server-app client-tests-app node_modules
node run.mjs
npx mocha --require test/fixtures.mjs

node_modules: package.json package-lock.json
npm ci
Expand All @@ -12,4 +16,4 @@ node_modules: package.json package-lock.json
clean:
rm -rf .gren
rm -rf node_modules
rm -f app
rm -f server-app client-tests-app
Binary file not shown.
Binary file not shown.
45 changes: 45 additions & 0 deletions integration-tests/websocket/run.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import * as path from "node:path";
import * as childProc from "node:child_process";

// Start the Gren WebSocket server, run the Gren client tests, then shut down.
// The mocha server tests are run separately by the Makefile (they start their
// own server instance via fixtures.mjs).

function fork(name) {
return childProc.fork(path.resolve(import.meta.dirname, name), [], {
silent: true,
});
}

function waitForServerStart(proc, timeoutMs = 5000) {
return new Promise((resolve, reject) => {
const timeout = setTimeout(() => {
reject(new Error("Server did not start within 5000ms"));
}, timeoutMs);

proc.stdout.on("data", (data) => {
if (data.toString().includes("WebSocket server started")) {
clearTimeout(timeout);
proc.stdout.resume();
proc.stderr.resume();
resolve();
}
});

proc.stderr.resume();
});
}

const server = fork("server-app");
await waitForServerStart(server);

const exitCode = await new Promise((resolve) => {
const client = fork("client-tests-app");
client.stdout.on("data", (data) => process.stdout.write(data));
client.stderr.on("data", (data) => process.stderr.write(data));
client.on("exit", resolve);
});

server.kill();

process.exit(exitCode);
Loading
Loading