Skip to content

Commit

Permalink
Cleanup in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pahen committed Aug 29, 2016
1 parent 9e50f29 commit 75dce71
Show file tree
Hide file tree
Showing 150 changed files with 152 additions and 542 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Read the [changelog](CHANGELOG.md) for latest changes.

## Examples

> Graph generated from the madge's own code and dependencies.
> Graph generated from madge's own code and dependencies.
<a href="http://pahen.github.io/madge/madge.svg">
<img src="http://pahen.github.io/madge/madge.svg" width="888"/>
Expand Down Expand Up @@ -129,6 +129,9 @@ const madge = require('madge');

madge('path/to/app.js')
.then((res) => res.image('path/to/image.svg'))
.then((writtenImagePath) => {
console.log('Image written to ' + writtenImagePath);
});
});
```

Expand Down
8 changes: 5 additions & 3 deletions lib/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,24 @@ function checkGraphvizInstalled(config) {
* @return {Object}
*/
function createGraphvizOptions(config) {
const graphVizOptions = config.graphVizOptions || {};

return {
G: Object.assign({
overlap: false,
pad: 0.111,
layout: config.layout,
bgcolor: config.backgroundColor
}, config.graphVizOptions.G),
}, graphVizOptions.G),
E: Object.assign({
color: config.edgeColor
}, config.graphVizOptions.E),
}, graphVizOptions.E),
N: Object.assign({
fontname: config.fontName,
fontsize: config.fontSize,
color: config.nodeColor,
fontcolor: config.nodeColor
}, config.graphVizOptions.N)
}, graphVizOptions.N)
};
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"lint": "eslint bin/cli.js lib test/*.js",
"debug": "node bin/cli.js --debug bin lib",
"generate": "npm run generate:small && npm run generate:madge",
"generate:small": "bin/cli.js --image /tmp/simple.svg test/files/cjs/circular/a.js",
"generate:small": "bin/cli.js --image /tmp/simple.svg test/commonjs/circular/a.js",
"generate:madge": "bin/cli.js --image /tmp/madge.svg bin lib"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion test/amd.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const madge = require('../lib/api');
require('should');

describe('AMD', () => {
const dir = __dirname + '/files/amd';
const dir = __dirname + '/amd';

it('finds recursive dependencies', (done) => {
madge(dir + '/ok/a.js').then((res) => {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
36 changes: 18 additions & 18 deletions test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ const madge = require('../lib/api');

require('should');

describe('Madge', () => {
describe('API', () => {
it('throws error on missing path argument', () => {
(() => {
madge();
}).should.throw('path argument not provided');
});

it('returns a Promise', () => {
madge(__dirname + '/files/cjs/a.js').should.be.Promise(); // eslint-disable-line new-cap
madge(__dirname + '/commonjs/a.js').should.be.Promise(); // eslint-disable-line new-cap
});

it('throws error if file or directory does not exists', (done) => {
Expand All @@ -27,7 +27,7 @@ describe('Madge', () => {
});

it('takes single file as path', (done) => {
madge(__dirname + '/files/cjs/a.js').then((res) => {
madge(__dirname + '/commonjs/a.js').then((res) => {
res.obj().should.eql({
'a': ['b', 'c'],
'b': ['c'],
Expand All @@ -38,7 +38,7 @@ describe('Madge', () => {
});

it('takes an array of files as path and combines the result', (done) => {
madge([__dirname + '/files/cjs/a.js', __dirname + '/files/cjs/normal/d.js']).then((res) => {
madge([__dirname + '/commonjs/a.js', __dirname + '/commonjs/normal/d.js']).then((res) => {
res.obj().should.eql({
'a': ['b', 'c'],
'b': ['c'],
Expand All @@ -50,7 +50,7 @@ describe('Madge', () => {
});

it('take a single directory as path and find files in it', (done) => {
madge(__dirname + '/files/cjs/normal').then((res) => {
madge(__dirname + '/commonjs/normal').then((res) => {
res.obj().should.eql({
'a': ['sub/b'],
'd': [],
Expand All @@ -62,7 +62,7 @@ describe('Madge', () => {
});

it('takes an array of directories as path and compute the basedir correctly', (done) => {
madge([__dirname + '/files/cjs/multibase/1', __dirname + '/files/cjs/multibase/2']).then((res) => {
madge([__dirname + '/commonjs/multibase/1', __dirname + '/commonjs/multibase/2']).then((res) => {
res.obj().should.eql({
'1/a': [],
'2/b': []
Expand All @@ -72,7 +72,7 @@ describe('Madge', () => {
});

it('can exclude modules using RegExp', (done) => {
madge(__dirname + '/files/cjs/a.js', {
madge(__dirname + '/commonjs/a.js', {
excludeRegExp: ['^b$']
}).then((res) => {
res.obj().should.eql({
Expand All @@ -83,9 +83,9 @@ describe('Madge', () => {
}).catch(done);
});

describe('#obj', () => {
describe('obj()', () => {
it('returns dependency object', (done) => {
madge(__dirname + '/files/cjs/a.js').then((res) => {
madge(__dirname + '/commonjs/a.js').then((res) => {
res.obj().should.eql({
a: ['b', 'c'],
b: ['c'],
Expand All @@ -96,9 +96,9 @@ describe('Madge', () => {
});
});

describe('#dot', () => {
describe('dot()', () => {
it('returns a promise resolved with graphviz DOT output', (done) => {
madge(__dirname + '/files/cjs/b.js')
madge(__dirname + '/commonjs/b.js')
.then((res) => res.dot())
.then((output) => {
output.should.eql('digraph G {\n "b";\n "c";\n "b" -> "c";\n}\n');
Expand All @@ -108,16 +108,16 @@ describe('Madge', () => {
});
});

describe('#depends', () => {
describe('depends()', () => {
it('returns modules that depends on another', (done) => {
madge(__dirname + '/files/cjs/a.js').then((res) => {
madge(__dirname + '/commonjs/a.js').then((res) => {
res.depends('c').should.eql(['a', 'b']);
done();
}).catch(done);
});
});

describe('#image', () => {
describe('image()', () => {
let imagePath;

beforeEach(() => {
Expand All @@ -129,7 +129,7 @@ describe('Madge', () => {
});

it('rejects if a filename is not supplied', (done) => {
madge(__dirname + '/files/cjs/a.js')
madge(__dirname + '/commonjs/a.js')
.then((res) => res.image())
.catch((err) => {
err.message.should.eql('imagePath not provided');
Expand All @@ -138,7 +138,7 @@ describe('Madge', () => {
});

it('rejects on unsupported image format', (done) => {
madge(__dirname + '/files/cjs/a.js')
madge(__dirname + '/commonjs/a.js')
.then((res) => res.image('image.zyx'))
.catch((err) => {
err.message.should.match(/Format: "zyx" not recognized/);
Expand All @@ -147,7 +147,7 @@ describe('Madge', () => {
});

it('rejects if graphviz is not installed', (done) => {
madge(__dirname + '/files/cjs/a.js', {graphVizPath: '/invalid/path'})
madge(__dirname + '/commonjs/a.js', {graphVizPath: '/invalid/path'})
.then((res) => res.image('image.png'))
.catch((err) => {
err.message.should.match(/Could not execute .*gvpr \-V/);
Expand All @@ -156,7 +156,7 @@ describe('Madge', () => {
});

it('writes image to file', (done) => {
madge(__dirname + '/files/cjs/a.js')
madge(__dirname + '/commonjs/a.js')
.then((res) => res.image(imagePath))
.then((writtenImagePath) => {
writtenImagePath.should.eql(imagePath);
Expand Down
2 changes: 1 addition & 1 deletion test/cjs.js → test/commonjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const madge = require('../lib/api');
require('should');

describe('CommonJS', () => {
const dir = __dirname + '/files/cjs';
const dir = __dirname + '/commonjs';

it('finds recursive dependencies', (done) => {
madge(dir + '/normal/a.js').then((res) => {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
52 changes: 11 additions & 41 deletions test/es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,17 @@ const madge = require('../lib/api');
require('should');

describe('ES6', () => {
const dir = __dirname + '/files/es6';
const dir = __dirname + '/es6';

it('extracts dependencies', (done) => {
madge(dir + '/absolute.js').then((res) => {
res.obj().should.eql({
'absolute': ['absolute/a'],
'absolute/a': []
});
done();
}).catch(done);
});

it('finds circular dependencies', (done) => {
madge(dir + '/circular/a.js').then((res) => {
Expand All @@ -25,26 +35,6 @@ describe('ES6', () => {
}).catch(done);
});

it('finds absolute imports from the root', (done) => {
madge(dir + '/absolute.js').then((res) => {
res.obj().should.eql({
'absolute': ['absolute/a'],
'absolute/a': []
});
done();
}).catch(done);
});

it('finds imports on files with ES7', (done) => {
madge(dir + '/async.js').then((res) => {
res.obj().should.eql({
'absolute/b': [],
'async': ['absolute/b']
});
done();
}).catch(done);
});

it('supports export x from "./file"', (done) => {
madge(dir + '/re-export/c.js').then((res) => {
res.obj().should.eql({
Expand All @@ -61,24 +51,4 @@ describe('ES6', () => {
done();
}).catch(done);
});

it('finds imports on files with JSX content', (done) => {
madge(dir + '/jsx.js').then((res) => {
res.obj().should.eql({
'jsx': ['absolute/b'],
'absolute/b': []
});
done();
}).catch(done);
});

it('finds import in JSX files', (done) => {
madge(dir + '/jsx/basic.jsx').then((res) => {
res.obj().should.eql({
'basic': ['other'],
'other': []
});
done();
}).catch(done);
});
});
File renamed without changes.
3 changes: 3 additions & 0 deletions test/es6/absolute/a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import {B} from 'test/es6/absolute/b';

export const A = 'A';
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
19 changes: 19 additions & 0 deletions test/es7.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* eslint-env mocha */
'use strict';

const madge = require('../lib/api');
require('should');

describe('ES7', () => {
const dir = __dirname + '/es7';

it('extracts dependencies', (done) => {
madge(dir + '/async.js').then((res) => {
res.obj().should.eql({
'other': [],
'async': ['other']
});
done();
}).catch(done);
});
});
2 changes: 2 additions & 0 deletions test/es7/async.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import {OTHER} from './other';
async function foo() {}
File renamed without changes.
1 change: 0 additions & 1 deletion test/files/amd/a-built.js

This file was deleted.

3 changes: 0 additions & 3 deletions test/files/amd/anon/a.js

This file was deleted.

6 changes: 0 additions & 6 deletions test/files/amd/anon/b.js

This file was deleted.

32 changes: 0 additions & 32 deletions test/files/amd/anon/circular-tests.js

This file was deleted.

13 changes: 0 additions & 13 deletions test/files/amd/anon/circular.html

This file was deleted.

11 changes: 0 additions & 11 deletions test/files/amd/anon/funcFour.js

This file was deleted.

Loading

0 comments on commit 75dce71

Please sign in to comment.