-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgulpfile.js
150 lines (134 loc) · 3.62 KB
/
gulpfile.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
var gulp = require('gulp');
var istanbul = require('gulp-istanbul');
var jasmineWebdriverio = require('./index.js');
var jshint = require('gulp-jshint');
var bump = require('gulp-bump');
var yargs = require('yargs').argv;
var git = require('gulp-git');
var fs = require('fs');
var run = require('gulp-run');
var github_release = require('gulp-github-release');
var getPackageJson = function () {
return JSON.parse(fs.readFileSync('./package.json', 'utf8'));
};
// We'll use mocha here, but any test framework will work
var mocha = require('gulp-mocha');
gulp.task('unit-test', function (cb) {
var srcs = typeof yargs.env == 'undefined'
? ['test/test.js']
: typeof yargs.env == 'local'
? ['test/test.js']
: ['test/test-ci.js'];
return gulp.src(['index.js'])
.pipe(istanbul()) // Covering files
.pipe(istanbul.hookRequire()) // Force `require` to return covered files
.on('finish', function () {
return gulp.src(srcs)
.pipe(mocha({
reporter: 'spec',
globals: {
should: require('should')
}
}))
.on('end', function(){
return gulp.src(['index.js'])
.pipe(istanbul.writeReports({
dir: './reports/coverage',
reporters: [ 'lcov', 'json', 'text', 'text-summary' ],
reportOpts: { dir: './reports/coverage' }
})) // Creating the reports after tests ran
.pipe(istanbul.enforceThresholds({ thresholds: {
global: 10,
each: 10
} })) // Enforce a coverage of at least 80%
.on('error', function(e){
throw e.message;
})
});
});
});
gulp.task('watch-test', ['unit-test'], function() {
gulp.watch(['index.js', 'test/*.js', 'wdio.conf.js'], function (event) {
gulp.start('unit-test');
});
});
gulp.task('regression-test', function() {
return gulp.src('usecases/regressionTest.js', {
read: false
})
.pipe(jasmineWebdriverio({
args: {
logLevel: 'verbose',
desiredCapabilities: {
browserName: 'phantomjs'
}
}
}));
});
gulp.task('angularjs-regression-test', function() {
return gulp.src('usecases/angularJsRegressionTest.js', {
read: false
})
.pipe(jasmineWebdriverio({
//configFile: './wdio.conf.js',
args: {
logLevel: 'log'
,ngRoot: 'html' // main application selector
}
}));
});
gulp.task('test', function() {
return gulp.src('usecases/test*.js', {
read: false
}).pipe(jasmineWebdriverio({
configFile: './wdio.conf.js',
args: {
logLevel: 'verbose',
desiredCapabilities: {
browserName: 'phantomjs'
}
}
}));
});
gulp.task('linting', function() {
return gulp.src('./index.js', {
read: false
})
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
gulp.task('bump', function(){
return gulp.src('./package.json')
.pipe(bump({type: yargs.type}))
.pipe(gulp.dest('./'));
});
gulp.task('commit', ['bump'], function(){
// reget package
var pkg = getPackageJson();
return gulp.src('./package.json')
.pipe(git.commit('Release version ' + pkg.version));
});
gulp.task('push', ['tag'], function(){
git.push('origin', 'master', function (err) {
if (err) throw err;
});
});
// Tag the repo with a version
gulp.task('tag', ['commit'], function(){
// reget package
var pkg = getPackageJson();
git.tag(pkg.version, pkg.version + ' released version', function (err) {
if (err) throw err;
});
});
gulp.task('npmPublish', ['push'], function (done) {
run('npm prune').exec();
run('npm publish').exec();
});
gulp.task('githubRelease', ['npmPublish'], function (done) {
github_release();
});
gulp.task('release', ['bump', 'tag', 'push', 'commit', 'npmPublish', 'githubRelease'], function(){});
gulp.task('default', function(){
gulp.watch("./index.js", ['linting']);
});