Skip to content

add check-header test #293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 29, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 40 additions & 5 deletions test/syntax_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ var glob = require('glob');

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

var BLACK_LIST = ['fdescribe', 'fit', 'xdescribe', 'xit'];
var logs = [];
// check for for focus and exclude jasmine blocks

var BLACK_LIST = ['fdescribe', 'fit', 'xdescribe', 'xit'];
var testGlob = path.join(constants.pathToJasmineTests, '**/*.js');
var bundleTestGlob = path.join(constants.pathToJasmineBundleTests, '**/*.js');


var logsJasmine = [];
glob('{' + 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([
logsJasmine.push([
path.basename(file),
'[line ' + node.loc.start.line + '] :',
'contains either a *fdescribe*, *fit*,',
Expand All @@ -30,5 +30,40 @@ glob('{' + testGlob + ',' + bundleTestGlob + '}', function(err, files) {

});

if(logs.length) throw new Error('\n' + logs.join('\n') + '\n');
if(logsJasmine.length) {
throw new Error('\n' + logsJasmine.join('\n') + '\n');
}
});

// check for header in src and lib files

var licenseSrc = constants.licenseSrc;
var licenseStr = licenseSrc.substring(2, licenseSrc.length - 2);
var srcGlob = path.join(constants.pathToSrc, '**/*.js');
var libGlob = path.join(constants.pathToLib, '**/*.js');

var logsHeader = [];
glob('{' + 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) {
logsHeader.push(file + ' : has no header information.');
return;
}

if(header.value !== licenseStr) {
logsHeader.push(file + ' : has incorrect header information.');
}
});

if(logsHeader.length) {
throw new Error('\n' + logsHeader.join('\n') + '\n');
}
});