Skip to content

Commit 4bca73f

Browse files
authored
test: fix improper teardown in jest (#1342)
1 parent 0b54d33 commit 4bca73f

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

tests/test-cases/gitlab-runner-emulation/integration.emulate-runner.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,36 @@ import {WriteStreamsMock} from "../../../src/write-streams";
22
import {handler} from "../../../src/handler";
33
import {initBashSpy, initSpawnSpy} from "../../mocks/utils.mock";
44
import {WhenStatics} from "../../mocks/when-statics";
5+
import {cleanupJobResources, Job} from "../../../src/job";
56
import {
67
GitlabRunnerCPUsPresetValue,
78
GitlabRunnerMemoryPresetValue,
89
GitlabRunnerPresetValues,
910
} from "../../../src/gitlab-preset";
1011

12+
let jobs: Job[] = [];
1113
beforeAll(() => {
1214
initSpawnSpy([...WhenStatics.all, {
1315
cmdArgs: ["docker", "cp", expect.any(String), expect.any(String)],
1416
returnValue: {stdout: "Ok"},
1517
}]);
1618
});
1719

20+
beforeEach(async () => {
21+
jobs = [];
22+
});
23+
24+
afterEach(async () => {
25+
await cleanupJobResources(jobs);
26+
});
27+
1828
test("--container-emulate some_unexisting_runner", async () => {
1929
try {
2030
const writeStreams = new WriteStreamsMock();
2131
await handler({
2232
cwd: "tests/test-cases/container-executable",
2333
containerEmulate: "some_unexisting_runner",
24-
}, writeStreams);
34+
}, writeStreams, jobs);
2535

2636
expect(true).toBe(false);
2737
} catch (e: unknown) {

tests/test-cases/network-arg/integration.network-arg.test.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
import {WriteStreamsMock} from "../../../src/write-streams";
22
import {handler} from "../../../src/handler";
3+
import {Job, cleanupJobResources} from "../../../src/job";
34
import chalk from "chalk";
45
import {initSpawnSpy, initBashSpy} from "../../mocks/utils.mock";
56
import {WhenStatics} from "../../mocks/when-statics";
67
import assert from "assert";
78
import {AssertionError} from "assert";
89

10+
let jobs: Job[] = [];
911
beforeAll(() => {
1012
initSpawnSpy(WhenStatics.all);
1113
});
1214

15+
beforeEach(async () => {
16+
jobs = [];
17+
});
18+
19+
afterEach(async () => {
20+
await cleanupJobResources(jobs);
21+
});
1322

1423
test("network-host <test-job>", async () => {
1524
const bashSpy = initBashSpy([]);
@@ -36,7 +45,7 @@ test("network-host <service-job>", async () => {
3645
cwd: "tests/test-cases/network-arg",
3746
job: ["service-job"],
3847
network: ["host"],
39-
}, writeStreams);
48+
}, writeStreams, jobs);
4049
} catch (e) {
4150
assert(e instanceof AssertionError, "e is not instanceof AssertionError");
4251
expect(e.message).toBe(chalk`Cannot add service network alias with network mode 'host'`);
@@ -68,7 +77,7 @@ test("network-none <service-job>", async () => {
6877
cwd: "tests/test-cases/network-arg",
6978
job: ["service-job"],
7079
network: ["none"],
71-
}, writeStreams);
80+
}, writeStreams, jobs);
7281
} catch (e) {
7382
assert(e instanceof AssertionError, "e is not instanceof AssertionError");
7483
expect(e.message).toBe(chalk`Cannot add service network alias with network mode 'none'`);

0 commit comments

Comments
 (0)