Skip to content

Commit c9aa098

Browse files
committed
clean up syntax_test.js
1 parent fb87442 commit c9aa098

File tree

1 file changed

+57
-50
lines changed

1 file changed

+57
-50
lines changed

test/syntax_test.js

Lines changed: 57 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -6,64 +6,71 @@ var glob = require('glob');
66

77
var constants = require('../tasks/util/constants');
88

9+
10+
// main
11+
assertJasmineSuites();
12+
assertHeaders();
13+
914
// check for for focus and exclude jasmine blocks
15+
function assertJasmineSuites() {
16+
var BLACK_LIST = ['fdescribe', 'fit', 'xdescribe', 'xit'];
17+
var testGlob = path.join(constants.pathToJasmineTests, '**/*.js');
18+
var bundleTestGlob = path.join(constants.pathToJasmineBundleTests, '**/*.js');
19+
var logs = [];
20+
21+
glob('{' + testGlob + ',' + bundleTestGlob + '}', function(err, files) {
22+
files.forEach(function(file) {
23+
var code = fs.readFileSync(file, 'utf-8');
24+
25+
falafel(code, {locations: true}, function(node) {
26+
if(node.type === 'Identifier' && BLACK_LIST.indexOf(node.name) !== -1) {
27+
logs.push([
28+
path.basename(file),
29+
'[line ' + node.loc.start.line + '] :',
30+
'contains either a *fdescribe*, *fit*,',
31+
'*xdescribe* or *xit* block.'
32+
].join(' '));
33+
}
34+
});
1035

11-
var BLACK_LIST = ['fdescribe', 'fit', 'xdescribe', 'xit'];
12-
var testGlob = path.join(constants.pathToJasmineTests, '**/*.js');
13-
var bundleTestGlob = path.join(constants.pathToJasmineBundleTests, '**/*.js');
14-
15-
var logsJasmine = [];
16-
glob('{' + testGlob + ',' + bundleTestGlob + '}', function(err, files) {
17-
files.forEach(function(file) {
18-
var code = fs.readFileSync(file, 'utf-8');
19-
20-
falafel(code, {locations: true}, function(node) {
21-
if(node.type === 'Identifier' && BLACK_LIST.indexOf(node.name) !== -1) {
22-
logsJasmine.push([
23-
path.basename(file),
24-
'[line ' + node.loc.start.line + '] :',
25-
'contains either a *fdescribe*, *fit*,',
26-
'*xdescribe* or *xit* block.'
27-
].join(' '));
28-
}
2936
});
3037

38+
if(logs.length) {
39+
throw new Error('\n' + logs.join('\n') + '\n');
40+
}
3141
});
32-
33-
if(logsJasmine.length) {
34-
throw new Error('\n' + logsJasmine.join('\n') + '\n');
35-
}
36-
});
42+
}
3743

3844
// check for header in src and lib files
45+
function assertHeaders() {
46+
var licenseSrc = constants.licenseSrc;
47+
var licenseStr = licenseSrc.substring(2, licenseSrc.length - 2);
48+
var srcGlob = path.join(constants.pathToSrc, '**/*.js');
49+
var libGlob = path.join(constants.pathToLib, '**/*.js');
50+
var logs = [];
51+
52+
glob('{' + srcGlob + ',' + libGlob + '}', function(err, files) {
53+
files.forEach(function(file) {
54+
var code = fs.readFileSync(file, 'utf-8');
55+
56+
// parse through code string while keeping track of comments
57+
var comments = [];
58+
falafel(code, {onComment: comments, locations: true}, function() {});
59+
60+
var header = comments[0];
61+
62+
if(!header || header.loc.start.line > 1) {
63+
logs.push(file + ' : has no header information.');
64+
return;
65+
}
3966

40-
var licenseSrc = constants.licenseSrc;
41-
var licenseStr = licenseSrc.substring(2, licenseSrc.length - 2);
42-
var srcGlob = path.join(constants.pathToSrc, '**/*.js');
43-
var libGlob = path.join(constants.pathToLib, '**/*.js');
44-
45-
var logsHeader = [];
46-
glob('{' + srcGlob + ',' + libGlob + '}', function(err, files) {
47-
files.forEach(function(file) {
48-
var code = fs.readFileSync(file, 'utf-8');
49-
50-
// parse through code string while keeping track of comments
51-
var comments = [];
52-
falafel(code, {onComment: comments, locations: true}, function() {});
53-
54-
var header = comments[0];
55-
56-
if(!header || header.loc.start.line > 1) {
57-
logsHeader.push(file + ' : has no header information.');
58-
return;
59-
}
67+
if(header.value !== licenseStr) {
68+
logs.push(file + ' : has incorrect header information.');
69+
}
70+
});
6071

61-
if(header.value !== licenseStr) {
62-
logsHeader.push(file + ' : has incorrect header information.');
72+
if(logs.length) {
73+
throw new Error('\n' + logs.join('\n') + '\n');
6374
}
6475
});
65-
66-
if(logsHeader.length) {
67-
throw new Error('\n' + logsHeader.join('\n') + '\n');
68-
}
69-
});
76+
}

0 commit comments

Comments
 (0)