简体   繁体   English

在本地主机上针对静态Web应用运行内部功能测试

[英]Run intern functional tests against static web app on localhost

I have a static web app. 我有一个静态网络应用程序。 Html, JS (requirejs modules), and some CSS. HTML,JS(requirejs模块)和一些CSS。 Currently the 'serverUrl' is being set through a property module, which i can 'require' and use values from it: 当前,“ serverUrl”是通过属性模块设置的,我可以“请求”并使用其中的值:

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. 我具有Intern设置,可以在浏览器中使用src / index.html作为入口点运行功能测试。

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. 给定serverUrl在属性文件中进行了硬编码,我试图找到一种对Web应用程序运行测试的方法,其中serverUrl指向localhost:1234/someFakeServer以便可以测试错误情况等。

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. 有一些使用配置模块的NODE应用程序解决方案,但是由于我从来没有“启动”我的Web应用程序-它只是文件,因此这些文件对我不起作用。

Some solutions I've thought about, but can't figure out how to achieve: 我已经考虑过一些解决方案,但无法解决如何实现:

  • Intern is proxying the files on :9000, so if I can somehow 'build' an application with another properties file pointing to localhost, all is good. 实习生正在代理:9000上的文件,因此,如果我能以某种方式用另一个指向localhost的属性文件来“构建”一个应用程序,那一切都很好。 But I've no idea how to do that - I've looked at webpack and similar but they don't seem to do what I want. 但是我不知道该怎么做-我看过webpack和类似的东西,但是他们似乎并没有按照我的意愿去做。
  • I've looked at Interns 'Setup' config item, which allows a function to be run before the tests are started - so I thought about modifying the properties file in there, but seems too hacky and not sure how I'd put it back... 我看过Interns的“ Setup”配置项,该配置项允许在测试开始之前运行一个功能-所以我考虑过修改那里的属性文件,但是似乎太过分了,不确定我怎么把它放回去...

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. 假设Intern可以访问属性文件,则只需让Intern加载属性文件并将服务器URL从中拉出即可。 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). 如果您有多个潜在的属性文件,则可以在Intern配置中设置要使用的属性文件,或将其作为自定义命令行变量传递(该变量将用于在Intern配置中设置属性)。 The test module can get the name of the properties file from Intern's config and then load the relevant file. 测试模块可以从Intern的配置中获取属性文件的名称,然后加载相关文件。 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
            });
        }
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM