Skip to content

Commit cdf72cc

Browse files
committed
updated testing framework
1 parent 2d494f9 commit cdf72cc

File tree

8 files changed

+152
-387
lines changed

8 files changed

+152
-387
lines changed

.github/workflows/test.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Test TypeScript SDK
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
13+
- name: Install Deno
14+
uses: denoland/setup-deno@v1
15+
with:
16+
deno-version: 'latest'
17+
18+
- name: Install Bun
19+
uses: oven-sh/setup-bun@v1
20+
with:
21+
bun-version: 'latest'
22+
23+
- name: Install Go
24+
uses: actions/setup-go@v5
25+
with:
26+
go-version: '1.22'
27+
28+
- name: Install Node.js
29+
uses: actions/setup-node@v4
30+
with:
31+
node-version: '20'
32+
33+
- name: Run all tests
34+
run: bash test/run-all.sh

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,7 @@ dist-ssr
2323
*.njsproj
2424
*.sln
2525
*.sw?
26-
npm
26+
npm
27+
28+
# Ignore the datastar core repo used for tests
29+
/datastar/

README.md

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ To develop or contribute to this SDK, you'll need:
177177
- [Deno](https://deno.land/) (primary development environment)
178178
- [Node.js](https://nodejs.org/) (for Node.js compatibility testing)
179179
- [Bun](https://bun.sh/) (for Bun compatibility testing)
180+
- [Go](https://golang.org/) (required for running the Go test suite)
180181

181182
### Building
182183

@@ -195,53 +196,36 @@ deno run -A build.ts VERSION
195196
196197
### Testing
197198

198-
#### Automated Testing
199+
To run all tests for Node.js, Deno, and Bun (mirroring CI):
199200

200-
Run tests for all runtimes:
201201
```bash
202-
# Node.js
203-
npm run test-node
204-
205-
# Deno
206-
deno task test-deno
207-
208-
# Bun
209-
bun run test-bun
202+
bash test/run-all.sh
210203
```
211204

212-
#### Manual Testing
213-
214-
Start a development server:
215-
```bash
216-
# Node.js
217-
npm run serve-node
218-
219-
# Deno
220-
deno task serve-deno
205+
- This script will:
206+
- Check for required tools (`deno`, `node`, `bun`, `go`, `git`)
207+
- Clone or update the core datastar repo for test files (in `/datastar/`, which is gitignored)
208+
- Build the SDK
209+
- Start test servers for each runtime
210+
- Run the Go test suite against each server
211+
- Print results and logs
221212

222-
# Bun
223-
bun run serve-bun
224-
```
225-
226-
Then run the test suite manually:
227-
```bash
228-
cd ../test
229-
./test-all.sh http://127.0.0.1:3000
230-
```
213+
> **Note:** This is the same script used by GitHub Actions for CI.
231214
232215
### Project Structure
233216

234217
```
235218
typescript/
236-
├── src/
237-
│ ├── node/ # Node.js-specific implementation
238-
│ ├── web/ # Web standards implementation (Deno/Bun)
239-
│ └── abstract/ # Abstract base classes
240-
├── examples/
241-
│ ├── node/ # Node.js example
242-
│ ├── deno/ # Deno example
243-
│ └── bun/ # Bun example
244-
└── test/ # Test suite
219+
├── src/ # SDK source code
220+
│ ├── node/ # Node.js-specific implementation
221+
│ ├── web/ # Web standards implementation (Deno/Bun)
222+
│ └── abstract/ # Abstract base classes
223+
├── examples/ # Example apps for each runtime
224+
│ ├── node/
225+
│ ├── deno/
226+
│ └── bun/
227+
├── test/ # Unified test runner and test entrypoints
228+
└── datastar/ # (gitignored) Cloned core repo for Go test files (used by test/run-all.sh)
245229
```
246230

247231
## Runtime Support

package.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,8 @@
33
"version": "1.0.0-RC.1",
44
"description": "TypeScript SDK for Datastar",
55
"scripts": {
6-
"check": "deno lint && deno check src/node/node.ts && deno check src/web/deno.ts && bun run --check src/web/bun.ts",
76
"build": "deno run -A build.ts",
8-
"serve-deno": "deno run -A test/deno.ts",
9-
"serve-bun": "bun run test/bun.ts",
10-
"serve-node": "deno run -A build.ts && node npm/esm/test/node.js",
11-
"test-node": "./test/test-node.sh",
12-
"test-deno": "./test/test-deno.sh",
13-
"test-bun": "./test/test-bun.sh"
7+
"test": "bash ./test/run-all.sh"
148
},
159
"type": "module",
1610
"repository": {

test/run-all.sh

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Always run from project root
5+
cd "$(dirname "$0")/.."
6+
7+
# Check for required tools
8+
for tool in bun node deno go git; do
9+
if ! command -v $tool >/dev/null 2>&1; then
10+
echo "[error] $tool is not installed. Please install $tool to run the tests."
11+
exit 1
12+
fi
13+
done
14+
15+
# Clone datastar core repo if not present
16+
if [ ! -d "datastar/.git" ]; then
17+
echo "[setup] Cloning datastar core repo..."
18+
git clone --depth 1 --branch develop https://github.com/starfederation/datastar.git datastar
19+
else
20+
echo "[setup] datastar core repo already present. Fetching latest..."
21+
(cd datastar && git fetch origin develop && git checkout develop && git pull)
22+
fi
23+
24+
# Build the SDK (for Node)
25+
echo "[build] Building SDK for Node..."
26+
deno run -A build.ts
27+
28+
# Start servers and run tests
29+
30+
declare -A servers
31+
servers[node]="node npm/esm/test/node.js"
32+
servers[bun]="bun run test/bun.ts"
33+
servers[deno]="deno run --allow-net test/deno.ts"
34+
declare -A ports
35+
ports[node]=3000
36+
ports[bun]=8001
37+
ports[deno]=8000
38+
39+
declare -A pids
40+
41+
echo "[test] Starting servers..."
42+
for runtime in node bun deno; do
43+
echo "[test] Starting $runtime server on port ${ports[$runtime]}..."
44+
nohup ${servers[$runtime]} > $runtime-server.log 2>&1 &
45+
pids[$runtime]=$!
46+
sleep 5
47+
done
48+
49+
# Function to cleanup servers on exit
50+
cleanup() {
51+
echo "[cleanup] Stopping servers..."
52+
for runtime in node bun deno; do
53+
if kill -0 ${pids[$runtime]} 2>/dev/null; then
54+
kill ${pids[$runtime]} || true
55+
fi
56+
done
57+
}
58+
trap cleanup EXIT
59+
60+
# Run Go SDK tests for each server
61+
declare -A results
62+
for runtime in node bun deno; do
63+
port=${ports[$runtime]}
64+
echo "[test] Running Go SDK tests for $runtime (http://127.0.0.1:$port)..."
65+
(cd datastar/sdk/tests && go run ./cmd/datastar-sdk-tests -server http://127.0.0.1:$port)
66+
results[$runtime]=$?
67+
done
68+
69+
# Print server logs and results
70+
echo "\n[test] Server logs:"
71+
for runtime in node bun deno; do
72+
echo "--- $runtime server log (last 20 lines) ---"
73+
tail -n 20 $runtime-server.log || echo "No log file found."
74+
done
75+
76+
echo "\n[test] Results:"
77+
for runtime in node bun deno; do
78+
if [ "${results[$runtime]}" -eq 0 ]; then
79+
echo "$runtime: PASS"
80+
else
81+
echo "$runtime: FAIL"
82+
fi
83+
done
84+
85+
# Exit with failure if any test failed
86+
for runtime in node bun deno; do
87+
if [ "${results[$runtime]}" -ne 0 ]; then
88+
exit 1
89+
fi
90+
done
91+
92+
echo "[test] All tests passed!"

test/test-bun.sh

Lines changed: 0 additions & 113 deletions
This file was deleted.

0 commit comments

Comments
 (0)