-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathgulpfile.js
More file actions
122 lines (98 loc) · 2.75 KB
/
Copy pathgulpfile.js
File metadata and controls
122 lines (98 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
'use strict';
/* eslint no-process-exit:0 */
const colors = require( 'colors/safe' );
const del = require( 'del' );
const enforcement = require( '@sinet/coverage-enforcement' );
const gulp = require( 'gulp' );
const istanbul = require( 'gulp-istanbul' );
const mocha = require( 'gulp-mocha' );
const mkdirp = require( 'mkdirp' );
gulp.task( 'clean-coverage', function () {
del( [ 'instrumented' ] );
} );
gulp.task( 'test', [ 'clean-coverage', 'create-log-dir' ], function () {
const covEnforcerOpts = { 'thresholds' : enforcement.thresholds };
const paths = {
'cover' : [
// Include everything to be covered
'**/*.js',
// Exclude files
'!gulpfile.js',
// Exclude directories that are not code
'!config/**',
'!instrumented/**',
'!node_modules/**',
'!test/api/**',
'!test/**'
],
'test' : [ 'test/unit/**/*.js', 'test/it/**/*.js' ],
'coverage' : 'instrumented'
};
const mochaOptions = {
'ui' : 'bdd',
'reporter' : 'spec',
'bail' : true,
'timeout' : 5000
};
return gulp.src( paths.cover )
.pipe( istanbul( { 'includeUntested' : true } ) )
.pipe( istanbul.hookRequire() )
.on( 'finish', function () {
gulp.src( paths.test, { 'read' : false } )
.pipe(
mocha( mochaOptions )
.on( 'error', function ( mochaError ) {
console.log( mochaError.stack );
process.exit( 1 );
}
) )
.pipe( istanbul.writeReports( {
'dir' : paths.coverage,
'reporters' : enforcement.reporters,
'reportOpts' : {
'dir' : paths.coverage,
'watermarks' : enforcement.watermarks
}
} ) )
.pipe( istanbul.enforceThresholds( covEnforcerOpts )
.on( 'error', function () {
console.log( 'error - coverage enforcer' );
enforcement.log();
process.exit( 1 );
} ) )
.on( 'error', function () {
process.exit( 1 );
} )
.on( 'end', function () {
enforcement.log();
process.exit();
} );
} );
} );
gulp.task( 'create-log-dir', function ( callback ) {
mkdirp( 'logs', function ( error ) {
if ( error ) {
console.log( error.stack );
process.exit( 1 );
}
callback();
} );
} );
gulp.task( 'inspect-queues', function () {
// delay to give time reading queues
setTimeout( function () {
const spawn = require( 'child_process' ).spawn;
const queue = spawn( 'node', [ 'test/api' ] );
queue.stdout.on( 'data', function ( data ) {
console.log( data.toString() );
} );
queue.stderr.on( 'data', function ( data ) {
if ( parseInt( data.toString(), 10 ) ) {
console.log( colors.red( 'error - having unacked/ready msgs' ) );
} else {
console.log( colors.green( 'Success - no unacked/ready msgs' ) );
}
process.exit( data );
} );
}, 2000 );
} );