forked from appium/appium
-
Notifications
You must be signed in to change notification settings - Fork 9
/
grunt.js
114 lines (110 loc) · 3.74 KB
/
grunt.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
"use strict";
var build = require('./build.js')
, path = require('path')
, rimraf = require('rimraf')
, http = require('http')
, exec = require('child_process').exec
, gruntHelpers = require('./grunt-helpers.js')
, startAppium = gruntHelpers.startAppium
, authorize = gruntHelpers.authorize
, runTestsWithServer = gruntHelpers.runTestsWithServer
, fs = require('fs');
module.exports = function(grunt) {
grunt.initConfig({
lint: {
all: ['*.js', 'app/*.js', 'app/test/unit/*.js', 'instruments/*.js', 'test/functional/*.js', 'test/unit/*.js', 'test/uicatalog/*.js', 'test/helpers/*.js']
}
, jshint: {
all: {
options: {
laxcomma: true
, es5: true
, trailing: true
, node: true
, strict: true
}
}
}
, mochaTest: {
unit: ['app/test/unit/*.js']
}
, mochaTestWithServer: {
TestApp: {
functional: ['test/functional/*.js']
, unit: ['app/test/unit/*.js']
}
, UICatalog: {
uicatalog: ['test/uicatalog/findElement.js']
}
}
, mochaTestConfig: {
options: {
timeout: 60000,
reporter: 'spec'
}
}
});
grunt.loadNpmTasks('grunt-mocha-test');
grunt.registerTask('functional', "Run functional tests", function(log) {
runTestsWithServer(grunt, 'TestApp', 'functional', log === "log", this.async());
});
grunt.registerTask('uicatalog', "Run UICatalog tests", function(log) {
runTestsWithServer(grunt, 'UICatalog', 'uicatalog', log === "log", this.async());
});
grunt.registerTask('test', 'lint buildApp:TestApp buildApp:UICatalog unit functional uicatalog');
grunt.registerTask('unit', 'mochaTest:unit');
grunt.registerTask('default', 'lint test');
grunt.registerTask('appium', "Start the Appium server", function(appName) {
if (typeof appName === "undefined") {
appName = "TestApp";
}
startAppium(appName, true, function() {}, this.async());
});
grunt.registerTask('mobileSafari', "Start the Appium server with MobileSafari", function(version) {
if (typeof version === "undefined") {
version = "6.0";
}
var app = "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator" + version + ".sdk/Applications/MobileSafari.app";
startAppium(app, function() {}, this.async());
});
grunt.registerTask('downloadApp', "Download UICatalog", function() {
var done = this.async();
var appBasePath = path.resolve(__dirname, 'sample-code/apps');
var appPath = path.resolve(appBasePath, 'UICatalog');
var zipPath = path.resolve(appBasePath, 'UICatalog.zip');
var UICatUrl = "http://developer.apple.com/library/ios/samplecode/UICatalog/UICatalog.zip";
// clear out anything that's there
try {
fs.unlinkSync(zipPath);
} catch(e) {}
rimraf(appPath, function() {
var file = fs.createWriteStream(zipPath);
console.log("Downloading UI catalog into " + zipPath);
http.get(UICatUrl, function(response) {
response.pipe(file);
response.on('end', function() {
console.log("Download complete");
exec("unzip UICatalog.zip", {cwd: appBasePath}, function() {
console.log("Unzipped into " + appPath);
done();
});
});
});
});
});
grunt.registerTask('buildApp', "Build the test app", function(appDir) {
var done = this.async();
var appRoot = path.resolve(__dirname, 'sample-code/apps/', appDir);
build(appRoot, function(err) {
if (err) {
console.log(err);
done(false);
} else {
done(true);
}
});
});
grunt.registerTask('authorize', "Authorize developer", function() {
authorize(grunt, this.async());
});
};