feat: Enable Cooperative Intercept Mode for puppeteer E2E testing

オープン
#4,504 コメント 0 件 リアクション 4 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
45/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
typescript
領域
testing

調査の方向性

src/testing/puppeteer/puppeteer-page.ts の、参照されているリクエストインターセプトのコード周辺から始め、Puppeteer の Cooperative Intercept Mode のドキュメントを確認してください。優先度引数と後方互換性が既存の E2EPage API にどのような影響を与えるかを判断してください。複数のリクエストハンドラーが、現在のインターセプト動作を壊すことなく共存できれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Feature: Want this? Upvote it!
Prerequisites
Describe the Feature Request

Puppeteer provides what's called Cooperative Intercept Mode which would allow for multiple request handlers to be registered. I'm asking for the following code to be modified to take advantage of this feature:

https://github.com/ionic-team/stencil/blob/f722b24f56c428102f1f0acd7a9f58ce3b001a43/src/testing/puppeteer/puppeteer-page.ts#L242-L254

I think that passing a second argument to the .respond() and .continue() methods of 0 would allow multiple request interceptors to be added.

Describe the Use Case

I have a component that dynamically builds an href, and when the markup gets rendered a request is made to the URL. The file doesn't really exist since I'm passing in dummy values for the test, so I get console.error logs in the test output for the 404 even though my tests pass. I would like to intercept the request and respond with a mock so that I don't get the noisy messages that don't represent real-world use.

Describe Preferred Solution

I think this would be a starting point:

  const interceptedReqCallback = (interceptedRequest: any) => {
    if (pageUrl === interceptedRequest.url()) {
      interceptedRequest.respond({
        status: 200,
        contentType: 'text/html',
        body: output.join('\n'),
      }, 0);
    } else {
      interceptedRequest.continue({}, 0);
    }
  };

This is based on a few things from the documentation:

All resolutions must supply a numeric priority argument to abort/continue/respond.

There are more details on how to maintain backwards compatibility, so a full solution may involve another export on the E2EPage.

Describe Alternatives

This is a known issue and there is a workaround in https://github.com/ionic-team/stencil/issues/2434#issuecomment-714776773. However, it is admittedly hacky, especially since puppeteer provides a built-in way of handling this exact situation.

Related Code

No response

Additional Information

No response

主要言語
TypeScript
スター
13.2k
フォーク
865
平均マージ
2日 16時間
マージ済み PR(30日)
29

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

stenciljs/core のほかの issue

stenciljs/core の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。