Skip to content

Commit a7fc211

Browse files
Downgrade archiver to restore Jest CJS compatibility (#1366)
1 parent 79f9707 commit a7fc211

7 files changed

Lines changed: 50 additions & 266 deletions

File tree

.github/workflows/checks.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ jobs:
141141
run: node packages/testcontainers/smoke-test.mjs
142142
env:
143143
DEBUG: "testcontainers*"
144+
- name: Run Jest CommonJS runtime smoke test
145+
run: npm exec --yes --package jest@30.4.2 -- jest --testMatch "**/smoke-test.jest.js" --runInBand --no-cache
146+
env:
147+
DEBUG: "testcontainers*"
144148

145149
test:
146150
if: ${{ needs.detect-modules.outputs.modules_count != '0' }}

package-lock.json

Lines changed: 18 additions & 252 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/testcontainers/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"dependencies": {
3333
"@balena/dockerignore": "^1.0.2",
3434
"@types/dockerode": "^4.0.1",
35-
"archiver": "^8.0.0",
35+
"archiver": "^7.0.1",
3636
"async-lock": "^1.4.1",
3737
"byline": "^5.0.0",
3838
"debug": "^4.4.3",
@@ -47,7 +47,7 @@
4747
"undici": "^8.3.0"
4848
},
4949
"devDependencies": {
50-
"@types/archiver": "^8.0.0",
50+
"@types/archiver": "^7.0.0",
5151
"@types/async-lock": "^1.4.2",
5252
"@types/byline": "^4.2.36",
5353
"@types/debug": "^4.1.13",
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const { GenericContainer } = require("./build/index");
2+
3+
jest.setTimeout(120_000);
4+
5+
test("starts a container under Jest CommonJS runtime", async () => {
6+
let container;
7+
try {
8+
container = await new GenericContainer("alpine:3.12")
9+
.withCommand(["sleep", "infinity"])
10+
.start();
11+
} finally {
12+
await container?.stop();
13+
}
14+
});

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TarArchive, type EntryData } from "archiver";
1+
import archiver from "archiver";
22
import getPort from "get-port";
33
import path from "path";
44
import { RandomUuid } from "../common";
@@ -521,8 +521,8 @@ describe("GenericContainer", { timeout: 180_000 }, () => {
521521
.withExposedPorts(8080)
522522
.start();
523523

524-
const tar = new TarArchive();
525-
tar.append("hello world", { name: targetWithCopyOwnership.slice(1), uid, gid } as EntryData);
524+
const tar = archiver("tar");
525+
tar.append("hello world", { name: targetWithCopyOwnership.slice(1), uid, gid } as archiver.EntryData);
526526
tar.finalize();
527527

528528
await container.copyArchiveToContainer(tar, "/", { copyUIDGID: true });
@@ -536,8 +536,8 @@ describe("GenericContainer", { timeout: 180_000 }, () => {
536536
const uid = 4242;
537537
const gid = 4343;
538538
const targetWithCopyOwnership = "/tmp/with-copy-archives-copyuidgid.txt";
539-
const tar = new TarArchive();
540-
tar.append("hello world", { name: targetWithCopyOwnership.slice(1), uid, gid } as EntryData);
539+
const tar = archiver("tar");
540+
tar.append("hello world", { name: targetWithCopyOwnership.slice(1), uid, gid } as archiver.EntryData);
541541
tar.finalize();
542542

543543
await using containerWithCopyOwnership = await new GenericContainer("cristianrgreco/testcontainer:1.1.14")

packages/testcontainers/src/generic-container/generic-container.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TarArchive, type Archiver } from "archiver";
1+
import archiver from "archiver";
22
import AsyncLock from "async-lock";
33
import { Container, ContainerCreateOptions, ContainerInspectInfo, HostConfig } from "dockerode";
44
import { promises as fs } from "fs";
@@ -275,8 +275,8 @@ export class GenericContainer implements TestContainer {
275275
}
276276
}
277277

278-
private async createArchiveToCopyToContainer(): Promise<Archiver> {
279-
const tar = new TarArchive();
278+
private async createArchiveToCopyToContainer(): Promise<archiver.Archiver> {
279+
const tar = archiver("tar");
280280
const filesToCopyWithStats = await Promise.all(
281281
this.filesToCopy.map(async (fileToCopy) => ({
282282
...fileToCopy,

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TarArchive } from "archiver";
1+
import archiver from "archiver";
22
import AsyncLock from "async-lock";
33
import Dockerode, { ContainerInspectInfo } from "dockerode";
44
import { promises as fs } from "fs";
@@ -192,7 +192,7 @@ export class StartedGenericContainer implements StartedTestContainer {
192192
public async copyFilesToContainer(filesToCopy: FileToCopy[]): Promise<void> {
193193
log.debug(`Copying files to container...`, { containerId: this.container.id });
194194
const client = await getContainerRuntimeClient();
195-
const tar = new TarArchive();
195+
const tar = archiver("tar");
196196
const filesToCopyWithStats = await Promise.all(
197197
filesToCopy.map(async (fileToCopy) => ({
198198
...fileToCopy,
@@ -208,7 +208,7 @@ export class StartedGenericContainer implements StartedTestContainer {
208208
public async copyDirectoriesToContainer(directoriesToCopy: DirectoryToCopy[]): Promise<void> {
209209
log.debug(`Copying directories to container...`, { containerId: this.container.id });
210210
const client = await getContainerRuntimeClient();
211-
const tar = new TarArchive();
211+
const tar = archiver("tar");
212212
directoriesToCopy.forEach(({ source, target }) => tar.directory(source, target));
213213
tar.finalize();
214214
await client.container.putArchive(this.container, tar, "/");
@@ -218,7 +218,7 @@ export class StartedGenericContainer implements StartedTestContainer {
218218
public async copyContentToContainer(contentsToCopy: ContentToCopy[]): Promise<void> {
219219
log.debug(`Copying content to container...`, { containerId: this.container.id });
220220
const client = await getContainerRuntimeClient();
221-
const tar = new TarArchive();
221+
const tar = archiver("tar");
222222
contentsToCopy.forEach(({ content, target, mode }) => tar.append(content, { name: target, mode: mode }));
223223
tar.finalize();
224224
await client.container.putArchive(this.container, tar, "/");

0 commit comments

Comments
 (0)