-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtests.js
114 lines (104 loc) · 3.57 KB
/
tests.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
var vows = require('vows'),
_ = require('underscore')._,
Post = require('./models/post'),
RawTests = require('./raw_tests'),
nopt = require('nopt');
// load command line options
var args = nopt(null, null, process.argv, 2);
// define different service configurations
var allConfs = {
'local': {
processes: 4,
maxTests: false,
serviceName: 'local',
caps: [
{browserName: "chrome", version: '', platform: "MAC", proxy: {proxyType: 'direct'}},
{browserName: "firefox", version: '', platform: "MAC", proxy: {proxyType: 'direct'}}
]
},
'sauce': {
host: "ondemand.saucelabs.com",
port: 80,
username: process.env.SAUCE_USERNAME,
accessKey: process.env.SAUCE_ACCESS_KEY,
processes: 23,
maxTests: false,
serviceName: 'sauce',
caps: [
{browserName: "internet explorer", version: '8', platform: "XP", proxy: {proxyType: 'direct'}, 'selenium-version': '2.21.0'},
{browserName: "firefox", version: '14', platform: "Windows 2003", proxy: {proxyType: 'direct'}},
{browserName: "chrome", version: '', platform: "VISTA", proxy: {proxyType: 'direct'}}
// pre-prep mobile stuff
// {browserName: "ipad", version: '', platform: "Mac 10.6", deviceOrientation: "landscape", proxy: {proxyType: 'direct'}}
// {browserName: "android", version: '4', platform: "linux", deviceType: "tablet", proxy: {proxyType: 'direct'}}
]
}
};
// load configurations we're using from command line option
var confs = {};
_.each(args, function(val, arg) {
if (typeof allConfs[arg] !== 'undefined') {
confs[arg] = allConfs[arg];
}
});
// makeSuite takes a configuration and makes a batch of tests, splitting
// up tests according to 'conf.processes'
var makeSuite = function(conf) {
var getCapText = function(conf, cap) {
return " (" + cap.browserName+"_"+cap.version+"_"+cap.platform+"_"+conf.serviceName+")";
}
// gets a version of the testbase relativized to a particular config
// and capability request
var getTestsForCap = function(cap) {
var capText = getCapText(conf, cap);
var allTests = RawTests.allTests(conf, cap, capText);
var capTests = {};
// Replace the name of each test with a relativized name showing
// which conf and caps we are using
_.each(allTests, function(test, testName) {
capTests[testName+capText] = test;
});
return capTests;
};
// Gather tests for all capabilities requests into one big dict
var allTests = {};
_.each(conf.caps, function(cap) {
var tests = getTestsForCap(cap);
_.each(tests, function(test, testName) {
allTests[testName] = test;
});
});
// Split tests into batches according to how parallelized we want to be
var numTests = _.size(allTests);
if (conf.maxTests && conf.maxTests < numTests) {
numTests = conf.maxTests;
}
var numBatches = Math.ceil(numTests / conf.processes);
if (numBatches >= 1) {
var batches = {};
var testsPerBatch = numBatches * conf.processes;
var i = 0;
var total = 0;
_.each(allTests, function(test, testName) {
if (!conf.maxTests || total < conf.maxTests) {
if (typeof batches[i] === 'undefined') {
batches[i] = {};
}
batches[i][testName] = test;
if (i < numBatches - 1) {
i++;
} else {
i = 0;
}
total++;
}
});
_.each(batches, function(batch, index) {
vows.describe(conf.serviceName + ": Batch " + index ).addBatch(batch).export(module);
});
}
};
// Register batches with vows for every conf we are using
_.each(confs, function(conf) {
makeSuite(conf);
});