Git Product home page Git Product logo

Comments (5)

iamchrismiller avatar iamchrismiller commented on August 10, 2024

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?

from grunt-casper.

shsnyder avatar shsnyder commented on August 10, 2024

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.

from grunt-casper.

iamchrismiller avatar iamchrismiller commented on August 10, 2024

I will check this out after work tonight and see if I can re-create the issue.

from grunt-casper.

shsnyder avatar shsnyder commented on August 10, 2024

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.

from grunt-casper.

iamchrismiller avatar iamchrismiller commented on August 10, 2024

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.

from grunt-casper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.