Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/data-expander.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,10 @@ export function needsComplex (data: any) {
export function needsEach (jobName: string, gitlabData: any) {
const jobData = gitlabData[jobName];
if (!jobData.needs) return;
assert(Array.isArray(jobData.needs), chalk`{blueBright ${jobName}} {yellow needs:} must be an array`);
Comment thread
firecow marked this conversation as resolved.

for (const [i, n] of Object.entries<any>(jobData.needs)) {
assert(n != null, chalk`{blueBright ${jobName}} {yellow needs:} entries cannot be empty`);
jobData.needs[i] = needsComplex(n);
}
}
Expand Down
10 changes: 10 additions & 0 deletions tests/test-cases/needs-empty-entry/.gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
build-job:
script:
- echo "build"

dev-job:
needs:
- ~
script:
- echo "dev"
18 changes: 18 additions & 0 deletions tests/test-cases/needs-empty-entry/integration.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {WriteStreamsMock} from "../../../src/write-streams.js";
import {handler} from "../../../src/handler.js";
import {initSpawnSpy} from "../../mocks/utils.mock.js";
import {WhenStatics} from "../../mocks/when-statics.js";
import chalk from "chalk-template";

beforeAll(() => {
initSpawnSpy(WhenStatics.all);
});

test.concurrent("needs-empty-entry <dev-job>", async () => {
const writeStreams = new WriteStreamsMock();

await expect(handler({
cwd: "tests/test-cases/needs-empty-entry",
stateDir: ".gitlab-ci-local-needs-empty-entry",
}, writeStreams)).rejects.toThrow(chalk`{blueBright dev-job} {yellow needs:} entries cannot be empty`);
});
9 changes: 9 additions & 0 deletions tests/test-cases/needs-not-array/.gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
build-job:
script:
- echo "build"

dev-job:
needs: build-job
script:
- echo "dev"
18 changes: 18 additions & 0 deletions tests/test-cases/needs-not-array/integration.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {WriteStreamsMock} from "../../../src/write-streams.js";
import {handler} from "../../../src/handler.js";
import {initSpawnSpy} from "../../mocks/utils.mock.js";
import {WhenStatics} from "../../mocks/when-statics.js";
import chalk from "chalk-template";

beforeAll(() => {
initSpawnSpy(WhenStatics.all);
});

test.concurrent("needs-not-array <dev-job>", async () => {
const writeStreams = new WriteStreamsMock();

await expect(handler({
cwd: "tests/test-cases/needs-not-array",
stateDir: ".gitlab-ci-local-needs-not-array",
}, writeStreams)).rejects.toThrow(chalk`{blueBright dev-job} {yellow needs:} must be an array`);
});