茉莉花Maven插件和RequireJS导致路径问题

4
我正在使用require-js来建立我的JavaScript项目中的依赖关系。我还使用jasmine编写BDD风格的测试用例,并使用jasmine-maven-plugin:1.1.0在无头模式下执行这些测试。
这是我的源项目结构。
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测试运行中,runner将它们视为相对于target/jasmine/runner.html。由于我的模块不知道(也不应该知道)额外的jasmine/src文件夹,所以我认为这是个问题。
当我运行mvn clean install时,我会收到以下错误信息:
“无法执行目标com.github.searls:jasmine-maven-plugin:1.1.0:test(default) on project mywebapp: jasmine-maven-plugin遇到了异常: java.lang.RuntimeException: org.openqa.selenium.WebDriverException: com.gargoylesoftware.htmlunit.ScriptException: 包装了com.gargoylesoftware.htmlunit.ScriptException: 包装了com.gargoylesoftware.htmlunit.ScriptException: 包装了com.gargoylesoftware.htmlunit.ScriptException: 包装了java.lang.RuntimeException: java.io.FileNotFoundException: C:\Jenkins\jobs\job1\workspace\mywebapp\target\jasmine\api\data-util.js(系统找不到指定的路径)”
有没有人有一些解决或配置的想法?
3个回答

3
我遇到了同样的问题: 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下可以找到高级示例。

1

与此同时,我通过配置maven-resources-plugin找到了一种解决方法或修复方法(不太确定)

<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
    <execution>
        <id>copy-js-files</id>
        <phase>generate-test-resources</phase>
        <goals>
            <goal>copy-resources</goal>
        </goals>
        <configuration>
            <outputDirectory>${project.build.directory}/jasmine</outputDirectory>
            <resources>
                <resource>
                    <directory>src/main/javascript</directory>
                    <filtering>false</filtering>
                </resource>
                <resource>
                    <directory>src/main/webapp</directory>
                    <filtering>false</filtering>
                </resource>
                <resource>
                    <directory>src/test/webapp</directory>
                    <filtering>false</filtering>
                </resource>
            </resources>
        </configuration>
    </execution>
</executions>

我将该配置放在一个单独的配置文件中,在测试期间激活。


0

我看到你有lib/require-jquery.js,但是你的文件树没有显示“lib”位于哪里。 is loaded relative to ,但你没有一个。也许这就是你的问题所在。我写了一篇快速文章总结了我的jasmine-maven-plugin和使用Require.js的经验。其中包括我的pom.xml。我的pom.xml似乎比你的小很多,但插件对我来说运行得很好。也许我的文章会有所帮助。Jasmine+Maven+Requirejs+Coverage


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接