Skip to content
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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V9 migrate from got to fetch #11942

Merged
merged 24 commits into from Feb 14, 2024
Merged

Conversation

tamil777selvan
Copy link
Member

Proposed changes

Fixes #11862

Types of changes

  • 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

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 necessary documentation (if appropriate)
  • I have added proper type definitions for new commands (if appropriate)

Further comments

Reviewers: @webdriverio/project-committers

erwinheitzman and others added 10 commits December 11, 2023 22:48
* (internal): drop support for Node.js 16

update engines of package.json files

* (internal): drop support for Node.js 16

update CONTRIBUTING.md with Node.js 20 as recommendation

* (internal): drop support for Node.js 16

update github workflows

* (internal): drop support for Node.js 16

update external packages that dropped the support already

* (internal): drop support for Node.js 16

resolve PR feedback

* Update packages/webdriver/package.json

* Update packages/wdio-cucumber-framework/package.json

* Update package.json

---------

Co-authored-by: Christian Bromann <git@bromann.dev>
…iverio#11857)

* (webdriverio): merge isDisplayed and isDisplayedWithinViewport

* allow to specify withinViewport check in waitForDisplayed
* (internal): drop support for Node.js 16

update engines of package.json files

* (internal): drop support for Node.js 16

update CONTRIBUTING.md with Node.js 20 as recommendation

* (internal): drop support for Node.js 16

update github workflows

* (internal): drop support for Node.js 16

update external packages that dropped the support already

* (internal): drop support for Node.js 16

resolve PR feedback

* Update packages/webdriver/package.json

* Update packages/wdio-cucumber-framework/package.json

* Update package.json

---------

Co-authored-by: Christian Bromann <git@bromann.dev>
…iverio#11857)

* (webdriverio): merge isDisplayed and isDisplayedWithinViewport

* allow to specify withinViewport check in waitForDisplayed
@tamil777selvan
Copy link
Member Author

tamil777selvan commented Jan 2, 2024

Progress Update

Tasks associated with this pull request.

  • Migrate Got & KV to Native Fetch
  • Update mocks
  • Rectify unit tests
  • Rectify smoke tests
  • Rectify component tests
  • Rectify E2E tests
  • Proxy Setup
  • Using rejectunauthorized

Challenges and Blockers

  • The Nock library currently lacks support for requests made by fetch, as documented in this issue. The ongoing progress on this pull request indicates an expected update to include fetch support in the coming weeks, this currently blocks the smoke tests.
  • The fetch functionality ignores the passed Host header as per this, leading E2E test failures specifically on Safari. A potential workaround involves adjusting the hostname to localhost (instead of 0.0.0.0) only for the Safari browser.

cc: @christian-bromann

@christian-bromann
Copy link
Member

  • A potential workaround involves adjusting the hostname to localhost (instead of 0.0.0.0) only for the Safari browser.

Sounds reasonable to me. @erwinheitzman was working on #11542 to make this happen for all browser but it doesn't seem to be working.

@christian-bromann
Copy link
Member

@tamil777selvan can we rebase this too?

@tamil777selvan tamil777selvan marked this pull request as ready for review February 4, 2024 05:33
Copy link
Member

@christian-bromann christian-bromann left a comment

Choose a reason for hiding this comment

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

Fantastic work 👏 really excited to clean up this mess of multiple request libs. Added some comments to further clean up the code, particularly the request factory is not needed anymore


export type Method = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'HEAD' | 'DELETE' | 'OPTIONS' | 'TRACE' | 'get' | 'post' | 'put' | 'patch' | 'head' | 'delete' | 'options' | 'trace'

export interface RequestLibOptions {
agent?: Agents
followRedirect?: boolean
Copy link
Member

Choose a reason for hiding this comment

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

Do we need RequestLibOptions at this point? We can just rely on the fetch types since we use it for all requests. I think we had this type to ensure that requests made through got (in Node.js environments) and ky (in browser environments) are compatible. We had this to support https://www.npmjs.com/package/web2driver.

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess we might need this. After extending RequestInit, below are the additional options which are used internally. Please share your thoughts,

export interface RequestLibOptions extends RequestInit {
    json?: Record<string, unknown>;
    searchParams?: Record<string, string | number | boolean | null | undefined> | URLSearchParams;
    timeout?: number;
    url?: URL;
    path?: string;
    username?: string;
    password?: string;
}

Copy link
Member

Choose a reason for hiding this comment

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

We should update to the RequestInit interface everywhere, e.g.

  • json: use body: opts.body ?? JSON.stringify(opts.json)
  • searchParams: use URLSearchParams instead and add it to the url
  • timeout: use AbortController as mentioned here
  • url remove as it is passed as second argument
  • path should not be needed anymore, I think it makes sense to have a helper function that can compose the full url based on connection credential options
  • username and password: use headers.set('Authorization', 'Basic ' + btoa(username + ":" + password))

What do you think? Can we introduce these further cleanups? I am not sure how many times we pass along RequestLibOptions but it would be idea if this is all using cross platform features.

Copy link
Member Author

Choose a reason for hiding this comment

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

Certainly, the cleanup sounds logical. I'll get started on it.

Copy link
Member Author

Choose a reason for hiding this comment

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

As suggested, I've made the cleanup on RequestLibOptions. Regarding moving timeout to AbortController, I have not done because we're using it in the request.ts file where we handle timeout clearance. I'm open to your thoughts on this.

Copy link
Member

Choose a reason for hiding this comment

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

Can we get rid of it completely?

packages/webdriver/src/request/factory.ts Outdated Show resolved Hide resolved
packages/webdriver/src/request/request.ts Show resolved Hide resolved
@erwinheitzman
Copy link
Member

This is some amazing work! Well done 👏

packages/wdio-crossbrowsertesting-service/src/service.ts Outdated Show resolved Hide resolved
packages/wdio-browserstack-service/src/util.ts Outdated Show resolved Hide resolved
headers: {
Authorization: `Bearer ${token}`,
}
})

const { location } = headers
const location = response.headers.get('location')
Copy link
Member

Choose a reason for hiding this comment

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

Is there ever a chance that location is undefined?

Suggested change
const location = response.headers.get('location')
const location = response.headers.get('location') as string

Copy link
Member Author

Choose a reason for hiding this comment

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

So far, I've only observed the location as a string and not any other type.

packages/wdio-testingbot-service/src/service.ts Outdated Show resolved Hide resolved

export type Method = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'HEAD' | 'DELETE' | 'OPTIONS' | 'TRACE' | 'get' | 'post' | 'put' | 'patch' | 'head' | 'delete' | 'options' | 'trace'

export interface RequestLibOptions {
agent?: Agents
followRedirect?: boolean
Copy link
Member

Choose a reason for hiding this comment

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

Can we get rid of it completely?

packages/webdriver/src/request/index.ts Outdated Show resolved Hide resolved
Copy link
Member

@christian-bromann christian-bromann left a comment

Choose a reason for hiding this comment

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

As @erwinheitzman pointed out, excellent work. Thanks a lot! This is a big milestone for v9!

@christian-bromann christian-bromann merged commit bec68b3 into webdriverio:v9 Feb 14, 2024
6 of 8 checks passed
@tamil777selvan tamil777selvan deleted the v9-fetch branch February 14, 2024 06:40
christian-bromann added a commit that referenced this pull request Feb 17, 2024
* V9 drop support for Node.js 16 (#11493)

* (internal): drop support for Node.js 16

update engines of package.json files

* (internal): drop support for Node.js 16

update CONTRIBUTING.md with Node.js 20 as recommendation

* (internal): drop support for Node.js 16

update github workflows

* (internal): drop support for Node.js 16

update external packages that dropped the support already

* (internal): drop support for Node.js 16

resolve PR feedback

* Update packages/webdriver/package.json

* Update packages/wdio-cucumber-framework/package.json

* Update package.json

---------

Co-authored-by: Christian Bromann <git@bromann.dev>

* (webdriverio): merge isDisplayed and isDisplayedWithinViewport (#11857)

* (webdriverio): merge isDisplayed and isDisplayedWithinViewport

* allow to specify withinViewport check in waitForDisplayed

* V9 drop support for Node.js 16 (#11493)

* (internal): drop support for Node.js 16

update engines of package.json files

* (internal): drop support for Node.js 16

update CONTRIBUTING.md with Node.js 20 as recommendation

* (internal): drop support for Node.js 16

update github workflows

* (internal): drop support for Node.js 16

update external packages that dropped the support already

* (internal): drop support for Node.js 16

resolve PR feedback

* Update packages/webdriver/package.json

* Update packages/wdio-cucumber-framework/package.json

* Update package.json

---------

Co-authored-by: Christian Bromann <git@bromann.dev>

* (webdriverio): merge isDisplayed and isDisplayedWithinViewport (#11857)

* (webdriverio): merge isDisplayed and isDisplayedWithinViewport

* allow to specify withinViewport check in waitForDisplayed

* Migrating from got to fetch

* Migrate got to fetch in packages

* migrate got to fetch & update unit test

* doc update for proxy setup

* rebase and migrate got to fetch in browserstack

* Migrate hostname from 0.0.0.0 to localhost

* fix unit test by removing headers in safari driver

* fix smoke test: update nock to beta

* fix launch test for firefox

* fix unit test for startGeckodriver

* fix firefox executions in node 18

* Incorporating review comments

* fix component tests

* cleaning up RequestLibOptions

* Removing RequestLibOptions & incorporating other review comments

* use process from globalThis

---------

Co-authored-by: Erwin Heitzman <15839059+erwinheitzman@users.noreply.github.com>
Co-authored-by: Christian Bromann <git@bromann.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants