Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 18, 2025

This PR refactors the e2e test suite to use modern Playwright APIs, improving test reliability and maintainability while keeping all functionality intact.

What Changed

Modernized 4 key e2e test files by replacing deprecated Playwright patterns with current best practices:

  • e2e/utils/search.ts - Core search utility used across multiple test files
  • e2e/fixtures/basic/index.test.ts - Main functionality tests (dark mode, navigation, styles)
  • e2e/fixtures/production/index.test.ts - Production build validation
  • e2e/fixtures/no-config-root/index.test.ts - Configuration-less project tests

Key Improvements

API Modernization

  • Replaced deprecated page.$() with page.locator() - More robust element selection
  • Eliminated page.evaluate() calls - Using direct locator methods instead
  • Updated to modern assertion patterns - await expect(locator) for better error messages

Enhanced Reliability

  • Improved wait strategies - Using page.waitForLoadState() and waitFor() instead of hardcoded timeouts
  • Better element interactions - Using locator.fill() and locator.clear() instead of keyboard events
  • Robust class validation - Using regex patterns with toHaveClass() for theme testing

Developer Experience

  • Enhanced TypeScript typing - Better return types and parameter documentation
  • Clearer error messages - Modern assertions provide more helpful debugging info
  • Improved code readability - Consistent patterns and descriptive comments

Example of Changes

Before (deprecated pattern):

const darkModeButton = await page.$('.rspress-nav-appearance');
const html = await page.$('html');
let htmlClass = await page.evaluate(html => html?.getAttribute('class'), html);
expect(htmlClass?.includes('dark')).toBe(defaultMode !== 'dark');

After (modern pattern):

const darkModeButton = page.locator('.rspress-nav-appearance');
const htmlElement = page.locator('html');
await expect(htmlElement).toHaveClass(
  defaultMode === 'dark' ? /^(?!.*dark).*$/ : /.*dark.*/
);

Benefits

  • More stable tests - Modern APIs are less prone to flakiness
  • Better debugging - Clearer error messages when tests fail
  • Future-proof - Uses current Playwright best practices
  • Zero breaking changes - All test functionality preserved

All changes maintain 100% backward compatibility while bringing the test suite up to current Playwright standards (v1.55.0).

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Created from VS Code via the GitHub Pull Request extension.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@Copilot Copilot AI changed the title [WIP] 你可以在 Rspress 仓库中的 e2e 测试,进行一些重构,比如重构为 playwright 较新的 api,这只是一个例子,让测试逻辑更顺畅,每个 Pull Request 修改的文件数量保持在 1-5 个以内 refactor(e2e): modernize Playwright tests with latest APIs Sep 18, 2025
@Copilot Copilot AI requested a review from SoonIter September 18, 2025 14:15
Copilot finished work on behalf of SoonIter September 18, 2025 14:15
@SoonIter SoonIter marked this pull request as ready for review September 18, 2025 14:19
@SoonIter SoonIter force-pushed the syt/theme-refactor-1 branch 4 times, most recently from c5c80fc to 19ecfce Compare September 24, 2025 11:59
@SoonIter SoonIter force-pushed the syt/theme-refactor-1 branch from 3b0e1ef to 86b8ede Compare October 9, 2025 07:15
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.

3 participants