forked from plotly/plotly.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyntax_test.js
More file actions
106 lines (82 loc) · 2.95 KB
/
Copy pathsyntax_test.js
File metadata and controls
106 lines (82 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
var path = require('path');
var fs = require('fs');
var falafel = require('falafel');
var glob = require('glob');
var constants = require('../tasks/util/constants');
var srcGlob = path.join(constants.pathToSrc, '**/*.js');
var libGlob = path.join(constants.pathToLib, '**/*.js');
var testGlob = path.join(constants.pathToJasmineTests, '**/*.js');
var bundleTestGlob = path.join(constants.pathToJasmineBundleTests, '**/*.js');
// main
assertJasmineSuites();
assertHeaders();
assertFileNames();
// check for for focus and exclude jasmine blocks
function assertJasmineSuites() {
var BLACK_LIST = ['fdescribe', 'fit', 'xdescribe', 'xit'];
var logs = [];
glob(combineGlobs([testGlob, bundleTestGlob]), function(err, files) {
files.forEach(function(file) {
var code = fs.readFileSync(file, 'utf-8');
falafel(code, {locations: true}, function(node) {
if(node.type === 'Identifier' && BLACK_LIST.indexOf(node.name) !== -1) {
logs.push([
path.basename(file),
'[line ' + node.loc.start.line + '] :',
'contains either a *fdescribe*, *fit*,',
'*xdescribe* or *xit* block.'
].join(' '));
}
});
});
log(logs);
});
}
// check for header in src and lib files
function assertHeaders() {
var licenseSrc = constants.licenseSrc;
var licenseStr = licenseSrc.substring(2, licenseSrc.length - 2);
var logs = [];
glob(combineGlobs([srcGlob, libGlob]), function(err, files) {
files.forEach(function(file) {
var code = fs.readFileSync(file, 'utf-8');
// parse through code string while keeping track of comments
var comments = [];
falafel(code, {onComment: comments, locations: true}, function() {});
var header = comments[0];
if(!header || header.loc.start.line > 1) {
logs.push(file + ' : has no header information.');
return;
}
if(header.value !== licenseStr) {
logs.push(file + ' : has incorrect header information.');
}
});
log(logs);
});
}
// check that all file names are in lower case
function assertFileNames() {
var logs = [];
glob(combineGlobs([srcGlob, libGlob, testGlob, bundleTestGlob]), function(err, files) {
files.forEach(function(file) {
var base = path.basename(file);
if(base !== base.toLowerCase()) {
logs.push([
file, ' :',
'has a file name containing some',
'non-lower-case characters'
]);
}
});
log(logs);
});
}
function combineGlobs(arr) {
return '{' + arr.join(',') + '}';
}
function log(logs) {
if(logs.length) {
throw new Error('\n' + logs.join('\n') + '\n');
}
}