-
Notifications
You must be signed in to change notification settings - Fork 92
/
Copy pathgulpfile.js
120 lines (99 loc) · 3.82 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
"use strict";
const gulp = require("gulp");
const gutil = require("gulp-util");
const bower = require("bower");
const sh = require("shelljs");
const cp = require("child_process");
const protractor = require('gulp-protractor').protractor;
const runSequence = require('run-sequence');
const path = require("path");
let appium_process;
require("dotenv").load();
gulp.task("default", ["test:integration:local"]);
gulp.task("set-play-services-location-version", function () {
sh.exec("sed -i 's/play-services-location:+/play-services-location:6.5.87/g' platforms/android/project.properties");
});
gulp.task("build-debug", ["set-play-services-location-version"], function (callback) {
cp.exec("ionic build android", function (error) {
if (error) {
return callback(error);
}
callback();
});
});
gulp.task("start-appium", function (callback) {
appium_process = cp.spawn("appium", ["--chromedriver-executable", "/home/tomasz/.bin/chromedriver"]);
appium_process.stdout.on("data", function (data) {
if (data.toString().indexOf("Appium REST http interface listener started") > -1) {
callback();
}
});
appium_process.stderr.pipe(process.stderr);
});
gulp.task("protractor:local:android-4.4.2", runTestOn.bind(null, "local", "android-4.4.2"));
gulp.task("protractor:local:android-5.0.1", runTestOn.bind(null, "local", "android-5.0.1"));
gulp.task("protractor:local:android-5.1.1", runTestOn.bind(null, "local", "android-5.1.1"));
gulp.task("protractor:local:android-6.0", runTestOn.bind(null, "local", "android-6.0"));
gulp.task("test:integration:local", ["build-debug", "start-appium"], function (callback) {
runSequence(
"protractor:local:android-4.4.2",
"protractor:local:android-5.0.1",
"protractor:local:android-5.1.1",
"protractor:local:android-6.0",
function () {
cleanup();
callback();
process.exit(0);
}
);
});
gulp.task("test:integration:sauce", ["upload-apk-to-sauce"], function () {
return runTestOn("sauce", "all");
});
gulp.task("upload-apk-to-sauce", ["build-debug"], function () {
const apk_path = path.resolve("platforms/android/build/outputs/apk/android-debug.apk");
sh.exec(`curl -u $SAUCE_USERNAME:$SAUCE_ACCESS_KEY -X POST http://saucelabs.com/rest/v1/storage/$SAUCE_USERNAME/ionic-geofence-debug.apk?overwrite=true -H 'Content-Type: application/octet-stream' --data-binary @${apk_path}`);
});
gulp.task("watch", function () {
gulp.watch(paths.sass, ["sass"]);
});
gulp.task("install", ["git-check"], function () {
return bower.commands.install()
.on("log", function (data) {
gutil.log("bower", gutil.colors.cyan(data.id), data.message);
});
});
gulp.task("git-check", function (done) {
if (!sh.which("git")) {
console.log(
" " + gutil.colors.red("Git is not installed."),
"\n Git, the version control system, is required to download Ionic.",
"\n Download git here:", gutil.colors.cyan("http://git-scm.com/downloads") + ".",
"\n Once git is installed, run \"" + gutil.colors.cyan("gulp install") + "\" again."
);
process.exit(1);
}
done();
});
function runTestOn(server, device) {
return gulp.src(["./tests/e2e/**/*_test.js"])
.pipe(protractor({
configFile: `tests/e2e/${server}.config.js`,
args: [`--params.avd=${device}`]
}))
.on("error", function (e) { console.log(gutil.colors.red(e)); })
.on("end", killEmulator);
}
function cleanup() {
if (appium_process) {
appium_process.kill("SIGINT");
}
killEmulator();
}
function killEmulator() {
sh.exec("adb -s emulator-5554 emu kill");
}
process.once("uncaughtException", function (error) {
cleanup();
throw error;
});