@suffolklitlab/alkiln 4.10.4-feat-debug-cache → 4.11.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/CHANGELOG.md CHANGED
@@ -38,11 +38,11 @@ Format:
38
38
  ### Security
39
39
  -
40
40
  -->
41
+ <!-- ## [Unreleased] -->
41
42
 
42
- ## [Unreleased]
43
- ### Added
44
- - Story table can take screenshots after each visited page.
45
- - Projects created in da each have a unique name. We assume for now this will not build up test packages in the server.
43
+ ## [4.11.0] - 2023-03-13
44
+ ### Changed
45
+ - Shorten Axios errors to make them more readable (https://github.com/SuffolkLITLab/ALKiln/pull/632)
46
46
 
47
47
  ## [4.10.4] - 2023-02-15
48
48
  ### Added
@@ -24,7 +24,11 @@ da.get_dev_id = async function ( timeout ) {
24
24
  timeout: timeout,
25
25
  };
26
26
 
27
- return await axios.request( options );
27
+ try {
28
+ return await axios.request( options );
29
+ } catch (error) {
30
+ throw error.toJSON();
31
+ }
28
32
  }; // Ends da.get_dev_id()
29
33
 
30
34
 
@@ -41,8 +45,11 @@ da.create_project = async function ( project_name, timeout ) {
41
45
  timeout: timeout,
42
46
  };
43
47
 
44
- return await axios.request( options );
45
-
48
+ try {
49
+ return await axios.request( options );
50
+ } catch (error) {
51
+ throw error.toJSON();
52
+ }
46
53
  }; // Ends da.create_project()
47
54
 
48
55
 
@@ -61,7 +68,11 @@ da.pull = async function ( timeout ) {
61
68
  timeout: timeout,
62
69
  };
63
70
 
64
- return await axios.request( options );
71
+ try {
72
+ return await axios.request( options );
73
+ } catch (error) {
74
+ throw error.toJSON();
75
+ }
65
76
  }; // Ends da.pull()
66
77
 
67
78
 
@@ -78,7 +89,11 @@ da.has_task_finished = async function ( task_id, timeout ) {
78
89
  timeout: timeout,
79
90
  };
80
91
 
81
- return await axios.request( options );
92
+ try {
93
+ return await axios.request( options );
94
+ } catch (error) {
95
+ throw error.toJSON();
96
+ }
82
97
  }; // Ends da.has_task_finished()
83
98
 
84
99
 
@@ -95,7 +110,11 @@ da.delete_project = async function ( timeout ) {
95
110
  timeout: timeout,
96
111
  };
97
112
 
98
- return await axios.request( options );
113
+ try {
114
+ return await axios.request( options );
115
+ } catch (error) {
116
+ throw error.toJSON();
117
+ }
99
118
  }; // Ends da.delete_project()
100
119
 
101
120
 
@@ -121,9 +140,9 @@ da.__delete_projects_starting_with = async function ( base_name, starting_num=1,
121
140
  timeout: 30 * 1000,
122
141
  };
123
142
 
124
- await axios.request( options );
143
+ await axios.request( options );
125
144
  } catch ( error ) {
126
- console.log( error )
145
+ console.log( error.toJSON() )
127
146
  }
128
147
  name_incrementor++;
129
148
  }
@@ -204,16 +204,16 @@ da_i.loop_to_create_project = async function( creation_options ) {
204
204
  let wait_seconds = creation_options.wait_seconds || 5;
205
205
 
206
206
  let project_name = null;
207
- let num_tries = 0;
207
+ let name_incrementor = 0;
208
208
 
209
209
  // Try to create a project. If the project name is already taken, increment and loop again.
210
- while ( num_tries <= max_tries ) {
211
- num_tries++;
210
+ while ( name_incrementor <= max_tries ) {
211
+ name_incrementor++;
212
212
  try {
213
213
 
214
- // Try adding a new timestamp to the name. Must remove all non-valid characters
214
+ // Try next name that could be unique. Must remove all non-valid characters
215
215
  // TODO: This sanitization is already done in session_vars, so remove it from here
216
- project_name = session_vars.get_project_base_name().replace(/[^A-Za-z0-9]/g, '') + `${Date.now()}`;
216
+ project_name = session_vars.get_project_base_name().replace(/[^A-Za-z0-9]/g, '') + name_incrementor;
217
217
  log.info({ pre: `Trying to create a docassemble Project with the name ${ project_name }` });
218
218
  let response = await _da_REST.create_project( project_name, timeout );
219
219
  log.info({ pre: `The docassemble server is ready. Created a Project named ${ project_name }` });
@@ -226,7 +226,7 @@ da_i.loop_to_create_project = async function( creation_options ) {
226
226
 
227
227
  if ( response && response.data ) {
228
228
  if ( response.data.includes( `Invalid project` ) ) {
229
- if ( num_tries < max_tries ) {
229
+ if ( name_incrementor < max_tries ) {
230
230
  // A non-unique project name. Try the next project name.
231
231
  continue;
232
232
 
@@ -250,17 +250,15 @@ da_i.loop_to_create_project = async function( creation_options ) {
250
250
  });
251
251
  throw ( error );
252
252
  }
253
-
254
- // ends if error.response
255
- } else {
253
+ } else { // for if error.response
256
254
 
257
255
  // If it's a timeout error, server is busy. Try again after waiting.
258
256
  // Why are we using `max_tries` for timeout error as well?
259
- if ( is_timeout_error( error ) && num_tries < max_tries ) {
257
+ if ( is_timeout_error( error ) && name_incrementor < max_tries ) {
260
258
  log.info({ pre: `The docassemble server was busy when we tried to `
261
- + `create the Project. Attempt ${ num_tries } of `
259
+ + `create the Project. Attempt ${ name_incrementor } of `
262
260
  + `${ max_tries }. Will try again in ${ wait_seconds } seconds.` });
263
- num_tries--; // Try this name again next time
261
+ name_incrementor--; // Try this name again next time
264
262
  await time.waitForTimeout( wait_seconds * 1000 );
265
263
  continue;
266
264
 
@@ -272,8 +270,6 @@ da_i.loop_to_create_project = async function( creation_options ) {
272
270
  } // ends type of non-response error
273
271
  } // ends type of response error
274
272
  } // ends try
275
-
276
- // TODO: Add a message that we're done trying to create a project, successful or not
277
273
  } // ends while
278
274
  }; // Ends da_i.loop_to_create_project()
279
275
 
@@ -437,12 +433,9 @@ da_i.delete_project = async function ( delete_options ) {
437
433
  log.info({ pre: `Trying to delete Project ${ project_name }` });
438
434
 
439
435
  try {
440
-
441
436
  let response = await _da_REST.delete_project( timeout );
442
437
  log.info({ pre: `Deleted Project "${ project_name }"` });
443
-
444
438
  } catch ( error ) {
445
- // Status 400
446
439
  log.error({ pre: `Ran into an error when deleting Project "${ project_name }"` });
447
440
  log.debug({ pre: `See https://docassemble.org/docs/api.html#playground_delete_project.` });
448
441
  throw error;
@@ -20,7 +20,17 @@ const setup = async () => {
20
20
 
21
21
  // Create a project on the da server's account with a unique name then
22
22
  // store it locally for later deleting the project.
23
- let project_name = await da_i.loop_to_create_project();
23
+ let project_name = null;
24
+ // Explicit try-catch prevents "Unhandled promise rejection error"
25
+ // avoids showing confusing node errors to users that they shouldn't have to fix
26
+ try {
27
+ project_name = await da_i.loop_to_create_project();
28
+ } catch (error) {
29
+ log.error({type: `setup`, pre: `an unexpected error occurred while trying to create a docassemble project in the user's account`, data: JSON.stringify(error, null, 4)})
30
+ // we don't re-throw the exception, so make sure to exit with 1 to let Github Actions know the script failed
31
+ process.exitCode = 1;
32
+ return;
33
+ }
24
34
  // Once the name is created, save that name to a local file.
25
35
  session_vars.save_project_name( project_name );
26
36
 
@@ -10,9 +10,17 @@ const takedown = async () => {
10
10
  * Project created for this test.
11
11
  * For local development, clean up project name file. */
12
12
  log.info({ type: `takedown`, pre: `Trying to remove the docassemble Project from the testing account.` });
13
- await da_i.delete_project();
14
- session_vars.delete_project_name();
15
- log.info({ type: `takedown`, pre: `Success! Test takedown has finished successfully.` });
13
+ // Explicit try-catch prevents "Unhandled promise rejection error"
14
+ // avoids showing confusing node errors to users that they shouldn't have to fix
15
+ try {
16
+ await da_i.delete_project();
17
+ session_vars.delete_project_name();
18
+ log.info({ type: `takedown`, pre: `Success! Test takedown has finished successfully.` });
19
+ } catch (error) {
20
+ log.error({type: `takedown`, pre: `could not delete project`, data: JSON.stringify(error, null, 4)})
21
+ // we don't re-throw the exception, so make sure to exit with 1 to let Github Actions know the script failed
22
+ process.exitCode = 1;
23
+ }
16
24
  };
17
25
 
18
26
  takedown();
package/lib/scope.js CHANGED
@@ -2002,13 +2002,6 @@ module.exports = {
2002
2002
  if ( row_used.source ) { row_used.source.times_used += 1 }
2003
2003
  row_used.times_used += 1;
2004
2004
 
2005
- let { id } = scope.examinePageID( scope );
2006
- await scope.page.screenshot({
2007
- path: `./${ scope.paths.scenario }/pic-${Date.now()}-${ id }.jpg`,
2008
- type: 'jpeg',
2009
- fullPage: true
2010
- });
2011
-
2012
2005
  // TODO: special continue/navigation button function that handles url and all?
2013
2006
 
2014
2007
  // Have to catch errors right now or may get stuck in an infinite loop?
@@ -2022,7 +2015,6 @@ module.exports = {
2022
2015
  // Discuss moving this out of here. Having to pass in `id` just for
2023
2016
  // these messages smells bad. Con: Already a lot of code out there.
2024
2017
  error = await scope.waitUntilContinued( scope, { url: page_url, id });
2025
-
2026
2018
  // if ( error.was_found ) {
2027
2019
  // await scope.throwPageError( scope, { id: id });
2028
2020
  // }
@@ -2061,14 +2053,6 @@ module.exports = {
2061
2053
  if ( !did_navigate && ensure_navigation ) {
2062
2054
  // All fields on this page should be taken care of
2063
2055
  let page_url = await scope.page.url();
2064
-
2065
- let { id } = scope.examinePageID( scope );
2066
- await scope.page.screenshot({
2067
- path: `./${ scope.paths.scenario }/pic-${Date.now()}-${ id }.jpg`,
2068
- type: 'jpeg',
2069
- fullPage: true
2070
- });
2071
-
2072
2056
  await scope.continue( scope );
2073
2057
  // Have to catch errors right now or may get stuck in an infinite loop?
2074
2058
  // TODO: Don't catch errors - maybe the developer expected/wanted an error
package/lib/steps.js CHANGED
@@ -386,12 +386,6 @@ When(/^(?:the user gets)?(?:I get)? to ?(?:the)?(?: ?question)?(?: id)? "([^"]+)
386
386
  if( row1.report_str > row2.report_str ) { return 1; }
387
387
  return 0;
388
388
  });
389
-
390
- await scope.page.screenshot({
391
- path: `./${ scope.paths.scenario }/pic-${Date.now()}-${ id }.jpg`,
392
- type: 'jpeg',
393
- fullPage: true
394
- });
395
389
 
396
390
  // Add full used table to report so it can be copied if needed.
397
391
  // TODO: Should we/How do we get this in the final scenario report instead of here?
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suffolklitlab/alkiln",
3
- "version": "4.10.4-feat-debug-cache",
3
+ "version": "4.11.0",
4
4
  "description": "Integrated automated end-to-end testing with docassemble, puppeteer, and cucumber.",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {