-
Notifications
You must be signed in to change notification settings - Fork 167
/
gulpfile-tests.babel.js
150 lines (130 loc) · 3.76 KB
/
gulpfile-tests.babel.js
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
'use strict';
var vfs = require('vinyl-fs'),
path = require('path'),
plumber = require('gulp-plumber'),
jscs = require('gulp-jscs'),
jshint = require('gulp-jshint'),
mocha = require('gulp-mocha'),
karma = require('karma').server,
coverage = require('istanbul'),
istanbul = require('gulp-istanbul'),
through = require('through2'),
runSequence = require('run-sequence'),
del = require('del'),
tasks;
module.exports = function registerTasks(gulp) {
Object.keys(tasks).forEach( (task) => {
gulp.task(task, tasks[task]);
});
};
tasks = {
//jscs:disable disallowQuotedKeysInObjects
'jscs': runJscs,
'jshint': runJsHint,
'lint:js': ['jscs', 'jshint'],
'test:unit': runUnitTests,
'test:integration': runIntegrationTests,
'test:integration:structure': runStructureIntegrationTests,
'test:angular:unit': runAngularUnitTests,
'test:angular:functional': runAngularFunctionalTests,
'test:angular': runAngularTests,
'test:fast': runFastTests,
'test': runAllTests,
'clean-coverage': cleanCoverageDir,
'generate-coverage-report': generateCoverageReport
//jscs:enable disallowQuotedKeysInObjects
};
function srcJsLint() {
return vfs.src([
'gulpfile.babel.js',
'gulpfile-tests.babel.js',
'gulp-tasks/*',
'bin/**/*.js',
'lib/**/*.js',
'test/**/*.js',
'!lib/dist/**/*.js',
'!lib/app/js/components/**/*.js'
]);
}
function runJscs() {
return srcJsLint()
.pipe(plumber())
.pipe(jscs({configPath: '.jscsrc'}));
}
function runJsHint() {
return srcJsLint()
.pipe(plumber())
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(jshint.reporter('fail'));
}
function runMocha() {
return mocha({reporter: 'spec'});
}
function runUnitTests(done) {
vfs.src(['lib/modules/**/*.js'])
.pipe(istanbul({includeUntested: true}))
.pipe(istanbul.hookRequire())
.on('finish', () => {
vfs.src(['test/unit/**/*.js'])
.pipe(runMocha())
.pipe(writeUnitTestCoverage())
.pipe(printUnitTestCoverage())
.on('end', done);
});
}
function writeUnitTestCoverage() {
return istanbul.writeReports({
reporters: ['json'],
reportOpts: {file: path.resolve('./coverage/unit-coverage.json')}
});
}
function printUnitTestCoverage() {
return istanbul.writeReports({reporters: ['text']});
}
function runStructureIntegrationTests() {
return vfs.src(['test/integration/**/*.js', '!test/integration/npm-package.test.js']).pipe(runMocha());
}
function runIntegrationTests() {
return vfs.src('test/integration/**/*.js').pipe(runMocha());
}
function runAngularUnitTests(done) {
karma.start({
configFile: path.resolve('./test/karma.conf.js'),
exclude: ['test/angular/functional/**/*.js']
}, done);
}
function runAngularFunctionalTests(done) {
karma.start({
configFile: path.resolve('./test/karma.conf.js'),
exclude: ['test/angular/unit/**/*.js'],
preprocessors: {},
reporters: ['mocha']
}, done);
}
function runAngularTests(done) {
runSequence('test:angular:unit', 'test:angular:functional', done);
}
function runFastTests(done) {
runSequence('lint:js', 'test:unit', 'test:angular', 'test:integration:structure', done);
}
function runAllTests(done) {
runSequence('test:unit', 'test:angular', 'test:integration', 'lint:js', done);
}
function cleanCoverageDir(done) {
del('coverage/*', done);
}
function generateCoverageReport() {
var collector = new coverage.Collector(),
lcov = coverage.Report.create('lcov', {dir: 'coverage'}),
summary = coverage.Report.create('text');
return vfs.src('coverage/*.json')
.pipe(through.obj( (file, enc, done) => {
collector.add(JSON.parse(file.contents.toString()));
done();
}, (callback) => {
lcov.writeReport(collector);
summary.writeReport(collector);
callback();
}));
}