-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add hasJoin function and fix hasCycle
- Loading branch information
Showing
5 changed files
with
93 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict'; | ||
|
||
/** | ||
* Calculate if the workflow contains a cycle, e.g. A -> B -> A | ||
* @method hasCycle | ||
* @param {Object} workflowGraph Graph representation of workflow | ||
* @return {Boolean} True if a cycle exists anywhere in the workflow | ||
*/ | ||
const hasJoin = workflowGraph => | ||
// Check from all the nodes to capture deteached workflows | ||
workflowGraph.edges.some(edge => edge.join); | ||
|
||
module.exports = hasJoin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
'use strict'; | ||
|
||
const assert = require('chai').assert; | ||
const hasJoin = require('../../lib/hasJoin'); | ||
|
||
describe('hasJoin', () => { | ||
it('should return true if a workflow has a join', () => { | ||
const workflow = { | ||
nodes: [ | ||
{ name: '~pr' }, | ||
{ name: '~commit' }, | ||
{ name: 'A' }, | ||
{ name: 'B' }, | ||
{ name: 'C' } | ||
], | ||
edges: [ | ||
{ src: '~commit', dest: 'A' }, // start | ||
{ src: 'A', dest: 'C', join: true }, // join | ||
{ src: 'B', dest: 'C', join: true } // join | ||
] | ||
}; | ||
|
||
assert.isTrue(hasJoin(workflow)); | ||
}); | ||
|
||
it('should return false if workflow has no join', () => { | ||
const workflow = { | ||
nodes: [ | ||
{ name: '~pr' }, | ||
{ name: '~commit' }, | ||
{ name: 'A' }, | ||
{ name: 'B' } | ||
], | ||
edges: [ | ||
{ src: '~commit', dest: 'A' }, // start | ||
{ src: 'A', dest: 'B' } // end | ||
] | ||
}; | ||
|
||
assert.isFalse(hasJoin(workflow)); | ||
}); | ||
}); |