test: run cloud sketches tests on the CI (#2092)

- fix(test): integration tests are more resilient.
   - run the Create integration tests with other slow tests,
   - queued `PUT`/`DELETE` requests to make the test timeout happy,
   - reduced the `/sketches/search` offset to 1/5th and
   - remove Create API logging.
 - fix(linter): ignore `lib` folder. Remove obsolete `.node_modules`
pattern.
 - feat(ci): enable Create API integration tests.

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
Co-authored-by: per1234 <accounts@perglass.com>
This commit is contained in:
Akos Kitta
2023-10-07 10:38:54 +02:00
committed by GitHub
parent 3f4d2745a8
commit 0b2410d49a
5 changed files with 94 additions and 37 deletions

View File

@@ -179,7 +179,8 @@ export class CreateApi {
);
})
.catch((reason) => {
if (reason?.status === 404) return [] as Create.Resource[];
if (reason?.status === 404)
return [] as Create.Resource[]; // TODO: must not swallow 404
else throw reason;
});
}
@@ -486,18 +487,12 @@ export class CreateApi {
await this.run(url, init, ResponseResultProvider.NOOP);
}
private fetchCounter = 0;
private async run<T>(
requestInfo: URL,
init: RequestInit | undefined,
resultProvider: ResponseResultProvider = ResponseResultProvider.JSON
): Promise<T> {
const fetchCount = `[${++this.fetchCounter}]`;
const fetchStart = performance.now();
const method = init?.method ? `${init.method}: ` : '';
const url = requestInfo.toString();
const response = await fetch(requestInfo.toString(), init);
const fetchEnd = performance.now();
if (!response.ok) {
let details: string | undefined = undefined;
try {
@@ -508,18 +503,7 @@ export class CreateApi {
const { statusText, status } = response;
throw new CreateError(statusText, status, details);
}
const parseStart = performance.now();
const result = await resultProvider(response);
const parseEnd = performance.now();
console.debug(
`HTTP ${fetchCount} ${method}${url} [fetch: ${(
fetchEnd - fetchStart
).toFixed(2)} ms, parse: ${(parseEnd - parseStart).toFixed(
2
)} ms] body: ${
typeof result === 'string' ? result : JSON.stringify(result)
}`
);
return result;
}

View File

@@ -82,6 +82,13 @@ export function isNotFound(err: unknown): err is NotFoundError {
return isErrorWithStatusOf(err, 404);
}
export type UnprocessableContentError = CreateError & { status: 422 };
export function isUnprocessableContent(
err: unknown
): err is UnprocessableContentError {
return isErrorWithStatusOf(err, 422);
}
function isErrorWithStatusOf(
err: unknown,
status: number