|
| 1 | +/* |
| 2 | + * Copyright (C) 2013 Conjur Inc |
| 3 | + * |
| 4 | + * Permission is hereby granted, free of charge, to any person obtaining a copy of |
| 5 | + * this software and associated documentation files (the "Software"), to deal in |
| 6 | + * the Software without restriction, including without limitation the rights to |
| 7 | + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
| 8 | + * the Software, and to permit persons to whom the Software is furnished to do so, |
| 9 | + * subject to the following conditions: |
| 10 | + * |
| 11 | + * The above copyright notice and this permission notice shall be included in all |
| 12 | + * copies or substantial portions of the Software. |
| 13 | + * |
| 14 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
| 16 | + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
| 17 | + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
| 18 | + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 19 | + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 20 | + */ |
| 21 | + |
| 22 | +"use strict"; |
| 23 | + |
| 24 | +var gulp = require('gulp'), |
| 25 | + jslint = require('gulp-jslint'), |
| 26 | + mocha = require('gulp-mocha'), |
| 27 | + silenceLogger = require('./testconfig'); |
| 28 | + |
| 29 | +require('coffee-script/register'); |
| 30 | + |
| 31 | +var sources = ['lib/**/*.js']; |
| 32 | +var tests = ['test/**/*_test.coffee']; |
| 33 | + |
| 34 | + |
| 35 | +function chooseMochaReporter(){ |
| 36 | + // if TEST_REPORTER is set, use that |
| 37 | + if(process.env.TEST_REPORTER){ |
| 38 | + return process.env.TEST_REPORTER; |
| 39 | + } |
| 40 | + |
| 41 | + if(process.stdout.isTTY){ |
| 42 | + // use the always popular nyancat reporter if we're |
| 43 | + // in someones terminal |
| 44 | + return 'nyan'; |
| 45 | + } |
| 46 | + // spec is a useful format, and looks good whether or not you're |
| 47 | + // in a terminal. |
| 48 | + return 'spec'; |
| 49 | +} |
| 50 | + |
| 51 | + |
| 52 | + |
| 53 | +var mochaOpts = { |
| 54 | + reporter: chooseMochaReporter() |
| 55 | +}; |
| 56 | + |
| 57 | +var jslintOpts = { |
| 58 | + // assume node.js |
| 59 | + node: true, |
| 60 | + // don't worry about sloppy whitespace |
| 61 | + white: true, |
| 62 | + // this one makes regexps of any kind impossible to use, |
| 63 | + // for example it calls "." insecure, as well as "^", even |
| 64 | + // when using it in a character class like "[^foo]". |
| 65 | + regexp: true, |
| 66 | + // This one makes maintaining backwards compatibility more or less impossible. |
| 67 | + // See the xyzUrl functions in lib/config.js |
| 68 | + unparam: true, |
| 69 | + // don't print successes |
| 70 | + errorsOnly: true |
| 71 | +}; |
| 72 | + |
| 73 | + |
| 74 | +gulp.task('lint', function(){ |
| 75 | + return gulp.src(sources) |
| 76 | + .pipe(jslint(jslintOpts)); |
| 77 | +}); |
| 78 | + |
| 79 | +gulp.task('test', function(){ |
| 80 | + silenceLogger(); |
| 81 | + return gulp.src(tests, {read: false}) |
| 82 | + .pipe(mocha(mochaOpts)); |
| 83 | +}); |
| 84 | + |
| 85 | +gulp.task('default', ['lint', 'test']); |
| 86 | + |
| 87 | +gulp.task('watch', function(){ |
| 88 | + gulp.watch(['lib/**/*.js', 'test/**/*.coffee', 'gulpfile.js'], ['default']); |
| 89 | +}); |
0 commit comments