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

Cloud code #3

Open
JulienKode opened this issue Feb 17, 2018 · 6 comments
Open

Cloud code #3

JulienKode opened this issue Feb 17, 2018 · 6 comments

Comments

@JulienKode
Copy link

JulienKode commented Feb 17, 2018

Best way to test cloud code:

I'm wondering what is the best way to test cloud code functions.
It is better to launch the server with all cloud code or just test the function appropriately without cloud code plugged

@flovilmart
Copy link
Contributor

HI @JulienKode. In our setup, we need to reference cloud main file with the full path:

cloud: `${__dirname }/../cloud/main.js`

Then it should be good

@JulienKode
Copy link
Author

Perfect, thank you 👍 @flovilmart

@flovilmart
Copy link
Contributor

We always run our tests with the full cloud code loaded for edge to edge tests. Then it you wanna test a particular JavaScript method, you don’t need parse server. The best test harnesses have a good balance between edge to edge an unit tests

@omairvaiyani
Copy link

@flovilmart really great stuff here! Worked like a charm!

Could I ask, where's the best place to set the beforeAll, afterAl, beforeEach hooks in order to re-use them across our testing suites, rather then copying it for each file?

@flovilmart
Copy link
Contributor

flovilmart commented Apr 28, 2018

@omairvaiyani what you could do is leverage a global function in your helper.js given you’re using jasmine. Or you could put it in any module and simply export it where you need it.

global.parseSuite = function(name, contents) {
   describe(name, () => {
        beforeEach(...)
        afterEach(...)
        contents();
    });
}

Then in your tests, instead of calling describe you’ll need to call parseSuite

Fill in the beforeEach/afterEach/beforeAll/afterAll with cleaningDb, starting / stopping the server etc...

Does it make sense?

Sent with GitHawk

@omairvaiyani
Copy link

That's great thanks!

I ended placing the hooks at the root-level suite, therefore the server will only start once across all the suites. I'll see if I run into side-effects, in which case your example would be helpful.

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

3 participants