This repository has been archived by the owner on Feb 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
142 lines (122 loc) · 4.26 KB
/
gulpfile.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
'use strict';
import gulp from 'gulp';
import gulpUtil from 'gulp-util';
// Tasks for e2e-testing with protractor
import {protractor, webdriver_update} from './test/e2e/helper/gulp-protractor-plugin';
// Config builder helper
import {protractorCfgBuilder} from './test/e2e/configs/builder';
// Get parsed command line arguments.
import {argv} from 'yargs';
let Xvfb = null;
try {
Xvfb = require('xvfb');
} catch (error) {
gulpUtil.log(`[${gulpUtil.colors.red("✖")}] Xvfb not found, headless mode will not be available.`);
}
// Check if headless mode is available, was selected, and we're not aiming a remote target.
let useHeadlessMode = Xvfb && argv.headless && !argv.remote;
let runWithHeadless = function (execFunc, done) {
let xvfb = new Xvfb();
xvfb.start(function (err) {
if (err) {
throw err;
}
execFunc().on('end', function () {
gulpUtil.log('Stream ended, shutting down Xvfb...');
xvfb.stop(function (err) {
if (err) {
throw err;
}
done();
});
});
});
};
/** 1st task definition: Updating webdriver.
* This should be performed regularly to ensure to have the most recent supported version of the selenium-standalone stuff available.
* To ease this up, we will define a particular task for it and add it as a dependency to the runner itself.
*/
// A list of drivers to load in case they are not present yet.
let drivers = ['chrome'];
// Load driver for Internet Explorer iff executed on windows.
/^win/.test(process.platform) && drivers.push('ie');
// Bind this created list to the update function itself.
let webdriverUpdate = webdriver_update.bind(null, {browsers: drivers});
// Define the task itself.
gulp.task('webdriver:update', (cb) => {
webdriverUpdate(cb);
});
// Define task for each supported browser - here: Firefox and Chrome.
// It is required to just reference the config files here, since the protractor task is executed in a different process
let supportedBrowsers = ['firefox', 'chrome', 'ie9', 'ie10', 'ie11', 'safari'],
executionFunction = function (browserName) {
let cfg = protractorCfgBuilder(browserName, argv);
return gulp.src('test/e2e/specs/**/*.spec.js')
.pipe(protractor(cfg))
.on('error', (e) => {
throw e;
});
};
supportedBrowsers.forEach((browserName) => {
gulp.task(`e2e:${browserName}`, ['webdriver:update'], function (done) {
if (useHeadlessMode) {
runWithHeadless(executionFunction.bind(null, browserName), done);
} else {
executionFunction(browserName).on('done', done);
}
});
});
// Tasks for the dev-mode itself.
import gulpSass from 'gulp-sass';
import sourceMaps from 'gulp-sourcemaps';
import concat from 'gulp-concat';
import browserSync from 'browser-sync';
const reload = browserSync.reload;
gulp.task('sass:dev', function () {
gulp.src('./app/stylesheets/*.sass')
.pipe(sourceMaps.init())
.pipe(gulpSass().on('error', gulpSass.logError))
.pipe(concat("app.css"))
.pipe(sourceMaps.write())
.pipe(gulp.dest('./app/css'))
.pipe(browserSync.stream());
});
gulp.task('sass', function () {
gulp.src('./app/stylesheets/*.sass')
.pipe(sourceMaps.init())
.pipe(gulpSass().on('error', gulpSass.logError))
.pipe(concat("app.css"))
.pipe(sourceMaps.write())
.pipe(gulp.dest('./app/css'));
});
gulp.task('serve', ['sass'], (cb) => {
browserSync({
open: false,
notify: false,
logPrefix: 'BS',
// Allow scroll syncing across breakpoints
//scrollElementMapping: ['main', '.mdl-layout'],
// Run as an https by uncommenting 'https: true'
// Note: this uses an unsigned certificate which on first access
// will present a certificate warning in the browser.
// https: true,
server: ['app'],
port: 3333
});
gulp.watch("app/**/*.html", reload);
gulp.watch("app/**/*.js", reload);
gulp.watch('./app/stylesheets/**/*.sass', ['sass:dev']);
});
// Things related to generating a PDF.
import {inlineImage} from './gulp/inlineImage';
import {toPDF} from './gulp/pdf';
import rename from 'gulp-rename';
gulp.task('pdf:all', () => {
gulp.src('./test/e2e/reports/**/*.html', {base: '.'})
.pipe(inlineImage())
.pipe(toPDF())
.pipe(rename({extname: '.pdf'}))
.pipe(gulp.dest('.'));
});
// The default task.
gulp.task('default', ['serve']);