New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add New spooky.exec("code") method. #43
Conversation
Cool! I need this, please merge and promote to npm if possible |
…hat it works as expected.
I just added in a unit test to make sure that the exec option was working as expected. |
Ok, finally have a sec to look at this. Sorry for the delay. Thanks for this work. It's a legit problem that Spooky can't execute code in the Casper/Phantom context outside of a I see two main contributions in this PR:
I am sold on the former, but not the latter. In particular, I don't like adding this much complexity to the require('spooky-exec-or-whatevs').exec({
file: 'my-casper-test.js',
args: [42]
}); I also don't think the stdio server should stop listening when it hears spooky.exec('/* do some setup in casper/phantom context */');
spooky.start();
spooky.thenOpen('http://example.com');
spooky.exec('/* do something else in casper/phantom context */');
spooky.run(); So, I propose:
What do you think? |
// Attempt to evaluate the code | ||
// Note that we also redefine the `instance` variable to be | ||
// `casper` in the context of this code, which makes more sense. | ||
eval("(function(casper){\n" + code + "\n})(instance);"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will evaluate code
in the local scope, giving it access to the internals of bootstrap/casper
, which is probably not desirable.
Did you consider using createFunction
here instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Single quotes, please.
The exec seems to get stuck when I fork your code and run it. |
If an unhandled error occurs, the bootstrap script emits an error event and exits with a non-zero exit code. Partial progress toward SpookyJS#4.
Remove buffering logic close SpookyJS#42
Include offending line in the error message Close SpookyJS#46
Accept npm's format for package.json so --save is less disruptive in the future.
Also factor child spawning out as a separate module for tests
`lib/bootstrap/emit` now provides `emit(<event>, params...)` and `console.log(what...)` and friends. For now, `console` methods with a level other than `log` prepend their level to the message. So: ```javascript var console = require(options.spooky_lib + 'lib/bootstrap/emit').console; console.log('hey', 'yo'); // -> emit('console', 'hey yo'); console.debug('hey', 'yo'); // -> emit('console', 'debug hey yo'); ``` close SpookyJS#45
Previously, the constructor did not pass new instances through EventEmitter, so all Spooky instances shared the same EventEmitter instance state. Instead, use util.inherits and call EventEmitter when constructing Spooky instances. Thanks to @tomchentw for figuring this one out. Close SpookyJS#51, SpookyJS#60
News about this pull? |
I never got a response from @jeresig to my comments, so there's been no progress thus far. I may actually hack on this off and on over the next week. As a first step, I'm going to think about the right API and post it up for comment on this issue. Look for that later tonight. |
Ok, had to fix #73 before I could get started on this. As I said before, I think this is a great idea. In fact, on further reflection, Given Here's a strawman API:
|
Any news on this ? |
@davidlinse I started work on this but had to set it aside last fall. I don't expect to be able to pick it back up for a month or two at least. I'd love help if anyone is game. |
oh, thats sad to hear.. maybe i'll find the time to have look. ~david |
This adds a new method to the Spooky API named
exec()
. This method takes in a string of JavaScript and executes it in the CasperJS/PhantomJS environment. Additionally it stops waiting for stdin if the stdio transport is being used.With this particular method it becomes really easy to load a CasperJS file (using
fs.readFileSync
, or some such) and pass it to Spooky/Casper for execution.An example of how it would be used:
I also added in a new option to pass to Spooky so that you can do this even more simply, like so:
This makes it so that you can use Spooky as a purely event-driven tool for handling Casper.