Skip to content

Commit cc2010f

Browse files
committed
test: cover comment directive anchoring
Asserts each @description lands on its own job, across a multi-line comment whose text contains a colon, a job name with spaces and one with a slash.
1 parent 9594ca5 commit cc2010f

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
# @Description Runs first
3+
firstjob:
4+
script:
5+
- echo "first"
6+
7+
# @Description Upload source maps. Opt in per brand:
8+
# sourcemaps:
9+
# extends: [.foo]
10+
sourcemaps:
11+
script:
12+
- echo "sourcemaps"
13+
14+
# @Description Deploys everything
15+
deploy to prod:
16+
script:
17+
- echo "deploy"
18+
19+
# @Description Builds the image
20+
build/image:
21+
script:
22+
- echo "build"
23+
24+
# @Description Runs the tests
25+
plainjob:
26+
script:
27+
- echo "test"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import {WriteStreamsMock} from "../../../src/write-streams.js";
2+
import {handler} from "../../../src/handler.js";
3+
import {initSpawnSpy} from "../../mocks/utils.mock.js";
4+
import {WhenStatics} from "../../mocks/when-statics.js";
5+
6+
beforeAll(() => {
7+
initSpawnSpy(WhenStatics.all);
8+
});
9+
10+
test.concurrent("comment-directive-anchor --list", async () => {
11+
const writeStreams = new WriteStreamsMock();
12+
await handler({
13+
cwd: "tests/test-cases/comment-directive-anchor/",
14+
list: true,
15+
noColor: true,
16+
stateDir: ".gitlab-ci-local-comment-directive-anchor",
17+
}, writeStreams);
18+
19+
const descriptionOf = (jobName: string) => {
20+
const line = writeStreams.stdoutLines.find(l => l.startsWith(`${jobName} `));
21+
expect(line, `no output line for job ${jobName}`).toBeDefined();
22+
return line!.slice(jobName.length).trimStart().replace(/\s{2,}.*$/, "");
23+
};
24+
25+
expect(descriptionOf("firstjob")).toBe("Runs first");
26+
expect(descriptionOf("sourcemaps")).toBe("Upload source maps. Opt in per brand:");
27+
expect(descriptionOf("deploy to prod")).toBe("Deploys everything");
28+
expect(descriptionOf("build/image")).toBe("Builds the image");
29+
expect(descriptionOf("plainjob")).toBe("Runs the tests");
30+
});

0 commit comments

Comments
 (0)