Closed occasl closed 11 years ago
On second thought, I'll just keep my specs in the default directory (that works).
That, however, leads to a different issue. The plugin is not picking up my vendor libs that I need bootstrapped (e.g., ExtJS). So I have this in the configuration for the plugin:
<configuration>
<!--<jsTestSrcDir>${basedir}/src/main/webapp/spec</jsTestSrcDir>-->
<jsSrcDir>${basedir}/src/main/webapp</jsSrcDir>
<sourceIncludes>
<include>src/main/webapp/lib/extjs4/**/*.js</include>
<include>src/main/webapp/app/**/*.js</include>
</sourceIncludes>
<!--<specIncludes>
<include>${basedir}/src/main/webapp/spec/**/*.js</include>
</specIncludes>-->
</configuration>
But then I see this in the output:
J A S M I N E S P E C S
-------------------------------------------------------
[INFO]
Jasmine Check
Check Ext <<< FAILURE!
* ReferenceError: "Ext" is not defined. in file:/C:/dev/QES/ponderosa-ui/UiView/ponderosa-ui/target/jasmine/spec/JasmineExtSpec.js (line 3)
Jasmine Check
Check Ext4 Exists <<< FAILURE!
* ReferenceError: "Ext" is not defined. in file:/C:/dev/QES/ponderosa-ui/UiView/ponderosa-ui/target/jasmine/spec/spec/JasmineExtSpec.js (line 3)
2 failures:
1.) Jasmine Check it Check Ext <<< FAILURE!
* ReferenceError: "Ext" is not defined. in file:/C:/dev/QES/ponderosa-ui/UiView/ponderosa-ui/target/jasmine/spec/JasmineExtSpec.js (line 3)
2.) Jasmine Check it Check Ext4 Exists <<< FAILURE!
* ReferenceError: "Ext" is not defined. in file:/C:/dev/QES/ponderosa-ui/UiView/ponderosa-ui/target/jasmine/spec/spec/JasmineExtSpec.js (line 3)
Results: 2 specs, 2 failures
Thoughts?
Everything inside sourceIncludes
is relative to jsSrcDir
, so it's going to be looking for ${basedir}/src/main/webapp/src/main/webapp/...
the way you have it configured now. The same is true for specs.
Additionally, if you're using ExtJS in your tests, you'll want to modify the default runner template so that the tests execute from Ext.onReady()
, otherwise you're likely to run into some odd bugs (some of which you may see anyway, just because of exactly when the various different portions of a Jasmine spec get executed)
Ok, thanks that resolves the issue.
I've seemed to run into another issue when I actually start testing the codebase. I decided to reproduce this using the ExtJS simple project. This only happens with the plugin as I can run the tests as expected when running in a browser. Here's the error:
1.) Users it should have users <<< FAILURE!
* TypeError: Cannot call method "getController" of null in file:/C:/apps/apache-tomcat-7.0.14/webapps/simple/target/jasmine/spec/specs/users.js (line 6)
* TypeError: Cannot call method "getCount" of null in file:/C:/apps/apache-tomcat-7.0.14/webapps/simple/target/jasmine/spec/specs/users.js (line 23)
2.) Users it should open the editor window <<< FAILURE!
* TypeError: Cannot call method "getController" of null in file:/C:/apps/apache-tomcat-7.0.14/webapps/simple/target/jasmine/spec/specs/users.js (line 6)
* TypeError: Cannot call method "editUser" of null in file:/C:/apps/apache-tomcat-7.0.14/webapps/simple/target/jasmine/spec/specs/users.js (line 29)
Here is how I have things configured:
<configuration>
<srcDirectoryName>/</srcDirectoryName>
<jsSrcDir>${basedir}</jsSrcDir>
<sourceIncludes>
<include>extjs4/**/*.js</include>
<include>app-test.js</include>
<include>app/**/*.js</include>
</sourceIncludes>
<jsTestSrcDir>${basedir}/app-test</jsTestSrcDir>
<specIncludes>
<include>specs/**/*.js</include>
</specIncludes>
<specRunnerHtmlFileName>run-tests.html</specRunnerHtmlFileName>
</configuration>
Debug output:
[DEBUG] (f) browserVersion = FIREFOX_3
[DEBUG] (f) debug = false
[DEBUG] (f) format = documentation
[DEBUG] (f) haltOnFailure = true
[DEBUG] (f) jasmineTargetDir = C:\apps\apache-tomcat-7.0.14\webapps\simple\target\jasmine
[DEBUG] (f) jsSrcDir = C:\apps\apache-tomcat-7.0.14\webapps\simple
[DEBUG] (f) jsTestSrcDir = C:\apps\apache-tomcat-7.0.14\webapps\simple\app-test
[DEBUG] (f) junitXmlReportFileName = TEST-jasmine.xml
[DEBUG] (f) manualSpecRunnerHtmlFileName = ManualSpecRunner.html
[DEBUG] (f) mavenProject = MavenProject: com.qualcomm.ssat.poc.simple:simple-ui:1.0.0-SNAPSHOT @ C:\apps\apache-tomcat-7.0.14\webapps\simple\pom.xml
[DEBUG] (f) packageDir = C:\apps\apache-tomcat-7.0.14\webapps\simple\target\simple-ui-1.0.0-SNAPSHOT
[DEBUG] (f) packageJavaScriptPath = js
[DEBUG] (f) serverPort = 8234
[DEBUG] (f) sourceIncludes = [extjs4/**/*.js, app-test.js, app/**/*.js]
[DEBUG] (f) specDirectoryName = spec
[DEBUG] (f) specIncludes = [specs/**/*.js]
[DEBUG] (f) specRunnerHtmlFileName = run-tests.html
[DEBUG] (f) srcDirectoryName = /
[DEBUG] (f) timeout = 300
[DEBUG] -- end configuration --
I also created a my own spec runner, run-tests.html, that is as follows:
<head>
<link rel="stylesheet" type="text/css" href="app-test/lib/jasmine-1.1.0/jasmine.css">
<script type="text/javascript" src="extjs4/ext-all-debug.js"></script>
<script type="text/javascript" src="app-test/lib/jasmine-1.1.0/jasmine.js"></script>
<script type="text/javascript" src="app-test/lib/jasmine-1.1.0/jasmine-html.js"></script>
<script type="text/javascript" src="app-test/specs/example.js"></script>
<script type="text/javascript" src="app-test/specs/users.js"></script>
<script type="text/javascript" src="app-test.js"></script>
</head>
Thanks for your assistance. Additionally, I posted the entire project to my github account https://github.com/occasl/jasmine-simple.
Thanks for posting the project, that'll be helpful.
Be warned that others have tried & failed to get ExtJS to work under HtmlUnit. :-/
Your custom spec runner isn't being used. Try <customRunnerTemplate>run-tests.html</customRunnerTemplate>
instead of that <specRunnerHtmlFileName>
entry in your pom.xml.
Your setup appears to have some race conditions; running with the jasmine:bdd
goal and just refreshing the page several times, I see two of the tests pass/fail seemingly at random. There may be other issues as well -- Justin is right that HtmlUnit and ExtJS aren't always cooperative with one another on the first go, but it's definitely doable with some trial and error.
I gave that a try but unfortunately I get this:
Caused by: net.sourceforge.htmlunit.corejs.javascript.EcmaError: ReferenceError: "reporter" is not defined. (injected script#1)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3772)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3750)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.notFoundError(ScriptRuntime.java:3835)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.name(ScriptRuntime.java:1763)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1781)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:845)
at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:164)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:429)
at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:269)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3162)
at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.exec(InterpretedFunction.java:175)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$3.doRun(JavaScriptEngine.java:490)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:595)
... 31 more
I really gave it an honest effort the last few days, and I can get it to run fairly consistent with jasmine:bdd
but I can't get it to run with the Maven plugin which is disappointing. I continue to get the error above. I'm going to look into phantom.js as an alternative.
Hi Lou,
I'm sorry to hear about your frustrations. I personally use jasmine-headless-webkit for almost all of my day-to-day development, and it works great in CI too. Why don't you give that a try?
I had the same problem.
I guess it is an Error in HTML-Unit I got this error only each second time and was a little bit confused. The reporter is the window.reporter defined in html Template. So it is a JavaScript error which comes up in the Runtime only every second time :)
I could fix it by changing the html template
...
window.reporter = new jasmine.$reporter$();
require(specs, function() {
jasmine.getEnv().addReporter(window.reporter);
jasmine.getEnv().execute();
});
As you can see I use RequireJS template.
Are you using ExtJS too? I tried the window.reporter trick but no dice. My template looks like this to integrate with ExtJS4:
Ext.Loader.setConfig({enabled: true,
paths: {
'Ext.ux':'lib/extjs4/ux/',
'Ponderosa': 'app'
}
});
Ext.require([
'Ext.grid.*',
'Ext.data.*',
'Ext.util.*',
'Ext.grid.PagingScroller',
'Ext.ux.grid.FiltersFeature',
'Ext.grid.feature.Grouping',
'Ext.grid.plugin.CellEditing',
'Ext.state.CookieProvider'/*,
'Ext.QuickTips'*/
]);
var Application = null;
window.reporter = new jasmine.TrivialReporter();
Ext.onReady(function() {
Application = Ext.create('Ext.app.Application', {
name: 'Ponderosa',
controllers: [
'vehicle.VehiclesTabController'
],
launch: function() {
jasmine.getEnv().addReporter(window.reporter);
jasmine.getEnv().execute();
}
});
});
No I don't use ExtJS I use RequireJS with BackboneJS.
I think the problem is that Rhino which is shipped with HTMLUnit as JavaScript engine, is trying to interpret the JavaScript in parallel so it has not all global variables set. For example I had to mock up 'console' because it is also sometimes not there.
So the trick would be to try out when he can find the 'reporter' variable without ExtJS- only plain Jasmine. and than experiment a little :)
On the second thought maybe this will help
jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
Run into the same issue. What is important for the 'jasmine maven plugin' is the global var 'window.reporter' to be assigned with an jasmine reporter instance. Otherwise you get the above 'ReferenceError: "reporter" is not defined.' error.
@occasl Not sure if you are even using the plugin anymore since this issue is over a year old but there have been quite a few changes to the plugin recently so I'd ask that you please try out that version. In the meantime, I'm going to close this issue. If you are still experiencing issues with the latest version let me know and I'll reopen the issue.
Hi,
I must be missing something, but I feel I have everything correctly configured. Here's the output I have from Maven debug, but the plugin can't seem to find my specs to run; it always says "Results: 0 specs, 0 failures" . Any suggestions?
The spec I'm trying to run is as follows under the spec directory identified above:
Finally, here is how it's configured in the POM:
TIA, Lou