Skip to content

Commit ef5da25

Browse files
committed
feat(test): next start, cf preview
1 parent 3090528 commit ef5da25

File tree

8 files changed

+126
-200
lines changed

8 files changed

+126
-200
lines changed

.github/workflows/docs-build-pr.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ jobs:
3333
- name: Install dependencies
3434
run: bun install --frozen-lockfile
3535

36-
- name: Build
37-
run: bun run build
36+
- name: Build (Next + Cloudflare)
37+
run: bun run build:cf
3838

3939
- name: Test
4040
run: bun test

bun.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"@next/mdx": "^16.0.1",
3636
"@opennextjs/cloudflare": "^1.11.0",
3737
"@tailwindcss/postcss": "^4.1.5",
38+
"@types/bun": "^1.3.3",
3839
"@types/fs-extra": "^11.0.4",
3940
"@types/mdx": "^2.0.13",
4041
"@types/node": "22.14.1",
@@ -617,6 +618,8 @@
617618

618619
"@tsconfig/node18": ["@tsconfig/[email protected]", "", {}, "sha512-RbwvSJQsuN9TB04AQbGULYfOGE/RnSFk/FLQ5b0NmDf5Kx2q/lABZbHQPKCO1vZ6Fiwkplu+yb9pGdLy1iGseQ=="],
619620

621+
"@types/bun": ["@types/[email protected]", "", { "dependencies": { "bun-types": "1.3.3" } }, "sha512-ogrKbJ2X5N0kWLLFKeytG0eHDleBYtngtlbu9cyBKFtNL3cnpDZkNdQj8flVf6WTZUX5ulI9AY1oa7ljhSrp+g=="],
622+
620623
"@types/debug": ["@types/[email protected]", "", { "dependencies": { "@types/ms": "*" } }, "sha512-vIChWdVG3LG1SMxEvI/AK+FWJthlrqlTu7fbrlywTkkaONwk/UAGaULXRlf8vkzFBLVm0zkMdCquhL5aOjhXPQ=="],
621624

622625
"@types/estree": ["@types/[email protected]", "", {}, "sha512-dWHzHa2WqEXI/O1E9OjrocMTKJl2mSrEolh1Iomrv6U+JuNwaHXsXx9bLu5gG7BUWFIN0skIQJQ/L1rIex4X6w=="],
@@ -711,6 +714,8 @@
711714

712715
"buffer-from": ["[email protected]", "", {}, "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ=="],
713716

717+
"bun-types": ["[email protected]", "", { "dependencies": { "@types/node": "*" } }, "sha512-z3Xwlg7j2l9JY27x5Qn3Wlyos8YAp0kKRlrePAOjgjMGS5IG6E7Jnlx736vH9UVI4wUICwwhC9anYL++XeOgTQ=="],
718+
714719
"bytes": ["[email protected]", "", {}, "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg=="],
715720

716721
"call-bind": ["[email protected]", "", { "dependencies": { "call-bind-apply-helpers": "^1.0.0", "es-define-property": "^1.0.0", "get-intrinsic": "^1.2.4", "set-function-length": "^1.2.2" } }, "sha512-oKlSFMcMwpUg2ednkhQ454wfWiU/ul3CkJe/PEHcTKuiX6RpbehUiFMXu13HalGZxfUwCQzZG747YXBn1im9ww=="],

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"@next/mdx": "^16.0.1",
5555
"@opennextjs/cloudflare": "^1.11.0",
5656
"@tailwindcss/postcss": "^4.1.5",
57+
"@types/bun": "^1.3.3",
5758
"@types/fs-extra": "^11.0.4",
5859
"@types/mdx": "^2.0.13",
5960
"@types/node": "22.14.1",

scripts/download-references.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { $ } from 'bun';
2-
import { existsSync, mkdirSync } from 'fs';
2+
import { existsSync, mkdirSync, unlinkSync } from 'fs';
33
import { join } from 'path';
44

55
const repositories = [
@@ -54,6 +54,19 @@ for (const repo of repositories) {
5454
console.error(`✗ Failed to clone ${repo.name}:`, error);
5555
}
5656
}
57+
58+
// Remove test file from react-native repository
59+
if (repo.name === 'react-native') {
60+
const testFilePath = join(repoPath, 'src', '__tests__', 'index.test.tsx');
61+
if (existsSync(testFilePath)) {
62+
try {
63+
unlinkSync(testFilePath);
64+
console.log(`✓ Removed ${testFilePath}`);
65+
} catch (error) {
66+
console.error(`✗ Failed to remove ${testFilePath}:`, error);
67+
}
68+
}
69+
}
5770
}
5871

5972
console.log('\nAll repositories have been processed!');

test/cf-preview.test.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// test/cf-preview.test.ts
2+
import { test, expect } from "bun:test";
3+
import { spawn } from "child_process";
4+
5+
const PORT = 8790;
6+
const BASE_URL = `http://127.0.0.1:${PORT}`;
7+
8+
function waitForServer(url: string, timeoutMs = 60000) {
9+
const start = Date.now();
10+
return new Promise<void>((resolve, reject) => {
11+
const tick = async () => {
12+
try {
13+
const res = await fetch(url, { signal: AbortSignal.timeout(2000) });
14+
if (res.ok) return resolve();
15+
} catch {
16+
// ignore
17+
}
18+
19+
if (Date.now() - start > timeoutMs) {
20+
reject(new Error(`CF preview server didn't become ready at ${url}`));
21+
} else {
22+
setTimeout(tick, 500);
23+
}
24+
};
25+
tick();
26+
});
27+
}
28+
29+
test("Cloudflare preview runs and serves /docs/home", async () => {
30+
// Assumes `bun run build:cf` has already run in CI
31+
const server = spawn(
32+
"bunx",
33+
["opennextjs-cloudflare", "preview", "--port", String(PORT)],
34+
{
35+
stdio: "inherit",
36+
}
37+
);
38+
39+
try {
40+
await waitForServer(`${BASE_URL}/docs/home`, 60000);
41+
const res = await fetch(`${BASE_URL}/docs/home`);
42+
expect(res.status).toBe(200);
43+
44+
const html = await res.text();
45+
expect(html).toContain("Superwall");
46+
expect(html).toContain("Welcome");
47+
} finally {
48+
// SIGINT is usually enough to bring down wrangler/preview
49+
server.kill("SIGINT");
50+
}
51+
});

test/dev-server.test.ts

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

test/next-start.test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// test/next-start.test.ts
2+
import { test, expect } from "bun:test";
3+
import { spawn } from "child_process";
4+
5+
const PORT = 8293;
6+
const BASE_URL = `http://localhost:${PORT}`;
7+
8+
function waitForServer(url: string, timeoutMs = 20000) {
9+
const start = Date.now();
10+
return new Promise<void>((resolve, reject) => {
11+
const tick = async () => {
12+
try {
13+
const res = await fetch(url, { signal: AbortSignal.timeout(2000) });
14+
if (res.ok) return resolve();
15+
} catch {
16+
// ignore
17+
}
18+
19+
if (Date.now() - start > timeoutMs) {
20+
reject(new Error(`Server didn't become ready at ${url}`));
21+
} else {
22+
setTimeout(tick, 300);
23+
}
24+
};
25+
tick();
26+
});
27+
}
28+
29+
test("next build/start runs and serves /docs/home", async () => {
30+
// Assumes `bun run build` has already run in CI
31+
const server = spawn("bunx", ["next", "start", "-p", String(PORT)], {
32+
stdio: "inherit",
33+
});
34+
35+
try {
36+
await waitForServer(`${BASE_URL}/docs/home`);
37+
const res = await fetch(`${BASE_URL}/docs/home`);
38+
expect(res.status).toBe(200);
39+
40+
const html = await res.text();
41+
expect(html).toContain("Superwall");
42+
expect(html).toContain("Welcome");
43+
} finally {
44+
server.kill("SIGTERM");
45+
}
46+
});

test/tsconfig.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"compilerOptions": {
4+
"types": ["bun"]
5+
},
6+
"include": ["**/*.ts", "**/*.tsx"]
7+
}

0 commit comments

Comments
 (0)