Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit fec4ef3

Browse files
committed
feat(Scenario): autodisable animations when running e2e tests
animations cause the dom to contain elements that have been removed from the model but are being animated out. we could teach the e2e runner to wait for animations but that would make all tests slower. it should be quite safe to just disable animations automatically when the app is running via the e2e test runner. this change disables only css animations. we should make additional change that disables js animations as well, but since we don't need this right now I'm punting on it.
1 parent ecdf119 commit fec4ef3

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

src/bootstrap/bootstrap-prettify.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ directive.ngEvalJavascript = ['getEmbeddedTemplate', function(getEmbeddedTemplat
179179
}];
180180

181181

182-
directive.ngEmbedApp = ['$templateCache', '$browser', '$rootScope', '$location', function($templateCache, $browser, docsRootScope, $location) {
182+
directive.ngEmbedApp = ['$templateCache', '$browser', '$rootScope', '$location', '$sniffer',
183+
function($templateCache, $browser, docsRootScope, $location, $sniffer) {
183184
return {
184185
terminal: true,
185186
link: function(scope, element, attrs) {
@@ -189,6 +190,7 @@ directive.ngEmbedApp = ['$templateCache', '$browser', '$rootScope', '$location',
189190
$provide.value('$templateCache', $templateCache);
190191
$provide.value('$anchorScroll', angular.noop);
191192
$provide.value('$browser', $browser);
193+
$provide.value('$sniffer', $sniffer);
192194
$provide.provider('$location', function() {
193195
this.$get = ['$rootScope', function($rootScope) {
194196
docsRootScope.$on('$locationChangeSuccess', function(event, oldUrl, newUrl) {
@@ -223,6 +225,7 @@ directive.ngEmbedApp = ['$templateCache', '$browser', '$rootScope', '$location',
223225
event.preventDefault();
224226
}
225227
});
228+
226229
angular.bootstrap(element, modules);
227230
}
228231
};

src/ngScenario/Application.js

+23-5
Original file line numberDiff line numberDiff line change
@@ -49,29 +49,47 @@ angular.scenario.Application.prototype.getWindow_ = function() {
4949
*/
5050
angular.scenario.Application.prototype.navigateTo = function(url, loadFn, errorFn) {
5151
var self = this;
52-
var frame = this.getFrame_();
52+
var frame = self.getFrame_();
5353
//TODO(esprehn): Refactor to use rethrow()
5454
errorFn = errorFn || function(e) { throw e; };
5555
if (url === 'about:blank') {
5656
errorFn('Sandbox Error: Navigating to about:blank is not allowed.');
5757
} else if (url.charAt(0) === '#') {
5858
url = frame.attr('src').split('#')[0] + url;
5959
frame.attr('src', url);
60-
this.executeAction(loadFn);
60+
self.executeAction(loadFn);
6161
} else {
6262
frame.remove();
63-
this.context.find('#test-frames').append('<iframe>');
64-
frame = this.getFrame_();
63+
self.context.find('#test-frames').append('<iframe>');
64+
frame = self.getFrame_();
65+
66+
frame[0].contentWindow.name = "NG_DEFER_BOOTSTRAP!";
67+
6568
frame.load(function() {
6669
frame.unbind();
6770
try {
71+
var $window = self.getWindow_();
72+
73+
if ($window.angular) {
74+
// Disable animations
75+
76+
// TODO(i): this doesn't disable javascript animations
77+
// we don't need that for our tests, but it should be done
78+
$window.angular.resumeBootstrap([['$provide', function($provide) {
79+
$provide.decorator('$sniffer', function($delegate) {
80+
$delegate.supportsTransitions = false;
81+
return $delegate;
82+
});
83+
}]]);
84+
}
85+
6886
self.executeAction(loadFn);
6987
} catch (e) {
7088
errorFn(e);
7189
}
7290
}).attr('src', url);
7391
}
74-
this.context.find('> h2 a').attr('href', url).text(url);
92+
self.context.find('> h2 a').attr('href', url).text(url);
7593
};
7694

7795
/**

test/ngScenario/ApplicationSpec.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,20 @@ describe('angular.scenario.Application', function() {
99
}
1010

1111
beforeEach(function() {
12+
document.body.innerHTML = '';
1213
frames = _jQuery("<div></div>");
14+
_jQuery(document.body).append(frames);
1315
app = new angular.scenario.Application(frames);
1416
});
1517

16-
it('should return new $window and $document after navigate', function() {
18+
19+
afterEach(function() {
20+
_jQuery('iframe').unbind(); // cleanup any leftover onload handlers
21+
document.body.innerHTML = '';
22+
});
23+
24+
25+
it('should return new $window and $document after navigateTo', function() {
1726
var called;
1827
var testWindow, testDocument, counter = 0;
1928
app.getWindow_ = function() {

0 commit comments

Comments
 (0)