Skip to content

Commit

Permalink
test: fix improper teardown in jest (#1342)
Browse files Browse the repository at this point in the history
  • Loading branch information
ANGkeith committed Sep 16, 2024
1 parent 0b54d33 commit 4bca73f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,36 @@ import {WriteStreamsMock} from "../../../src/write-streams";
import {handler} from "../../../src/handler";
import {initBashSpy, initSpawnSpy} from "../../mocks/utils.mock";
import {WhenStatics} from "../../mocks/when-statics";
import {cleanupJobResources, Job} from "../../../src/job";
import {
GitlabRunnerCPUsPresetValue,
GitlabRunnerMemoryPresetValue,
GitlabRunnerPresetValues,
} from "../../../src/gitlab-preset";

let jobs: Job[] = [];
beforeAll(() => {
initSpawnSpy([...WhenStatics.all, {
cmdArgs: ["docker", "cp", expect.any(String), expect.any(String)],
returnValue: {stdout: "Ok"},
}]);
});

beforeEach(async () => {
jobs = [];
});

afterEach(async () => {
await cleanupJobResources(jobs);
});

test("--container-emulate some_unexisting_runner", async () => {
try {
const writeStreams = new WriteStreamsMock();
await handler({
cwd: "tests/test-cases/container-executable",
containerEmulate: "some_unexisting_runner",
}, writeStreams);
}, writeStreams, jobs);

expect(true).toBe(false);
} catch (e: unknown) {
Expand Down
13 changes: 11 additions & 2 deletions tests/test-cases/network-arg/integration.network-arg.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import {WriteStreamsMock} from "../../../src/write-streams";
import {handler} from "../../../src/handler";
import {Job, cleanupJobResources} from "../../../src/job";
import chalk from "chalk";
import {initSpawnSpy, initBashSpy} from "../../mocks/utils.mock";
import {WhenStatics} from "../../mocks/when-statics";
import assert from "assert";
import {AssertionError} from "assert";

let jobs: Job[] = [];
beforeAll(() => {
initSpawnSpy(WhenStatics.all);
});

beforeEach(async () => {
jobs = [];
});

afterEach(async () => {
await cleanupJobResources(jobs);
});

test("network-host <test-job>", async () => {
const bashSpy = initBashSpy([]);
Expand All @@ -36,7 +45,7 @@ test("network-host <service-job>", async () => {
cwd: "tests/test-cases/network-arg",
job: ["service-job"],
network: ["host"],
}, writeStreams);
}, writeStreams, jobs);
} catch (e) {
assert(e instanceof AssertionError, "e is not instanceof AssertionError");
expect(e.message).toBe(chalk`Cannot add service network alias with network mode 'host'`);
Expand Down Expand Up @@ -68,7 +77,7 @@ test("network-none <service-job>", async () => {
cwd: "tests/test-cases/network-arg",
job: ["service-job"],
network: ["none"],
}, writeStreams);
}, writeStreams, jobs);
} catch (e) {
assert(e instanceof AssertionError, "e is not instanceof AssertionError");
expect(e.message).toBe(chalk`Cannot add service network alias with network mode 'none'`);
Expand Down

0 comments on commit 4bca73f

Please sign in to comment.