|
| 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 | +// workflow:rules:variables should be applied as global variables when a rule matches |
| 11 | +test.concurrent("workflow-rules-variables are applied", async () => { |
| 12 | + const writeStreams = new WriteStreamsMock(); |
| 13 | + await handler({ |
| 14 | + cwd: "tests/test-cases/workflow-rules-variables", |
| 15 | + stateDir: ".gitlab-ci-local-workflow-rules-variables", |
| 16 | + }, writeStreams); |
| 17 | + |
| 18 | + const output = writeStreams.stdoutLines.join("\n"); |
| 19 | + expect(output).toContain("WORKFLOW_VAR=from-workflow-rules"); |
| 20 | +}); |
| 21 | + |
| 22 | +test.concurrent("workflow-rules-variables not applied when rule does not match", async () => { |
| 23 | + const writeStreams = new WriteStreamsMock(); |
| 24 | + await handler({ |
| 25 | + cwd: "tests/test-cases/workflow-rules-variables", |
| 26 | + file: ".gitlab-ci-no-match.yml", |
| 27 | + stateDir: ".gitlab-ci-local-workflow-rules-variables-no-match", |
| 28 | + }, writeStreams); |
| 29 | + |
| 30 | + const output = writeStreams.stdoutLines.join("\n"); |
| 31 | + expect(output).not.toContain("WORKFLOW_VAR=from-workflow-rules"); |
| 32 | +}); |
| 33 | + |
| 34 | +test.concurrent("workflow-rules-variables overridden by job variables", async () => { |
| 35 | + const writeStreams = new WriteStreamsMock(); |
| 36 | + await handler({ |
| 37 | + cwd: "tests/test-cases/workflow-rules-variables", |
| 38 | + file: ".gitlab-ci-job-override.yml", |
| 39 | + stateDir: ".gitlab-ci-local-workflow-rules-variables-job-override", |
| 40 | + }, writeStreams); |
| 41 | + |
| 42 | + const output = writeStreams.stdoutLines.join("\n"); |
| 43 | + expect(output).toContain("WORKFLOW_VAR=from-job"); |
| 44 | +}); |
0 commit comments