Jasmine-maven-plugin and require-js lead to path issues

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

This is my original 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>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> 

During maven build, all js sources are copied to target / jasmine / src. Runner.html, which links to my main.js, is in target / jasmine.

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

When you run mvn clean install, you receive the following error message:

Failed to fulfill the goal com.github.searls: jasmine-maven-plugin: 1.1.0: test (by default) on the mywebapp project: 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.html.lun. RuntimeException: java.io.FileNotFoundException: C: \ Jenkins \ JOBS \ job1 \ workspace \ mywebapp \ target \ jasmine \ api \ Data-util.js (The system cannot find the path specified)

Anyone who has the idea of โ€‹โ€‹getting around or setting this up?

+4
source share
3 answers

I had the same problem: java.io.FileNotFoundException

with JS requirement and jasmine

but you do not need to use the maven-resources plugin and hack js files into the second output directory.

I used 'srcDirectoryName'

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

and extended examples at https://github.com/searls/jasmine-maven-plugin/tree/master/src/test/resources/examples

+3
source

In the meantime, I found a workaround or fix (not sure) by setting up 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 this configuration in a separate profile, which I activate during testing.

+1
source

I see that you have lib / require-jquery.js, but your file tree does not show where "lib" is. loading relatively, but you donโ€™t have it. Maybe your problem. I wrote a quick post summarizing my experience using the jasmine-maven plugin and using Require.js. In it I have pom.xml. My pom.xml seems a little smaller than yours, but the plugin works fine for me. Maybe my post will help. Jasmine + Maven + Call + Cover

0
source

Source: https://habr.com/ru/post/1403841/


All Articles