searls / jasmine-maven-plugin

Maven plugin to execute Jasmine Specs. Creates your HTML runners for you, runs headlessly, outputs JUnit XML
http://searls.github.io/jasmine-maven-plugin
Other
290 stars 163 forks source link

Path to javascript src directory is different between jasmine:bdd and jasmine:test #35

Closed dehru closed 13 years ago

dehru commented 13 years ago

Hello, thanks so much for sharing this maven plugin. I am trying to integrate this into an Ext JS 4 project. Ext JS uses dynamic loading ( in development mode ) of it's various components...so it needs to know where those files are on the server relative to the html file that is running it. I configure Ext JS like this.

Ext.Loader.setPath('Ext', 'ext/src');

What I'm finding is that the relative urls are different between running jasmine:bdd and jasmine:test.

Here's my configuration:'

<configuration>
    <jsSrcDir>${project.basedir}/src/main/webapp</jsSrcDir>
    <sourceIncludes>
        <include>ext/ext-debug.js</include>
        <include>ucas/utils.js</include>
        <include>ucas.js</include>
    </sourceIncludes>
</configuration>

When I run mvn jasmine:bdd the path to ext-debug.js is:

http://localhost:8234/src/main/webapp/ext/ext-debug.js

and the file is served out of the src directory here:

${project.basedir}/src/main/webapp/ext/

but when I run mvn jasmine:test, that url path is different since it runs out of target.

The same file is now located at the relative url ( Notice no main/webapp ):

[HEADLESS SERVER]/src/ext/ext-debug.js

because it is serving it out of:

target/jasmine/src/ext

This may not be an issue for others. But because Ext JS goes after it's own source files with relative paths, I have to change the configuration of Ext if doing BDD vs running on my CI.

What would you recommend the best way to deal with this issue?

I'm thinking about trying to use a custom spec runner file and trying to configure Ext "on the fly" with the correct path based on whether I'm running in bdd mode or in test mode ( headless ).

Anyway, if you have any suggestions I'd love to hear about it. Otherwise, I'll share any solution that I come up with.

Cheers, Dehru

searls commented 13 years ago

A custom runner is probably the simplest solution in this case. Sorry :/

dehru commented 13 years ago

Searls, I thought I'd post this simple solution in case anyone runs into the same issue.

This is what I ended up adding to my custom runner. Works like a charm...even if a little hardcoded.

<script type="text/javascript">

        var appDirectory = "src/"; //this works for jasmine:test
        if (document.location.port == 8234) { //key off the port used for bdd
            appDirectory = "src/main/webapp/";//this works for jasmine:bdd
        }

    </script>

then i use document.write to append the appDirectory to the script tag src property.
Cheers!

p33t commented 12 years ago

I really wish I knew what "then i use document.write to append the appDirectory to the script tag src property." meant.

p33t commented 12 years ago

So I finally got my ExtJS 4, Jasmine, Maven learning project going. Its available to the public for what it's worth... http://subversion.assembla.com/svn/freshcode_public/learn/extjs/ (The READ_ME.txt is really important)

Particular caveats include: