UNPKG

1.77 kBJavaScriptView Raw
1/*eslint no-process-env: "off" */
2/*eslint no-console: "off" */
3const gulp = require('gulp');
4const mocha = require('gulp-mocha');
5const eslint = require('gulp-eslint');
6const istanbul = require('gulp-istanbul');
7const gulpExit = require('gulp-exit');
8const gulpIf = require('gulp-if');
9
10const isFixed = (file) => {
11 // Has ESLint fixed the file contents?
12 return file.eslint != null && file.eslint.fixed;
13};
14
15gulp.task('test:dirty', () => {
16 return gulp.src('tests/**/*.spec.js')
17 .pipe(mocha({reporter: 'spec'}))
18 .pipe(gulpExit());
19});
20
21const lint = () => {
22 return gulp.src([
23 '**/*.js',
24 '!node_modules/**',
25 '!coverage/**',
26 '!docker/**'
27 ])
28 .pipe(eslint({
29 fix: true,
30 verbose: true
31 }))
32 .pipe(eslint.format())
33 .pipe(eslint.failAfterError())
34 .once('error', () => {
35 console.error('lint failed');
36 process.exit(1);
37 })
38 .pipe(gulpIf(isFixed, gulp.dest('.')))
39 .once('end', () => {
40 process.exit();
41 });
42};
43
44gulp.task('lint', () => {
45 return lint();
46});
47
48gulp.task('pre-test', () => {
49 return gulp.src('app/**/*.js')
50 .pipe(istanbul())
51 .pipe(istanbul.hookRequire());
52});
53
54gulp.task('test:coverage', ['pre-test'], () => {
55 return gulp.src(['tests/**/*.spec.js'])
56 .pipe(mocha({reporter: 'spec'}))
57 .pipe(istanbul.writeReports({
58 reporters: [
59 'text',
60 'html',
61 'lcov'
62 ]
63 }))
64 .pipe(istanbul.enforceThresholds({
65 thresholds: {
66 lines: 80,
67 branches: 65,
68 functions: 80,
69 statements: 80
70 }
71 }))
72 .once('error', () => {
73 console.error('coverage failed');
74 process.exit(1);
75 });
76});
77
78gulp.task('test:lint', ['test:coverage'], () => {
79 return lint();
80});
81
82gulp.task('test', ['test:lint'], () => {
83 return gulp.src(['*.js']);
84});
\No newline at end of file