@argos-ci/core 0.7.3 → 0.8.1

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.
Files changed (2) hide show
  1. package/dist/index.mjs +49 -13
  2. package/package.json +2 -2
package/dist/index.mjs CHANGED
@@ -267,7 +267,20 @@ const service = {
267
267
  }
268
268
  };
269
269
 
270
- const debug = createDebug("@argos-ci/core");
270
+ const KEY = "@argos-ci/core";
271
+ const debug = createDebug(KEY);
272
+ const debugTime = (arg)=>{
273
+ const enabled = createDebug.enabled(KEY);
274
+ if (enabled) {
275
+ console.time(arg);
276
+ }
277
+ };
278
+ const debugTimeEnd = (arg)=>{
279
+ const enabled = createDebug.enabled(KEY);
280
+ if (enabled) {
281
+ console.timeEnd(arg);
282
+ }
283
+ };
271
284
 
272
285
  const getCiEnvironmentFromEnvCi = (ctx)=>{
273
286
  const ciContext = envCi(ctx);
@@ -441,6 +454,22 @@ const upload$1 = async (input)=>{
441
454
  });
442
455
  };
443
456
 
457
+ /**
458
+ * Split an array into chunks of a given size.
459
+ */ const chunk = (collection, size)=>{
460
+ const result = [];
461
+ // add each chunk to the result
462
+ for(let x = 0; x < Math.ceil(collection.length / size); x++){
463
+ let start = x * size;
464
+ let end = start + size;
465
+ result.push(collection.slice(start, end));
466
+ }
467
+ return result;
468
+ };
469
+
470
+ /**
471
+ * Size of the chunks used to upload screenshots to Argos.
472
+ */ const CHUNK_SIZE = 10;
444
473
  const getConfigFromOptions = (options)=>{
445
474
  const config = createConfig();
446
475
  const ciEnv = getCiEnvironment();
@@ -509,18 +538,25 @@ const getConfigFromOptions = (options)=>{
509
538
  prNumber: config.prNumber
510
539
  });
511
540
  debug("Got screenshots", result);
512
- // Upload screenshots
513
- debug("Uploading screenshots");
514
- await Promise.all(result.screenshots.map(async ({ key , putUrl })=>{
515
- const screenshot = screenshots.find((s)=>s.hash === key);
516
- if (!screenshot) {
517
- throw new Error(`Invariant: screenshot with hash ${key} not found`);
518
- }
519
- await upload$1({
520
- url: putUrl,
521
- path: screenshot.optimizedPath
522
- });
523
- }));
541
+ debug(`Split screenshots in chunks of ${CHUNK_SIZE}`);
542
+ const chunks = chunk(result.screenshots, CHUNK_SIZE);
543
+ debug(`Starting upload of ${chunks.length} chunks`);
544
+ for(let i = 0; i < chunks.length; i++){
545
+ debug(`Uploading chunk ${i + 1}/${chunks.length}`);
546
+ const timeLabel = `Chunk ${i + 1}/${chunks.length}`;
547
+ debugTime(timeLabel);
548
+ await Promise.all(chunks[i].map(async ({ key , putUrl })=>{
549
+ const screenshot = screenshots.find((s)=>s.hash === key);
550
+ if (!screenshot) {
551
+ throw new Error(`Invariant: screenshot with hash ${key} not found`);
552
+ }
553
+ await upload$1({
554
+ url: putUrl,
555
+ path: screenshot.optimizedPath
556
+ });
557
+ }));
558
+ debugTimeEnd(timeLabel);
559
+ }
524
560
  // Update build
525
561
  debug("Updating build");
526
562
  await apiClient.updateBuild({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@argos-ci/core",
3
3
  "description": "Visual testing solution to avoid visual regression. The core component of Argos SDK that handles build creation.",
4
- "version": "0.7.3",
4
+ "version": "0.8.1",
5
5
  "scripts": {
6
6
  "prebuild": "rm -rf dist",
7
7
  "build": "rollup -c",
@@ -60,5 +60,5 @@
60
60
  "rollup-plugin-dts": "^4.2.3",
61
61
  "rollup-plugin-swc3": "^0.6.0"
62
62
  },
63
- "gitHead": "56d7e2259161c49265d8983ce0f0ecfe71910d2b"
63
+ "gitHead": "12cffdc1330d8e8c89db91cb87ddcc6775da34be"
64
64
  }