@argos-ci/core 1.2.0 → 1.2.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 +56 -47
  2. package/package.json +2 -2
package/dist/index.mjs CHANGED
@@ -558,9 +558,29 @@ const getConfigFromOptions = ({ parallel, ...options })=>{
558
558
  });
559
559
  return config;
560
560
  };
561
+ async function uploadFilesToS3(files) {
562
+ debug(`Split files in chunks of ${CHUNK_SIZE}`);
563
+ const chunks = chunk(files, CHUNK_SIZE);
564
+ debug(`Starting upload of ${chunks.length} chunks`);
565
+ for(let i = 0; i < chunks.length; i++){
566
+ // Upload files
567
+ debug(`Uploading chunk ${i + 1}/${chunks.length}`);
568
+ const timeLabel = `Chunk ${i + 1}/${chunks.length}`;
569
+ debugTime(timeLabel);
570
+ await Promise.all(chunks[i].map(async ({ url, path, contentType })=>{
571
+ await upload$1({
572
+ url,
573
+ path,
574
+ contentType
575
+ });
576
+ }));
577
+ debugTimeEnd(timeLabel);
578
+ }
579
+ }
561
580
  /**
562
581
  * Upload screenshots to argos-ci.com.
563
582
  */ const upload = async (params)=>{
583
+ var _result_pwTraces;
564
584
  debug("Starting upload with params", params);
565
585
  // Read config
566
586
  const config = getConfigFromOptions(params);
@@ -602,20 +622,21 @@ const getConfigFromOptions = ({ parallel, ...options })=>{
602
622
  }));
603
623
  // Create build
604
624
  debug("Creating build");
605
- const screenshotKeys = Array.from(new Set(screenshots.map((screenshot)=>screenshot.hash)));
606
- const pwTraces = screenshotKeys.reduce((pwTraces, key)=>{
607
- const screenshot = screenshots.find((screenshot)=>screenshot.hash === key);
608
- if (!screenshot) {
609
- throw new Error(`Invariant: screenshot with hash ${key} not found`);
625
+ const [pwTraceKeys, screenshotKeys] = screenshots.reduce(([pwTraceKeys, screenshotKeys], screenshot)=>{
626
+ if (screenshot.pwTrace && !pwTraceKeys.includes(screenshot.pwTrace.hash)) {
627
+ pwTraceKeys.push(screenshot.pwTrace.hash);
610
628
  }
611
- if (screenshot.pwTrace) {
612
- pwTraces.push({
613
- screenshotKey: screenshot.hash,
614
- traceKey: screenshot.pwTrace.hash
615
- });
629
+ if (!screenshotKeys.includes(screenshot.hash)) {
630
+ screenshotKeys.push(screenshot.hash);
616
631
  }
617
- return pwTraces;
618
- }, []);
632
+ return [
633
+ pwTraceKeys,
634
+ screenshotKeys
635
+ ];
636
+ }, [
637
+ [],
638
+ []
639
+ ]);
619
640
  const result = await apiClient.createBuild({
620
641
  commit: config.commit,
621
642
  branch: config.branch,
@@ -623,50 +644,38 @@ const getConfigFromOptions = ({ parallel, ...options })=>{
623
644
  parallel: config.parallel,
624
645
  parallelNonce: config.parallelNonce,
625
646
  screenshotKeys,
626
- pwTraces,
647
+ pwTraceKeys,
627
648
  prNumber: config.prNumber,
628
649
  prHeadCommit: config.prHeadCommit,
629
650
  referenceBranch: config.referenceBranch,
630
651
  referenceCommit: config.referenceCommit
631
652
  });
632
- debug("Got screenshots", result);
633
- debug(`Split screenshots in chunks of ${CHUNK_SIZE}`);
634
- const chunks = chunk(result.screenshots, CHUNK_SIZE);
635
- debug(`Starting upload of ${chunks.length} chunks`);
636
- for(let i = 0; i < chunks.length; i++){
637
- // Upload screenshots
638
- debug(`Uploading chunk ${i + 1}/${chunks.length}`);
639
- const timeLabel = `Chunk ${i + 1}/${chunks.length}`;
640
- debugTime(timeLabel);
641
- await Promise.all(chunks[i].map(async ({ key, putUrl, putTraceUrl })=>{
653
+ debug("Got uploads url", result);
654
+ const uploadFiles = [
655
+ ...result.screenshots.map(({ key, putUrl })=>{
642
656
  const screenshot = screenshots.find((s)=>s.hash === key);
643
657
  if (!screenshot) {
644
658
  throw new Error(`Invariant: screenshot with hash ${key} not found`);
645
659
  }
646
- await Promise.all([
647
- // Upload screenshot
648
- upload$1({
649
- url: putUrl,
650
- path: screenshot.optimizedPath,
651
- contentType: "image/png"
652
- }),
653
- // Upload trace
654
- (async ()=>{
655
- if (putTraceUrl) {
656
- if (!screenshot.pwTrace) {
657
- throw new Error(`Invariant: screenshot with hash ${key} has a putTraceUrl but no pwTrace`);
658
- }
659
- await upload$1({
660
- url: putTraceUrl,
661
- path: screenshot.pwTrace.path,
662
- contentType: "application/zip"
663
- });
664
- }
665
- })()
666
- ]);
667
- }));
668
- debugTimeEnd(timeLabel);
669
- }
660
+ return {
661
+ url: putUrl,
662
+ path: screenshot.optimizedPath,
663
+ contentType: "image/png"
664
+ };
665
+ }),
666
+ ...((_result_pwTraces = result.pwTraces) === null || _result_pwTraces === void 0 ? void 0 : _result_pwTraces.map(({ key, putUrl })=>{
667
+ const screenshot = screenshots.find((s)=>s.pwTrace && s.pwTrace.hash === key);
668
+ if (!screenshot || !screenshot.pwTrace) {
669
+ throw new Error(`Invariant: trace with ${key} not found`);
670
+ }
671
+ return {
672
+ url: putUrl,
673
+ path: screenshot.pwTrace.path,
674
+ contentType: "application/json"
675
+ };
676
+ })) ?? []
677
+ ];
678
+ await uploadFilesToS3(uploadFiles);
670
679
  // Update build
671
680
  debug("Updating build");
672
681
  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": "1.2.0",
4
+ "version": "1.2.1",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
7
7
  "types": "./dist/index.d.ts",
@@ -59,5 +59,5 @@
59
59
  "build": "rollup -c",
60
60
  "e2e": "node ./e2e/upload.cjs && node ./e2e/upload.mjs"
61
61
  },
62
- "gitHead": "47a939474ca0c0d55ca5360dcaa5f8912547ed76"
62
+ "gitHead": "366dc3bdb4a0a8ed87fc7a2cbf28db1f218567ad"
63
63
  }