Skip to content

Commit 5c0e4fe

Browse files
author
Akos Kitta
committed
test: split up test cases
Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
1 parent 5c0719d commit 5c0e4fe

File tree

1 file changed

+39
-82
lines changed

1 file changed

+39
-82
lines changed

arduino-ide-extension/src/test/browser/create-api.test.ts

+39-82
Original file line numberDiff line numberDiff line change
@@ -228,89 +228,46 @@ describe('create-api', () => {
228228
expect(findByName(otherName, sketches)).to.be.not.undefined;
229229
});
230230

231-
it('should not run unnecessary fetches when retrieving all sketches', async () => {
232-
const content = 'void setup(){} void loop(){}';
233-
const maxLimit = 50; // https://github.com/arduino/arduino-ide/pull/875
234-
const sketchNames = [...Array(maxLimit - 1).keys()].map(() => v4());
235-
236-
// #region - sketch count < offset
237-
await sketchNames
238-
.map((name) => createApi.createSketch(toPosix(name), content))
239-
.reduce(async (acc, curr) => {
240-
await acc;
241-
return curr;
242-
}, Promise.resolve() as Promise<unknown>);
243-
244-
createApi.resetRequestRecording();
245-
let sketches = await createApi.sketches();
246-
let actualRecording = createApi.requestRecording.slice();
247-
248-
expect(sketches.length).to.be.equal(maxLimit - 1);
249-
sketchNames.forEach(
250-
(name) => expect(findByName(name, sketches)).to.be.not.undefined
251-
);
252-
253-
expect(actualRecording.length).to.be.equal(1);
254-
let getSketchesRequests = actualRecording.filter(
255-
(description) =>
256-
description.method === 'GET' &&
257-
description.pathname === '/create/v2/sketches' &&
258-
description.query &&
259-
description.query.includes(`limit=${maxLimit}`)
260-
);
261-
expect(getSketchesRequests.length).to.be.equal(1);
262-
// #endregion
263-
264-
// #region - sketch count === offset
265-
let extraName = v4();
266-
sketchNames.push(extraName);
267-
await createApi.createSketch(toPosix(extraName), content);
268-
269-
createApi.resetRequestRecording();
270-
sketches = await createApi.sketches();
271-
actualRecording = createApi.requestRecording.slice();
272-
273-
expect(sketches.length).to.be.equal(maxLimit);
274-
sketchNames.forEach(
275-
(name) => expect(findByName(name, sketches)).to.be.not.undefined
276-
);
277-
278-
expect(actualRecording.length).to.be.equal(2);
279-
getSketchesRequests = actualRecording.filter(
280-
(description) =>
281-
description.method === 'GET' &&
282-
description.pathname === '/create/v2/sketches' &&
283-
description.query &&
284-
description.query.includes(`limit=${maxLimit}`)
285-
);
286-
expect(getSketchesRequests.length).to.be.equal(2);
287-
// #endregion
288-
289-
// #region - sketch count > offset
290-
extraName = v4();
291-
sketchNames.push(extraName);
292-
await createApi.createSketch(toPosix(extraName), content);
293-
294-
createApi.resetRequestRecording();
295-
sketches = await createApi.sketches();
296-
actualRecording = createApi.requestRecording.slice();
297-
298-
expect(sketches.length).to.be.equal(maxLimit + 1);
299-
sketchNames.forEach(
300-
(name) => expect(findByName(name, sketches)).to.be.not.undefined
301-
);
231+
[
232+
[-1, 1],
233+
[0, 2],
234+
[1, 2],
235+
].forEach(([diff, expected]) =>
236+
it(`should not run unnecessary fetches when retrieving all sketches (sketch count ${
237+
diff < 0 ? '<' : diff > 0 ? '>' : '='
238+
} limit)`, async () => {
239+
const content = 'void setup(){} void loop(){}';
240+
const maxLimit = 50; // https://github.com/arduino/arduino-ide/pull/875
241+
const sketchCount = maxLimit + diff;
242+
const sketchNames = [...Array(sketchCount).keys()].map(() => v4());
243+
244+
await sketchNames
245+
.map((name) => createApi.createSketch(toPosix(name), content))
246+
.reduce(async (acc, curr) => {
247+
await acc;
248+
return curr;
249+
}, Promise.resolve() as Promise<unknown>);
250+
251+
createApi.resetRequestRecording();
252+
const sketches = await createApi.sketches();
253+
const allRequests = createApi.requestRecording.slice();
254+
255+
expect(sketches.length).to.be.equal(sketchCount);
256+
sketchNames.forEach(
257+
(name) => expect(findByName(name, sketches)).to.be.not.undefined
258+
);
302259

303-
expect(actualRecording.length).to.be.equal(2);
304-
getSketchesRequests = actualRecording.filter(
305-
(description) =>
306-
description.method === 'GET' &&
307-
description.pathname === '/create/v2/sketches' &&
308-
description.query &&
309-
description.query.includes(`limit=${maxLimit}`)
310-
);
311-
expect(getSketchesRequests.length).to.be.equal(2);
312-
// #endregion
313-
});
260+
expect(allRequests.length).to.be.equal(expected);
261+
const getSketchesRequests = allRequests.filter(
262+
(description) =>
263+
description.method === 'GET' &&
264+
description.pathname === '/create/v2/sketches' &&
265+
description.query &&
266+
description.query.includes(`limit=${maxLimit}`)
267+
);
268+
expect(getSketchesRequests.length).to.be.equal(expected);
269+
})
270+
);
314271

315272
['.', '-', '_'].map((char) => {
316273
it(`should create a new sketch with '${char}' in the sketch folder name although it's disallowed from the Create Editor`, async () => {

0 commit comments

Comments
 (0)