From 00f784cda8e128d2ee31a84e71b04941bdd48d79 Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Fri, 16 Aug 2013 10:49:37 -0700 Subject: [PATCH 1/4] chore(ngdocs): disable lunr search during e2e tests lunr has been responsible for slowdown in our test suite by adding ~1sec per end-to-end test. (this is because it initializes the index when the app starts) since out test suite primarily tests the examples, it's reasonable do disable the search as a temporary meansure. the real fix is to use protractor and extract all of the examples into standalone apps which can be tested without bootstrapping the whole docs app. --- docs/src/templates/index.html | 9 ++++++++- docs/src/templates/js/docs.js | 7 ++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/docs/src/templates/index.html b/docs/src/templates/index.html index e4afc731ccd3..1deb08e1c4f9 100644 --- a/docs/src/templates/index.html +++ b/docs/src/templates/index.html @@ -20,6 +20,11 @@ // we can't add css/js the usual way, because some browsers (FF) eagerly prefetch resources // before the base attribute is added, causing 404 and terribly slow loading of the docs app. (function() { + if (window.name.indexOf('NG_DEFER_BOOTSTRAP!') == 0) { + //TODO(i): super ugly hack to temporarily speed up our e2e tests until we move to protractor + extracted examples + window.RUNNING_IN_NG_TEST_RUNNER = true; + } + var indexFile = (location.pathname.match(/\/(index[^\.]*\.html)/) || ['', ''])[1], rUrl = /(#!\/|api|guide|misc|tutorial|cookbook|error|index[^\.]*\.html).*$/, baseUrl = location.href.replace(rUrl, indexFile), @@ -50,7 +55,9 @@ addTag('script', {src: 'components/angular-bootstrap.js' }, sync); addTag('script', {src: 'components/angular-bootstrap-prettify.js' }, sync); addTag('script', {src: 'components/google-code-prettify.js' }, sync); - addTag('script', {src: 'components/' + (debug ? 'lunr.js' : 'lunr.min.js') }, sync); + if (!window.RUNNING_IN_NG_TEST_RUNNER) { + addTag('script', {src: 'components/' + (debug ? 'lunr.js' : 'lunr.min.js') }, sync); + } addTag('script', {src: 'components/marked.js' }, sync); addTag('script', {src: 'docs-data.js'}, sync); addTag('script', {src: 'js/docs.js'}, sync); diff --git a/docs/src/templates/js/docs.js b/docs/src/templates/js/docs.js index 16042b3a380e..1deea88e634b 100644 --- a/docs/src/templates/js/docs.js +++ b/docs/src/templates/js/docs.js @@ -109,6 +109,8 @@ docsApp.controller.DocsNavigationCtrl = ['$scope', '$location', 'docsSearch', fu docsApp.serviceFactory.lunrSearch = function() { return function(properties) { + if (window.RUNNING_IN_NG_TEST_RUNNER) return null; + var engine = lunr(properties); return { store : function(values) { @@ -122,7 +124,10 @@ docsApp.serviceFactory.lunrSearch = function() { }; docsApp.serviceFactory.docsSearch = ['$rootScope','lunrSearch', 'NG_PAGES', - function($rootScope, lunrSearch, NG_PAGES) { + function($rootScope, lunrSearch, NG_PAGES) { + if (window.RUNNING_IN_NG_TEST_RUNNER) { + return null; + } var index = lunrSearch(function() { this.ref('id'); From 705404ff8e3187dcc23b1fbafd60a67eaca26c7d Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Fri, 16 Aug 2013 10:53:18 -0700 Subject: [PATCH 2/4] chore(ngdocs): disable code prettification in e2e tests code prettification is expensive and not needed for e2e tests, so I'm disabling it to speed up the e2e test suite. this is a temporary measure, see previous commit for more info. --- docs/components/angular-bootstrap/bootstrap-prettify.js | 7 ++++++- docs/src/templates/index.html | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/components/angular-bootstrap/bootstrap-prettify.js b/docs/components/angular-bootstrap/bootstrap-prettify.js index 9d8a7d23482e..169d232b6075 100644 --- a/docs/components/angular-bootstrap/bootstrap-prettify.js +++ b/docs/components/angular-bootstrap/bootstrap-prettify.js @@ -102,7 +102,12 @@ directive.prettyprint = ['reindentCode', function(reindentCode) { //ensure that angular won't compile {{ curly }} values html = html.replace(/\{\{/g, '{{') .replace(/\}\}/g, '}}'); - element.html(window.prettyPrintOne(reindentCode(html), undefined, true)); + if (window.RUNNING_IN_NG_TEST_RUNNER) { + element.html(html); + } + else { + element.html(window.prettyPrintOne(reindentCode(html), undefined, true)); + } } }; }]; diff --git a/docs/src/templates/index.html b/docs/src/templates/index.html index 1deb08e1c4f9..4807019a3db2 100644 --- a/docs/src/templates/index.html +++ b/docs/src/templates/index.html @@ -54,8 +54,8 @@ addTag('script', {src: path('angular-animate.js') }, sync); addTag('script', {src: 'components/angular-bootstrap.js' }, sync); addTag('script', {src: 'components/angular-bootstrap-prettify.js' }, sync); - addTag('script', {src: 'components/google-code-prettify.js' }, sync); if (!window.RUNNING_IN_NG_TEST_RUNNER) { + addTag('script', {src: 'components/google-code-prettify.js' }, sync); addTag('script', {src: 'components/' + (debug ? 'lunr.js' : 'lunr.min.js') }, sync); } addTag('script', {src: 'components/marked.js' }, sync); From 35d4993c3dc9f0068b77bb09b7ae2ec979bdeaad Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Fri, 16 Aug 2013 10:56:04 -0700 Subject: [PATCH 3/4] chore(ngdocs): disable google analytics in e2e tests GA is not needed during e2e tests, so I'm removing it to speed up the e2e test suite. See previous commits for more info. --- docs/src/templates/index.html | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/src/templates/index.html b/docs/src/templates/index.html index 4807019a3db2..0788e4153626 100644 --- a/docs/src/templates/index.html +++ b/docs/src/templates/index.html @@ -119,11 +119,13 @@ _gaq.push(['_setAccount', 'UA-8594346-3']); _gaq.push(['_setDomainName', '.angularjs.org']); - (function() { - var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; - ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; - var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); - })(); + if (!window.RUNNING_IN_NG_TEST_RUNNER) { + (function() { + var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; + ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; + var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); + })(); + } From 44b6b72e5e9d193ec878ac7a4f25a00815f68cca Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Fri, 16 Aug 2013 06:21:26 -0700 Subject: [PATCH 4/4] fix($injector): don't parse fns with no args When annotating a fn, it is wasteful to try to parse a fn that has no arguments as such fn has no injectable dependencies --- src/auto/injector.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/auto/injector.js b/src/auto/injector.js index f165030fb335..96ea0bf45c25 100644 --- a/src/auto/injector.js +++ b/src/auto/injector.js @@ -52,13 +52,15 @@ function annotate(fn) { if (typeof fn == 'function') { if (!($inject = fn.$inject)) { $inject = []; - fnText = fn.toString().replace(STRIP_COMMENTS, ''); - argDecl = fnText.match(FN_ARGS); - forEach(argDecl[1].split(FN_ARG_SPLIT), function(arg){ - arg.replace(FN_ARG, function(all, underscore, name){ - $inject.push(name); + if (fn.length) { + fnText = fn.toString().replace(STRIP_COMMENTS, ''); + argDecl = fnText.match(FN_ARGS); + forEach(argDecl[1].split(FN_ARG_SPLIT), function(arg){ + arg.replace(FN_ARG, function(all, underscore, name){ + $inject.push(name); + }); }); - }); + } fn.$inject = $inject; } } else if (isArray(fn)) {