arthur-e / Wicket

A modest library for moving between Well-Known Text (WKT) and various framework geometries
https://arthur-e.github.io/Wicket/
Other
586 stars 227 forks source link

waits for google to load, to pass karma tests #124

Closed ffflabs closed 6 years ago

ffflabs commented 6 years ago

This fixes the error reported in issue https://github.com/arthur-e/Wicket/issues/123

Currently, PhantomJS isn't able to load https resources unless you pass the flag --ignore-ssl-errors=true. Therefore, the config in karma.conf.js has a new section to configure PhantomJS:

        phantomjsLauncher: {
            exitOnResourceError: false,
            flags: [
                '--web-security=false',
                '--load-images=false',
                '--ignore-ssl-errors=true'
            ]
        },

(The other approach would be to request google maps API using http instead of https, but we don't know if they would support that protocol in the long term).

I also pinned google.maps.api version to 3.31 (current stable) because 3.32 (3.exp) adds a new renderer and base map that will be subject to several changes soon, so why take the risk now.

The test file wicket-gmap3-spec.js has now a testAsync function:

function testAsync(done) {
        if (window.google) {
            done();
        }
        console.log('waiting for google to load');
        // Wait one second, then check if google has loaded.
        // If it hasn't, then wait for another second and so forth
        setTimeout(function() {
            if (window.google) {
                done();
            } else {
                testAsync(done);
            }
        }, 1000);
    }

This condition is checked declaring beforeEach

    beforeEach(function(done) {
        // Make an async call, passing the special done callback 
        // to ensure google maps is loaded.
        testAsync(done);
    });

And we add an assertion to ensure google.maps is loaded:

    it("Type of window.google should be 'object' to ensure the library is loaded in the global scope", function() {
        expect(typeof window.google).toEqual('object');
    });
ffflabs commented 6 years ago

@arthur-e I'm still unsure if it was a good idea to remove google.maps.api key. It's a key I use for tests and examples in Stack Overflow, and I'm comfortable enough making it public. It's still your call tho.

arthur-e commented 6 years ago

This is great! Dream come true. Thanks for fixing the tests for Travis CI.

Re: API key, it sounds like I should register one that is dedicated to Wicket and apply it.