-
Notifications
You must be signed in to change notification settings - Fork 4
/
Gulpfile.js
110 lines (82 loc) · 3.14 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
var path = require('path');
var gulp = require('gulp');
var babel = require('gulp-babel');
var del = require('del');
var execa = require('execa');
var PACKAGE_PARENT_DIR = path.join(__dirname, '../');
var PACKAGE_SEARCH_PATH = (process.env.NODE_PATH ? process.env.NODE_PATH + path.delimiter : '') + PACKAGE_PARENT_DIR;
function clean () {
return del('lib');
}
function lint () {
var eslint = require('gulp-eslint');
return gulp
.src([
'src/**/*.js',
'test/**/*.js',
'Gulpfile.js'
])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
}
function build () {
return gulp
.src('src/**/*.js')
.pipe(babel())
.pipe(gulp.dest('lib'));
}
function ensureAuthCredentials () {
const ERROR_MESSAGES = require('./lib/templates/error-messages');
if (!process.env.BROWSERSTACK_USERNAME || !process.env.BROWSERSTACK_ACCESS_KEY)
throw new Error(ERROR_MESSAGES.BROWSERSTACK_AUTHENTICATION_FAILED());
}
function testMocha () {
ensureAuthCredentials();
var mochaCmd = path.join(__dirname, 'node_modules/.bin/mocha');
var mochaOpts = [
'--ui', 'bdd',
'--reporter', 'spec',
'--timeout', typeof v8debug === 'undefined' ? 2000 : Infinity,
'test/mocha/**/*test.js'
];
// NOTE: we must add the parent of plugin directory to NODE_PATH, otherwise testcafe will not be able
// to find the plugin. So this function starts mocha with proper NODE_PATH.
process.env.NODE_PATH = PACKAGE_SEARCH_PATH;
return execa(mochaCmd, mochaOpts, { stdio: 'inherit' });
}
function testMochaRest () {
process.env.BROWSERSTACK_USE_AUTOMATE = 0;
return testMocha();
}
function testMochaAutomate () {
process.env.BROWSERSTACK_USE_AUTOMATE = 1;
return testMocha();
}
function testTestcafe (browsers) {
ensureAuthCredentials();
var testCafeCmd = path.join(__dirname, 'node_modules/.bin/testcafe');
var testCafeOpts = [
browsers,
'test/testcafe/**/*test.js',
'-s', '.screenshots'
];
// NOTE: we must add the parent of plugin directory to NODE_PATH, otherwise testcafe will not be able
// to find the plugin. So this function starts testcafe with proper NODE_PATH.
process.env.NODE_PATH = PACKAGE_SEARCH_PATH;
return execa(testCafeCmd, testCafeOpts, { stdio: 'inherit' });
}
function testTestcafeRest () {
process.env.BROWSERSTACK_USE_AUTOMATE = '0';
return testTestcafe('browserstack:chrome:windows 10,browserstack:[email protected]');
}
function testTestcafeAutomate () {
process.env.BROWSERSTACK_USE_AUTOMATE = '1';
return testTestcafe('browserstack:chrome:windows 10,browserstack:Google [email protected],browserstack:[email protected]');
}
exports.clean = clean;
exports.lint = lint;
exports.build = gulp.parallel(gulp.series(clean, build), lint);
exports.test = gulp.series(exports.build, testMochaRest, testMochaAutomate, testTestcafeRest, testTestcafeAutomate);
exports.testTestcafeRest = gulp.series(exports.build, testTestcafeRest);
exports.testTestcafeAutomate = gulp.series(exports.build, testTestcafeAutomate);