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

How to run jasmine-node tests #323

Closed
johannesjo opened this issue Nov 6, 2015 · 12 comments
Closed

How to run jasmine-node tests #323

johannesjo opened this issue Nov 6, 2015 · 12 comments

Comments

@johannesjo
Copy link

When I try to run tests written with jasmine-node, all of jasmins core functions are not defind like spyOn or even expect.

"before each" hook: spyOn is not defined
    at api/auth/authC-spec.js:48

1 failing tests, 0 passing

api/auth/authC-spec.js authC should have the following methods available [1 ms]

    expect is not defined
        at api/auth/authC-spec.js:35

Here is the config:

module.exports = function ()
{
    return {
        files: [
            'api/**/*.js',
            '!api/**/*spec.js'
        ],
        tests: [
            'api/**/*spec.js'
        ],
        env: {
            type: 'node',
            runner: 'node',
            env: 'NODE_ENV=test'
        }
    }
};

@johannesjo
Copy link
Author

Ok I was able to resolve the issue by using test-framework: jasmine and using jasmine-node@2.0.0. See also: mhevery/jasmine-node#282

Still though jasmine and jasmine-node are not the same and I might run into issues later on.

@johannesjo
Copy link
Author

I also run into this issue with mongoose models once the tests are run a second time:

OverwriteModelError: Cannot overwrite `User` model once compiled

That doesn't happen with jasmine-node --autotest

@ArtemGovorov
Copy link
Member

Still though jasmine and jasmine-node are not the same and I might run into issues later on.

Yep, I have only tested it with jasmine (for node), not jasmine-node, so you may find something interesting. Please let me know if you do, I don't yet see any reasons why it shouldn't work and will try to fix it if it doesn't.

I also run into this issue with mongoose models once the tests are run a second time

Try setting workers: {recycle: true} - #239

@johannesjo
Copy link
Author

Thanks for getting back to me so quickly. workers: {recycle:true} doesn't do anything for me unfortunately.

@ArtemGovorov
Copy link
Member

Interesting, could you please try workers: {recycle:true, initial: 1, regular: 1}?
If the suggestion above doesn't help, would it be possible to create a small sample github repo where it works with jasmine-node --autotest but doesn't work with wallaby? I definitely would like to find out what is going on.

@johannesjo
Copy link
Author

That did the trick! Thank you very much. Are these options documented somewhere?

You still need the repo?

@ArtemGovorov
Copy link
Member

Ok, cool. Yes here is the documentation - http://wallabyjs.com/docs/config/workers.html. The issue is that by default wallaby tries to run your tests in parallel and mongoose doesn't seem to like it.

@ArtemGovorov
Copy link
Member

One possible solution to still allow running your tests in parallel is perhaps using different DBs per worker. You may consider using wallaby.js bootstrap function to set up a DB for worker.

@johannesjo
Copy link
Author

Good suggestion and good documentation. Was not able to find that earlier somehow.

I might try that at a later point. So far the tests are still running very fast in my current project.

@ArtemGovorov
Copy link
Member

Awesome, then you probably don't need to bother trying to speed it up right now, but can just leave the option for later.
BTW, does it work without recycle:true, just with workers set to 1: workers: {initial: 1, regular: 1}?

@johannesjo
Copy link
Author

No it doesn't.

@ArtemGovorov
Copy link
Member

Cool, good to know, thanks for checking!

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