Pregunta

For my current project, I'm setting up JS testing with Jasmine. We want our tests to run automatically on each build, so I plugged it into our Maven build. I can run some basic tests of the Javascript, and everything is working peachy. So far so good!

However, we are building a rich client interface, and doing a lot of callbacks to the server - so, we have a lot of $.ajax calls in our code. Whenever I try to load our JS files that contain the call (not execute tests, the processing isn't even there yet), the Maven build crashes each time, because it tries to do the callback already:

[ERROR] Caused by: java.io.FileNotFoundException: F:\Users\gjoris\Development\Source\xxx\xxx-war\target\jasmine\rest\xxx\search (The system cannot find the path specified)

So, just to make it very clear: I'm not running tests here, I'm just loading the sources. This is the configuration for my plugin thusfar:

            <plugin>
            <groupId>com.github.searls</groupId>
            <artifactId>jasmine-maven-plugin</artifactId>
            <version>1.2.0.0</version>
            <extensions>true</extensions>
            <executions>
                <execution>
                    <goals>
                        <goal>test</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <sourceIncludes>
                    <include>sorting*.js</include>
                    <include>*blabla*.js</include>
                </sourceIncludes>
                <jsSrcDir>${project.basedir}/src/main/webapp/resources/scripts/</jsSrcDir>
                <jsTestSrcDir>${project.basedir}/src/test/javascript</jsTestSrcDir>
                <timeout>300</timeout>
                <preloadSources>
                    <!-- Load basic libraries for application-->
                    <source>${project.basedir}/src/main/webapp/resources/scripts/libs/knockout-2.1.0.js</source>
                    <source>${project.basedir}/src/main/webapp/resources/scripts/libs/jquery-1.7.2.min.js</source>
                    <!-- Load all necessary Jasmine plugins -->
                    <source>${project.basedir}/src/test/javascript/libs/jasmine-ajax/mock-ajax.js</source>
                    <source>${project.basedir}/src/test/javascript/libs/jasmine-jquery/jasmine-jquery.js</source>
                    <!-- Load our own mocks -->
                    (some of our mocks in JS go here)
                    <!-- Load additional libraries, application specific, which are needed to run -->
                    (some general JS, which are used everywhere)
                </preloadSources>
            </configuration>
        </plugin>

Anybody any experience with this, and knows how I have to configure it?

¿Fue útil?

Solución

I have an answer already, but to be sure, I'll post it here.

The problem was that we are using KnockoutJS as well, and that the model, upon load, executed the ajax call.

What I did now, was to extract the knockout load features into a different JS file, which I'm not loading into my preloaded sources. That way, I can test everything on my model, but the ajax call does not execute on preload. And thus, I can mock the ajax calls.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top