testeranto 0.158.1 → 0.160.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/utils/api.ts CHANGED
@@ -16,26 +16,52 @@ export const fetchTestData = async (
16
16
  projectName: string,
17
17
  filepath: string,
18
18
  runTime: string
19
- ) => {
19
+ ): Promise<{
20
+ testData: any | null;
21
+ logs: string;
22
+ typeErrors: string;
23
+ lintErrors: string;
24
+ error: string | null;
25
+ }> => {
20
26
  const basePath = `reports/${projectName}/${filepath
21
27
  .split(".")
22
28
  .slice(0, -1)
23
29
  .join(".")}/${runTime}`;
24
30
 
25
- const [testRes, logsRes, typeRes, lintRes] = await Promise.all([
26
- fetch(`${basePath}/tests.json`),
27
- fetch(`${basePath}/logs.txt`),
28
- fetch(`${basePath}/type_errors.txt`),
29
- fetch(`${basePath}/lint_errors.txt`),
30
- ]);
31
+ try {
32
+ const [testRes, logsRes, typeRes, lintRes] = await Promise.all([
33
+ fetch(`${basePath}/tests.json`),
34
+ fetch(`${basePath}/logs.txt`),
35
+ fetch(`${basePath}/type_errors.txt`),
36
+ fetch(`${basePath}/lint_errors.txt`),
37
+ ]);
31
38
 
32
- return {
33
- // testData: await testRes.json(),
34
- testData: fakeTestJson,
35
- logs: await logsRes.text(),
36
- typeErrors: await typeRes.text(),
37
- lintErrors: await lintRes.text(),
38
- };
39
+ if (!testRes.ok) {
40
+ return {
41
+ testData: null,
42
+ logs: await logsRes.text(),
43
+ typeErrors: await typeRes.text(),
44
+ lintErrors: await lintRes.text(),
45
+ error: "Tests did not complete successfully. Please check the build and runtime logs for errors."
46
+ };
47
+ }
48
+
49
+ return {
50
+ testData: await testRes.json(),
51
+ logs: await logsRes.text(),
52
+ typeErrors: await typeRes.text(),
53
+ lintErrors: await lintRes.text(),
54
+ error: null
55
+ };
56
+ } catch (err) {
57
+ return {
58
+ testData: null,
59
+ logs: "",
60
+ typeErrors: "",
61
+ lintErrors: "",
62
+ error: `Failed to load test data: ${err instanceof Error ? err.message : String(err)}`
63
+ };
64
+ }
39
65
  };
40
66
 
41
67
  export const fetchBuildLogs = async (projectName: string, runtime: string) => {
@@ -45,182 +71,3 @@ export const fetchBuildLogs = async (projectName: string, runtime: string) => {
45
71
  return await res.json();
46
72
  };
47
73
 
48
- const fakeTestJson = {
49
- name: "Testing the Rectangle class",
50
- givens: [
51
- {
52
- key: "test0",
53
- name: "Default",
54
- whens: [
55
- {
56
- name: "setWidth: 4",
57
- error: true,
58
- },
59
- {
60
- name: "setHeight: 19",
61
- error: true,
62
- },
63
- ],
64
- thens: [
65
- {
66
- name: "getWidth: 4",
67
- error: false,
68
- },
69
- {
70
- name: "getHeight: 19",
71
- error: false,
72
- },
73
- ],
74
- error: null,
75
- features: [
76
- "https://api.github.com/repos/adamwong246/testeranto/issues/8",
77
- ],
78
- },
79
- {
80
- key: "test1",
81
- name: "Default",
82
- whens: [
83
- {
84
- name: "setWidth: 4",
85
- error: true,
86
- },
87
- {
88
- name: "setHeight: 5",
89
- error: true,
90
- },
91
- ],
92
- thens: [
93
- {
94
- name: "getWidth: 4",
95
- error: false,
96
- },
97
- {
98
- name: "getHeight: 5",
99
- error: false,
100
- },
101
- {
102
- name: "area: 20",
103
- error: false,
104
- },
105
- {
106
- name: "AreaPlusCircumference: 38",
107
- error: false,
108
- },
109
- ],
110
- error: null,
111
- features: ["Rectangles have width and height."],
112
- },
113
- {
114
- key: "test2",
115
- name: "Default",
116
- whens: [
117
- {
118
- name: "setHeight: 4",
119
- error: true,
120
- },
121
- {
122
- name: "setWidth: 33",
123
- error: true,
124
- },
125
- ],
126
- thens: [
127
- {
128
- name: "area: 132",
129
- error: false,
130
- },
131
- ],
132
- error: null,
133
- features: ["Rectangles have area"],
134
- },
135
- {
136
- key: "test2_1",
137
- name: "Default",
138
- whens: [],
139
- thens: [
140
- {
141
- name: "getWidth: 2",
142
- error: false,
143
- },
144
- {
145
- name: "getHeight: 2",
146
- error: false,
147
- },
148
- ],
149
- error: null,
150
- features: ["Rectangles have default size"],
151
- },
152
- {
153
- key: "test3",
154
- name: "Default",
155
- whens: [
156
- {
157
- name: "setHeight: 5",
158
- error: true,
159
- },
160
- {
161
- name: "setWidth: 5",
162
- error: true,
163
- },
164
- ],
165
- thens: [
166
- {
167
- name: "area: 25",
168
- error: false,
169
- },
170
- ],
171
- error: null,
172
- features: [
173
- "file:///Users/adam/Code/testeranto-starter/src/Rectangle/README.md",
174
- ],
175
- },
176
- {
177
- key: "test4",
178
- name: "Default",
179
- whens: [
180
- {
181
- name: "setHeight: 6",
182
- error: true,
183
- },
184
- {
185
- name: "setWidth: 6",
186
- error: true,
187
- },
188
- ],
189
- thens: [
190
- {
191
- name: "area: 36",
192
- error: false,
193
- },
194
- ],
195
- error: null,
196
- features: ["Rectangles have area"],
197
- },
198
- {
199
- key: "test5",
200
- name: "Default",
201
- whens: [],
202
- thens: [
203
- {
204
- name: "getWidth: 2",
205
- error: false,
206
- },
207
- {
208
- name: "getHeight: 2",
209
- error: false,
210
- },
211
- ],
212
- error: null,
213
- features: ["Rectangles have default size, again"],
214
- },
215
- ],
216
- checks: [],
217
- fails: 0,
218
- features: [
219
- "https://api.github.com/repos/adamwong246/testeranto/issues/8",
220
- "Rectangles have width and height.",
221
- "Rectangles have area",
222
- "Rectangles have default size",
223
- "file:///Users/adam/Code/testeranto-starter/src/Rectangle/README.md",
224
- "Rectangles have default size, again",
225
- ],
226
- };