Skip to content
This repository has been archived by the owner on May 27, 2018. It is now read-only.

loadFixture doesn't work in Chrome when use file:///... URL. #1

Closed
yushchenko opened this issue Dec 15, 2010 · 6 comments
Closed

loadFixture doesn't work in Chrome when use file:///... URL. #1

yushchenko opened this issue Dec 15, 2010 · 6 comments

Comments

@yushchenko
Copy link

The test contains only loadFixtures() call.
It works fine in Firefox but throws the following error in Chrome:

NETWORK_ERR: NETWORK_ERR: XMLHttpRequest Exception 101

I opened test runner using file:// URL
file:///.../runner.html

If it's possible, it would be great to have ability to run tests without web server in all browsers.

@jeffwatkins
Copy link
Owner

I don't suppose you could post the test you're using? That would be helpful.

@yushchenko
Copy link
Author

Tried to reproduce using small sample (test.js)

describe('jasmine-dom', function(){
    it('should load the fixture without errors', function() {
        loadFixtures('fixture.html');
    });
});

fixture.html content

<div id="testdiv">123</div>

Used URL file:///C:/home/projects/jasmine-dom-test/runner.html with for default jasmine test runner. Files runner.hml, test.js, feature.html are located in the same directory.

The test pass only in Safary and FF but in Chrome and IE8 it fails with error like that

NETWORK_ERR: NETWORK_ERR: XMLHttpRequest Exception 101

As i now understand it shouldn't work in any browser because jasmine-dom uses XHR to get a fixture so a web server is must...

In fact, even in Safary and FF adding check, if the fixture has been loaded, broke the test:

    it('should load the fixture without errors', function() {
        loadFixtures('fixture.html');
        var div = document.getElementById('testdiv');
        expect(div).toHaveId('testdiv');
    });

So loadFixtures doesn't load html into DOM, just not throws an exception in these browsers... looks a bit inconsistent...

Obvious work around - use web server, but sometimes it would be very convenient just click on runner.html and get test results.

I'm not sure but loading markup using iframe should work with such file://... URLs.

@jeffwatkins
Copy link
Owner

Thanks for digging into that. I'll see what I can do. I know I use XHR with file URLs all the time, so there must be more to it.

@jeffwatkins
Copy link
Owner

Chrome has a bug that prevents XHR from loading anything when loaded from a file URL. Based on the discussions on the ticket, this is unlikely to change any time soon.

However, I believe I've fixed this for the other browsers. I've tested this now for Firefox and Safari on my Mac and it worked fine. Please let me know if you have trouble with IE. In Firefox, the XHR was never calling the onreadystatechange callback, because the request was synchronous.

@xiongchiamiov
Copy link
Contributor

It should be noted that, according to the previously-linked discussion, this should work if you launch Chrome with the --allow-file-access-from-files flag.

You might want to add this information to the README.

@jeffwatkins
Copy link
Owner

Updated README.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants