Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Add lifecycle hooks that do not need a subclass

Aperta
#1,554 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
docker, node.js, typescript
Ambito
backend, testing

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.
Lingua principale
TypeScript
Stelle
2.6k
Fork
274
Merge medio
1g 14h
PR unite (30g)
44

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di testcontainers/testcontainers-node

Tutte le issue di testcontainers/testcontainers-node

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.