javascript - jasmine-maven-plugin and require-js result in path issues - Stack Overflow

I am using require-js to model dependencies in my java script project. I also use jasmine to write BDD

I am using require-js to model dependencies in my java script project. I also use jasmine to write BDD styled test cases and the jasmine-maven-plugin:1.1.0 to execute these tests in headless mode.

This is my source project structure

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

This is my webapp pom jasmine configuration:

<plugin>
    <groupId>.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>

During the maven build all js sources are copied to target/jasmine/src. The runner.html that refers to my main.js is at target/jasmine.

Now the problem is that my require-js modules define their dependencies relative to the main.js, whereas in the maven test run, the runner assumes them to be relative to target/jasmine/runner.html. Since my modules are not (and must not be) aware of the additional jasmine/src folder, IMHO that is an issue.

I receive the following error message when I run mvn clean install:

Failed to execute goal .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: .gargoylesoftware.htmlunit.ScriptException: Wrapped .gargoylesoftware.htmlunit.ScriptException: Wrapped .gargoylesoftware.htmlunit.ScriptException: Wrapped .gargoylesoftware.htmlunit.ScriptException: Wrapped .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)

Anybody out there having some idea to work around or configure that?

I am using require-js to model dependencies in my java script project. I also use jasmine to write BDD styled test cases and the jasmine-maven-plugin:1.1.0 to execute these tests in headless mode.

This is my source project structure

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

This is my webapp pom jasmine configuration:

<plugin>
    <groupId>.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>

During the maven build all js sources are copied to target/jasmine/src. The runner.html that refers to my main.js is at target/jasmine.

Now the problem is that my require-js modules define their dependencies relative to the main.js, whereas in the maven test run, the runner assumes them to be relative to target/jasmine/runner.html. Since my modules are not (and must not be) aware of the additional jasmine/src folder, IMHO that is an issue.

I receive the following error message when I run mvn clean install:

Failed to execute goal .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: .gargoylesoftware.htmlunit.ScriptException: Wrapped .gargoylesoftware.htmlunit.ScriptException: Wrapped .gargoylesoftware.htmlunit.ScriptException: Wrapped .gargoylesoftware.htmlunit.ScriptException: Wrapped .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)

Anybody out there having some idea to work around or configure that?

Share Improve this question edited Mar 28, 2012 at 15:49 Robert asked Mar 28, 2012 at 9:31 RobertRobert 1,9502 gold badges21 silver badges39 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

I faced the same problem: java.io.FileNotFoundException

with requireJS and jasmine

but you don't have to use the maven-resources-plugin and hack the js files to a second output directory.

I used 'srcDirectoryName'

you can find all possible params at https://github./searls/jasmine-maven-plugin/blob/master/src/main/java//github/searls/jasmine/mojo/AbstractJasmineMojo.java

and advanced examples under https://github./searls/jasmine-maven-plugin/tree/master/src/test/resources/examples

In the meantime I found a workaround or a fix (not sure) by configuring the 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>

I put that configuration in a separate profile which I activate during testing.

I see that you've got lib/require-jquery.js, but your file tree doesn't show where "lib" is located. is loaded relative to , but you don't have one. Maybe that's your problem. I wrote a quick post summarizing my experience with the jasmine-maven-plugin and using Require.js. In it I've got my pom.xml. My pom.xml seems quite a bit smaller than yours but the plugin works fine for me. Maybe my post will help. Jasmine+Maven+Requirejs+Coverage

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745131429a4612990.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信