gpt4 book ai didi

javascript - jasmine-maven-plugin 和 require-js 导致路径问题

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:49:54 24 4
gpt4 key购买 nike

我正在使用 require-js 为我的 java 脚本项目中的依赖项建模。我还使用 jasmine 编写 BDD 样式的测试用例,并使用 jasmine-maven-plugin:1.1.0 在 headless 模式下执行这些测试。

这是我的源项目结构

project/
| src/main/javascript
| | api/*.js
| | main.js
| src/test/javascript
| | spec/*spec.js

这是我的 webapp pom jasmine 配置:

<plugin>
<groupId>com.github.searls</groupId>
<artifactId>jasmine-maven-plugin</artifactId>
<version>1.1.0</version>
<executions>
<execution>
<goals>
<goal>generateManualRunner</goal>
<goal>resources</goal>
<goal>testResources</goal>
<goal>test</goal>
<goal>preparePackage</goal>
</goals>
</execution>
</executions>
<configuration>
<specRunnerTemplate>REQUIRE_JS</specRunnerTemplate>
<scriptLoaderPath>lib/require-jquery.js</scriptLoaderPath>
<sourceIncludes>
<include>lib/require-jquery.js</include>
<include>lib/underscore.js</include>
<include>lib/backbone.js</include>
<include>lib/d3.js</include>
<include>lib/d3.layout.js</include>
<include>lib/bootstrap.js</include>
<include>main.js</include>
</sourceIncludes>
<preloadSources>
<source>lib/require-jquery.js</source>
<source>lib/underscore.js</source>
<source>lib/backbone.js</source>
<source>lib/d3.js</source>
<source>lib/d3.layout.js</source>
<source>lib/bootstrap.js</source>
<source>main.js</source>
</preloadSources>
<browserVersion>FIREFOX_3_6</browserVersion>
</configuration>
</plugin>

在 maven 构建期间,所有 js 源都被复制到 target/jasmine/src。引用我的 main.js 的 runner.html 位于 target/jasmine。

现在的问题是我的 require-js 模块定义了它们相对于 main.js 的依赖关系,而在 Maven 测试运行中,运行器假设它们是相对于 target/jasmine/runner.html 的。由于我的模块没有(也不能)知道额外的 jasmine/src 文件夹,恕我直言,这是一个问题。

我在运行 mvn clean install 时收到以下错误消息:

Failed to execute goal com.github.searls:jasmine-maven-plugin:1.1.0:test (default) on project mywebapp: The jasmine-maven-plugin encountered an exception: java.lang.RuntimeException: org.openqa.selenium.WebDriverException: com.gargoylesoftware.htmlunit.ScriptException: Wrapped com.gargoylesoftware.htmlunit.ScriptException: Wrapped com.gargoylesoftware.htmlunit.ScriptException: Wrapped com.gargoylesoftware.htmlunit.ScriptException: Wrapped com.gargoylesoftware.htmlunit.ScriptException: Wrapped java.lang.RuntimeException: java.io.FileNotFoundException: C:\Jenkins\jobs\job1\workspace\mywebapp\target\jasmine\api\data-util.js (The system cannot find the path specified)

有人想解决或配置它吗?

最佳答案

我遇到了同样的问题:java.io.FileNotFoundException

使用 requireJS 和 jasmine

但您不必使用 maven-resources-plugin 并将 js 文件破解到第二个输出目录。

我使用了'srcDirectoryName'

您可以在 https://github.com/searls/jasmine-maven-plugin/blob/master/src/main/java/com/github/searls/jasmine/mojo/AbstractJasmineMojo.java 找到所有可能的参数

https://github.com/searls/jasmine-maven-plugin/tree/master/src/test/resources/examples 下的高级示例

关于javascript - jasmine-maven-plugin 和 require-js 导致路径问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9904713/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com