Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Add lifecycle hooks that do not need a subclass

Abierto
#1,554 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
48/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
docker, node.js, typescript
Área
backend, testing

Línea de trabajo

Start with the three files named under “Where,” then read #1520, #1521, and #1582 to understand the dependencies on builder state, reuse behavior, and startup time. Implement registered lifecycle hooks and the startup command shorthand while retaining the protected methods. Done means hooks receive the described context and can be combined; verify behavior for each lifecycle stage and reused containers.

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

Descripción

enhancement minor

What happens

The lifecycle hooks are protected methods: beforeContainerCreated, containerCreated, containerStarting and containerStarted on GenericContainer, and containerStopping and containerStopped on AbstractStartedContainer. Using one means writing a subclass.

  • A hook cannot be added to a module container without subclassing the module.
  • Two independent behaviours cannot be combined, because each wants to be the subclass.
  • A one-off "run this command once the container is ready" needs a class.

Expected

Hooks can be registered on the builder, and several can be registered:

new PostgreSqlContainer(image).withLifecycleHooks({
  started: async (container) => {
    await container.exec(["psql", "-f", "/seed.sql"]);
  },
});

plus a shorthand for the commonest case, withStartupCommands([...]). The protected methods keep working.

Where

  • packages/testcontainers/src/generic-container/generic-container.ts
  • packages/testcontainers/src/generic-container/started-generic-container.ts
  • packages/testcontainers/src/test-container.ts

Notes

  • Go has WithLifecycleHooks and WithAdditionalLifecycleHooks, with hooks for each of pre/post create, start, ready, stop and terminate, and the shorthands WithStartupCommand and WithAfterReadyCommand.
  • Each hook should be told whether the container was reused.
  • Pass hooks one context object instead of more positional arguments. It should carry reused, the remaining startup time and, later, an abort signal.

Dependencies

  • Stack on #1520: registered hooks are builder state, and they run inside the reworked start().
  • Coordinate with #1521: that issue decides when hooks run for a reused container.
  • Coordinate with #1582: the hook context carries the remaining startup time.
Lenguaje dominante
TypeScript
Estrellas
2.6k
Forks
274
Merge medio
1 d 14 h
PR fusionados (30 d)
44

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

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 testcontainers/testcontainers-node

Todos los issues de testcontainers/testcontainers-node

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.