Skip to content

Local module loader and ugly React component testing solution for Playwright.

License

Notifications You must be signed in to change notification settings

visortelle/playwright-module-loader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

playwright-module-loader

Load local modules to browser

Playwright has a page.evaluate function that allows to run some code in the browser context.

As I know, unfortunately Playwright doesn't implement ability to load local modules to browser context.

This package tries to fix it.

Component testing

This module provides a simple component testing implemenation for the Playwright.

There is an implemented mount(reactElement) helper function for React.

Example: Button.spec.ts.

The React.createElement(Button.default) instead of JSX syntax may looks ugly, but it's fixable after solving microsoft/playwright#7121.

For now I don't see how to easilly fix IDE support (typechicking, autocompletion).

I hope that a better approach will be provided by Playwright maintainers. In any case it shouldn't be hard to migrate tests to officially supported implementation. Tracking issue: microsoft/playwright#7148.

Usage

Install Playwright test runner. Follow official instructions.

Install this package by running npm i -D playwright-module-loader.

Create you load() function:

Write test: Button.spec.ts.

Disclaimer

This package is tested with webpack config I use in a pet project, so don't give any guarantees.

You can try it with your webpack configuration and it's the only way we can figure out is it works or not. 🙂

Webpack Playwriaght
5.x.x 🟢 1.12.x 🟢
4.x.x 🔴 < 1.12.x 🔴 Regarding webpack v4 - I just don't want to introduce extra complexity and support it. If you want, PRs are welcome.

FAQ

  • Given an error similar to: page.evaluate: Evaluation failed: Error: A cross-origin error was thrown. React doesn't have access to the actual error object in development. See https://reactjs.org/link/crossorigin-error for more information..

Solution: call await page.pause() before the line where the error happens and try to call the evaluation code in the devtools console.

Contributing

Clone the repo, npm run build, then run npm test.

Release: no CI or any other automation for now. Change package version manually, then npm publish, git tag v1.x.x, git push --tag.

About

Local module loader and ugly React component testing solution for Playwright.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published