@argos-ci/core 0.1.0 → 0.4.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/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import * as sharp from 'sharp';
2
+
1
3
  interface UploadParameters {
2
4
  /** Globs matching image file paths to upload */
3
5
  files?: string[];
@@ -33,6 +35,7 @@ declare const upload: (params: UploadParameters) => Promise<{
33
35
  };
34
36
  screenshots: {
35
37
  optimizedPath: string;
38
+ format: keyof sharp.FormatEnum;
36
39
  hash: any;
37
40
  name: string;
38
41
  path: string;
package/dist/index.mjs CHANGED
@@ -200,12 +200,33 @@ const discoverScreenshots = async (patterns, { root =process.cwd() , ignore } =
200
200
  };
201
201
 
202
202
  const tmpFile = promisify(tmp.file);
203
- const optimizeScreenshot = async (filepath)=>{
203
+ const getImageFormat = async (filepath)=>{
204
+ const metadata = await sharp(filepath).metadata();
205
+ if (!metadata.format) {
206
+ throw new Error(`Could not get image format for ${filepath}`);
207
+ }
208
+ return metadata.format;
209
+ };
210
+ const optimizeScreenshot = async (filepath, format)=>{
204
211
  const resultFilePath = await tmpFile();
205
- await sharp(filepath).resize(1024, 1024, {
212
+ const optimization = sharp(filepath).resize(2048, 20480, {
206
213
  fit: "inside",
207
214
  withoutEnlargement: true
208
- }).jpeg().toFile(resultFilePath);
215
+ });
216
+ switch(format){
217
+ case "jpeg":
218
+ case "jpg":
219
+ {
220
+ optimization.jpeg();
221
+ break;
222
+ }
223
+ case "png":
224
+ {
225
+ optimization.png();
226
+ break;
227
+ }
228
+ }
229
+ await optimization.toFile(resultFilePath);
209
230
  return resultFilePath;
210
231
  };
211
232
 
@@ -239,6 +260,12 @@ const createArgosApiClient = (options)=>{
239
260
  });
240
261
  return response.data;
241
262
  } catch (error) {
263
+ if (error?.response?.data?.error?.message) {
264
+ // @ts-ignore
265
+ throw new Error(error.response.data.error.message, {
266
+ cause: error
267
+ });
268
+ }
242
269
  throw error;
243
270
  }
244
271
  };
@@ -253,6 +280,17 @@ const createArgosApiClient = (options)=>{
253
280
  };
254
281
  };
255
282
 
283
+ const formatToContentType = (format)=>{
284
+ switch(format){
285
+ case "jpeg":
286
+ case "jpg":
287
+ return "image/jpeg";
288
+ case "png":
289
+ return "image/png";
290
+ default:
291
+ throw new Error(`Unsupported format ${format}`);
292
+ }
293
+ };
256
294
  const upload$1 = async (input)=>{
257
295
  const file = await readFile(input.path);
258
296
  await axios({
@@ -260,7 +298,7 @@ const upload$1 = async (input)=>{
260
298
  url: input.url,
261
299
  data: file,
262
300
  headers: {
263
- "Content-Type": "image/png"
301
+ "Content-Type": formatToContentType(input.format)
264
302
  }
265
303
  });
266
304
  };
@@ -308,11 +346,13 @@ const getConfigFromOptions = (options)=>{
308
346
  });
309
347
  // Optimize & compute hashes
310
348
  const screenshots = await Promise.all(foundScreenshots.map(async (screenshot)=>{
311
- const optimizedPath = await optimizeScreenshot(screenshot.path);
349
+ const format = await getImageFormat(screenshot.path);
350
+ const optimizedPath = await optimizeScreenshot(screenshot.path, format);
312
351
  const hash = await hashFile(optimizedPath);
313
352
  return {
314
353
  ...screenshot,
315
354
  optimizedPath,
355
+ format,
316
356
  hash
317
357
  };
318
358
  }));
@@ -328,7 +368,7 @@ const getConfigFromOptions = (options)=>{
328
368
  name: config.buildName,
329
369
  parallel: config.parallel,
330
370
  parallelNonce: config.parallelNonce,
331
- screenshotKeys: screenshots.map((screenshot)=>screenshot.hash)
371
+ screenshotKeys: Array.from(new Set(screenshots.map((screenshot)=>screenshot.hash)))
332
372
  });
333
373
  debug("Got screenshots", result);
334
374
  // Upload screenshots
@@ -340,7 +380,8 @@ const getConfigFromOptions = (options)=>{
340
380
  }
341
381
  await upload$1({
342
382
  url: putUrl,
343
- path: screenshot.optimizedPath
383
+ path: screenshot.optimizedPath,
384
+ format: screenshot.format
344
385
  });
345
386
  }));
346
387
  // Update build
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.1.0",
4
+ "version": "0.4.0",
5
5
  "scripts": {
6
6
  "prebuild": "rm -rf dist",
7
7
  "build": "rollup -c",
@@ -29,7 +29,7 @@
29
29
  "url": "https://github.com/argos-ci/argos-javascript/issues"
30
30
  },
31
31
  "engines": {
32
- "node": ">=16.14.0"
32
+ "node": ">=14.0.0"
33
33
  },
34
34
  "license": "MIT",
35
35
  "keywords": [
@@ -60,5 +60,5 @@
60
60
  "rollup-plugin-dts": "^4.2.2",
61
61
  "rollup-plugin-swc3": "^0.3.0"
62
62
  },
63
- "gitHead": "ff22c7f1ecf8cbbd1468440b3247d10b3b7b7310"
63
+ "gitHead": "e0f6d67663b59b5f00180988ccbb0736a8755aa4"
64
64
  }