Skip to content

Commit 29dae6e

Browse files
committed
fix: add more test coverage
1 parent 657f3db commit 29dae6e

File tree

2 files changed

+76
-2
lines changed

2 files changed

+76
-2
lines changed

src/coverage.test.ts

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const mockSchema = {
2727
},
2828
{
2929
name: "bar",
30+
paramStructure: "by-name",
3031
params: [
3132
{
3233
name: "barParam",
@@ -49,6 +50,54 @@ const mockSchema = {
4950
type: "boolean",
5051
},
5152
},
53+
examples: [
54+
{
55+
name: "fooExample",
56+
summary: "foo example",
57+
description: "this is an example of foo",
58+
params: [
59+
{
60+
name: "barParam",
61+
value: "bar",
62+
},
63+
{
64+
name: "barParam2",
65+
value: "bar",
66+
}
67+
],
68+
result: {
69+
name: "fooResult",
70+
schema: {
71+
type: "boolean",
72+
},
73+
},
74+
},
75+
],
76+
},
77+
{
78+
name: "baz",
79+
params: [
80+
{
81+
name: "bazParam",
82+
required: true,
83+
schema: {
84+
type: "string",
85+
enum: ["baz"],
86+
},
87+
},
88+
{
89+
name: "bazParam2",
90+
schema: {
91+
type: "string",
92+
},
93+
},
94+
],
95+
result: {
96+
name: "bazResult",
97+
schema: {
98+
type: "boolean",
99+
},
100+
},
52101
examples: [
53102
{
54103
name: "fooExample",
@@ -109,6 +158,29 @@ describe("coverage", () => {
109158
});
110159
});
111160
});
161+
describe("coverage tests", () => {
162+
it("throws an error when there are no methods", async () => {
163+
const reporter = new class CustomReporter {
164+
onBegin() {}
165+
onTestBegin() {}
166+
onTestEnd() {}
167+
onEnd() {}
168+
};
169+
const spy = jest.spyOn(reporter, "onTestBegin");
170+
const transport = () => Promise.resolve({});
171+
const openrpcDocument = mockSchema;
172+
const options = {
173+
reporter,
174+
transport,
175+
openrpcDocument,
176+
skip: ['foo', 'bar', 'baz'],
177+
only: [],
178+
};
179+
180+
await coverage(options);
181+
expect(spy).toHaveBeenCalledTimes(0);
182+
});
183+
});
112184
describe("transport", () => {
113185
it("can call the transport", (done) => {
114186
const transport = () => {
@@ -124,7 +196,7 @@ describe("coverage", () => {
124196
});
125197
});
126198
});
127-
describe("reporter", () => {
199+
describe("reporter more tests", () => {
128200
// reporter integration tests
129201
it("onBegin is called", async () => {
130202
// this is a test that the reporter is called
@@ -162,7 +234,7 @@ describe("coverage", () => {
162234
};
163235

164236
await coverage(options);
165-
expect(spy).toHaveBeenCalledTimes(11);
237+
expect(spy).toHaveBeenCalledTimes(12);
166238
});
167239
});
168240
});

src/coverage.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export default async (options: IOptions) => {
6868
servers.forEach(({ url }) => {
6969
filteredMethods.forEach((method) => {
7070
if (method.examples === undefined || method.examples.length === 0) {
71+
console.log("method : ", method);
7172
for (let i = 0; i < 10; i++) {
7273
const p = getFakeParams(method.params);
7374
// handle object or array case
@@ -92,6 +93,7 @@ export default async (options: IOptions) => {
9293
method.paramStructure === "by-name"
9394
? paramsToObj(p, method.params as ContentDescriptorObject[])
9495
: p;
96+
console.log("params : ", params);
9597
exampleCalls.push({
9698
title: method.name + " > example params and expect result to match: " + ex.name,
9799
methodName: method.name,

0 commit comments

Comments
 (0)