| 
									
										
										
										
											2015-03-06 11:46:33 -08:00
										 |  |  | var fs = require('fs-extra'); | 
					
						
							| 
									
										
										
										
											2015-02-11 10:13:49 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-17 10:32:09 -08:00
										 |  |  | var argv = require('yargs') | 
					
						
							|  |  |  |     .usage('Angular e2e/perf test options.') | 
					
						
							|  |  |  |     .options({ | 
					
						
							|  |  |  |       'sample-size': { | 
					
						
							| 
									
										
										
										
											2015-03-26 16:56:53 -07:00
										 |  |  |         describe: 'Used for perf: sample size.', | 
					
						
							| 
									
										
										
										
											2015-02-27 13:41:53 -08:00
										 |  |  |         default: 20 | 
					
						
							| 
									
										
										
										
											2015-02-17 10:32:09 -08:00
										 |  |  |       }, | 
					
						
							|  |  |  |       'force-gc': { | 
					
						
							| 
									
										
										
										
											2015-03-26 16:56:53 -07:00
										 |  |  |         describe: 'Used for perf: force gc.', | 
					
						
							| 
									
										
										
										
											2015-02-17 10:32:09 -08:00
										 |  |  |         default: false, | 
					
						
							|  |  |  |         type: 'boolean' | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       'benchmark': { | 
					
						
							| 
									
										
										
										
											2015-03-26 16:56:53 -07:00
										 |  |  |         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.', | 
					
						
							| 
									
										
										
										
											2015-02-17 10:32:09 -08:00
										 |  |  |         default: false | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       'browsers': { | 
					
						
							| 
									
										
										
										
											2015-03-26 16:56:53 -07:00
										 |  |  |         describe: 'Comma separated list of preconfigured browsers to use.', | 
					
						
							| 
									
										
										
										
											2015-02-17 10:32:09 -08:00
										 |  |  |         default: 'ChromeDesktop' | 
					
						
							| 
									
										
										
										
											2015-02-23 10:34:58 -08:00
										 |  |  |       }, | 
					
						
							|  |  |  |       'spec': { | 
					
						
							| 
									
										
										
										
											2015-03-26 16:56:53 -07:00
										 |  |  |         describe: 'Comma separated file patterns to test. By default, globs all test/perf files.', | 
					
						
							| 
									
										
										
										
											2015-02-23 10:34:58 -08:00
										 |  |  |         default: false | 
					
						
							| 
									
										
										
										
											2015-02-17 10:32:09 -08:00
										 |  |  |       } | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |     .help('ng-help') | 
					
						
							|  |  |  |     .wrap(40) | 
					
						
							|  |  |  |     .argv | 
					
						
							| 
									
										
										
										
											2015-02-11 10:13:49 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-17 10:32:09 -08:00
										 |  |  | var browsers = argv['browsers'].split(','); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-27 09:07:16 -08:00
										 |  |  | var CHROME_OPTIONS = { | 
					
						
							|  |  |  |   'args': ['--js-flags=--expose-gc'], | 
					
						
							|  |  |  |   'perfLoggingPrefs': { | 
					
						
							| 
									
										
										
										
											2015-11-09 19:11:58 -08:00
										 |  |  |     'traceCategories': 'v8,blink.console,devtools.timeline,disabled-by-default-devtools.timeline' | 
					
						
							| 
									
										
										
										
											2015-02-27 09:07:16 -08:00
										 |  |  |   } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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 | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-17 10:32:09 -08:00
										 |  |  | var BROWSER_CAPS = { | 
					
						
							|  |  |  |   Dartium: { | 
					
						
							|  |  |  |     name: 'Dartium', | 
					
						
							|  |  |  |     browserName: 'chrome', | 
					
						
							| 
									
										
										
										
											2015-02-27 09:07:16 -08:00
										 |  |  |     chromeOptions: mergeInto(CHROME_OPTIONS, { | 
					
						
							|  |  |  |       'mobileEmulation': CHROME_MOBILE_EMULATION, | 
					
						
							| 
									
										
										
										
											2015-06-25 16:56:59 +02:00
										 |  |  |       'binary': process.env.DARTIUM_BIN | 
					
						
							| 
									
										
										
										
											2015-02-27 09:07:16 -08:00
										 |  |  |     }), | 
					
						
							| 
									
										
										
										
											2015-02-17 10:32:09 -08:00
										 |  |  |     loggingPrefs: { | 
					
						
							|  |  |  |       performance: 'ALL', | 
					
						
							|  |  |  |       browser: 'ALL' | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   ChromeDesktop: { | 
					
						
							|  |  |  |     browserName: 'chrome', | 
					
						
							| 
									
										
										
										
											2015-02-27 09:07:16 -08:00
										 |  |  |     chromeOptions: mergeInto(CHROME_OPTIONS, { | 
					
						
							| 
									
										
										
										
											2015-06-03 09:42:58 -07:00
										 |  |  |       // 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
 | 
					
						
							| 
									
										
										
										
											2015-02-27 09:07:16 -08:00
										 |  |  |     }), | 
					
						
							| 
									
										
										
										
											2015-02-17 10:32:09 -08:00
										 |  |  |     loggingPrefs: { | 
					
						
							|  |  |  |       performance: 'ALL', | 
					
						
							|  |  |  |       browser: 'ALL' | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2015-11-19 23:37:55 +01:00
										 |  |  |   ChromeOnTravis: { | 
					
						
							|  |  |  |     browserName: 'chrome', | 
					
						
							|  |  |  |     chromeOptions: mergeInto({ | 
					
						
							|  |  |  |       'args': ['--no-sandbox', '--js-flags=--expose-gc'], | 
					
						
							|  |  |  |       'binary': process.env.CHROME_BIN | 
					
						
							|  |  |  |     }, CHROME_OPTIONS), | 
					
						
							|  |  |  |     loggingPrefs: { | 
					
						
							|  |  |  |       performance: 'ALL', | 
					
						
							|  |  |  |       browser: 'ALL' | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2015-02-17 10:32:09 -08:00
										 |  |  |   ChromeAndroid: { | 
					
						
							|  |  |  |     browserName: 'chrome', | 
					
						
							| 
									
										
										
										
											2015-02-27 09:07:16 -08:00
										 |  |  |     chromeOptions: mergeInto(CHROME_OPTIONS, { | 
					
						
							|  |  |  |       'androidPackage': 'com.android.chrome', | 
					
						
							|  |  |  |     }), | 
					
						
							| 
									
										
										
										
											2015-02-17 10:32:09 -08:00
										 |  |  |     loggingPrefs: { | 
					
						
							|  |  |  |       performance: 'ALL', | 
					
						
							|  |  |  |       browser: 'ALL' | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-02-18 14:39:52 -08:00
										 |  |  |   }, | 
					
						
							|  |  |  |   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' | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-02-17 10:32:09 -08:00
										 |  |  |   } | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2015-01-08 14:20:05 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-26 16:56:53 -07:00
										 |  |  | var getTestFiles = function (benchmark, spec) { | 
					
						
							| 
									
										
										
										
											2015-02-23 10:34:58 -08:00
										 |  |  |   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'); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-03-26 16:56:53 -07:00
										 |  |  |   return benchmark ? perfFiles : specFiles; | 
					
						
							| 
									
										
										
										
											2015-02-23 10:34:58 -08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-08 14:20:05 -08:00
										 |  |  | var config = exports.config = { | 
					
						
							|  |  |  |   onPrepare: function() { | 
					
						
							| 
									
										
										
										
											2015-03-26 16:56:53 -07:00
										 |  |  |     // TODO(juliemr): remove this hack and use the config option
 | 
					
						
							|  |  |  |     // restartBrowserBetweenTests once that is not hanging.
 | 
					
						
							|  |  |  |     // See https://github.com/angular/protractor/issues/1983
 | 
					
						
							| 
									
										
										
										
											2015-10-06 21:00:26 -07:00
										 |  |  |     //
 | 
					
						
							| 
									
										
										
										
											2015-03-04 10:27:26 -08:00
										 |  |  |     // 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, ...)
 | 
					
						
							| 
									
										
										
										
											2015-04-01 16:47:30 -07:00
										 |  |  |     if (argv['benchmark'] && !argv['dryrun']) { | 
					
						
							| 
									
										
										
										
											2015-03-04 10:27:26 -08:00
										 |  |  |       var originalBrowser = browser; | 
					
						
							|  |  |  |       var _tmpBrowser; | 
					
						
							|  |  |  |       beforeEach(function() { | 
					
						
							|  |  |  |         global.browser = originalBrowser.forkNewDriverInstance(); | 
					
						
							|  |  |  |         global.element = global.browser.element; | 
					
						
							|  |  |  |         global.$ = global.browser.$; | 
					
						
							|  |  |  |         global.$$ = global.browser.$$; | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       afterEach(function() { | 
					
						
							| 
									
										
										
										
											2015-03-26 16:56:53 -07:00
										 |  |  |        global.browser.quit(); | 
					
						
							|  |  |  |        global.browser = originalBrowser; | 
					
						
							| 
									
										
										
										
											2015-03-04 10:27:26 -08:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2015-01-08 14:20:05 -08:00
										 |  |  |     } | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-26 16:56:53 -07:00
										 |  |  |   specs: getTestFiles(argv['benchmark'], argv['spec']), | 
					
						
							| 
									
										
										
										
											2015-02-17 10:32:09 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   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; | 
					
						
							|  |  |  |   }), | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-08 20:59:03 -08:00
										 |  |  |   framework: 'jasmine2', | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-06 21:00:26 -07:00
										 |  |  |   useAllAngular2AppRoots: true, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-08 14:20:05 -08:00
										 |  |  |   jasmineNodeOpts: { | 
					
						
							|  |  |  |     showColors: true, | 
					
						
							| 
									
										
										
										
											2015-03-26 16:56:53 -07:00
										 |  |  |     defaultTimeoutInterval: argv['benchmark'] ? 1200000 : 60000 | 
					
						
							| 
									
										
										
										
											2015-02-11 10:13:49 -08:00
										 |  |  |   }, | 
					
						
							|  |  |  |   params: { | 
					
						
							|  |  |  |     benchmark: { | 
					
						
							|  |  |  |       scaling: [{ | 
					
						
							|  |  |  |         userAgent: /Android/, value: 0.125 | 
					
						
							|  |  |  |       }] | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-01-08 14:20:05 -08:00
										 |  |  |   } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-11 10:13:49 -08:00
										 |  |  | exports.createBenchpressRunner = function(options) { | 
					
						
							| 
									
										
										
										
											2015-07-01 16:37:16 -07:00
										 |  |  |   // benchpress will also load traceur runtime as our tests are written in es6
 | 
					
						
							|  |  |  |   var benchpress = require('./dist/build/benchpress_bundle'); | 
					
						
							|  |  |  |   global.benchpress = benchpress; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-17 10:32:09 -08:00
										 |  |  |   var nodeUuid = require('node-uuid'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-11 10:13:49 -08:00
										 |  |  |   // 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; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-03-06 11:46:33 -08:00
										 |  |  |   var resultsFolder = './dist/benchmark_results'; | 
					
						
							|  |  |  |   fs.ensureDirSync(resultsFolder); | 
					
						
							| 
									
										
										
										
											2015-02-11 10:13:49 -08:00
										 |  |  |   var bindings = [ | 
					
						
							| 
									
										
										
										
											2015-03-02 09:23:09 -08:00
										 |  |  |     benchpress.SeleniumWebDriverAdapter.PROTRACTOR_BINDINGS, | 
					
						
							| 
									
										
										
										
											2015-02-17 10:32:09 -08:00
										 |  |  |     benchpress.bind(benchpress.Options.FORCE_GC).toValue(argv['force-gc']), | 
					
						
							| 
									
										
										
										
											2015-08-26 13:40:12 -07:00
										 |  |  |     benchpress.bind(benchpress.Options.DEFAULT_DESCRIPTION) | 
					
						
							|  |  |  |         .toValue({'lang': options.lang, 'runId': runId}), | 
					
						
							| 
									
										
										
										
											2016-03-21 16:27:17 +05:30
										 |  |  |     benchpress.JsonFileReporter.PROVIDERS, | 
					
						
							| 
									
										
										
										
											2015-03-06 11:46:33 -08:00
										 |  |  |     benchpress.bind(benchpress.JsonFileReporter.PATH).toValue(resultsFolder) | 
					
						
							| 
									
										
										
										
											2015-02-11 10:13:49 -08:00
										 |  |  |   ]; | 
					
						
							| 
									
										
										
										
											2015-03-26 16:56:53 -07:00
										 |  |  |   if (!argv['dryrun']) { | 
					
						
							| 
									
										
										
										
											2015-02-20 13:32:54 -08:00
										 |  |  |     bindings.push(benchpress.Validator.bindTo(benchpress.RegressionSlopeValidator)); | 
					
						
							| 
									
										
										
										
											2015-02-17 10:32:09 -08:00
										 |  |  |     bindings.push(benchpress.bind(benchpress.RegressionSlopeValidator.SAMPLE_SIZE).toValue(argv['sample-size'])); | 
					
						
							| 
									
										
										
										
											2015-04-01 16:47:30 -07:00
										 |  |  |     bindings.push(benchpress.MultiReporter.createBindings([ | 
					
						
							|  |  |  |       benchpress.ConsoleReporter, | 
					
						
							|  |  |  |       benchpress.JsonFileReporter | 
					
						
							|  |  |  |     ])); | 
					
						
							| 
									
										
										
										
											2015-02-17 10:32:09 -08:00
										 |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2015-02-20 13:32:54 -08:00
										 |  |  |     bindings.push(benchpress.Validator.bindTo(benchpress.SizeValidator)); | 
					
						
							| 
									
										
										
										
											2015-02-11 10:13:49 -08:00
										 |  |  |     bindings.push(benchpress.bind(benchpress.SizeValidator.SAMPLE_SIZE).toValue(1)); | 
					
						
							| 
									
										
										
										
											2015-04-01 16:47:30 -07:00
										 |  |  |     bindings.push(benchpress.MultiReporter.createBindings([])); | 
					
						
							|  |  |  |     bindings.push(benchpress.MultiMetric.createBindings([])); | 
					
						
							| 
									
										
										
										
											2015-02-11 10:13:49 -08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   global.benchpressRunner = new benchpress.Runner(bindings); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-02-27 09:07:16 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | function mergeInto(src, target) { | 
					
						
							|  |  |  |   for (var prop in src) { | 
					
						
							|  |  |  |     target[prop] = src[prop]; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return target; | 
					
						
							| 
									
										
										
										
											2015-06-01 17:49:14 -07:00
										 |  |  |  } |