blazer82 / meteor-casperjs

CasperJS end to end test integration for meteor using velocity
MIT License
20 stars 2 forks source link

Exception in queued task: Error: ENOENT, no such file or directory #2

Open chip opened 9 years ago

chip commented 9 years ago

Hi, I'm trying to use this with velocity:html-reporter and am receiving the following error after clicking on the button in html-reporter that adds a Casperjs test:

meteor
[[[[[ ~/code/meteor.chipcastle.com ]]]]]      

=> Started proxy.                             
=> Started MongoDB.                           
=> Started your app.                          

=> App running at: http://localhost:3000/
I20141210-12:15:47.406(-6)? [casperjs] Run tests for file /Users/chip/code/meteor.chipcastle.com/tests/casperjs/sampleTest.coffee...
I20141210-12:15:48.219(-6)? Exception in queued task: Error: ENOENT, no such file or directory '/Users/chip/code/meteor.chipcastle.com/tests/.reports/casperjs/sampleTest.coffee.xml'
I20141210-12:15:48.220(-6)?     at Object.fs.openSync (fs.js:432:18)
I20141210-12:15:48.221(-6)?     at Object.fs.readFileSync (fs.js:289:15)
I20141210-12:15:48.221(-6)?     at parseReport (packages/nblazer:casperjs/nblazer:casperjs.coffee:74:17)
I20141210-12:15:48.221(-6)?     at Object.runTestFile (packages/nblazer:casperjs/nblazer:casperjs.coffee:61:1)
I20141210-12:15:48.221(-6)?     at observeChangesCallbacks.added (packages/minimongo/observe.js:153)
I20141210-12:15:48.221(-6)?     at self.applyChange.added (packages/minimongo/observe.js:53)
I20141210-12:15:48.221(-6)?     at packages/mongo/observe_multiplex.js:163
I20141210-12:15:48.221(-6)?     at Array.forEach (native)
I20141210-12:15:48.221(-6)?     at Function._.each._.forEach (packages/underscore/underscore.js:105)
I20141210-12:15:48.221(-6)?     at Object.task (packages/mongo/observe_multiplex.js:157)

My project has the following packages installed:

accounts-base                 1.1.2  A user account system
accounts-password             1.0.4  Password support for accounts
accounts-ui                   1.1.3  Simple templates to add login widgets to an app
alanning:roles                1.2.13  Role-based authorization
anti:fake                     0.4.1  Random text and data generator
cmather:handlebars-server     0.2.0* Allows handlebars templates to be defined on the server in .handlebars files
coffeescript                  1.0.4  Javascript dialect with fewer braces and semicolons
cunneen:mailgun               0.9.1  Easily send emails using Mailgun as your email provider.
dburles:collection-helpers    1.0.1  Transform your collections with helpers that you define
dburles:factory               0.3.7  Factories for Meteor
fuatsengul:iron-router-auth   1.0.7  Iron:Router Auth for 1.0
iron:router                   1.0.3  Routing specifically designed for Meteor
joshowens:accounts-entry      1.0.3  Make signin and signout their own pages with routes.
joshowens:simple-form         0.2.2  A meteorite package that makes building dynamic two way forms easy
less                          1.0.11  The dynamic stylesheet language
manuelschoebel:ms-seo         0.4.1  Easily config SEO for your routes
matb33:collection-hooks       0.7.6  Extends Mongo.Collection with before/after hooks for insert/update/remove/find/findOne
meteor-platform               1.2.0  Include a standard set of Meteor packages in your app
meteorhacks:zones             1.4.0  Zone.Js integration for meteor
mrt:moment                    2.8.1  Moment.js, a JavaScript date library for dates, packaged for Meteor. See http://momentjs.com.
mrt:underscore-string-latest  2.3.3  underscore.string repackaged for Meteor
nblazer:casperjs              0.1.6  CasperJS end to end test integration with velocity.
reywood:publish-composite     1.3.5  Publish a set of related documents from multiple collections with a reactive join
velocity:html-reporter        0.3.1  Reactive Velocity test reports in your app.
zimme:iron-router-active      1.0.1  Active route/path template helpers for iron:router

Any clues on how to fix or troubleshoot would be appreciated. Thanks. :smile:

blazer82 commented 9 years ago

I just created a new meteor app and added the casperjs package as well as the html-reporter. When clicking on "Create casperjs tests" in the reporter, everything seemed to be working fine. The test file was created and the tests were executed.

Is there anything in your meteor.chipcastle.com/tests/casperjs directory?

chip commented 9 years ago

@blazer82 - Thanks for the prompt reply. I created a sample app just like you said and it worked fine, so I think there is a conflict, possibly with mike:mocha. I removed that package and now casperjs works.

With mike:mocha installed I got this:

=> App running at: http://localhost:3000/
W20141211-11:57:19.847(-6)? (STDERR)          
W20141211-11:57:19.849(-6)? (STDERR) /Users/chip/.meteor/packages/meteor-tool/.1.0.36.1qasj7f++os.osx.x86_64+web.browser+web.cordo
va/meteor-tool-os.osx.x86_64/dev_bundle/lib/node_modules/fibers/future.js:173
W20141211-11:57:19.849(-6)? (STDERR)                                            throw(ex);
W20141211-11:57:19.850(-6)? (STDERR)                                                  ^
W20141211-11:57:19.850(-6)? (STDERR) ReferenceError: casper is not defined
W20141211-11:57:19.850(-6)? (STDERR)     at Package (packages/velocity:test-proxy/tests/casperjs/sampleTest.coffee:2)
W20141211-11:57:19.850(-6)? (STDERR)     at /Users/chip/code/meteor.chipcastle.com/.meteor/local/build/programs/server/packages/ve
locity_test-proxy.js:33:4
W20141211-11:57:19.851(-6)? (STDERR)     at /Users/chip/code/meteor.chipcastle.com/.meteor/local/build/programs/server/packages/ve
locity_test-proxy.js:67:3
W20141211-11:57:19.851(-6)? (STDERR)     at /Users/chip/code/meteor.chipcastle.com/.meteor/local/build/programs/server/boot.js:168
:10
W20141211-11:57:19.851(-6)? (STDERR)     at Array.forEach (native)
W20141211-11:57:19.851(-6)? (STDERR)     at Function._.each._.forEach (/Users/chip/.meteor/packages/meteor-tool/.1.0.36.1qasj7f++o
s.osx.x86_64+web.browser+web.cordova/meteor-tool-os.osx.x86_64/dev_bundle/lib/node_modules/underscore/underscore.js:79:11)
W20141211-11:57:19.851(-6)? (STDERR)     at /Users/chip/code/meteor.chipcastle.com/.meteor/local/build/programs/server/boot.js:82:
5
=> Exited with code: 8

Actually, that's just the first part of the stack trace, as it appeared to repeat several times.

Please note the ReferenceError: casper is not defined, which is strange because I do have it installed:

brew list | grep casper
casperjs

I'll try to find a more appropriate package for using mocha, but please make a suggestion if you have any further ideas. Thank you for your help! :+1:

chip commented 9 years ago

Actually, I now see that I added mike:mocha after I posted this, so I'm not sure exactly what happened. I realize now that I can also write unit tests with casperjs and it should work with velocity, so mocha is not necessary. Sorry for the noise. Closing.

samhatoum commented 9 years ago

Hey. It's not noise!

What do you mean unit tests with casper? I'm not sure that's possible as casper is an end-to-end UI testing framework

blazer82 commented 9 years ago

Sam is right, casperjs is meant for end-to-end testing. I would advise to use another framework to do unit tests. I'm gonna reopen this issue and I'm hoping to be able to look into it in more detail within the next few days.

Noise status not yet confirmed ;)

chip commented 9 years ago

@samhatoum & @blazer82 - Thanks for the info on unit testing. I'll try to dig further into this issue and will let you know if I find anything.

chip commented 9 years ago

As an update, I'm still getting this error after removing mike:mocha, adding sanjo:jasmine and updating all of my packages:

=> Started MongoDB.                           
W20141212-12:41:33.721(-6)? (STDERR)          
W20141212-12:41:33.770(-6)? (STDERR) /Users/chip/.meteor/packages/meteor-tool/.1.0.36.1qasj7f++os.osx.x86_64+web.browser+web.cordo
va/meteor-tool-os.osx.x86_64/dev_bundle/lib/node_modules/fibers/future.js:173
W20141212-12:41:33.771(-6)? (STDERR)                                            throw(ex);
W20141212-12:41:33.771(-6)? (STDERR)                                                  ^
W20141212-12:41:33.771(-6)? (STDERR) ReferenceError: casper is not defined
W20141212-12:41:33.771(-6)? (STDERR)   at Package (/Users/chip/code/meteor.chipcastle.com/.meteor/local/build/programs/server/packages/velocity_test-proxy.js:18:1)
W20141212-12:41:33.771(-6)? (STDERR)   at /Users/chip/code/meteor.chipcastle.com/.meteor/local/build/programs/server/packages/velo
city_test-proxy.js:33:4
W20141212-12:41:33.771(-6)? (STDERR)   at /Users/chip/code/meteor.chipcastle.com/.meteor/local/build/programs/server/packages/velo
city_test-proxy.js:67:3
W20141212-12:41:33.771(-6)? (STDERR)   at /Users/chip/code/meteor.chipcastle.com/.meteor/local/build/programs/server/boot.js:168:1
0
W20141212-12:41:33.772(-6)? (STDERR)   at Array.forEach (native)
W20141212-12:41:33.772(-6)? (STDERR)   at Function._.each._.forEach (/Users/chip/.meteor/packages/meteor-tool/.1.0.36.1qasj7f++os.osx.x86_64+web.browser+web.cordova/meteor-tool-os.osx.x86_64/dev_bundle/lib/node_modules/underscore/underscore.js:79:11)
W20141212-12:41:33.772(-6)? (STDERR)   at /Users/chip/code/meteor.chipcastle.com/.meteor/local/build/programs/server/boot.js:82:5
W20141212-12:41:33.773(-6)? (STDERR) 
=> Exited with code: 8

Here's my updated list of packages for reference:

accounts-base                 1.1.2  A user account system
accounts-password             1.0.4  Password support for accounts
accounts-ui                   1.1.3  Simple templates to add login widgets to an app
alanning:roles                1.2.13  Role-based authorization
anti:fake                     0.4.1  Random text and data generator
cmather:handlebars-server     0.2.0* Allows handlebars templates to be defined on the server in .handlebars files
coffeescript                  1.0.4  Javascript dialect with fewer braces and semicolons
cunneen:mailgun               0.9.1  Easily send emails using Mailgun as your email provider.
dburles:collection-helpers    1.0.1  Transform your collections with helpers that you define
dburles:factory               0.3.7  Factories for Meteor
fuatsengul:iron-router-auth   1.0.7  Iron:Router Auth for 1.0
iron:router                   1.0.3  Routing specifically designed for Meteor
joshowens:accounts-entry      1.0.3  Make signin and signout their own pages with routes.
joshowens:simple-form         0.2.2  A meteorite package that makes building dynamic two way forms easy
less                          1.0.11  The dynamic stylesheet language
manuelschoebel:ms-seo         0.4.1  Easily config SEO for your routes
matb33:collection-hooks       0.7.6  Extends Mongo.Collection with before/after hooks for insert/update/remove/find/findOne
meteor-platform               1.2.0  Include a standard set of Meteor packages in your app
meteorhacks:zones             1.4.0  Zone.Js integration for meteor
mrt:moment                    2.8.1  Moment.js, a JavaScript date library for dates, packaged for Meteor. See http://momentjs.com.
mrt:underscore-string-latest  2.3.3  underscore.string repackaged for Meteor
nblazer:casperjs              0.1.6  CasperJS end to end test integration with velocity.
reywood:publish-composite     1.3.5  Publish a set of related documents from multiple collections with a reactive join
sanjo:jasmine                 0.9.0  Easily use Jasmine in Meteor
velocity:html-reporter        0.3.2  Reactive Velocity test reports in your app.
zimme:iron-router-active      1.0.1  Active route/path template helpers for iron:router

I also tried the suggestion of editing my .meteor/packages as reported in sanjo/meteor-jasmine#103, but that didn't help. Here's my packages file for reference:

# Meteor packages used by this project, one per line.
#
# 'meteor add' and 'meteor remove' will edit this file for you,
# but you can also edit it by hand.

coffeescript
less
accounts-ui
accounts-password
alanning:roles
iron:router
zimme:iron-router-active
manuelschoebel:ms-seo
cmather:handlebars-server@0.2.0
joshowens:accounts-entry
joshowens:simple-form
meteorhacks:zones
dburles:collection-helpers
reywood:publish-composite
mrt:moment
mrt:underscore-string-latest
fuatsengul:iron-router-auth
dburles:factory
anti:fake
cunneen:mailgun
accounts-base
meteor-platform
velocity:html-reporter
sanjo:jasmine
matb33:collection-hooks
nblazer:casperjs

I've also tried rearranging other packages, to no avail. I'll let you know if I find any further clues. Thanks.

samhatoum commented 9 years ago

Here's my theory: The clue in the logs is that this error is coming from the test-proxy. The test-proxy is a package that exposes all the tests to the mirror, and also to the main app. As such, you need to be sure to guard your tests by returning before you reference the casper object.

Could you try to comment out all the code in your casper tests and see if this issue still happens?

chip commented 9 years ago

Your theory was spot-on! After commenting out the sample casper test, meteor and velocity both load up fine:

[[[[[ ~/code/meteor.chipcastle.com ]]]]]      

=> Started proxy.                             
=> Started MongoDB.                           
I20141212-12:58:32.714(-6)? [casperjs] Run tests for file /Users/chip/code/meteor.chipcastle.com/tests/casperjs/sampleTest.coffee...
I20141212-12:58:40.853(-6)? [casperjs] Run tests for file /Users/chip/code/meteor.chipcastle.com/tests/casperjs/sampleTest.coffee...
=> Meteor server restarted
=> Started your app.

=> App running at: http://localhost:3000/
samhatoum commented 9 years ago

Awesome!

@chip You can fix this by adding this line to your test:

if (process.env.IS_MIRROR) {
  return;
}

@blazer82 you ought to add this to the casper framework like this

The users can write tests like this:

Casper.onTest(function() {
  // insert your tests in here
});
samhatoum commented 9 years ago

Good thing about onTest is it gives the framework full control over how many tests are added etc, whilst creating full isolation.

When we get to doing Meteor plugins (hopefully), then we can omit this step for users and automatically wrap anything that the framework regex picks up with <framework>.onTest. We're not there yet!

chip commented 9 years ago

@samhatoum - Since the sample test is in coffeescript, I edited it like so:


return if process.env.IS_MIRROR

casper.test.begin "Sample Test", 2, (test) ->
   casper.start "http://localhost:3000", ->
      @waitForSelector "body", ->
         test.assert true, "True is true"

   casper.then ->
      test.assertNot false, "False is false"

   casper.run -> test.done()

However, ReferenceError: casper is not defined still occurs. I would edit the source javascript file if I saw where it was compiling it. What did I do wrong here?

samhatoum commented 9 years ago

oh wait, maybe you need to invert that. I think casper runs on the main process and hits the mirror. Could you try return unless process.env.IS_MIRROR

chip commented 9 years ago

Getting closer. That worked in terms of meteor starting up, but velocity reports the following:

ReferenceError: Can't find variable: process
samhatoum commented 9 years ago

oh, that's because the test is getting to the client. Those tests should only run on the server. Just add another directory called server at the same level of the test and move your file in there.

Or you can put another guard return unless Meteor.isServer and process.env.IS_MIRROR

chip commented 9 years ago

The guard caused a ReferenceError: Can't find variable: Meteor error in velocity.

Moving the test file to tests/server/casperjs caused this issue:

While Building package `velocity:test-proxy`:
error: File not found: tests/casperjs/sampleTest.coffee

I'm not sure how Meteor caches the test runs, though.

samhatoum commented 9 years ago

The first error is odd.

Seems like you hit a known bug in the test-proxy! Could you delete /packages/test-proxy and try again please? Also keep an eye on the first startup and if you find any error, please post the log here

samhatoum commented 9 years ago

It's not meteor doing the caching, it's the test proxy. It basically dynamically creates a package.js file that symlinks back to your /tests directory. This is so we can include the /tests files in the app.

blazer82 commented 9 years ago

@samhatoum, @chip I see you two are already deep into the debugging process here, that's great, thank you!

Unfortunately I've got very little time at the moment and I'm hoping that I'll soon be able to go through this thread and derive the appropriate changes to my code.

In the meantime, if any of you would like to speed things up a little, feel free to fork and to create pull requests.

chip commented 9 years ago

@blazer82 - I totally understand that you're busy. I'm new to the Meteor community, so I'm in unfamiliar territory. I'm not sure how I can help, so if you have any suggestions, please let me know. I'll do my best.

blazer82 commented 9 years ago

@chip Please excuse my late reply...

I just meant that if you would like to go through my code and suggest any direct changes, you may fork the project here on github and create pull requests with your changes for me to merge back into my codebase.

Or you may just wait 'til I find some time to fix a few things myself. Anyway, I hope to be more helpful soon enough!

chip commented 9 years ago

@blazer82 - No worries. In case I have time to work on this, would you be able to offer me some direction on how you'd approach a solution? Thanks!

drenfr01 commented 9 years ago

Hi All,

I just hit that this bug as well. Is there anything I can do to help resolve it? Like Chip, I'm new to the community but definitely willing to dive in.

Cheers, Duncan

blazer82 commented 9 years ago

@drenfr01 @chip I appreciate your offer to help, thank you guys! I've got zero resources to work on this project right now. So, by all means, you are very welcome to help :) First thing for you to do would be to fork this repository (you know how to fork on github?). As soon as you've got your forked repo on your local dev environment, you just need to link to the repo from inside your meteor project, so that meteor uses your local source code of this package instead of the official package.

So, let's say you've got your forked version of this repository at the following path: /path/to/your/workspace/nblazer:casperjs

And your own app might be here: /path/to/your/workspace/yourmeteorapp

You then need to create a packages directory inside your app folder: /path/to/your/workspace/yourmeteorapp/packages

Inside of this directory you need to link to the casperjs package. The link will look something like this: nblazer:casperjs -> ../../nblazer:casperjs

The next time you start your meteor app, it should use the linked package which means you can edit the code of the package and test it with your own app. (Make sure the package remains listed in the .meteor/packages file of your app!)

Once you've done some changes to the package you'd like to publish, create a pull request on github and I'll merge your code.

Hope this helps.

If there are any further questions, don't hesitate to ask! I'll try to help! And thanks again for your help!! I really appreciate it since I'm unable to fix things myself.

0o-de-lally commented 9 years ago

@blazer82 Having same issue here. I haven't got this package to work with the default configs and sample tests. I've tried a few things in this (long) thread to no avail. I know you are busy, but can I ask you to update the documentation and samples for this?

pmp0x commented 9 years ago

Hey, for me the issue laid within casperjs. Have you tried run it manually? e.g. 'casperjs test file.js'

For me that gave me an error. So as it seems the homebrew version is shipping phantomjs 2.0 but casperjs (devel) can just handel phantomjs 1.X

See ticket for me replacing bootstrap.js inside '/usr/local/Cellar/casperjs/1.1-beta3/libexec/bin' with this one helped ;)

blazer82 commented 9 years ago

@chip, @samhatoum, @drenfr01, @keyscores, @pmp0x Please read my comment on 8#issuecomment-90605956, thank you!