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

Extend `exec`: reject on failure, stdin, streaming output and a timeout

Abierto
#1,548 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
45/100
Tipo de issue
Nueva funcionalidad
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
docker, node.js, typescript
Área
testing, tooling

Línea de trabajo

Read ExecOptions in packages/testcontainers/src/types.ts and the two exec implementations in packages/testcontainers/src/generic-container/started-generic-container.ts and packages/testcontainers/src/container-runtime/clients/container/docker-container-client.ts. Check the dependency issues #1525, #1531, and #1532, then trace existing exec tests and callers. Done means the four optional behaviors work while defaults stay unchanged; the issue says the work can be split by option.

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

Descripción

enhancement minor

What happens

exec runs a command and resolves with { output, stdout, stderr, exitCode } once it finishes. Its options are workingDir, user and env. Four things are missing.

It never rejects on failure, so callers who expect success check every time:

const result = await container.exec(["psql", "-c", sql]);
if (result.exitCode !== 0) {
  throw new Error(`Command failed with exit code ${result.exitCode}: ${result.output}`);
}

Seven module files carry this check, nine times in total, each with its own message. In tests it is easy to forget, and a failed setup command then surfaces later as an unrelated assertion failure.

It cannot be given input. Piping a SQL file or a dump into a command means copying the file into the container first.

Output is buffered in full and returned at the end. A long-running command shows nothing until it exits, and a large output is held in memory.

It has no timeout. A command that never exits never resolves.

Expected

await container.exec(["psql", "-U", "test"], {
  throwOnError: true,
  stdin: fs.createReadStream("./seed.sql"),
  onOutput: (chunk, stream) => process.stdout.write(chunk),
  timeout: 30_000,
});
  • throwOnError rejects on a non-zero exit code, with an error that carries the command, exit code, stdout and stderr.
  • stdin accepts a string, Buffer or Readable.
  • onOutput receives output as it arrives.
  • timeout rejects and stops waiting for the command.

The defaults stay as they are.

Where

  • exec in packages/testcontainers/src/generic-container/started-generic-container.ts
  • exec in packages/testcontainers/src/container-runtime/clients/container/docker-container-client.ts
  • ExecOptions in packages/testcontainers/src/types.ts

Notes

  • Java and Go return the exit code and leave the check to the caller, as this library does today. Go's exec.ProcessOption covers user, working directory and environment. This goes further than either.
  • Can be split into one change per option.

Dependencies

  • Stack on #1525, #1531: same function, and both change ExecOptions.
  • Coordinate with #1532: for the error class.
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.