Skip to content

Commit 93e2e1e

Browse files
committed
fix: allow empty task list in graph builder
Signed-off-by: Jean-Baptiste Bianchi <jb.bianchi@neuroglia.io>
1 parent 68cd1e7 commit 93e2e1e

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/lib/graph-builder.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,12 @@ function getNextTask(
209209
taskName: string | undefined = undefined,
210210
transition: string | undefined = undefined,
211211
): TransitionInfo {
212-
if (!tasksList?.size) throw new Error('The task list cannot be empty. No tasks list to get the next task from.');
212+
if (!tasksList?.size) {
213+
return {
214+
name: FlowDirective.Exit,
215+
index: -1,
216+
};
217+
}
213218
const currentTask: Task | undefined = tasksList.get(taskName || '');
214219
transition = transition || currentTask?.then || '';
215220
if (transition == FlowDirective.End || transition == FlowDirective.Exit) {

tests/graph/graph.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,11 @@ do:
136136
expect(forSubgraph.nodes.length).toBe(3); // entry --> waitForCheckup --> exit
137137
expect(forSubgraph.edges.length).toBe(2);
138138
});
139+
140+
it('should build an empty graph', () => {
141+
const graph = buildGraph({} as Specification.Workflow);
142+
expect(graph).toBeDefined();
143+
expect(graph.nodes.length).toBe(2); // start --> end
144+
expect(graph.edges.length).toBe(1);
145+
});
139146
});

0 commit comments

Comments
 (0)