parse-server-test-runner
parse-server-test-runner copied to clipboard
Cloud code
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
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
Perfect, thank you 👍 @flovilmart
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 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 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
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.