Skip to content

Commit

Permalink
Add tests for DependencyGraph
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanZim committed Oct 8, 2020
1 parent 6181647 commit 5ee9d2f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
20 changes: 20 additions & 0 deletions lib/DependencyGraph.test.js
@@ -0,0 +1,20 @@
'use strict'
const test = require('ava')
const path = require('path')
const createDependencyGraph = require('./DependencyGraph.js')

function resolveArray(arr) {
return arr.map((p) => path.resolve(p))
}

test('tracks dependencies', (t) => {
const graph = createDependencyGraph()
graph.add({ file: 'aa', parent: 'a' })
graph.add({ file: 'bb', parent: 'b' })
graph.add({ file: 'ab', parent: 'a' })
graph.add({ file: 'ab', parent: 'b' })
t.deepEqual(graph.dependantsOf('aa'), resolveArray(['a']))
t.deepEqual(graph.dependantsOf('bb'), resolveArray(['b']))
t.deepEqual(graph.dependantsOf('ab'), resolveArray(['a', 'b']))
t.deepEqual(graph.dependantsOf('nonexistent'), [])
})
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -48,7 +48,8 @@
"files": [
"bin",
"index.js",
"lib"
"lib",
"!*.test.js"
],
"keywords": [
"cli",
Expand Down

0 comments on commit 5ee9d2f

Please sign in to comment.