【问题标题】:jasmine-maven-plugin and require-js result in path issuesjasmine-maven-plugin 和 require-js 导致路径问题
【发布时间】:2012-03-28 09:31:46
【问题描述】:

我正在使用 require-js 对我的 java 脚本项目中的依赖项进行建模。我还使用 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 测试运行中,运行器假定它们是相对于 target/jasmine/runner.html 的。由于我的模块不(也一定不)知道额外的 jasmine/src 文件夹,恕我直言,这是一个问题。

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

未能执行目标 com.github.searls:jasmine-maven-plugin:1.1.0:test(默认)在项目上 mywebapp:jasmine-maven-plugin 遇到了一个 异常: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 (系统找不到指定的路径)

有人有想法解决或配置它吗?

【问题讨论】:

    标签: javascript maven requirejs jasmine


    【解决方案1】:

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

    使用 requireJS 和茉莉花

    但您不必使用 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下的高级示例

    【讨论】:

      【解决方案2】:

      与此同时,我通过配置 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>
      

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

      【讨论】:

        【解决方案3】:

        我看到你有 lib/require-jquery.js,但你的文件树没有显示“lib”的位置。相对于 加载,但您没有。也许那是你的问题。我写了一篇简短的文章,总结了我使用 jasmine-maven-plugin 和使用 Require.js 的经验。在里面我有我的 pom.xml。我的 pom.xml 看起来比你的要小很多,但是这个插件对我来说很好用。也许我的帖子会有所帮助。 Jasmine+Maven+Requirejs+Coverage

        【讨论】:

          猜你喜欢
          • 2015-12-15
          • 1970-01-01
          • 1970-01-01
          • 2013-05-07
          • 1970-01-01
          • 2014-04-01
          • 2011-05-30
          • 2011-07-05
          • 2013-05-01
          相关资源
          最近更新 更多