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

test(jqLite): make iframe contents() test less flaky #8157

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions karma-jqlite.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ module.exports = function(config) {
sharedConfig(config, {testName: 'AngularJS: jqLite', logFile: 'karma-jqlite.log'});

config.set({
files: angularFiles.mergeFilesFor('karma').concat({
pattern: "test/fixtures/**/*.html",
served: true,
watched: true,
included: false
}),
files: angularFiles.mergeFilesFor('karma'),
exclude: angularFiles.mergeFilesFor('karmaExclude'),

junitReporter: {
Expand Down
7 changes: 1 addition & 6 deletions karma-jquery.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ module.exports = function(config) {
sharedConfig(config, {testName: 'AngularJS: jQuery', logFile: 'karma-jquery.log'});

config.set({
files: angularFiles.mergeFilesFor('karmaJquery').concat({
pattern: "test/fixtures/**/*.html",
served: true,
watched: true,
included: false
}),
files: angularFiles.mergeFilesFor('karmaJquery'),
exclude: angularFiles.mergeFilesFor('karmaJqueryExclude'),

junitReporter: {
Expand Down
9 changes: 0 additions & 9 deletions test/fixtures/iframe.html

This file was deleted.

55 changes: 30 additions & 25 deletions test/jqLiteSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1444,32 +1444,37 @@ describe('jqLite', function() {
expect(contents[1].data).toEqual('before-');
});

// IE8 does not like this test, although the functionality may still work there.
if (!msie || msie > 8) {
it('should select all types iframe contents', function() {
var iframe_ = document.createElement('iframe'), tested,
iframe = jqLite(iframe_);
function test() {
var contents = iframe.contents();
expect(contents[0]).toBeTruthy();
expect(contents.length).toBe(1);
expect(contents.prop('nodeType')).toBe(9);
expect(contents[0].body).toBeTruthy();
expect(jqLite(contents[0].body).contents().length).toBe(3);
iframe.remove();
tested = true;
}
iframe_.onload = iframe_.onreadystatechange = function() {
if (iframe_.contentDocument) test();
};
iframe_.src = "/base/test/fixtures/iframe.html";
jqLite(document).find('body').append(iframe);
it('should select all types iframe contents', function() {
// IE8 does not like this test, although the functionality may still work there.
if (msie < 9) return;
var iframe_ = document.createElement('iframe');
var tested = false;
var iframe = jqLite(iframe_);
function test() {
var doc = iframe_.contentDocument || iframe_.contentWindow.document;
doc.body.innerHTML = '\n<span>Text</span>\n';

var contents = iframe.contents();
expect(contents[0]).toBeTruthy();
expect(contents.length).toBe(1);
expect(contents.prop('nodeType')).toBe(9);
expect(contents[0].body).toBeTruthy();
expect(jqLite(contents[0].body).contents().length).toBe(3);
iframe.remove();
doc = null;
tested = true;
}
iframe_.onload = iframe_.onreadystatechange = function() {
if (iframe_.contentDocument) test();
};
/* jshint scripturl:true */
iframe_.src = 'javascript:false';
jqLite(document).find('body').append(iframe);

// This test is potentially flaky on CI cloud instances, so there is a generous
// wait period...
waitsFor(function() { return tested; }, 2000);
});
}
// This test is potentially flaky on CI cloud instances, so there is a generous
// wait period...
waitsFor(function() { return tested; }, 2000);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still need to waitsFor because this is still asynchronous, but it''s not making a request anymore --- the fetch algorithm should abort this quickly.

Lets see how it does on travis...

});
});


Expand Down