jlgrock / ClosureJavascriptFramework

A group of plug-ins that can be used in conjunction with maven to execute the Google Closure Compiler on JavaScript code. This Framework allows for scaling and modularity.
MIT License
16 stars 7 forks source link

Test Classes need to be included as part of build #27

Open jlgrock opened 11 years ago

jlgrock commented 11 years ago

From a user:

I am trying to setup specific testing scenario and I can not find a way how to do it properly, thus I am contacting you directly, you might be able to give me some hints.

Here is the situation: I am implementing some application with Google Closure and I am using your CJF (1.14.0). Now, my javascript src files live in src/main/javascript/ and my test files live in src/test/javascript. I am not very familiar with what is really going on when I run 'mvn clean test' but I encountered situation when not all test resources are picked up and I am getting the following error (please see below for a more details):

ERROR Problem with require in file 'xxx/src/test/javascript/org/Manager_test.js'. Found goog.require for 'org.xyz.TestService', but did not find a corresponding goog.provide. java.lang.NullPointerException at com.github.jlgrock.javascriptframework.closurecompiler.CalcDeps.orderDependenciesForNamespace(CalcDeps.java:232) at com.github.jlgrock.javascriptframework.closurecompiler.CalcDeps.slowSort(CalcDeps.java:197) at com.github.jlgrock.javascriptframework.closurecompiler.CalcDeps.calculateDependencies(CalcDeps.java:101) at com.github.jlgrock.javascriptframework.closurecompiler.CalcDeps.executeCalcDeps(CalcDeps.java:299) at com.github.jlgrock.javascriptframework.closurecompiler.JsClosureCompileMojo.createDepsAndRequiresJS(JsClosureCompileMojo.java:95) at com.github.jlgrock.javascriptframework.closurecompiler.JsClosureCompileMojo.execute(JsClosureCompileMojo.java:516) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59) at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156) at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537) at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196) at org.apache.maven.cli.MavenCli.main(MavenCli.java:141) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)

jlgrock commented 11 years ago

The way the dependency manager works is that it can only currently pull requires from the src/main/javascript directory, so if you are adding additional classes within the testing (because you are being a decent programmer and refactoring shared functionality into additional classes), this isn't going to work. This is because of the way closure compiler was compiling the code. Since we didn't want to have the compiler run for every test case (which would take forever), we limited it to using only requires that are in the src/main/javascript folder (or from maven dependencies).

In the meantime, you might want to throw everything into a "testing" folder in src/main/javascript and then just omit them from the debug distribution, which is what we've been doing. The compiled code will have already removed anything that wasn't used. Not ideal, but it works.

I'm researching how this is done to see if this can be compiled into a test version of the compiled file and use it accordingly.