Giter VIP home page Giter VIP logo

playwright-module-loader's Introduction

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.

playwright-module-loader's People

Stargazers

 avatar

Watchers

 avatar  avatar

playwright-module-loader's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.