@suffolklitlab/alkiln 5.4.1 → 5.4.2

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/CHANGELOG.md CHANGED
@@ -42,8 +42,14 @@ Format:
42
42
  ### Internal
43
43
  -
44
44
  -->
45
+
45
46
  <!-- ## [Unreleased] -->
46
47
 
48
+ ## [5.4.2] - 2023-10-22
49
+
50
+ ### Changed
51
+ - Downloads are now faster! You won't have to wait for the full duration of a step (30 seconds by default) to download a file anymore. See [this PR](https://github.com/SuffolkLITLab/ALKiln/pull/798) for more details.
52
+
47
53
  ## [5.4.1] - 2023-10-18
48
54
 
49
55
  ### Internal
package/lib/scope.js CHANGED
@@ -2485,10 +2485,39 @@ module.exports = {
2485
2485
  if ( !elem ) { reports.addToReport(scope, { type: `error`, value: msg }); }
2486
2486
  expect( elem, msg ).to.exist;
2487
2487
 
2488
- scope.toDownload = filename;
2489
- // Should this be using `scope.tapElement()`?
2490
- await elem.evaluate( elem => { return elem.click(); });
2491
- await scope.detectDownloadComplete( scope );
2488
+ let failed_to_download = false;
2489
+ let err_msg = "";
2490
+ try {
2491
+ const binaryStr = await scope.page.evaluate(el => {
2492
+ const url = el.getAttribute("href");
2493
+ return new Promise(async (resolve, reject) => {
2494
+ const response = await fetch(url, {method: "GET"});
2495
+ const reader = new FileReader();
2496
+ reader.readAsBinaryString(await response.blob());
2497
+ reader.onload = () => resolve(reader.result);
2498
+ reader.onerror = () => reject(`Error occurred on page when downloading ${ url }: ${ reader.error }`);
2499
+ });
2500
+ }, elem);
2501
+ if (binaryStr !== '') {
2502
+ const fileData = Buffer.from(binaryStr, 'binary');
2503
+ fs.writeFileSync(`${ scope.paths.scenario }/${ filename }`, fileData);
2504
+ reports.addToReport(scope, { type: `info`, value: `Downloaded ${ filename } (${ fileData.length } bytes) to ${ scope.paths.scenario }`});
2505
+ } else {
2506
+ failed_to_download = true;
2507
+ err_msg = `Couldn't download ${ filename }, binary data for download was empty`;
2508
+ }
2509
+ } catch (error) {
2510
+ failed_to_download = true;
2511
+ err_msg = error;
2512
+ }
2513
+
2514
+ if (failed_to_download) {
2515
+ reports.addToReport(scope, { type: `warning`, value: `Could not download file using fetch (${ err_msg }). ALKiln will now fallback to the click download method` });
2516
+ scope.toDownload = filename;
2517
+ // Should this be using `scope.tapElement()`?
2518
+ await elem.evaluate( elem => { return elem.click(); });
2519
+ await scope.detectDownloadComplete( scope );
2520
+ }
2492
2521
  }, // Ends scope.steps.download()
2493
2522
 
2494
2523
  compare_pdfs: async function (scope, {existing_pdf_path, new_pdf_path}) {
package/lib/steps.js CHANGED
@@ -203,7 +203,6 @@ Given(/I start the interview at "([^"]+)"/, {timeout: -1}, async (file_name) =>
203
203
  scope.page.on('response', async response => {
204
204
  // Note: We can expect that only one file will be getting downloaded
205
205
  // at any one time since each step completes synchronously
206
-
207
206
  // If response has a file in it that matches the file we are downloading
208
207
  // Sadly, 'content-disposition' isn't working. We're not sure what will.
209
208
  if ( response.headers()['content-disposition'] && (response.headers()['content-disposition']).includes(`attachment;filename=${scope.toDownload}`) ) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suffolklitlab/alkiln",
3
- "version": "5.4.1",
3
+ "version": "5.4.2",
4
4
  "description": "Integrated automated end-to-end testing with docassemble, puppeteer, and cucumber.",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {