FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add tests for DependencyGraph by RyanZim · Pull Request #354 · postcss/postcss-cli · GitHub

Repository navigation

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

Filter by extension

Filter by extension .js  (4) .json  (1) All 2 file types selected
Only manifest files
Deleted files Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
3 changes: 2 additions & 1 deletion index.js
This file contains hidden or 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
Expand Up @@ -15,8 +15,9 @@ const postcssrc = require('postcss-load-config')
const reporter = require('postcss-reporter/lib/formatter')()

const argv = require('./lib/args')
const depGraph = require('./lib/depGraph')
const createDependencyGraph = require('./lib/DependencyGraph')
const getMapfile = require('./lib/getMapfile')
const depGraph = createDependencyGraph()

let input = argv._
const { dir, output } = argv
Expand Down
24 changes: 24 additions & 0 deletions lib/DependencyGraph.js
This file contains hidden or 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,24 @@
'use strict'
const path = require('path')
const { DepGraph } = require('dependency-graph')

module.exports = function () {
const graph = new DepGraph()
return {
add(message) {
message.parent = path.resolve(message.parent)
message.file = path.resolve(message.file)

graph.addNode(message.parent)
graph.addNode(message.file)
graph.addDependency(message.parent, message.file)
return message
},
dependantsOf(node) {
node = path.resolve(node)

if (graph.hasNode(node)) return graph.dependantsOf(node)
return []
},
}
}
20 changes: 20 additions & 0 deletions lib/DependencyGraph.test.js
This file contains hidden or 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,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'), [])
})
22 changes: 0 additions & 22 deletions lib/depGraph.js

This file was deleted.

3 changes: 2 additions & 1 deletion package.json
This file contains hidden or 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
Expand Up @@ -48,7 +48,8 @@
"files": [
"bin",
"index.js",
"lib"
"lib",
"!*.test.js"
],
"keywords": [
"cli",
Expand Down

Back | FazBrowse Home | New Git URL