Skip to content

Commit d07d053

Browse files
committed
build(ts): pixi browser test tasks
1 parent 5571d6b commit d07d053

File tree

5 files changed

+156
-49
lines changed

5 files changed

+156
-49
lines changed

ts/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
npm/
2+
test/browser-npm/node_modules/

ts/pixi.toml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ deno = "*"
1111

1212
[tasks]
1313
dev = "deno run --allow-all src/mod.ts"
14-
test = "deno test --allow-all"
14+
test = "deno test --allow-all --ignore=test/browser-npm/"
1515
lint = "deno lint"
1616
fmt = "deno fmt"
1717
check = "deno check src/mod.ts"
@@ -27,7 +27,22 @@ cmd = "deno lint"
2727
cmd = "deno check src/mod.ts"
2828

2929
[tasks.test-watch]
30-
cmd = "deno test --allow-all --watch"
30+
cmd = "deno test --allow-all --ignore=test/browser-npm/ --watch"
3131

3232
[tasks.build-npm]
33-
cmd = "deno run --allow-all scripts/build_npm.ts"
33+
cmd = "deno run --allow-all scripts/build_npm.ts"
34+
35+
[tasks.test-browser]
36+
cmd = "node scripts/run_playwright.mjs"
37+
38+
[tasks.test-browser-ui]
39+
cmd = "node scripts/run_playwright.mjs --ui"
40+
41+
[tasks.test-browser-npm]
42+
cmd = "deno run --allow-all scripts/build_npm.ts && node scripts/run_playwright.mjs"
43+
44+
[tasks.test-all]
45+
cmd = "deno test --allow-all --ignore=test/browser-npm/ && deno run --allow-all scripts/build_npm.ts && node scripts/run_playwright.mjs"
46+
47+
[tasks.test-deno]
48+
cmd = "which deno && deno --version"

ts/scripts/run_playwright.mjs

Lines changed: 82 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,91 @@ async function main() {
5050
// Install Playwright browsers
5151
await runCommand("npx", ["playwright", "install"], { cwd: testDir });
5252

53-
console.log("🎭 Running Playwright tests...");
53+
// Start the test server in the background
54+
console.log("🚀 Starting test server...");
55+
const serverProcess = spawn(
56+
"deno",
57+
["run", "--allow-all", "test/browser/server.ts"],
58+
{
59+
cwd: projectRoot,
60+
stdio: ["pipe", "pipe", "pipe"],
61+
detached: false,
62+
},
63+
);
64+
65+
// Log server output for debugging
66+
serverProcess.stdout.on("data", (data) => {
67+
console.log(`[Server] ${data.toString().trim()}`);
68+
});
5469

55-
// Run Playwright tests
56-
const playwrightArgs = process.argv.slice(2);
57-
await runCommand("npx", ["playwright", "test", ...playwrightArgs], {
58-
cwd: testDir,
70+
serverProcess.stderr.on("data", (data) => {
71+
console.error(`[Server Error] ${data.toString().trim()}`);
5972
});
6073

61-
console.log("✅ All tests completed successfully!");
74+
// Wait for server to be ready by checking if port 3000 is responding
75+
const waitForServer = async () => {
76+
for (let i = 0; i < 30; i++) {
77+
// Wait up to 30 seconds
78+
try {
79+
// Use a simple HTTP check with Node.js http module instead of fetch
80+
const http = await import("http");
81+
const response = await new Promise((resolve, reject) => {
82+
const req = http.request(
83+
"http://localhost:3000/npm-test",
84+
(res) => {
85+
resolve(res);
86+
},
87+
);
88+
req.on("error", reject);
89+
req.setTimeout(2000, () => {
90+
req.destroy();
91+
reject(new Error("Request timeout"));
92+
});
93+
req.end();
94+
});
95+
96+
if (response.statusCode === 200) {
97+
console.log("✅ Test server is ready!");
98+
return true;
99+
}
100+
} catch (_error) {
101+
// Server not ready yet, continue waiting
102+
}
103+
console.log(`⏳ Waiting for server... (${i + 1}/30)`);
104+
await new Promise((resolve) => setTimeout(resolve, 1000));
105+
}
106+
throw new Error("Server failed to start within 30 seconds");
107+
};
108+
109+
await waitForServer();
110+
111+
console.log("🎭 Running Playwright tests...");
112+
113+
try {
114+
// Run Playwright tests
115+
const playwrightArgs = process.argv.slice(2);
116+
await runCommand("npx", ["playwright", "test", ...playwrightArgs], {
117+
cwd: testDir,
118+
env: {
119+
...process.env,
120+
PLAYWRIGHT_PROJECT_ROOT: projectRoot,
121+
},
122+
});
123+
124+
console.log("✅ All tests completed successfully!");
125+
} finally {
126+
// Clean up server process
127+
if (serverProcess && !serverProcess.killed) {
128+
console.log("🛑 Shutting down test server...");
129+
serverProcess.kill("SIGTERM");
130+
// Give it a moment to shut down gracefully
131+
setTimeout(() => {
132+
if (!serverProcess.killed) {
133+
serverProcess.kill("SIGKILL");
134+
}
135+
}, 3000);
136+
}
137+
}
62138
} catch (error) {
63139
console.error("❌ Test execution failed:", error.message);
64140
process.exit(1);

ts/test/browser-npm/ngff-zarr.test.js

Lines changed: 49 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,20 @@ test.describe("NGFF Zarr NPM Package Tests", () => {
4040
try {
4141
const { MetadataSchema } = await import("./npm/esm/mod.js");
4242

43-
// Test valid metadata
43+
// Test valid NGFF metadata
4444
const validMetadata = {
45-
zarr_format: 2,
46-
shape: [1000, 1000],
47-
chunks: [100, 100],
48-
dtype: "float64",
49-
compressor: {
50-
id: "blosc",
51-
cname: "lz4",
52-
clevel: 5,
53-
shuffle: 1,
54-
blocksize: 0,
55-
},
56-
fill_value: 0.0,
57-
order: "C",
58-
filters: null,
45+
axes: [
46+
{ name: "y", type: "space", unit: "micrometer" },
47+
{ name: "x", type: "space", unit: "micrometer" },
48+
],
49+
datasets: [
50+
{
51+
path: "0",
52+
coordinateTransformations: [{ type: "scale", scale: [1.0, 1.0] }],
53+
},
54+
],
55+
name: "test-image",
56+
version: "0.4",
5957
};
6058

6159
const result = MetadataSchema.safeParse(validMetadata);
@@ -124,30 +122,48 @@ test.describe("NGFF Zarr NPM Package Tests", () => {
124122
test("should handle multiscale validation", async ({ page }) => {
125123
const multiscaleResult = await page.evaluate(async () => {
126124
try {
127-
const { MultiscalesSchema } = await import("./npm/esm/mod.js");
125+
const { MultiscalesOptionsSchema } = await import("./npm/esm/mod.js");
128126

129-
const validMultiscales = {
130-
version: "0.4",
131-
name: "test-image",
132-
type: "image",
133-
axes: [
134-
{ name: "y", type: "space", unit: "micrometer" },
135-
{ name: "x", type: "space", unit: "micrometer" },
136-
],
137-
datasets: [
127+
const validMultiscaleOptions = {
128+
images: [
138129
{
139-
path: "0",
140-
coordinateTransformations: [
141-
{
142-
type: "scale",
143-
scale: [1.0, 1.0],
144-
},
145-
],
130+
data: {
131+
shape: [1000, 1000],
132+
dtype: "float64",
133+
chunks: [[100, 100]],
134+
name: "test-image",
135+
},
136+
dims: ["y", "x"],
137+
scale: { y: 1.0, x: 1.0 },
138+
translation: { y: 0.0, x: 0.0 },
139+
name: "test-image",
140+
axesUnits: { y: "micrometer", x: "micrometer" },
146141
},
147142
],
143+
metadata: {
144+
axes: [
145+
{ name: "y", type: "space", unit: "micrometer" },
146+
{ name: "x", type: "space", unit: "micrometer" },
147+
],
148+
datasets: [
149+
{
150+
path: "0",
151+
coordinateTransformations: [
152+
{
153+
type: "scale",
154+
scale: [1.0, 1.0],
155+
},
156+
],
157+
},
158+
],
159+
name: "test-image",
160+
version: "0.4",
161+
},
148162
};
149163

150-
const result = MultiscalesSchema.safeParse([validMultiscales]);
164+
const result = MultiscalesOptionsSchema.safeParse(
165+
validMultiscaleOptions,
166+
);
151167
return {
152168
success: result.success,
153169
data: result.success ? result.data : undefined,

ts/test/browser-npm/playwright.config.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,13 @@ const config = {
6666
},
6767
},
6868
],
69-
7069
/* Run your local dev server before starting the tests */
71-
webServer: {
72-
command: "deno run --allow-all ../../test/browser/server.ts",
73-
url: "http://localhost:3000",
74-
reuseExistingServer: true,
75-
timeout: 120000,
76-
},
70+
// webServer: {
71+
// command: "cd ../.. && deno run --allow-all test/browser/server.ts",
72+
// url: "http://localhost:3000",
73+
// reuseExistingServer: true,
74+
// timeout: 120000,
75+
// },
7776
};
7877

7978
export default config;

0 commit comments

Comments
 (0)