From ced813388cf194e5b5adab299c0481e7e234269d Mon Sep 17 00:00:00 2001 From: Caitlin Potter Date: Tue, 7 Jul 2015 12:02:08 -0400 Subject: [PATCH] build(ci): check for ddescribe/iit in Travis-CI runs Prevent ddescribe()/iit() from sneaking in again Closes #3626. --- .travis.yml | 2 + gulp/tasks/ddescribe-iit.js | 97 +++++++++++++++++++++++++++++++++++++ gulp/tasks/validate.js | 2 +- 3 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 gulp/tasks/ddescribe-iit.js diff --git a/.travis.yml b/.travis.yml index 6487b9e5466..a1883f65e99 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,6 +17,8 @@ before_script: - git config --global user.name "ngMaterial Bot" script: + # Fail builds which use iit/ddescribe, but run the tests anyways + - gulp ddescribe-iit - gulp karma after_success: diff --git a/gulp/tasks/ddescribe-iit.js b/gulp/tasks/ddescribe-iit.js new file mode 100644 index 00000000000..a3d4b9b26c0 --- /dev/null +++ b/gulp/tasks/ddescribe-iit.js @@ -0,0 +1,97 @@ +var BUILD_MODE = require('../const').BUILD_MODE; + +var gulp = require('gulp'); +var PluginError = require('gulp-util').PluginError; +var path = require('path'); +var through2 = require('through2'); +var series = require('stream-series'); +var util = require('../util'); +var gulpif = require('gulp-if'); +var utils = require('../../scripts/gulp-utils.js'); + +var kDisallowedFunctions = [ + // Allow xit/xdescribe --- disabling tests is okay + 'fit', + 'iit', + //'xit', + 'fdescribe', + 'ddescribe', + //'xdescribe', + 'describe.only', + 'it.only' +]; + +function disallowedIndex(largeString, disallowedString) { + var notFunctionName = '[^A-Za-z0-9$_]'; + var regex = new RegExp('(^|' + notFunctionName + ')(' + disallowedString + ')' + notFunctionName + '*\\(', 'gm'); + var match = regex.exec(largeString); + // Return the match accounting for the first submatch length. + return match != null ? match.index + match[1].length : -1; +} + +function checkFile(fileContents, disallowed) { + var res = void 0; + if (Array.isArray(disallowed)) { + disallowed.forEach(function(str) { + var index = disallowedIndex(fileContents, str); + if (index !== -1) { + res = res || []; + res.push({ + str: str, + line: fileContents.substr(0, index).split('\n').length, + index: index + }); + } + }); + } + return res; +} + +exports.task = function() { + var failures = void 0; + return gulp.src(['src/**/*.spec.js', 'test/**/*-spec.js' ]) + .pipe(through2.obj(function(file, enc, next) { + var errors = checkFile(file.contents.toString(), kDisallowedFunctions); + if (errors) { + failures = failures || []; + failures.push({ + file: file, + contents: file.contents.toString(), + errors: errors + }); + } + next(); + }, function(callback) { + if (failures) { + var indented = true; + this.emit('error', new PluginError('ddescribe-iit', { + message: '\n' + failures.map(function(failure) { + var filename = path.relative(process.cwd(), failure.file.path); + var lines = failure.contents.split('\n'); + var start = 0; + var starts = lines.map(function(line) { var s = start; start += line.length + 1; return s; }); + return failure.errors.map(function(error) { + var line = lines[error.line - 1]; + var start = starts[error.line - 1]; + var col = (error.index - start); + var msg = ' `' + error.str + '` found at ' +filename + ':' + error.line + ':' + (col+1) + '\n' + + ' ' + line + '\n' + + ' ' + repeat(' ', col) + repeat('^', error.str.length); + return msg; + function repeat(c, len) { + var s = ''; + if (len > 0) { + for (var i = 0; i < len; ++i) { + s += c; + } + } + return s; + } + }).join('\n\n'); + }).join('\n\n'), + showStack: false + })); + } + callback(); + })); +}; diff --git a/gulp/tasks/validate.js b/gulp/tasks/validate.js index 132c7fbf7b2..e70bf6359d9 100644 --- a/gulp/tasks/validate.js +++ b/gulp/tasks/validate.js @@ -1 +1 @@ -exports.dependencies = ['jshint', 'karma']; +exports.dependencies = ['jshint', 'ddescribe-iit', 'karma'];