forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
protractor-shared.js
242 lines (223 loc) · 6.75 KB
/
protractor-shared.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
var fs = require('fs-extra');
var argv = require('yargs')
.usage('Angular e2e/perf test options.')
.options({
'sample-size': {
describe: 'Used for perf: sample size.',
default: 20
},
'force-gc': {
describe: 'Used for perf: force gc.',
default: false,
type: 'boolean'
},
'benchmark': {
describe: 'If true, run only the performance benchmarks. If false, run only the e2e tests.',
default: false
},
'dryrun': {
describe: 'If true, only run performance benchmarks once.',
default: false
},
'browsers': {
describe: 'Comma separated list of preconfigured browsers to use.',
default: 'ChromeDesktop'
},
'spec': {
describe: 'Comma separated file patterns to test. By default, globs all test/perf files.',
default: false
}
})
.help('ng-help')
.wrap(40)
.argv
var browsers = argv['browsers'].split(',');
var CHROME_OPTIONS = {
'args': ['--js-flags=--expose-gc'],
'perfLoggingPrefs': {
'traceCategories': 'v8,blink.console,devtools.timeline,disabled-by-default-devtools.timeline'
}
};
var CHROME_MOBILE_EMULATION = {
// Can't use 'deviceName':'Google Nexus 7 2'
// as this would yield wrong orientation,
// so we specify facts explicitly
'deviceMetrics': {
'width': 600,
'height': 960,
'pixelRatio': 2
}
};
var BROWSER_CAPS = {
Dartium: {
name: 'Dartium',
browserName: 'chrome',
chromeOptions: mergeInto(CHROME_OPTIONS, {
'mobileEmulation': CHROME_MOBILE_EMULATION,
'binary': process.env.DARTIUM_BIN
}),
loggingPrefs: {
performance: 'ALL',
browser: 'ALL'
}
},
ChromeDesktop: {
browserName: 'chrome',
chromeOptions: mergeInto(CHROME_OPTIONS, {
// TODO(tbosch): when we are using mobile emulation on
// chrome 44.0 beta, clicks are no more working.
// see https://github.com/angular/angular/issues/2309
// 'mobileEmulation': CHROME_MOBILE_EMULATION
}),
loggingPrefs: {
performance: 'ALL',
browser: 'ALL'
}
},
ChromeAndroid: {
browserName: 'chrome',
chromeOptions: mergeInto(CHROME_OPTIONS, {
'androidPackage': 'com.android.chrome',
}),
loggingPrefs: {
performance: 'ALL',
browser: 'ALL'
}
},
IPhoneSimulator: {
browserName: 'MobileSafari',
simulator: true,
CFBundleName: 'Safari',
device: 'iphone',
instruments: 'true',
loggingPrefs: {
performance: 'ALL',
browser: 'ALL'
}
},
IPadNative: {
browserName: 'MobileSafari',
simulator: false,
CFBundleName: 'Safari',
device: 'ipad',
loggingPrefs: {
performance: 'ALL',
browser: 'ALL'
}
}
};
var getTestFiles = function (benchmark, spec) {
var specFiles = [];
var perfFiles = [];
if (spec.length) {
spec.split(',').forEach(function (name) {
specFiles.push('dist/js/cjs/**/e2e_test/' + name)
perfFiles.push('dist/js/cjs/**/e2e_test/' + name)
});
} else {
specFiles.push('dist/js/cjs/**/e2e_test/**/*_spec.js');
perfFiles.push('dist/js/cjs/**/e2e_test/**/*_perf.js');
}
return benchmark ? perfFiles : specFiles;
};
var config = exports.config = {
onPrepare: function() {
// TODO(juliemr): remove this hack and use the config option
// restartBrowserBetweenTests once that is not hanging.
// See https://github.com/angular/protractor/issues/1983
//
// During benchmarking, we need to open a new browser
// for every benchmark, otherwise the numbers can get skewed
// from other benchmarks (e.g. Chrome keeps JIT caches, ...)
if (argv['benchmark'] && !argv['dryrun']) {
var originalBrowser = browser;
var _tmpBrowser;
beforeEach(function() {
global.browser = originalBrowser.forkNewDriverInstance();
global.element = global.browser.element;
global.$ = global.browser.$;
global.$$ = global.browser.$$;
});
afterEach(function() {
global.browser.quit();
global.browser = originalBrowser;
});
}
},
specs: getTestFiles(argv['benchmark'], argv['spec']),
exclude: [
'dist/js/cjs/**/node_modules/**',
],
multiCapabilities: browsers.map(function(browserName) {
var caps = BROWSER_CAPS[browserName];
console.log('Testing against', browserName);
if (!caps) {
throw new Error('Not configured browser name: '+browserName);
}
return caps;
}),
framework: 'jasmine2',
useAllAngular2AppRoots: true,
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: argv['benchmark'] ? 1200000 : 60000
},
params: {
benchmark: {
scaling: [{
userAgent: /Android/, value: 0.125
}]
}
}
};
exports.createBenchpressRunner = function(options) {
// benchpress will also load traceur runtime as our tests are written in es6
var benchpress = require('./dist/build/benchpress_bundle');
global.benchpress = benchpress;
var nodeUuid = require('node-uuid');
// TODO(tbosch): add cloud reporter again (only when !options.test)
// var cloudReporterConfig;
// if (process.env.CLOUD_SECRET_PATH) {
// console.log('using cloud reporter!');
// cloudReporterConfig = {
// auth: require(process.env.CLOUD_SECRET_PATH),
// projectId: 'angular-perf',
// datasetId: 'benchmarks',
// tableId: 'ng2perf'
// };
// }
var runId = nodeUuid.v1();
if (process.env.GIT_SHA) {
runId = process.env.GIT_SHA + ' ' + runId;
}
var resultsFolder = './dist/benchmark_results';
fs.ensureDirSync(resultsFolder);
var bindings = [
benchpress.SeleniumWebDriverAdapter.PROTRACTOR_BINDINGS,
benchpress.bind(benchpress.Options.FORCE_GC).toValue(argv['force-gc']),
benchpress.bind(benchpress.Options.DEFAULT_DESCRIPTION)
.toValue({'lang': options.lang, 'runId': runId}),
benchpress.JsonFileReporter.BINDINGS,
benchpress.bind(benchpress.JsonFileReporter.PATH).toValue(resultsFolder)
];
if (!argv['dryrun']) {
bindings.push(benchpress.Validator.bindTo(benchpress.RegressionSlopeValidator));
bindings.push(benchpress.bind(benchpress.RegressionSlopeValidator.SAMPLE_SIZE).toValue(argv['sample-size']));
bindings.push(benchpress.MultiReporter.createBindings([
benchpress.ConsoleReporter,
benchpress.JsonFileReporter
]));
} else {
bindings.push(benchpress.Validator.bindTo(benchpress.SizeValidator));
bindings.push(benchpress.bind(benchpress.SizeValidator.SAMPLE_SIZE).toValue(1));
bindings.push(benchpress.MultiReporter.createBindings([]));
bindings.push(benchpress.MultiMetric.createBindings([]));
}
global.benchpressRunner = new benchpress.Runner(bindings);
}
function mergeInto(src, target) {
for (var prop in src) {
target[prop] = src[prop];
}
return target;
}