parse-server-test-runner icon indicating copy to clipboard operation
parse-server-test-runner copied to clipboard

Cloud code

Open JulienKode opened this issue 7 years ago • 6 comments

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

JulienKode avatar Feb 17 '18 07:02 JulienKode

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

flovilmart avatar Feb 18 '18 17:02 flovilmart

Perfect, thank you 👍 @flovilmart

JulienKode avatar Feb 18 '18 17:02 JulienKode

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

flovilmart avatar Feb 18 '18 17:02 flovilmart

@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?

omairvaiyani avatar Apr 28 '18 12:04 omairvaiyani

@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

flovilmart avatar Apr 28 '18 15:04 flovilmart

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.

omairvaiyani avatar Apr 29 '18 19:04 omairvaiyani