我正在尝试使用RhinoUnit对基于XUL的独立JavaScript应用进行单元测试。我已经成功地改变了给定build.xml
中的很多路径 - 主要是改变RhinoUnit脚本的路径,我更喜欢将其放在另一个目录而不是默认目录中(也就是说,我将RhinoUnit文件放在chrome/content/rhino
中和chrome/content/lint
中的JSLint文件。但是,在某个时刻,我遇到了这个错误:
/<project-path>/build.xml:52: javax.script.ScriptException:
sun.org.mozilla.javascript.internal.WrappedException: Wrapped
java.io.FileNotFoundException: /<project-path>/jslint/fulljslint.js
(No such file or directory) (<Unknown source>#31) in <Unknown source>
at line number 31
jslint/fulljslint.js
中没有build.xml
的引用,但我在jslintant.js
找到了此代码:
var jsLintPath = "jslint/fulljslint.js";
if (attributes.get("jslintpath")) {
jsLintPath = attributes.get("jslintpath");
}
在我看来,此代码为变量设置了默认值,然后尝试使用某个attributes
对象中的值。我假设可以在脚本之外设置这些attributes
,例如一些<atttribute />
标记int build.xml
或一些配置文件。
我的问题是:如何更改对象的值?那可能吗?或者我应该从脚本中更改硬编码字符串吗?
答案 0 :(得分:1)
这是一种考虑的可能性。
如何弄清楚发生了什么:
如果你在jslintant.js
文件中插入它,就在jsLintPath赋值之前你提到:
echo = project.createTask( "echo" );
echo.setMessage( attributes );
echo.perform( );
然后运行RhinoUnit构建,您应该看到类似的内容:
run-js-lint:
[echo] {options={eqeqeq : false, white: true, plusplus : false, bitwise : ... }}
如何做你想做的事情 '选项'被定义为jslintant
scriptdef的属性。要传播jslintpath的值,需要在scriptdef中将其添加为属性,然后在使用如此定义的任务时设置它。例如:
<scriptdef name="jslintant"
src="jslint/jslintant.js"
language="javascript">
<attribute name="options" />
<attribute name="jslintpath" /> <!-- This line added. -->
<element name="fileset" type="fileset" />
</scriptdef>
然后使用任务:
<jslintant options="{eqeqeq : false, ... }"
jslintpath="your_path_here/fulljslint.js" />
如果您重新运行构建,则应该看到:
run-js-lint:
[echo] {jslintpath=your_path_here/fulljslint.js, options={eqeqeq : false, ... }}
您选择的路径将用于查找fulljslint.js
。