feat: Enable Cooperative Intercept Mode for puppeteer E2E testing

Abierto
#4,504 0 comentarios 4 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
45/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
typescript
Área
testing

Línea de trabajo

Comienza en src/testing/puppeteer/puppeteer-page.ts, alrededor del código de intercepción de solicitudes referenciado, y revisa la documentación de Cooperative Intercept Mode de Puppeteer. Determina cómo afectan los argumentos de prioridad y la compatibilidad con versiones anteriores a la API E2EPage existente. Se considera terminado cuando varios manejadores de solicitudes pueden coexistir sin romper el comportamiento actual de intercepción.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
TypeScript
Estrellas
13.2k
Forks
865
Merge medio
2 d 16 h
PR fusionados (30 d)
29

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de stenciljs/core

Todos los issues de stenciljs/core

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.