Skip to content

Commit fd6ba1d

Browse files
authored
Merge pull request #872 from plotly/try-madge
Add madge check for circular dependencies on test-syntax
2 parents ce8674f + 70cd8b5 commit fd6ba1d

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
"karma-coverage": "^1.0.0",
106106
"karma-firefox-launcher": "^1.0.0",
107107
"karma-jasmine": "^1.0.2",
108+
"madge": "^0.6.0",
108109
"node-sass": "^3.4.1",
109110
"npm-link-check": "^1.1.0",
110111
"open": "0.0.5",

tasks/test_syntax.js

+27-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var fs = require('fs');
33

44
var falafel = require('falafel');
55
var glob = require('glob');
6+
var madge = require('madge');
67

78
var constants = require('./util/constants');
89
var srcGlob = path.join(constants.pathToSrc, '**/*.js');
@@ -14,6 +15,7 @@ var bundleTestGlob = path.join(constants.pathToJasmineBundleTests, '**/*.js');
1415
assertJasmineSuites();
1516
assertHeaders();
1617
assertFileNames();
18+
assertCircularDeps();
1719

1820

1921
// check for for focus and exclude jasmine blocks
@@ -38,7 +40,7 @@ function assertJasmineSuites() {
3840

3941
});
4042

41-
log(logs);
43+
log('no jasmine suites focus/exclude blocks', logs);
4244
});
4345
}
4446

@@ -68,7 +70,7 @@ function assertHeaders() {
6870
}
6971
});
7072

71-
log(logs);
73+
log('correct headers in lib/ and src/', logs);
7274
});
7375
}
7476

@@ -89,17 +91,38 @@ function assertFileNames() {
8991
}
9092
});
9193

92-
log(logs);
94+
log('lower case only file names', logs);
9395
});
9496

9597
}
9698

99+
// check circular dependencies
100+
function assertCircularDeps() {
101+
var dependencyObject = madge(constants.pathToSrc);
102+
var circularDeps = dependencyObject.circular().getArray();
103+
var logs = [];
104+
105+
// as of v1.17.0 - 2016/09/08
106+
// see https://github.com/plotly/plotly.js/milestone/9
107+
// for more details
108+
var MAX_ALLOWED_CIRCULAR_DEPS = 33;
109+
110+
if(circularDeps.length > MAX_ALLOWED_CIRCULAR_DEPS) {
111+
logs.push('some new circular dependencies were added to src/');
112+
}
113+
114+
log('circular dependencies', logs);
115+
}
116+
97117
function combineGlobs(arr) {
98118
return '{' + arr.join(',') + '}';
99119
}
100120

101-
function log(logs) {
121+
function log(name, logs) {
102122
if(logs.length) {
123+
console.error('test-syntax error [' + name + ']\n');
103124
throw new Error('\n' + logs.join('\n') + '\n');
104125
}
126+
127+
console.log('ok ' + name);
105128
}

0 commit comments

Comments
 (0)