[英]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: 我已经考虑过一些解决方案,但无法解决如何实现:
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.