From a006590c2985e0c0726eb104eccf36c07276e6ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Mon, 29 Feb 2016 14:03:48 -0500 Subject: [PATCH] add check-header test --- test/syntax_test.js | 45 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/test/syntax_test.js b/test/syntax_test.js index ea9f744dc75..3f0a0e5bb70 100644 --- a/test/syntax_test.js +++ b/test/syntax_test.js @@ -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*,', @@ -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'); + } });