|
| 1 | +const dependencyGraph = require('../lib/dependency-graph') |
| 2 | +const assert = require('assert') |
| 3 | +const {describe, it, before, after} = require('mocha') |
| 4 | +const rimraf = require('rimraf') |
| 5 | +const {resolve} = require('path') |
| 6 | +const {mkdirSync, writeFileSync, readFileSync, symlinkSync} = require('fs') |
| 7 | +describe('dependency-graph', () => { |
| 8 | + it('has entries set', () => { |
| 9 | + assert(dependencyGraph.entries instanceof Set) |
| 10 | + }) |
| 11 | + it('has dependencyGraph map', () => { |
| 12 | + assert(dependencyGraph.dependencyGraph instanceof Map) |
| 13 | + }) |
| 14 | + it('has imported function', () => { |
| 15 | + assert.equal(typeof dependencyGraph.imported, 'function') |
| 16 | + }) |
| 17 | + describe('imported', () => { |
| 18 | + before(() => { |
| 19 | + rimraf.sync('./fixtures') |
| 20 | + mkdirSync('./fixtures') |
| 21 | + writeFileSync('./fixtures/index.js', ``) |
| 22 | + writeFileSync('./fixtures/one.js', ``) |
| 23 | + symlinkSync('./fixtures/one.js', './fixtures/link.js') |
| 24 | + const graph = {imports: new Map(), exports: new Set()} |
| 25 | + graph.imports.set(resolve('./fixtures/one.js'), new Set(['a', 'b'])) |
| 26 | + dependencyGraph.dependencyGraph.set('./fixtures/index.js', graph) |
| 27 | + }) |
| 28 | + after(() => { |
| 29 | + rimraf.sync('./fixtures') |
| 30 | + dependencyGraph.dependencyGraph.clear() |
| 31 | + }) |
| 32 | + it('gathers all imported files from dependencyGraph', () => { |
| 33 | + const {filenames} = dependencyGraph.imported() |
| 34 | + assert.deepEqual([...filenames], [ |
| 35 | + resolve('./fixtures/one.js') |
| 36 | + ]) |
| 37 | + }) |
| 38 | + it('gathers all imported identifiers from dependencyGraph', () => { |
| 39 | + const {identifiers} = dependencyGraph.imported() |
| 40 | + assert.deepEqual([...identifiers], [ |
| 41 | + resolve('./fixtures/one.js#a'), |
| 42 | + resolve('./fixtures/one.js#b') |
| 43 | + ]) |
| 44 | + }) |
| 45 | + it('follows symlinks', () => { |
| 46 | + const graph = dependencyGraph.dependencyGraph.get('./fixtures/index.js') |
| 47 | + graph.imports.delete('./fixtures/one.js') |
| 48 | + graph.imports.set('./fixtures/link.js', new Set(['a', 'b'])) |
| 49 | + const {filenames} = dependencyGraph.imported() |
| 50 | + assert.deepEqual([...filenames], [ |
| 51 | + resolve('./fixtures/one.js'), |
| 52 | + ]) |
| 53 | + }) |
| 54 | + }) |
| 55 | +}) |
0 commit comments