Skip to content

Add test framework#959

Open
MakinoharaShoko wants to merge 3 commits into
devfrom
add-test-framework
Open

Add test framework#959
MakinoharaShoko wants to merge 3 commits into
devfrom
add-test-framework

Conversation

@MakinoharaShoko
Copy link
Copy Markdown
Member

Close #928

@MakinoharaShoko MakinoharaShoko changed the base branch from main to dev May 20, 2026 13:40
@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying webgal-dev with  Cloudflare Pages  Cloudflare Pages

Latest commit: 4dac148
Status: ✅  Deploy successful!
Preview URL: https://e8461b47.webgal-dev.pages.dev
Branch Preview URL: https://add-test-framework.webgal-dev.pages.dev

View logs

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a comprehensive integration testing framework for the WebGAL engine using Playwright and Vitest, including a new webgal-test package, a custom static server, and updated project dependencies. The test suite covers core functionalities such as save/load consistency, backlog management, and complex animations. Feedback focuses on improving framework reliability and efficiency, specifically by suggesting safer HTTP header handling in the test server, optimized build verification logic, the use of state-based waits instead of fixed delays, and the reduction of non-determinism in test logic.


function createStaticServer(root: string): http.Server {
const normalizedRoot = path.resolve(root);
return http.createServer((req, res) => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The host header is not guaranteed to be present in all HTTP requests. If it is missing, the new URL() constructor will throw an error. It is safer to provide a fallback value like localhost for this internal test server.

    const url = new URL(req.url || '/', \

Comment on lines +43 to +49
function hasTestExposureInBundle(distDir: string): boolean {
const bundleFiles = listFiles(distDir).filter((file) => ['.js', '.mjs', '.html'].includes(extname(file)));
return bundleFiles.some((file) => {
const content = readFileSync(file, 'utf8');
return content.includes('webgalTest') && content.includes('WebGAL Test Mode Active');
});
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The hasTestExposureInBundle function recursively lists and reads every JS/HTML file in the dist directory to verify the build type. This can be very inefficient for large projects with many assets. Consider optimizing this by checking only the main entry point or looking for a specific marker file that indicates a test build.

Comment on lines +53 to +54
await delay(10000);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using a fixed 10-second delay slows down the test suite and can be unreliable depending on the environment. It is better to use waitForSentenceAdvance() to wait for a specific state change, which makes the test both faster and more robust.

Suggested change
await delay(10000);
// Wait for the sentence ID to advance instead of a fixed long delay\n await waitForSentenceAdvance(page, initialId);

Comment on lines +27 to +29
function randomDelay(min: number, max: number): number {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The use of Math.random() in tests introduces non-determinism, which can lead to flaky tests that are difficult to reproduce or debug. Consider using fixed values or a pseudo-random generator with a constant seed to ensure test runs are reproducible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WebGAL 测试框架

1 participant