-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] Usage advice for script injection and execution #5058
Comments
page.evaluate(func) will toString the func, move it to the browser and run it there. It'll work for local functions and functions with reasonable toString, but won't work for any imported behavior. Your imports are in the Node world and the scripts run in the Browser world. You can still inject your transpiled functions, say get a webpack output and evaluate it altogether so that it all appeared in the page, so you don't need a server for that. But you still need to inject some consistent scripts so that you could run them inside the browser... |
@pavelfeldman thanks for the reply, and @naripok sorry for the highjack! Could you please elaborate a little on, or point to some resource which explains how to achieve this:
Thanks in advance! |
There isn't much to expand on, page.evaluate accepts string script and this can be a compiled script, a result of the webpack run. So if you have a complex app and use webpack, you can feel the entire js file that webpack generates into the page. And it'll run there... |
Looks like there's no more actions on our end - closing this. Feel free to refile if we still can be helpful! |
Hello good people! 馃憢
I come for advice!
My use-case is as follow:
My
index.test.ts
file looks roughtly like this:And my configs:
I'm using
jest-playwright-preset
, but the problem is the same with vanillats-jest
configs.So, for functions defined inside the
page.evaluate
thunk, everything works fine, but things break for the imported stuff.I get errors of the
someBrowserApi is undefined
kind.My question is:
Is there a way to import my (transformed) to-be-tested code, inject it into the page and assert about its behaviours without having to actually spawn a server with transpiled code being served and navigate to it?
Thanks for the good work!
Cheers!
The text was updated successfully, but these errors were encountered: