-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
206 additions
and
199 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,127 +1,130 @@ | ||
var should = require('should'), | ||
madge = require('../lib/madge'); | ||
/* eslint-env mocha */ | ||
'use strict'; | ||
|
||
describe('module format (AMD)', function () { | ||
require('should'); | ||
const madge = require('../lib/madge'); | ||
|
||
it('should behave as expected on ok files', function () { | ||
describe('module format (AMD)', () => { | ||
|
||
it('should behave as expected on ok files', () => { | ||
madge([__dirname + '/files/amd/ok'], { | ||
format: 'amd' | ||
}).obj().should.eql({ 'a': [ 'sub/b' ], 'd': [], 'e': [ 'sub/c' ], 'sub/b': [ 'sub/c' ], 'sub/c': [ 'd' ] }); | ||
}).obj().should.eql({'a': ['sub/b'], 'd': [], 'e': ['sub/c'], 'sub/b': ['sub/c'], 'sub/c': ['d']}); | ||
}); | ||
|
||
it('should handle optimized files', function () { | ||
it('should handle optimized files', () => { | ||
madge([__dirname + '/files/amd/a-built.js'], { | ||
format: 'amd', | ||
optimized: true | ||
}).obj().should.eql({ 'a': [ 'sub/b' ], 'd': [], 'sub/b': [ 'sub/c' ], 'sub/c': [ 'd' ] }); | ||
}).obj().should.eql({'a': ['sub/b'], 'd': [], 'sub/b': ['sub/c'], 'sub/c': ['d']}); | ||
}); | ||
|
||
it('should handle optimized files originating with a `require` call', function() { | ||
it('should handle optimized files originating with a `require` call', () => { | ||
madge([__dirname + '/files/amd/b-built.js'], { | ||
format: 'amd', | ||
optimized: true, | ||
}).obj().should.eql({ '': [ 'sub/b' ], 'a': [], 'd': [], 'sub/b': [ 'sub/c' ], 'sub/c': [ 'd' ] }); | ||
optimized: true | ||
}).obj().should.eql({'': ['sub/b'], 'a': [], 'd': [], 'sub/b': ['sub/c'], 'sub/c': ['d']}); | ||
}); | ||
|
||
it('should handle optimized files originating with a `require` call and a designated main module', function() { | ||
it('should handle optimized files originating with a `require` call and a designated main module', () => { | ||
madge([__dirname + '/files/amd/b-built.js'], { | ||
format: 'amd', | ||
optimized: true, | ||
mainRequireModule: 'a' | ||
}).obj().should.eql({ 'a': [ 'sub/b' ], 'd': [], 'sub/b': [ 'sub/c' ], 'sub/c': [ 'd' ] }); | ||
}).obj().should.eql({'a': ['sub/b'], 'd': [], 'sub/b': ['sub/c'], 'sub/c': ['d']}); | ||
}); | ||
|
||
it('should merge in shim dependencies found in RequireJS config', function () { | ||
it('should merge in shim dependencies found in RequireJS config', () => { | ||
madge([__dirname + '/files/amd/requirejs/a.js'], { | ||
format: 'amd', | ||
requireConfig: __dirname + '/files/amd/requirejs/config.js' | ||
}).obj().should.eql({ 'a': [ 'jquery' ], 'jquery': [], 'jquery.foo': [ 'jquery' ], 'jquery.bar': [ 'jquery' ], 'baz': [ 'quux' ], 'quux': [] }); | ||
}).obj().should.eql({'a': ['jquery'], 'jquery': [], 'jquery.foo': ['jquery'], 'jquery.bar': ['jquery'], 'baz': ['quux'], 'quux': []}); | ||
}); | ||
|
||
it('should be able to exclude modules', function () { | ||
it('should be able to exclude modules', () => { | ||
madge([__dirname + '/files/amd/ok'], { | ||
format: 'amd', | ||
exclude: '^sub' | ||
}).obj().should.eql({ 'a': [], 'd': [], 'e': [] }); | ||
}).obj().should.eql({'a': [], 'd': [], 'e': []}); | ||
|
||
madge([__dirname + '/files/amd/ok'], { | ||
format: 'amd', | ||
exclude: '.*\/c$' | ||
}).obj().should.eql({ 'a': [ 'sub/b' ], 'd': [], 'e': [], 'sub/b': [] }); | ||
}).obj().should.eql({'a': ['sub/b'], 'd': [], 'e': [], 'sub/b': []}); | ||
|
||
madge([__dirname + '/files/amd/requirejs/a.js'], { | ||
format: 'amd', | ||
requireConfig: __dirname + '/files/amd/requirejs/config.js', | ||
exclude: '^jquery.foo|quux$' | ||
}).obj().should.eql({ a: [ 'jquery' ], 'jquery': [], 'jquery.bar': [ 'jquery' ] , 'baz': []}); | ||
}).obj().should.eql({a: ['jquery'], 'jquery': [], 'jquery.bar': ['jquery'], 'baz': []}); | ||
}); | ||
|
||
it('should tackle errors in files', function () { | ||
it('should tackle errors in files', () => { | ||
madge([__dirname + '/files/amd/error.js'], { | ||
format: 'amd' | ||
}).obj().should.eql({ error: [] }); | ||
}).obj().should.eql({error: []}); | ||
}); | ||
|
||
it('should handle named modules', function () { | ||
it('should handle named modules', () => { | ||
madge([__dirname + '/files/amd/namedWrapped/car.js'], { | ||
format: 'amd' | ||
}).obj().should.eql({ 'car': [ 'engine', 'wheels' ] }); | ||
}).obj().should.eql({'car': ['engine', 'wheels']}); | ||
}); | ||
|
||
it('should find circular dependencies', function () { | ||
it('should find circular dependencies', () => { | ||
madge([__dirname + '/files/amd/circular'], { | ||
format: 'amd' | ||
}).circular().getArray().should.eql([ ['a', 'c'], ['f', 'g', 'h'] ]); | ||
}).circular().getArray().should.eql([['a', 'c'], ['f', 'g', 'h']]); | ||
}); | ||
|
||
it('should find circular dependencies with relative paths', function () { | ||
it('should find circular dependencies with relative paths', () => { | ||
madge([__dirname + '/files/amd/circularRelative'], { | ||
format: 'amd' | ||
}).circular().getArray().should.eql([ [ 'a', 'foo/b' ] ]); | ||
}).circular().getArray().should.eql([['a', 'foo/b']]); | ||
}); | ||
|
||
it('should find circular dependencies with alias', function () { | ||
it('should find circular dependencies with alias', () => { | ||
madge([__dirname + '/files/amd/circularAlias'], { | ||
format: 'amd', | ||
requireConfig: __dirname + '/files/amd/circularAlias/config.js' | ||
}).circular().getArray().should.eql([ [ 'cpu', 'jsdos' ] ]); | ||
}).circular().getArray().should.eql([['cpu', 'jsdos']]); | ||
}); | ||
|
||
it('should find modules that depends on another', function () { | ||
it('should find modules that depends on another', () => { | ||
madge([__dirname + '/files/amd/ok'], { | ||
format: 'amd' | ||
}).depends('sub/c').should.eql([ 'e', 'sub/b' ]); | ||
}).depends('sub/c').should.eql(['e', 'sub/b']); | ||
}); | ||
|
||
it('should compile coffeescript on-the-fly', function () { | ||
it('should compile coffeescript on-the-fly', () => { | ||
madge([__dirname + '/files/amd/coffeescript'], { | ||
format: 'amd' | ||
}).obj().should.eql({ 'a': ['b'], 'b': [] }); | ||
}).obj().should.eql({'a': ['b'], 'b': []}); | ||
}); | ||
|
||
it('should resolve relative module indentifiers', function () { | ||
it('should resolve relative module indentifiers', () => { | ||
madge([__dirname + '/files/amd/relative'], { | ||
format: 'amd' | ||
}).obj().should.eql({ 'a': [], 'b': [ 'a' ], 'foo/bar/d': [ 'a' ], 'foo/c': [ 'a' ] }); | ||
}).obj().should.eql({'a': [], 'b': ['a'], 'foo/bar/d': ['a'], 'foo/c': ['a']}); | ||
}); | ||
|
||
it('should ignore plugins', function () { | ||
it('should ignore plugins', () => { | ||
madge([__dirname + '/files/amd/plugin.js'], { | ||
format: 'amd', | ||
breakOnError: true | ||
}).obj().should.eql({ plugin: [ 'ok/a' ] }); | ||
}).obj().should.eql({plugin: ['ok/a']}); | ||
}); | ||
|
||
it('should find nested dependencies', function () { | ||
it('should find nested dependencies', () => { | ||
madge([__dirname + '/files/amd/nested/main.js'], { | ||
format: 'amd', | ||
findNestedDependencies: true | ||
}).obj().should.eql({ 'main': ['a', 'b'] }); | ||
}).obj().should.eql({'main': ['a', 'b']}); | ||
}); | ||
|
||
it('should work for amd files with es6 code inside', function () { | ||
it('should work for amd files with es6 code inside', () => { | ||
madge([__dirname + '/files/amd/amdes6.js'], { | ||
format: 'amd' | ||
}).obj().should.eql({ 'amdes6': ['ok/a'] }); | ||
}).obj().should.eql({'amdes6': ['ok/a']}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,59 +1,61 @@ | ||
var should = require('should'), | ||
madge = require('../lib/madge'); | ||
/* eslint-env mocha */ | ||
'use strict'; | ||
|
||
describe('module format (CommonJS)', function () { | ||
const madge = require('../lib/madge'); | ||
require('should'); | ||
|
||
it('should behave as expected on ok files', function () { | ||
describe('module format (CommonJS)', () => { | ||
|
||
it('should behave as expected on ok files', () => { | ||
madge([__dirname + '/files/cjs/normal']) | ||
.obj().should.eql({ 'a': [ 'sub/b' ], 'fancy-main/not-index': [], 'd': [], 'sub/b': [ 'sub/c' ], 'sub/c': [ 'd' ] }); | ||
.obj().should.eql({'a': ['sub/b'], 'fancy-main/not-index': [], 'd': [], 'sub/b': ['sub/c'], 'sub/c': ['d']}); | ||
}); | ||
|
||
it('should handle expressions in require call', function () { | ||
it('should handle expressions in require call', () => { | ||
madge([__dirname + '/files/cjs/both.js']) | ||
.obj().should.eql({ 'both': [ 'node_modules/a', 'node_modules/b' ] }); | ||
.obj().should.eql({'both': ['node_modules/a', 'node_modules/b']}); | ||
}); | ||
|
||
it('should handle require call and chained functions', function () { | ||
it('should handle require call and chained functions', () => { | ||
madge([__dirname + '/files/cjs/chained.js']) | ||
.obj().should.eql({ 'chained': [ 'node_modules/a', 'node_modules/b', 'node_modules/c' ] }); | ||
.obj().should.eql({'chained': ['node_modules/a', 'node_modules/b', 'node_modules/c']}); | ||
}); | ||
|
||
it('should handle nested require call', function () { | ||
it('should handle nested require call', () => { | ||
madge([__dirname + '/files/cjs/nested.js']) | ||
.obj().should.eql({ 'nested': [ 'node_modules/a', 'node_modules/b', 'node_modules/c' ] }); | ||
.obj().should.eql({'nested': ['node_modules/a', 'node_modules/b', 'node_modules/c']}); | ||
}); | ||
|
||
it('should handle strings in require call', function () { | ||
it('should handle strings in require call', () => { | ||
madge([__dirname + '/files/cjs/strings.js']) | ||
.obj().should.eql({ strings: [ | ||
.obj().should.eql({strings: [ | ||
'events', 'node_modules/a', 'node_modules/b', 'node_modules/c', | ||
'node_modules/doom', 'node_modules/events2', 'node_modules/y' | ||
]}); | ||
}); | ||
|
||
it('should tackle errors in files', function () { | ||
it('should tackle errors in files', () => { | ||
madge([__dirname + '/files/cjs/error.js']) | ||
.obj().should.eql({ 'error': [] }); | ||
.obj().should.eql({'error': []}); | ||
}); | ||
|
||
it('should be able to exclude modules', function () { | ||
it('should be able to exclude modules', () => { | ||
madge([__dirname + '/files/cjs/normal'], { | ||
exclude: '^sub' | ||
}).obj().should.eql({ 'a': [], 'd': [], 'fancy-main/not-index': [] }); | ||
}).obj().should.eql({'a': [], 'd': [], 'fancy-main/not-index': []}); | ||
|
||
madge([__dirname + '/files/cjs/normal'], { | ||
exclude: '.*\/c$' | ||
}).obj().should.eql({ 'a': [ 'sub/b' ], 'd': [], 'sub/b': [], 'fancy-main/not-index': [], }); | ||
}).obj().should.eql({'a': ['sub/b'], 'd': [], 'sub/b': [], 'fancy-main/not-index': []}); | ||
}); | ||
|
||
it('should find circular dependencies', function () { | ||
it('should find circular dependencies', () => { | ||
madge([__dirname + '/files/cjs/circular']) | ||
.circular().getArray().should.eql([ ['a', 'b', 'c'] ]); | ||
.circular().getArray().should.eql([['a', 'b', 'c']]); | ||
}); | ||
|
||
it('should compile coffeescript on-the-fly', function () { | ||
it('should compile coffeescript on-the-fly', () => { | ||
madge([__dirname + '/files/cjs/coffeescript']) | ||
.obj().should.eql({ 'a': ['./b'], 'b': [] }); | ||
.obj().should.eql({'a': ['./b'], 'b': []}); | ||
}); | ||
|
||
}); | ||
}); |
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 |
---|---|---|
@@ -1,59 +1,71 @@ | ||
var should = require('should'), | ||
madge = require('../lib/madge'); | ||
|
||
describe('module format (ES6)', function () { | ||
|
||
it('should behave as expected on ok files', function () { | ||
madge([__dirname + '/files/es6/normal'], { | ||
format: 'es6' | ||
}).obj().should.eql({ 'a': [ 'sub/b' ], 'fancy-main/not-index': [], 'd': [], 'sub/b': [ 'sub/c' ], 'sub/c': [ 'd' ] }); | ||
}); | ||
|
||
it('should tackle errors in files', function () { | ||
madge([__dirname + '/files/es6/error.js'], { | ||
format: 'es6' | ||
}).obj().should.eql({ 'error': [] }); | ||
}); | ||
|
||
it('should be able to exclude modules', function () { | ||
madge([__dirname + '/files/es6/normal'], { | ||
exclude: '^sub', | ||
format: 'es6' | ||
}).obj().should.eql({ 'a': [], 'd': [], 'fancy-main/not-index': [] }); | ||
|
||
madge([__dirname + '/files/es6/normal'], { | ||
exclude: '.*\/c$', | ||
format: 'es6' | ||
}).obj().should.eql({ 'a': [ 'sub/b' ], 'd': [], 'sub/b': [], 'fancy-main/not-index': [], }); | ||
}); | ||
|
||
it('should find circular dependencies', function () { | ||
madge([__dirname + '/files/es6/circular'], { | ||
format: 'es6' | ||
}).circular().getArray().should.eql([ ['a', 'b', 'c'] ]); | ||
}); | ||
|
||
it('should find absolute imports from the root', function () { | ||
madge([__dirname + '/files/es6/absolute.js', __dirname + '/files/es6/absolute'], { | ||
format: 'es6' | ||
}).obj().should.eql({ 'absolute': [ 'absolute/a' ], 'absolute/a': [ 'absolute/b' ], 'absolute/b': [] }); | ||
}); | ||
|
||
it('should find imports on files with jsx', function() { | ||
var result = madge([__dirname + '/files/es6/jsx.js'], { | ||
format: 'es6' | ||
}).obj().should.eql({ 'jsx': [ 'absolute/b' ] }); | ||
}); | ||
|
||
it('should find imports on files with ES7', function() { | ||
madge([__dirname + '/files/es6/async.js'], { | ||
format: 'es6' | ||
}).obj().should.eql({ 'async': [ 'absolute/b' ] }); | ||
}); | ||
|
||
it('should support export x from "./file"', function() { | ||
madge([__dirname + '/files/es6/re-export'], { | ||
format: 'es6' | ||
}).obj().should.eql({ 'a': [], 'b-default': ['a'], 'b-named': ['a'], 'b-star': ['a'], 'c': ['b-default', 'b-named', 'b-star'] }); | ||
}); | ||
}); | ||
/* eslint-env mocha */ | ||
'use strict'; | ||
|
||
const madge = require('../lib/madge'); | ||
require('should'); | ||
|
||
describe('module format (ES6)', () => { | ||
|
||
it('should behave as expected on ok files', () => { | ||
madge([__dirname + '/files/es6/normal'], { | ||
format: 'es6' | ||
}).obj().should.eql({'a': ['sub/b'], 'fancy-main/not-index': [], 'd': [], 'sub/b': ['sub/c'], 'sub/c': ['d']}); | ||
}); | ||
|
||
it('should tackle errors in files', () => { | ||
madge([__dirname + '/files/es6/error.js'], { | ||
format: 'es6' | ||
}).obj().should.eql({'error': []}); | ||
}); | ||
|
||
it('should be able to exclude modules', () => { | ||
madge([__dirname + '/files/es6/normal'], { | ||
exclude: '^sub', | ||
format: 'es6' | ||
}).obj().should.eql({'a': [], 'd': [], 'fancy-main/not-index': []}); | ||
|
||
madge([__dirname + '/files/es6/normal'], { | ||
exclude: '.*\/c$', | ||
format: 'es6' | ||
}).obj().should.eql({'a': ['sub/b'], 'd': [], 'sub/b': [], 'fancy-main/not-index': []}); | ||
}); | ||
|
||
it('should find circular dependencies', () => { | ||
madge([__dirname + '/files/es6/circular'], { | ||
format: 'es6' | ||
}).circular().getArray().should.eql([['a', 'b', 'c']]); | ||
}); | ||
|
||
it('should find absolute imports from the root', () => { | ||
madge([__dirname + '/files/es6/absolute.js', __dirname + '/files/es6/absolute'], { | ||
format: 'es6' | ||
}).obj().should.eql({'absolute': ['absolute/a'], 'absolute/a': ['absolute/b'], 'absolute/b': []}); | ||
}); | ||
|
||
it('should find imports on files with jsx', () => { | ||
madge([__dirname + '/files/es6/jsx.js'], { | ||
format: 'es6' | ||
}).obj().should.eql({'jsx': ['absolute/b']}); | ||
}); | ||
|
||
it('should find imports on files with ES7', () => { | ||
madge([__dirname + '/files/es6/async.js'], { | ||
format: 'es6' | ||
}).obj().should.eql({'async': ['absolute/b']}); | ||
}); | ||
|
||
it('should support export x from "./file"', () => { | ||
madge([__dirname + '/files/es6/re-export'], { | ||
format: 'es6' | ||
}).obj().should.eql({'a': [], 'b-default': ['a'], 'b-named': ['a'], 'b-star': ['a'], 'c': ['b-default', 'b-named', 'b-star']}); | ||
}); | ||
|
||
it('can detect imports in JSX files', () => { | ||
madge([__dirname + '/files/es6/jsx/basic.jsx'], { | ||
format: 'es6' | ||
}).obj().should.eql({basic: [ | ||
'../../../../other', | ||
'../../../../react' | ||
]}); | ||
}); | ||
}); |
Oops, something went wrong.