Skip to content

Commit 363953d

Browse files
authored
Use test.concurrent for independent integration tests (#1769)
1 parent b2df74a commit 363953d

47 files changed

Lines changed: 393 additions & 237 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

tests/test-cases/after-script/integration.test.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ beforeAll(() => {
88
initSpawnSpy(WhenStatics.all);
99
});
1010

11-
test("after-script <test-job>", async () => {
11+
test.concurrent("after-script <test-job>", async () => {
1212
const writeStreams = new WriteStreamsMock();
1313
await handler({
1414
cwd: "tests/test-cases/after-script",
1515
job: ["test-job"],
16+
stateDir: ".gitlab-ci-local-after-script-test-job",
1617
}, writeStreams);
1718

1819
const expected = [
@@ -21,11 +22,12 @@ test("after-script <test-job>", async () => {
2122
expect(writeStreams.stdoutLines).toEqual(expect.arrayContaining(expected));
2223
});
2324

24-
test("after-script <build-job> (default)", async () => {
25+
test.concurrent("after-script <build-job> (default)", async () => {
2526
const writeStreams = new WriteStreamsMock();
2627
await handler({
2728
cwd: "tests/test-cases/after-script",
2829
job: ["build-job"],
30+
stateDir: ".gitlab-ci-local-after-script-build-job-default",
2931
}, writeStreams);
3032

3133
const expected = [
@@ -34,11 +36,12 @@ test("after-script <build-job> (default)", async () => {
3436
expect(writeStreams.stdoutLines).toEqual(expect.arrayContaining(expected));
3537
});
3638

37-
test("after-script <deploy-job>", async () => {
39+
test.concurrent("after-script <deploy-job>", async () => {
3840
const writeStreams = new WriteStreamsMock();
3941
await handler({
4042
cwd: "tests/test-cases/after-script",
4143
job: ["deploy-job"],
44+
stateDir: ".gitlab-ci-local-after-script-deploy-job",
4245
}, writeStreams);
4346

4447
const expected = [
@@ -48,11 +51,12 @@ test("after-script <deploy-job>", async () => {
4851
expect(writeStreams.stdoutLines).toEqual(expect.arrayContaining(expected));
4952
});
5053

51-
test("after-script <post-job>", async () => {
54+
test.concurrent("after-script <post-job>", async () => {
5255
const writeStreams = new WriteStreamsMock();
5356
await handler({
5457
cwd: "tests/test-cases/after-script",
5558
job: ["post-job"],
59+
stateDir: ".gitlab-ci-local-after-script-post-job",
5660
}, writeStreams);
5761

5862
const expected = [
Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,20 @@
11
import {WriteStreamsMock} from "../../../src/write-streams.js";
22
import {handler} from "../../../src/handler.js";
3-
import fs from "fs-extra";
43
import {initSpawnSpy} from "../../mocks/utils.mock.js";
54
import {WhenStatics} from "../../mocks/when-statics.js";
6-
import {basename} from "node:path/posix";
7-
import {dirname} from "node:path";
85

96
beforeAll(() => {
107
initSpawnSpy(WhenStatics.all);
118
});
129

13-
const name = basename(dirname(import.meta.url));
14-
const cwd = `tests/test-cases/${name}`;
15-
16-
describe(name, () => {
10+
test.concurrent("artifacts-docker-readonly-permissions should successfully export artifacts with read-only directories", async () => {
1711
const writeStreams = new WriteStreamsMock();
18-
beforeAll(async () => {
19-
await fs.rm(`${cwd}/.gitlab-ci-local/`, {recursive: true, force: true});
20-
21-
await handler({
22-
cwd,
23-
noColor: true,
24-
file: ".gitlab-ci.yml",
25-
}, writeStreams);
26-
});
12+
await handler({
13+
cwd: "tests/test-cases/artifacts-docker-readonly-permissions",
14+
noColor: true,
15+
file: ".gitlab-ci.yml",
16+
stateDir: ".gitlab-ci-local-artifacts-docker-readonly-permissions",
17+
}, writeStreams);
2718

28-
it("should successfully export artifacts with read-only directories", () => {
29-
expect(writeStreams.stdoutLines.join("\n")).toContain("produce-artifacts exported artifacts");
30-
});
19+
expect(writeStreams.stdoutLines.join("\n")).toContain("produce-artifacts exported artifacts");
3120
});

tests/test-cases/artifacts-dotenv/integration.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,25 @@ beforeAll(() => {
77
initSpawnSpy(WhenStatics.all);
88
});
99

10-
test("artifacts-dotenv <use-image-ref> --needs", async () => {
10+
test.concurrent("artifacts-dotenv <use-image-ref> --needs", async () => {
1111
const writeStreams = new WriteStreamsMock();
1212
await handler({
1313
cwd: "tests/test-cases/artifacts-dotenv",
1414
job: ["use-image-ref"],
1515
needs: true,
16+
stateDir: ".gitlab-ci-local-artifacts-dotenv-use-image-ref-needs",
1617
}, writeStreams);
1718

1819
expect(writeStreams.stderrLines.join("\n")).not.toMatch(/FAIL/);
1920
});
2021

21-
test("artifacts-dotenv <use-service-ref> --needs", async () => {
22+
test.concurrent("artifacts-dotenv <use-service-ref> --needs", async () => {
2223
const writeStreams = new WriteStreamsMock();
2324
await handler({
2425
cwd: "tests/test-cases/artifacts-dotenv",
2526
job: ["use-service-ref"],
2627
needs: true,
28+
stateDir: ".gitlab-ci-local-artifacts-dotenv-use-service-ref-needs",
2729
}, writeStreams);
2830

2931
expect(writeStreams.stderrLines.join("\n")).not.toMatch(/FAIL/);

tests/test-cases/artifacts-globstar/integration.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ beforeAll(() => {
88
initSpawnSpy(WhenStatics.all);
99
});
1010

11-
test("artifacts-globstar <test-job> --needs --shell-isolation", async () => {
11+
test.concurrent("artifacts-globstar <test-job> --needs --shell-isolation", async () => {
1212
const writeStreams = new WriteStreamsMock();
1313
await handler({
1414
cwd: "tests/test-cases/artifacts-globstar",
1515
job: ["test-job"],
1616
needs: true,
1717
shellIsolation: true,
18+
stateDir: ".gitlab-ci-local-artifacts-globstar-test-job-needs-shell-isolation",
1819
}, writeStreams);
1920

2021
const expected = [
@@ -23,12 +24,13 @@ test("artifacts-globstar <test-job> --needs --shell-isolation", async () => {
2324
expect(writeStreams.stdoutLines).toEqual(expect.arrayContaining(expected));
2425
});
2526

26-
test("artifacts-globstar <no-match> --shell-isolation", async () => {
27+
test.concurrent("artifacts-globstar <no-match> --shell-isolation", async () => {
2728
const writeStreams = new WriteStreamsMock();
2829
await handler({
2930
cwd: "tests/test-cases/artifacts-globstar",
3031
job: ["no-match"],
3132
shellIsolation: true,
33+
stateDir: ".gitlab-ci-local-artifacts-globstar-no-match-shell-isolation",
3234
}, writeStreams);
3335

3436
const expected = [

tests/test-cases/artifacts-reports-dotenv/integration.test.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,60 +7,65 @@ beforeAll(() => {
77
initSpawnSpy(WhenStatics.all);
88
});
99

10-
test("artifacts-reports-dotenv <deploy-image> --needs", async () => {
10+
test.concurrent("artifacts-reports-dotenv <deploy-image> --needs", async () => {
1111
const writeStreams = new WriteStreamsMock();
1212
await handler({
1313
cwd: "tests/test-cases/artifacts-reports-dotenv",
1414
job: ["deploy-image"],
1515
needs: true,
16+
stateDir: ".gitlab-ci-local-artifacts-reports-dotenv-deploy-image-needs",
1617
}, writeStreams);
1718

1819
expect(writeStreams.stderrLines.join("\n")).not.toMatch(/FAIL/);
1920
});
2021

21-
test("artifacts-reports-dotenv <deploy-shell-iso> --needs", async () => {
22+
test.concurrent("artifacts-reports-dotenv <deploy-shell-iso> --needs", async () => {
2223
const writeStreams = new WriteStreamsMock();
2324
await handler({
2425
cwd: "tests/test-cases/artifacts-reports-dotenv",
2526
job: ["deploy-shell-iso"],
2627
needs: true,
2728
shellIsolation: true,
29+
stateDir: ".gitlab-ci-local-artifacts-reports-dotenv-deploy-shell-iso-needs",
2830
}, writeStreams);
2931

3032
expect(writeStreams.stderrLines.join("\n")).not.toMatch(/FAIL/);
3133
});
3234

33-
test("artifacts-reports-dotenv <deploy-shell-noiso> --needs", async () => {
35+
test.concurrent("artifacts-reports-dotenv <deploy-shell-noiso> --needs", async () => {
3436
const writeStreams = new WriteStreamsMock();
3537
await handler({
3638
cwd: "tests/test-cases/artifacts-reports-dotenv",
3739
job: ["deploy-shell-noiso"],
3840
needs: true,
3941
shellIsolation: false,
42+
stateDir: ".gitlab-ci-local-artifacts-reports-dotenv-deploy-shell-noiso-needs",
4043
}, writeStreams);
4144

4245
expect(writeStreams.stderrLines.join("\n")).not.toMatch(/FAIL/);
4346
});
4447

45-
test("artifacts-reports-dotenv <test-multi-dotenv> --needs", async () => {
48+
test.concurrent("artifacts-reports-dotenv <test-multi-dotenv> --needs", async () => {
4649
const writeStreams = new WriteStreamsMock();
4750
await handler({
4851
cwd: "tests/test-cases/artifacts-reports-dotenv",
4952
job: ["test-multi-dotenv"],
5053
needs: true,
5154
file: ".gitlab-ci-issue-1160.yml",
55+
stateDir: ".gitlab-ci-local-artifacts-reports-dotenv-test-multi-dotenv-needs",
5256
}, writeStreams);
5357

5458
expect(writeStreams.stderrLines.join("\n")).not.toMatch(/FAIL/);
5559
});
5660

57-
test("artifacts-reports-dotenv <test-multi-dotenv-with-missing-file> --needs", async () => {
61+
test.concurrent("artifacts-reports-dotenv <test-multi-dotenv-with-missing-file> --needs", async () => {
5862
const writeStreams = new WriteStreamsMock();
5963
await handler({
6064
cwd: "tests/test-cases/artifacts-reports-dotenv",
6165
job: ["test-multi-dotenv-with-missing-file"],
6266
needs: true,
6367
file: ".gitlab-ci-issue-1160.yml",
68+
stateDir: ".gitlab-ci-local-artifacts-reports-dotenv-test-multi-dotenv-with-missing-file-needs",
6469
}, writeStreams);
6570

6671
expect(writeStreams.stderrLines.join("\n")).toContain("artifact reports dotenv 'multi4.env' could not be found");

tests/test-cases/artifacts-sequence/integration.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,24 @@ beforeAll(() => {
77
initSpawnSpy(WhenStatics.all);
88
});
99

10-
test("artifacts-sequence --shell-isolation artifacts copied to next stages", async () => {
10+
test.concurrent("artifacts-sequence --shell-isolation artifacts copied to next stages", async () => {
1111
const writeStreams = new WriteStreamsMock();
1212
await handler({
1313
cwd: "tests/test-cases/artifacts-sequence",
1414
shellIsolation: true,
15+
stateDir: ".gitlab-ci-local-artifacts-sequence-shell-isolation-artifacts-copie",
1516
}, writeStreams);
1617

1718
expect(writeStreams.stderrLines.join("\n")).not.toMatch(/FAIL/);
1819
});
1920

20-
test("artifacts-sequence --shell-isolation parallel matrix artifacts copied to next stages", async () => {
21+
test.concurrent("artifacts-sequence --shell-isolation parallel matrix artifacts copied to next stages", async () => {
2122
const writeStreams = new WriteStreamsMock();
2223
await handler({
2324
cwd: "tests/test-cases/artifacts-sequence",
2425
file: ".gitlab-ci-parallel.yml",
2526
shellIsolation: true,
27+
stateDir: ".gitlab-ci-local-artifacts-sequence-shell-isolation-parallel-matrix",
2628
}, writeStreams);
2729

2830
expect(writeStreams.stderrLines.join("\n")).not.toMatch(/FAIL/);
Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,21 @@
11
import {WriteStreamsMock} from "../../../src/write-streams.js";
22
import {handler} from "../../../src/handler.js";
3-
import fs from "fs-extra";
43
import {initSpawnSpy} from "../../mocks/utils.mock.js";
54
import {WhenStatics} from "../../mocks/when-statics.js";
6-
import {basename} from "node:path/posix";
7-
import {dirname} from "node:path";
85

96
beforeAll(() => {
107
initSpawnSpy(WhenStatics.all);
118
});
129

13-
const name = basename(dirname(import.meta.url));
14-
const cwd = `tests/test-cases/${name}`;
15-
16-
describe(name, () => {
10+
test.concurrent("cache-docker-readonly-permissions should successfully export cache with read-only directories", async () => {
1711
const writeStreams = new WriteStreamsMock();
18-
beforeAll(async () => {
19-
await fs.rm(`${cwd}/.gitlab-ci-local/cache/`, {recursive: true, force: true});
20-
21-
await handler({
22-
cwd,
23-
noColor: true,
24-
file: ".gitlab-ci.yml",
25-
}, writeStreams);
26-
});
12+
const stateDir = ".gitlab-ci-local-cache-docker-readonly-permissions";
13+
await handler({
14+
cwd: "tests/test-cases/cache-docker-readonly-permissions",
15+
noColor: true,
16+
file: ".gitlab-ci.yml",
17+
stateDir,
18+
}, writeStreams);
2719

28-
it("should successfully export cache with read-only directories", () => {
29-
expect(writeStreams.stdoutLines.join("\n")).toContain("produce-cache cache created in '.gitlab-ci-local/cache/default'");
30-
});
20+
expect(writeStreams.stdoutLines.join("\n")).toContain(`produce-cache cache created in '${stateDir}/cache/default'`);
3121
});

tests/test-cases/cache-paths-undefined-array/integration.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ beforeAll(() => {
88
initSpawnSpy(WhenStatics.all);
99
});
1010

11-
test("cache-paths-undefined-array <test-job>", async () => {
11+
test.concurrent("cache-paths-undefined-array <test-job>", async () => {
1212
const writeStreams = new WriteStreamsMock();
1313
await handler({
1414
cwd: "tests/test-cases/cache-paths-undefined-array",
1515
job: ["test-job"],
1616
maxJobNamePadding: 0,
17+
stateDir: ".gitlab-ci-local-cache-paths-undefined-array-test-job",
1718
}, writeStreams);
1819

1920

@@ -24,12 +25,13 @@ test("cache-paths-undefined-array <test-job>", async () => {
2425
});
2526

2627

27-
test("cache-paths-empty-object <test-job>", async () => {
28+
test.concurrent("cache-paths-empty-object <test-job>", async () => {
2829
const writeStreams = new WriteStreamsMock();
2930
await handler({
3031
cwd: "tests/test-cases/cache-paths-undefined-array",
3132
job: ["test-empty-cache-object"],
3233
maxJobNamePadding: 0,
34+
stateDir: ".gitlab-ci-local-cache-paths-empty-object-test-job",
3335
}, writeStreams);
3436

3537

tests/test-cases/concurrency/integration.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ beforeAll(() => {
88
initSpawnSpy(WhenStatics.all);
99
});
1010

11-
test("--concurrency 1 - should run sequentially", async () => {
11+
test.concurrent("--concurrency 1 - should run sequentially", async () => {
1212
const writeStreams = new WriteStreamsMock();
1313
await handler({
1414
cwd: "tests/test-cases/concurrency",
1515
concurrency: 1,
16+
stateDir: ".gitlab-ci-local-concurrency-1-should-run-sequentially",
1617
}, writeStreams);
1718

1819
const jobOneFinishedIndex = writeStreams.stdoutLines.findIndex((line) => {
@@ -27,10 +28,11 @@ test("--concurrency 1 - should run sequentially", async () => {
2728
expect(jobOneFinishedIndex + 1 === jobTwoStartingIndex).toBe(true);
2829
});
2930

30-
test("--concurrency not set", async () => {
31+
test.concurrent("--concurrency not set", async () => {
3132
const writeStreams = new WriteStreamsMock();
3233
await handler({
3334
cwd: "tests/test-cases/concurrency",
35+
stateDir: ".gitlab-ci-local-concurrency-not-set",
3436
}, writeStreams);
3537

3638
const jobOneStartingIndex = writeStreams.stdoutLines.findIndex((line) => {

tests/test-cases/coverage/integration.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,37 @@ beforeAll(() => {
88
initSpawnSpy(WhenStatics.all);
99
});
1010

11-
test("coverage <test-job>", async () => {
11+
test.concurrent("coverage <test-job>", async () => {
1212
const writeStreams = new WriteStreamsMock();
1313
await handler({
1414
cwd: "tests/test-cases/coverage",
1515
job: ["test-job"],
16+
stateDir: ".gitlab-ci-local-coverage-test-job",
1617
}, writeStreams);
1718

1819
const expected = [chalk`{black.bgGreenBright PASS } {blueBright test-job} 78.46% {gray coverage}`];
1920
expect(writeStreams.stdoutLines).toEqual(expect.arrayContaining(expected));
2021
});
2122

22-
test("coverage <import.meta.jest>", async () => {
23+
test.concurrent("coverage <import.meta.jest>", async () => {
2324
const writeStreams = new WriteStreamsMock();
2425
await handler({
2526
cwd: "tests/test-cases/coverage",
2627
job: ["import.meta.jest"],
28+
stateDir: ".gitlab-ci-local-coverage-import-meta-jest",
2729
}, writeStreams);
2830

2931
const expected = [chalk`{black.bgGreenBright PASS } {blueBright import.meta.jest} 97.91% {gray coverage}`];
3032
expect(writeStreams.stdoutLines).toEqual(expect.arrayContaining(expected));
3133
});
3234

33-
test("coverage <pcre regex>", async () => {
35+
test.concurrent("coverage <pcre regex>", async () => {
3436
const writeStreams = new WriteStreamsMock();
3537
await handler({
3638
cwd: "tests/test-cases/coverage",
3739
job: ["pcre regex"],
3840
noColor: true,
41+
stateDir: ".gitlab-ci-local-coverage-pcre-regex",
3942
}, writeStreams);
4043

4144
const expected = [chalk`{black.bgGreenBright PASS } {blueBright pcre regex} 100% {gray coverage}`];

0 commit comments

Comments
 (0)