Skip to content

fix(webdriverio): fix script execution#13470

Merged
christian-bromann merged 7 commits intomainfrom
cb/execute-fix
Sep 5, 2024
Merged

fix(webdriverio): fix script execution#13470
christian-bromann merged 7 commits intomainfrom
cb/execute-fix

Conversation

@christian-bromann
Copy link
Member

@christian-bromann christian-bromann commented Aug 28, 2024

Proposed changes

fixes #13444
fixes #13443

In addition, this patch will:

  • create nicer stack traces and print the line that caused the error, e.g.
    given following script:
    await browser.execute(async () => {
        const a: number = 1
        console.log('Hello Bidi')
        if (a) {
            if (a) {
                throw new Error('Hello Bidi')
            }
        }
    })
     Error: Error: Hello Bidi
         at Context.<anonymous> (/path/to/webdriverio/e2e/wdio/headless/bidi.e2e.ts:207:28)
         207 │ if(a){if(a){throw new Error("Hello Bidi")}}}
             ╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
         at parseScriptResult (/path/to/webdriverio/build/index.js:750:19)
         at Browser.execute (/path/to/webdriverio/build/index.js:2982:12)
         at Browser.wrapCommandFn (/path/to/wdio-utils/build/index.js:1368:23)
         at Context.<anonymous> (/path/to/webdriverio/e2e/wdio/headless/bidi.e2e.ts:207:28)
         at Context.executeAsync (/path/to/wdio-utils/build/index.js:1488:20)
         at Context.testFrameworkFnWrapper (/path/to/wdio-utils/build/index.js:1559:14)
    
  • it will deprecate executeAsync as there is not need for it anymore

Types of changes

  • Polish (an improvement for an existing feature)
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update (improvements to the project's docs)
  • Specification changes (updates to WebDriver command specifications)
  • Internal updates (everything related to internal scripts, governance documentation and CI files)

Checklist

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary documentation (if appropriate)
  • I have added proper type definitions for new commands (if appropriate)

Backport Request

//: # (The current main branch is the development branch for WebdriverIO v9. If your change should be released to the current major version of WebdriverIO (v8), please raise another PR with the same changes against the v8 branch.)

  • This change is solely for v9 and doesn't need to be back-ported
  • Back-ported PR at #XXXXX

Further comments

n/a

Reviewers: @webdriverio/project-committers

@christian-bromann christian-bromann added the PR: Bug Fix 🐛 PRs that contain bug fixes label Aug 28, 2024
@pkg-pr-new
Copy link

pkg-pr-new bot commented Aug 28, 2024

Open in Stackblitz

eslint-plugin-wdio

pnpm add https://pkg.pr.new/webdriverio/webdriverio/eslint-plugin-wdio@13470

@wdio/allure-reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/allure-reporter@13470

@wdio/appium-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/appium-service@13470

@wdio/browser-runner

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/browser-runner@13470

@wdio/cli

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/cli@13470

@wdio/browserstack-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/browserstack-service@13470

@wdio/config

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/config@13470

@wdio/concise-reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/concise-reporter@13470

@wdio/dot-reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/dot-reporter@13470

@wdio/cucumber-framework

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/cucumber-framework@13470

@wdio/firefox-profile-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/firefox-profile-service@13470

@wdio/globals

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/globals@13470

@wdio/jasmine-framework

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/jasmine-framework@13470

@wdio/json-reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/json-reporter@13470

@wdio/lighthouse-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/lighthouse-service@13470

@wdio/junit-reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/junit-reporter@13470

@wdio/logger

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/logger@13470

@wdio/local-runner

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/local-runner@13470

@wdio/protocols

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/protocols@13470

@wdio/mocha-framework

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/mocha-framework@13470

@wdio/reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/reporter@13470

@wdio/repl

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/repl@13470

@wdio/runner

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/runner@13470

@wdio/shared-store-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/shared-store-service@13470

@wdio/smoke-test-cjs-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/smoke-test-cjs-service@13470

@wdio/smoke-test-reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/smoke-test-reporter@13470

@wdio/smoke-test-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/smoke-test-service@13470

@wdio/spec-reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/spec-reporter@13470

@wdio/static-server-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/static-server-service@13470

@wdio/sumologic-reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/sumologic-reporter@13470

@wdio/testingbot-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/testingbot-service@13470

@wdio/types

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/types@13470

@wdio/utils

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/utils@13470

@wdio/webdriver-mock-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/webdriver-mock-service@13470

webdriver

pnpm add https://pkg.pr.new/webdriverio/webdriverio/webdriver@13470

webdriverio

pnpm add https://pkg.pr.new/webdriverio/webdriverio@13470

@wdio/sauce-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/sauce-service@13470

commit: 1345cea

'var __name = (target, value) => __defProp(target, \'name\', { value, configurable: true });' +
'globalThis.__name = __name;'
)
return closure()
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure this is all that's needed. See evanw/esbuild#607 (comment):

The __name function is just one of many code transforms that esbuild can make that assume functions aren't arbitrarily recompiled by converting them to a string and feeding them to eval. Other examples include converting a ** b to __pow(a, b) and {...a, ...b} to __assign({}, a), b).

Copy link
Member Author

Choose a reason for hiding this comment

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

Are you aware of more polyfills that are needed here?

Copy link
Contributor

@danielhjacobs danielhjacobs Aug 28, 2024

Choose a reason for hiding this comment

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

Ruffle doesn't need any others for its tests currently but that doesn't means others won't or that future tests won't require others. I think any from this file might be needed:

https://github.com/evanw/esbuild/blob/main/internal/runtime/runtime.go

As stated in evanw/esbuild#607 (comment)

Preserving the value of toString() on a function expression is not a design goal of esbuild. If that use case is important to you, it would be best to either arrange for the code to be passed as a string instead, or to use another tool that supports preserving the value of toString() on a function.

Copy link
Member Author

Choose a reason for hiding this comment

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

Understood. The amount of usecases for WDIO vs someone compiling a TS project with Esbuild is very different, e.g. no one would export variables from the test. My idea was to add more polyfills when needed as this seems the simplest approach while keeping the codebase as simple as possible.

@lararojasmr
Copy link
Contributor

lararojasmr commented Sep 4, 2024

@christian-bromann those changes fix #13444 without BiDi? I'm facing this issue now.

@christian-bromann
Copy link
Member Author

@lararojasmr non bidi sessions have not been impacted by this issue.

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

Labels

PR: Bug Fix 🐛 PRs that contain bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[🐛 Bug]: browser.execute breaks when declaring functions [🐛 Bug]: WDIO v9 breaks backwards compatibility of executeAsync when used with BiDi

3 participants