Skip to content
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

require('spine') in mocha tests in node #1

Open
jdubie opened this issue Aug 17, 2012 · 3 comments
Open

require('spine') in mocha tests in node #1

jdubie opened this issue Aug 17, 2012 · 3 comments

Comments

@jdubie
Copy link

jdubie commented Aug 17, 2012

I really like your choice of technologies in this repo but I'm unable to find a good way to test it using mocha. If you run this test in mocha in the nodejs runtime, Spine will not be defined. You can added Spine = window?.Spine ? require('spine') to the top app/models/example_model which will grab the global Spine in the browser and require the node_module spine in the nodejs runtime. However, this gets more complicated when you need Spine.Model.Ajax and Spine.Model.Relation.

How you found a clean way to do this?

test/unit/example_model.coffee:

ExampleModel = require('models/example_model')
should = require('should')

app/models/example_model.coffee:

class ExampleModel extends Spine.Model
  @configure 'ExampleModel'

@cbosco
Copy link
Owner

cbosco commented Aug 17, 2012

Hi Jack,

Thanks for the comment! This is admittedly a work in progress -- before I look closer did you check out the README? I'm not crazy about the way tests actually run in brunch and I do them a bit differently with this skeleton. Specifically:

With this skeleton, run npm test instead of brunch test or npm start in addition to brunch watch in order to automatically run tests. This runs the tests directly on the coffeescript files in test/ and utilizes NPM-installed test libraries instead of static ones from test/vendor/ as other skeletons do.

So tests are all headless on this skeleton (that sounds really weird). I'll look at adding your change so they might work both ways but was curious if you tried tests my way

@jdubie
Copy link
Author

jdubie commented Aug 17, 2012

Yes, I'm using your Makefile, make test which runs

./node_modules/.bin/mocha \
                --compilers coffee:coffee-script \
                --reporter spec \
                ./test/*.coffee

cbosco pushed a commit that referenced this issue Aug 20, 2012
cbosco pushed a commit that referenced this issue Aug 20, 2012
@cbosco
Copy link
Owner

cbosco commented Aug 20, 2012

So I added your suggestion for pulling from window or node runtime; I think it's fine actually. In the tests themselves, requiring spine is more straightforward since they only run under node. Does this seem ok to you?

To clarify with spine plugins like Ajax, it seems like you could use the same convention:

Spine.Ajax = window?.Spine?.Ajax or require '../../node_modules/spine/src/ajax'

The deep link into the file system is not great... I wonder if the spine module could be changed to make this look nicer but I'm not quite sure. Maybe splitting up the library is more trouble than its worth?

Also as I'm pretty new to spine, does simply requiring 'spine' bring in all of the plugins?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants