1 |
|
2 |
|
3 | const gulp = require('gulp');
|
4 | const mocha = require('gulp-mocha');
|
5 | const eslint = require('gulp-eslint');
|
6 | const istanbul = require('gulp-istanbul');
|
7 | const gulpExit = require('gulp-exit');
|
8 | const gulpIf = require('gulp-if');
|
9 |
|
10 | const isFixed = (file) => {
|
11 |
|
12 | return file.eslint != null && file.eslint.fixed;
|
13 | };
|
14 |
|
15 | gulp.task('test:dirty', () => {
|
16 | return gulp.src('tests/**/*.spec.js')
|
17 | .pipe(mocha({reporter: 'spec'}))
|
18 | .pipe(gulpExit());
|
19 | });
|
20 |
|
21 | const 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 |
|
44 | gulp.task('lint', () => {
|
45 | return lint();
|
46 | });
|
47 |
|
48 | gulp.task('pre-test', () => {
|
49 | return gulp.src('app/**/*.js')
|
50 | .pipe(istanbul())
|
51 | .pipe(istanbul.hookRequire());
|
52 | });
|
53 |
|
54 | gulp.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 |
|
78 | gulp.task('test:lint', ['test:coverage'], () => {
|
79 | return lint();
|
80 | });
|
81 |
|
82 | gulp.task('test', ['test:lint'], () => {
|
83 | return gulp.src(['*.js']);
|
84 | });
|
85 |
|