When attempting to reach recommended code coverage on an app, I managed to cover all possitive scenarios which produced the following code coverage results.
And when further inspecting server.js code in coverageI saw the following.
To Cover those negative cases (error scenarios) I wrote unit tests with the test frameworks pecificly targetting the code section above. and when running the tests all my tests pass while producing expected console logs. however, when inspecting code coverage, the following happened
Please ensure that when you are testing the app, there are no code changes and the test frameworks can cover all possible scenarios that way the app is end-to-end tested.
hey Jones,
Thanks for the response. I did follow the guide and i tried resetting existing coverage by deleting both coverage folder and report.json esentially setting up everything from scratch. And here’s what i observed when i ran the following tests with fdk test
describe("On App Install", function () {
it("should return a webhook url", function () {
const url =
"https://example.freshservice.com/event/hook/freshservice";
const stubGeneratedURL = this.stub("generateTargetUrl").resolves(url);
this.invoke("onAppInstall", onAppInstallArgs);
stubGeneratedURL.restore();
});
it("Should store webhook URL in db", function () {
const stubStoreDataInDB = this.stub("$db", "set").callsFake(function (
key,
value
) {
expect(key).to.equal("t_url");
expect(value).to.deep.equal({
target:
"https://example.freshservice.com/event/hook/freshservice",
});
});
this.invoke("onAppInstall", onAppInstallArgs);
stubStoreDataInDB.restore();
});
it("should return a error when unable to store webhook url", function () {
const stubDbStoreError = this.stub("$db", "set").rejects({
error: "unable to store data in DB",
});
this.invoke("onAppInstall", onAppInstallArgs);
stubDbStoreError.restore();
});
it("should throw error if unable to generate target url", function () {
const stubErrorGenerateTargetUrl = this.stub("generateTargetUrl").rejects({
error: "unable to generate target url",
});
this.invoke("onAppUninstall", onAppInstallArgs);
stubErrorGenerateTargetUrl.restore();
});
});
which definitely invokes those functions as expected as they produce expected console logs however when inspecting coverage i see the following
and when i tried testing the same appInstallHandler with local test simulations on /web/test the following happens
And i repeated the same thing again to be sure and when i run fdk test whole coverage gets resetted to the state above in image 1.
Hey Jones,
I tried everything on the guide even rewrote my tests, but nothing seems to be working still running into the same issue. I could cover all cases for the frontend but this app has been mostly built around the backend relying on SMI functions. When trying to test server code via unit testing it resets the coverage generated by testing app.js as the front end relies heavily on data from SMI functions. it is hard to create error scenarios as trying out the strategy described for testing app.js - Intentionally making mistakes like misspelling server invocations doesnt work as even small changes reset the coverage.
This either-or pattern for coverage doesnt make much sense as unit tests should conpensate for regular coverage testing and vice versa. if i only rely on coverage from unit tests my app.js coverage resets, and if i try to coverage for app.js my server.js resets.
Kindly help me with this. I wish to publish this app to marketplace ASAP.