Skip to content
Merged
3 changes: 3 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ It captures practical rules that prevent avoidable CI and PR churn.
- In docs Markdown, keep `<!--codeinclude-->` blocks tight with no blank lines between the markers and the include line, or the rendered snippet will contain blank lines between code lines.
- Tests should verify observable behavior changes, not only internal/config state.
- Example: for a security option, assert a real secure/insecure behavior difference.
- Tests should not pull container images that the test suite does not already pull.
- Every extra image increases how long the tests take to run and how much storage they need.
- Reuse an image the tests already use, for example `cristianrgreco/testcontainer:1.1.14` in `packages/testcontainers`, or the module's own image.
- When adding a regression test for a bug fix, follow a red-green-refactor workflow.
- Run the focused test against the pre-fix implementation and confirm it fails for the expected reason.
- Apply the implementation change, rerun the same test, and confirm it passes.
Expand Down
3 changes: 3 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
"preset": "recommended",
"correctness": {
"noUndeclaredDependencies": "error"
},
"nursery": {
"noFloatingPromises": "error"
}
}
},
Expand Down
10 changes: 6 additions & 4 deletions packages/modules/nats/src/nats-container.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@ describe("NatsContainer", { timeout: 180_000 }, () => {

const sub = nc.subscribe(SUBJECT);

(async () => {
const received = (async () => {
const messages: string[] = [];
for await (const m of sub) {
const actual = TD.decode(m.data);
expect(actual).toEqual(PAYLOAD);
messages.push(TD.decode(m.data));
}
})().then();
return messages;
})();

nc.publish(SUBJECT, TE.encode(PAYLOAD));

await nc.drain();
expect(await received).toEqual([PAYLOAD]);
await nc.close();
// }
});
Expand Down
11 changes: 8 additions & 3 deletions packages/testcontainers/smoke-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
const { GenericContainer } = require("./build/index");

(async () => {
const container = await new GenericContainer("alpine:3.12").withCommand(["sleep", "infinity"]).start();
void (async () => {
try {
const container = await new GenericContainer("alpine:3.12").withCommand(["sleep", "infinity"]).start();

await container.stop();
await container.stop();
} catch (err) {
console.error(err);
process.exit(1);
}
})();
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe("GenericContainer Dockerfile", { timeout: 180_000 }, () => {
await using dockerEventStream = await getDockerEventStream();
const dockerPullEventPromise = waitForDockerEvent(dockerEventStream.events, "pull");
let hasResolved = false;
dockerPullEventPromise.then(() => (hasResolved = true));
void dockerPullEventPromise.then(() => (hasResolved = true));
await containerSpec.build();

expect(hasResolved).toBeFalsy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,10 @@ export class GenericContainer implements TestContainer {

if (this.filesToCopy.length > 0 || this.directoriesToCopy.length > 0 || this.contentsToCopy.length > 0) {
const archive = await this.createArchiveToCopyToContainer();
archive.finalize();
await client.container.putArchive(container, archive, "/", this.copyToContainerOptions);
await Promise.all([
archive.finalize(),
client.container.putArchive(container, archive, "/", this.copyToContainerOptions),
]);
}

for (const archive of this.archivesToCopy) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,7 @@ export class StartedGenericContainer implements StartedTestContainer {
filesToCopyWithStats.forEach(({ source, target, mode, stats }) => {
tar.file(source, { name: target, mode, stats });
});
tar.finalize();
await client.container.putArchive(this.container, tar, "/");
await Promise.all([tar.finalize(), client.container.putArchive(this.container, tar, "/")]);
log.debug(`Copied files to container`, { containerId: this.container.id });
}

Expand All @@ -216,8 +215,7 @@ export class StartedGenericContainer implements StartedTestContainer {
directoriesToCopy.forEach(({ source, target }) => {
tar.directory(source, target);
});
tar.finalize();
await client.container.putArchive(this.container, tar, "/");
await Promise.all([tar.finalize(), client.container.putArchive(this.container, tar, "/")]);
log.debug(`Copied directories to container`, { containerId: this.container.id });
}

Expand All @@ -228,8 +226,7 @@ export class StartedGenericContainer implements StartedTestContainer {
contentsToCopy.forEach(({ content, target, mode }) => {
tar.append(content, { name: target, mode: mode });
});
tar.finalize();
await client.container.putArchive(this.container, tar, "/");
await Promise.all([tar.finalize(), client.container.putArchive(this.container, tar, "/")]);
log.debug(`Copied content to container`, { containerId: this.container.id });
}

Expand Down
Loading