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

mvn jasmine:bdd does not behave the same way as mvn test #182

Closed alex-dow closed 11 years ago

alex-dow commented 11 years ago

First off, I have two executions for Jasmine, as I want to run tests on our development code, and then later on run the same tests on compiled code. The compiled code doesn't need any AMD support, but jasmine:bdd is expected to run on development code and so, uses RequireJS.

This is my configuration:

<plugin>
    <groupId>com.github.searls</groupId>
    <artifactId>jasmine-maven-plugin</artifactId>
    <version>1.3.1.2</version>
    <executions>

        <!-- Executed before compilation -->
        <execution>
            <id>dev-test</id>
            <goals>
                <goal>test</goal>
                <goal>bdd</goal>
            </goals>
            <phase>test</phase>
            <configuration>
                <jsSrcDir>${project.basedir}/src/main/javascript</jsSrcDir>
                <jsTestSrcDir>${project.basedir}/src/test/javascript</jsTestSrcDir>

                <customRunnerConfiguration>
                    ${basedir}/src/test/resources/requirejs_config
                </customRunnerConfiguration>
                <specRunnerTemplate>REQUIRE_JS</specRunnerTemplate>
                <preloadSources>
                    <!-- Fill this with libraries that need to be loaded first -->
                    <source>${project.basedir}/src/main/site/javascript/lib/require-2.1.5.js</source>
                    <source>${project.basedir}/src/main/site/javascript/lib/jquery-1.8.3.js</source>
                    <source>${project.basedir}/src/main/site/javascript/lib/underscore-1.4.4.js</source>
                    <source>${project.basedir}/src/main/site/javascript/lib/backbone-1.0.0.js</source>
                    <source>${project.basedir}/src/main/site/javascript/lib/sinon-1.7.1.js</source>
                    <source>${project.basedir}/src/main/site/javascript/lib/jasmine-jquery-1.5.1.js</source>
                </preloadSources>
            </configuration>
        </execution>

        <!-- Executed after compilation -->
        <execution>
            <id>build-test</id>
            <goals>
                <goal>test</goal>
            </goals>
            <phase>verify</phase>
            <configuration>
                <jsSrcDir>${project.basedir}/target/compiled/prod</jsSrcDir>
                <jsTestSrcDir>${project.basedir}/target/js_specs</jsTestSrcDir>

                <preloadSources>
                    <source>${project.basedir}/src/main/site/javascript/lib/jquery-1.8.3.js</source>
                    <source>${project.basedir}/src/main/site/javascript/lib/underscore-1.4.4.js</source>
                    <source>${project.basedir}/src/main/site/javascript/lib/backbone-1.0.0.js</source>
                    <source>${project.basedir}/src/main/site/javascript/lib/sinon-1.7.1.js</source>
                    <source>${project.basedir}/src/main/site/javascript/lib/jasmine-jquery-1.5.1.js</source>
                </preloadSources>
            </configuration>
        </execution>
    </executions>

</plugin>

Everything works as expected when doing mvn clean install. The unit tests are run twice as expected and everything looks good. But when I run mvn jasmine:bdd everything failed. It seems that jasmine:bdd is not using the RequireJS runner template.

Is there a way to conifgure the behavior of the bdd goal? I had assumed the above configuration was good but obviously, I am wrong :(

alex-dow commented 11 years ago

ok I am a bit of a fool. My config was never going to work, I misunderstood the usage of the <goals> tag. Never the less, I need to be configure to the bdd goal separately from other executions and I am still unclear how to do so.

klieber commented 11 years ago

@v0idnull When executing a goal from the command line Maven will only pick up the configuration in your pom.xml if it is either outside of the execution block like this:

<plugin>
  <groupId>com.github.searls</groupId>
  <artifactId>jasmine-maven-plugin</artifactId>
  <version>1.3.1.2</version>
  <executions>
    <execution>
        <goals>
          <goal>test</goal>
        </goals>
      </execution>
   </executions>
  <configuration>
    <jsSrcDir>${project.basedir}/src/main/javascript</jsSrcDir>
    <jsTestSrcDir>${project.basedir}/src/test/javascript</jsTestSrcDir>
    <customRunnerConfiguration>
      ${basedir}/src/test/resources/requirejs_config
    </customRunnerConfiguration>
    <specRunnerTemplate>REQUIRE_JS</specRunnerTemplate>
    <preloadSources>
      <!-- Fill this with libraries that need to be loaded first -->
      <source>${project.basedir}/src/main/site/javascript/lib/require-2.1.5.js</source>
      <source>${project.basedir}/src/main/site/javascript/lib/jquery-1.8.3.js</source>
      <source>${project.basedir}/src/main/site/javascript/lib/underscore-1.4.4.js</source>
      <source>${project.basedir}/src/main/site/javascript/lib/backbone-1.0.0.js</source>
      <source>${project.basedir}/src/main/site/javascript/lib/sinon-1.7.1.js</source>
      <source>${project.basedir}/src/main/site/javascript/lib/jasmine-jquery-1.5.1.js</source>
    </preloadSources>
  </configuration>
</plugin

or if you give the execution an id of default-cli it will also work, see MNG3401 for details.

alex-dow commented 11 years ago

@klieber Ah neat. So it's a limitation of maven too, that's good to know. I've actually ended up using profiles but this seems a lot cleaner and simpler. Thank you.