OliverDeLange
OliverDeLange

Reputation: 633

Run intern functional tests against static web app on localhost

I have a static web app. Html, JS (requirejs modules), and some CSS. Currently the 'serverUrl' is being set through a property module, which i can 'require' and use values from it:

define({
    serverUrl: 'https://some.api/path/'
})

I have Intern setup to run functional tests in the browser using src/index.html as the entry point.

return this.remote
    .get(require.toUrl('src/index.html'))

Given the serverUrl is hardcoded in the properties file, I'm trying to find a way to run tests against the web app where serverUrl is pointing to localhost:1234/someFakeServer so I can test error scenarios and such.

I've trawled the web but can't find anyone doing anything remotely similar to me, which makes me think I'm doing something obviously wrong. There's solutions for NODE apps, using config modules, but because I never 'start' my web app - its just files, these won't work for me.

Some solutions I've thought about, but can't figure out how to achieve:

Upvotes: 0

Views: 239

Answers (1)

jason0x43
jason0x43

Reputation: 3363

Assuming the properties file is accessible to Intern, you could simply have Intern load the properties file and pull the server URL out of it. If you have multiple potential properties files, the one being used can be set in the Intern config or passed in as a custom command line variable (which would be used to set a property in the Intern config). The test module can get the name of the properties file from Intern's config and then load the relevant file. It could look something like this (untested):

// intern config
define({
    // ...
    propertiesFile: 'whatever',
})

// test file
define([ 'intern', ... ], function (intern, ...) {
    registerSuite({
        // ...
        'a test': function () {
            var did = this.async();
            var remote = this.remote;
            require([
                intern.config.propertiesFile
            ], dfd.callback(function (props) {
                return remote.get(props.url)
                    .otherStuff
            });
        }
    });
});

Upvotes: 1

Related Questions