Closed shsnyder closed 10 years ago
Hmm.. That doesn't make since. The tests would fail in travis if this was the case. What happens when you run it from the command line? What does your test file look like?
Here is my test file "simple.js" ( i renamed the file from simpletest.js to simple.js) I uncomment the create line when not running as a casperjs test.
// var casper = require('casper').create();
casper.options.verbose = false;
casper.options.logLevel = "debug";
capturePage = false;
var url = "http://www.google.com/";
casper.start();
casper.thenOpen(url, function() {
console.log('Opened page with title \"' + this.getTitle() + '"');
if (capturePage) {
casper.capture("google-home.png");
}
});
casper.run();
When not running as a test I get the following two outputs. Standalone works fine, but
Scotts-MacBook-Pro-2:grunttest sh_snyder$ casperjs simple.js
Opened page with title "Google"
Scotts-MacBook-Pro-2:grunttest sh_snyder$ grunt casper:simpletest
Running "casper:simpletest" (casper) task
Warning: Cannot read property 'length' of undefined Use --force to continue.
Aborted due to warnings.
When running as a test I get the following output:
Scotts-MacBook-Pro-2:grunttest sh_snyder$ casperjs test simple.js
Test file: simple.js
Opened page with title "Google"
Scotts-MacBook-Pro-2:grunttest sh_snyder$ grunt casper:simpletest
Running "casper:simpletest" (casper) task
ReferenceError: Can't find variable: casper
simple.js:4
Hint: you may want to use the `casperjs test` command.
which I mentioned before. Please let me know if there is some way I can track down the issue in my environment, by enabling some sort of debugging of your plugin, or some other test that I can execute to identify the problem.
I will check this out after work tonight and see if I can re-create the issue.
I did some experiments and looked at the code running grunt with verbose mode. In Gruntfile.js -> test:true and no casper = require('casper').create()
Running "casper:simpletest" (casper) task
Verifying property casper.simpletest exists in config...OK
Files: simple.js
Options: log-level="debug", test, parallel, concurrency=1
Arguments: (none)
Preparing casperjs spawn
Adding Option --log-level=debug
Spawning casperjs with args: --direct,simple.js,--log-level=debug,test
ReferenceError: Can't find variable: casper
simple.js:5
Hint: you may want to use the `casperjs test` command.
In Gruntfile.js -> test:false and no casper = require('casper').create()
Running "casper:simpletest" (casper) task
Verifying property casper.simpletest exists in config...OK
Files: simple.js
Options: log-level="debug", test=false, parallel, concurrency=1
Arguments: (none)
Preparing casperjs spawn
Adding Option --log-level=debug
Spawning casperjs with args: simple.js,--direct,--log-level=debug
ReferenceError: Can't find variable: casper
simple.js:5
Hint: you may want to use the `casperjs test` command.
so with test= true or test=false capserjs is not running in test mode. I suspect that it has something to do with the order of the args, when test=true test appeared at the end of the list of args, since it needs to be immediately after the casperjs call it looks like it is being ignored.
With casper = require('casper').create() in the casper file it was successful with test=true or false Omitting a test variable entirely and having a casper instance created was successful and resulted this
Running "casper:simpletest" (casper) task
Verifying property casper.simpletest exists in config...OK
Files: simple.js
Options: log-level="debug", test, parallel, concurrency=1
Arguments: (none)
Preparing casperjs spawn
Adding Option --log-level=debug
Spawning casperjs with args: --direct,simple.js,--log-level=debug,test
[warning] [phantom] [deprecated] --direct option has been deprecated since 1.1; you should use --verbose instead.
⚠ [deprecated] --direct option has been deprecated since 1.1; you should use --verbose instead.
Opened page with title "Google"
Casper Task 'casper:simpletest' took ~2916ms to run
Done, without errors.
which was expected BUT test appears in the arg list, which should not happen as the default is test=false. Finally, with all of the options commented out (an empty options stanza) we see this output
Running "casper:simpletest" (casper) task
Verifying property casper.simpletest exists in config...OK
Files: simple.js
Options: log-level="debug"
Arguments: (none)
Preparing casperjs spawn
Warning: Cannot read property 'length' of undefined Use --force to continue.
Aborted due to warnings.
which is signaling (I believe) an error in the length property of options.test.length,
Bottom line, it is never going into test mode regardless of the test settings and if there is an empty options stanza it tries to reference an options.test object that does not exist.
Looks like the logic had a flaw when the engine option was added. It is now fixed and published 0.2.4. Thanks for the catch. I have also added a test for this situation.
Setting the test attribute to true in either casper:options or within the test itself does not run the casperjs script in test mode. Test always fails on casper reference which is supposed to be defined within capserjs itself when running in test mode.
explicitly requiring casper results in failure in finding casper.test object. Here is my casper stanza:
Versions:
and grunt-casper version 0.2.3 on the Mac running 10.9
Is there something other than specifying "test" in the task options to have the capserjs script run in test mode?
-- Scott