@suffolklitlab/alkiln 4.6.0 → 4.7.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/.github/workflows/test_tests.yml +14 -34
- package/CHANGELOG.md +17 -0
- package/action.yml +6 -35
- package/lib/docassemble/setup.js +6 -0
- package/lib/scope.js +471 -105
- package/lib/steps.js +163 -17
- package/lib/utils/clean_reports.js +9 -3
- package/lib/utils/files.js +32 -0
- package/lib/utils/session_vars.js +56 -13
- package/package.json +2 -1
- package/tests/features/interactive_steps.feature +11 -2
- package/tests/features/observation_steps.feature +2 -2
- package/tests/features/random_input.feature +15 -0
- package/tests/features/story_tables.feature +1 -0
- package/tests/unit_tests/getSafeScenarioBaseFilename.fixtures.js +0 -2
- package/tests/unit_tests/getSafeScenarioBaseFilename.test.js +10 -21
- package/tests/unit_tests/getSafeScenarioFilename.test.js +6 -3
- package/tests/unit_tests/names.fixtures.js +8 -8
package/lib/steps.js
CHANGED
|
@@ -20,8 +20,10 @@ const { v4: uuidv4 } = require('uuid');
|
|
|
20
20
|
const scope = require('./scope');
|
|
21
21
|
const log = require('./utils/log');
|
|
22
22
|
const session_vars = require('./utils/session_vars');
|
|
23
|
+
const files = require('./utils/files' );
|
|
24
|
+
|
|
23
25
|
/* Of Note:
|
|
24
|
-
- We're using `*=` because sometimes da text has funny characters in it that are hard to anticipate
|
|
26
|
+
- We're using `*=` for selectors because sometimes da text has funny characters in it that are hard to anticipate
|
|
25
27
|
*/
|
|
26
28
|
|
|
27
29
|
|
|
@@ -70,7 +72,23 @@ BeforeAll(async () => {
|
|
|
70
72
|
scope.timeout = 30 * 1000;
|
|
71
73
|
scope.showif_timeout = 600;
|
|
72
74
|
scope.report = new Map();
|
|
73
|
-
|
|
75
|
+
|
|
76
|
+
// Store path names for files and docs created for the tests
|
|
77
|
+
scope.paths = {};
|
|
78
|
+
// Test setup should have created this filepath. Run setup if there's a problem with this.
|
|
79
|
+
scope.paths.artifacts = session_vars.get_artifacts_path_name();
|
|
80
|
+
// For GitHub tests, use the artifacts folder that was created during setup
|
|
81
|
+
// For local tests, make a new folder for each time scenarios start
|
|
82
|
+
if ( !session_vars.is_dev_env() ) {
|
|
83
|
+
// Make a new folder to store all the files for this run of the tests
|
|
84
|
+
scope.paths.artifacts = files.make_artifacts_folder();
|
|
85
|
+
// Save its name in a file. `session_vars` can get it back later.
|
|
86
|
+
session_vars.save_artifacts_path_name( scope.paths.artifacts );
|
|
87
|
+
}
|
|
88
|
+
scope.paths.report = `${ scope.paths.artifacts }/report.txt`;
|
|
89
|
+
|
|
90
|
+
scope.paths.debug_log = `${ scope.paths.artifacts }/${ log.debug_log_file }`;
|
|
91
|
+
fs.writeFileSync( scope.paths.debug_log, "" );
|
|
74
92
|
});
|
|
75
93
|
|
|
76
94
|
Before(async (scenario) => {
|
|
@@ -79,7 +97,14 @@ Before(async (scenario) => {
|
|
|
79
97
|
scope.expected_in_report = null;
|
|
80
98
|
|
|
81
99
|
await scope.addReportHeading(scope, {scenario});
|
|
100
|
+
// Make folder for this Scenario in the all-tests artifacts folder
|
|
82
101
|
scope.base_filename = await scope.getSafeScenarioBaseFilename(scope, {scenario});
|
|
102
|
+
// Add a date for uniqueness in case dev has accidentally copied a Scenario description
|
|
103
|
+
let date = files.readable_date();
|
|
104
|
+
scope.paths.scenario = `${ scope.paths.artifacts }/${ scope.base_filename }-${ date }`;
|
|
105
|
+
fs.mkdirSync( scope.paths.scenario );
|
|
106
|
+
// Store path name for this Scenario's individualized report
|
|
107
|
+
scope.paths.scenario_report = `${ scope.paths.scenario }/report.txt`;
|
|
83
108
|
|
|
84
109
|
// Downloads
|
|
85
110
|
scope.downloadComplete = false;
|
|
@@ -164,10 +189,9 @@ Given(/I start the interview at "([^"]+)"(?: in lang "([^"]+)")?/, {timeout: -1}
|
|
|
164
189
|
// I've seen stuff take an extra moment or two. Shame to have it everywhere
|
|
165
190
|
try {
|
|
166
191
|
// Interview files should get downloaded to downloads folder
|
|
167
|
-
let docs_dir = await scope.getSafeScenarioFilename( scope, { prefix: `downloads` });
|
|
168
192
|
await scope.page._client.send('Page.setDownloadBehavior', {
|
|
169
193
|
behavior: 'allow',
|
|
170
|
-
downloadPath: path.resolve(
|
|
194
|
+
downloadPath: path.resolve( scope.paths.scenario ), // Save in root of this scenario
|
|
171
195
|
});
|
|
172
196
|
resolve();
|
|
173
197
|
} catch ( err ) { reject( err ); }
|
|
@@ -178,7 +202,11 @@ Given(/I start the interview at "([^"]+)"(?: in lang "([^"]+)")?/, {timeout: -1}
|
|
|
178
202
|
await custom_download_behavior_timeout;
|
|
179
203
|
|
|
180
204
|
// ---- EVENT LISTENERS ----
|
|
181
|
-
|
|
205
|
+
|
|
206
|
+
// TODO: Wait for download to complete doesn't work. See notes in
|
|
207
|
+
// scope.js scope.detectDownloadComplete()
|
|
208
|
+
|
|
209
|
+
// ~Wait for possible download. From https://stackoverflow.com/a/51423688~
|
|
182
210
|
scope.page.on('response', async response => {
|
|
183
211
|
// Note: We can expect that only one file will be getting downloaded
|
|
184
212
|
// at any one time since each step completes synchronously
|
|
@@ -190,7 +218,7 @@ Given(/I start the interview at "([^"]+)"(?: in lang "([^"]+)")?/, {timeout: -1}
|
|
|
190
218
|
// destroyed when the page closes anyway.
|
|
191
219
|
|
|
192
220
|
// Watch event on download folder or file
|
|
193
|
-
await fs.watchFile(
|
|
221
|
+
await fs.watchFile( scope.paths.scenario, function (curr, prev) {
|
|
194
222
|
// If current size eq to size from response then close
|
|
195
223
|
if (parseInt(curr.size) === parseInt(response._headers['content-length'])) {
|
|
196
224
|
// Lets the related function in `scope` know that the download
|
|
@@ -430,7 +458,7 @@ Then(/I take a screenshot ?(?:named "([^"]+)")?/, { timeout: -1 }, async ( name
|
|
|
430
458
|
/* Here to make writing tests more comfortable. */
|
|
431
459
|
When("I do nothing", async () => { await scope.afterStep(scope); }); // √
|
|
432
460
|
|
|
433
|
-
Then(
|
|
461
|
+
Then(/the (?:question|page|screen) id should be "([^"]+)"/i, { timeout: -1 }, async ( question_id ) => {
|
|
434
462
|
/* Looks for a sanitized version of the question id as it's written
|
|
435
463
|
* in the .yml. docassemble's way */
|
|
436
464
|
let { question_has_id, id, id_matches } = await scope.examinePageID( scope, question_id );
|
|
@@ -650,7 +678,7 @@ Then(/(?:the )?text(?: in)?(?: the)?(?: JSON)?(?: var)?(?:iable)?(?: )?"([^"]+)"
|
|
|
650
678
|
*/
|
|
651
679
|
|
|
652
680
|
// Get JSON variable value
|
|
653
|
-
let {
|
|
681
|
+
let { json_path, json } = await scope.savePageJSONData( scope );
|
|
654
682
|
let actual_value = json.variables[ var_name ];
|
|
655
683
|
|
|
656
684
|
// Add warning to report if value is not as expected
|
|
@@ -658,8 +686,8 @@ Then(/(?:the )?text(?: in)?(?: the)?(?: JSON)?(?: var)?(?:iable)?(?: )?"([^"]+)"
|
|
|
658
686
|
await scope.addToReport( scope, {
|
|
659
687
|
type: `error`,
|
|
660
688
|
value: `The variable "${ var_name }" was not equal to the expected `
|
|
661
|
-
+ `value on the "${ scope.page_id }" screen. Check
|
|
662
|
-
+
|
|
689
|
+
+ `value on the "${ scope.page_id }" screen. Check `
|
|
690
|
+
+ `${ json_path } to see the page's JSON variables.`
|
|
663
691
|
});
|
|
664
692
|
}
|
|
665
693
|
|
|
@@ -735,11 +763,11 @@ When(/I tap the "([^"]+)" element and wait ([0-9]+) second(?:s)?/i, { timeout: -
|
|
|
735
763
|
});
|
|
736
764
|
|
|
737
765
|
When(/I check the page for (?:accessibility|a11y) issues/i, {timeout: -1}, async () => {
|
|
738
|
-
let { passed,
|
|
766
|
+
let { passed, axe_filepath } = await wrapPromiseWithTimeout(
|
|
739
767
|
scope.checkForA11y(scope),
|
|
740
768
|
scope.timeout
|
|
741
769
|
)
|
|
742
|
-
let msg = `Found potential accessibility issues on the ${ scope.page_id } screen. Details in ${
|
|
770
|
+
let msg = `Found potential accessibility issues on the ${ scope.page_id } screen. Details in ${ axe_filepath }.`;
|
|
743
771
|
expect( passed, msg ).to.be.true;
|
|
744
772
|
});
|
|
745
773
|
|
|
@@ -752,10 +780,107 @@ When(/I check all pages for (?:accessibility|a11y) issues/i, {timeout: -1}, asyn
|
|
|
752
780
|
// UI element interaction
|
|
753
781
|
//#####################################
|
|
754
782
|
|
|
783
|
+
// -------------------------------------
|
|
784
|
+
// --- RANDOM INPUT ---
|
|
785
|
+
When(/I answer randomly for at most ([0-9]+) (?:page(?:s)?|screen(?:s)?)/, { timeout: -1 }, async ( max_pages_str ) => {
|
|
786
|
+
/** Give random answers until the user can't continue any more.
|
|
787
|
+
*
|
|
788
|
+
* Variations:
|
|
789
|
+
* I answer randomly for at most 1 page
|
|
790
|
+
* I answer randomly for at most 10 pages
|
|
791
|
+
* I answer randomly for at most 101 screens
|
|
792
|
+
*/
|
|
793
|
+
scope.paths.random_screenshots = `${ scope.paths.scenario }/random_answers_screenshots`;
|
|
794
|
+
fs.mkdirSync( scope.paths.random_screenshots );
|
|
795
|
+
|
|
796
|
+
// Force the dev to prevent infinite loops
|
|
797
|
+
let max_pages = parseInt( max_pages_str );
|
|
798
|
+
let curr_page_num = 0;
|
|
799
|
+
|
|
800
|
+
// While a continue button is on the current page, fill out
|
|
801
|
+
// the fields and then try to continue
|
|
802
|
+
// let continue_exists = true;
|
|
803
|
+
// while ( continue_exists && curr_page_num < max_pages ) {
|
|
804
|
+
let buttons_exist = true;
|
|
805
|
+
while ( buttons_exist && curr_page_num < max_pages ) {
|
|
806
|
+
|
|
807
|
+
curr_page_num = curr_page_num + 1;
|
|
808
|
+
let { id } = await scope.examinePageID( scope, `no target id` );
|
|
809
|
+
|
|
810
|
+
// Ensure no infinite loop, but each page has a full timeout to run
|
|
811
|
+
let custom_timeout = new Promise(async function( resolve, reject ) {
|
|
812
|
+
|
|
813
|
+
// Set up timeout to stop infinite loops
|
|
814
|
+
let page_timeout_id = setTimeout(async function() {
|
|
815
|
+
|
|
816
|
+
let timeout_message = `The page with an id of "${ id }" took too long `
|
|
817
|
+
+ `to fill it with random answers (over ${ scope.timeout/1000/60 } min).`
|
|
818
|
+
await scope.addToReport( scope, { type: `error`, value: timeout_message });
|
|
819
|
+
throw( timeout_message );
|
|
820
|
+
|
|
821
|
+
}, scope.timeout);
|
|
822
|
+
|
|
823
|
+
// self-invoke an anonymous async function so we don't have to
|
|
824
|
+
// abstract the details of resolving and rejecting.
|
|
825
|
+
(async function() {
|
|
826
|
+
try {
|
|
827
|
+
|
|
828
|
+
// Set all the fields on the page
|
|
829
|
+
let buttons = await scope.steps.set_random_page_vars( scope );
|
|
830
|
+
|
|
831
|
+
// Take a screenshot of the page before continuing or ending
|
|
832
|
+
await scope.page.screenshot({
|
|
833
|
+
path: `${ scope.paths.random_screenshots }/${ Date.now() }.jpg`,
|
|
834
|
+
type: `jpeg`,
|
|
835
|
+
fullPage: true
|
|
836
|
+
});
|
|
837
|
+
|
|
838
|
+
// Prep for the next loop to possibly stop. Signature page buttons
|
|
839
|
+
// don't count as buttons in the way our field detects them
|
|
840
|
+
buttons_exist = buttons.length > 0;
|
|
841
|
+
// If there were any buttons, pick a random one to try to press
|
|
842
|
+
if ( buttons_exist ) {
|
|
843
|
+
await scope.set_random_input_for.buttons( scope, { fields: buttons });
|
|
844
|
+
} else {
|
|
845
|
+
// If can theoretically continue, try to. Also prep to
|
|
846
|
+
// stop or continue for the next loop
|
|
847
|
+
buttons_exist = await scope.continue_exists( scope );
|
|
848
|
+
if ( buttons_exist ) {
|
|
849
|
+
await scope.continue( scope );
|
|
850
|
+
} // ends if continue exists
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
if ( buttons_exist ) {
|
|
854
|
+
process.stdout.write(`\x1b[36m${ 'v' }\x1b[0m`); // pressed button
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
resolve();
|
|
858
|
+
|
|
859
|
+
} catch ( err ) {
|
|
860
|
+
let err_msg = `The page with the "${ id }" errored when trying to fill `
|
|
861
|
+
+ `it with random answers: ${ err.name }`
|
|
862
|
+
await scope.addToReport( scope, { type: `error`, value: err_msg });
|
|
863
|
+
throw( err );
|
|
864
|
+
|
|
865
|
+
} finally {
|
|
866
|
+
// prevent temporary hang at end of tests
|
|
867
|
+
clearTimeout( page_timeout_id );
|
|
868
|
+
}
|
|
869
|
+
})();
|
|
870
|
+
|
|
871
|
+
}); // ends custom_timeout for set_random_page_vars
|
|
872
|
+
|
|
873
|
+
await custom_timeout;
|
|
874
|
+
|
|
875
|
+
} // ends while continue_exists
|
|
876
|
+
|
|
877
|
+
|
|
878
|
+
}); // Ends random input
|
|
879
|
+
|
|
755
880
|
// -------------------------------------
|
|
756
881
|
// --- VARIABLES-BASED STEPS ---
|
|
757
882
|
|
|
758
|
-
When(/I set the var(?:iable)? "([^"]+)" to "([^"]+)"/, { timeout: -1 }, async ( var_name,
|
|
883
|
+
When(/I set the var(?:iable)? "([^"]+)" to "([^"]+)"/, { timeout: -1 }, async ( var_name, answer ) => {
|
|
759
884
|
/* Set a non-story table variable (with or without a choice associated with it) to a value. Set:
|
|
760
885
|
* - Buttons associated with variables
|
|
761
886
|
* - Dropdowns
|
|
@@ -769,7 +894,7 @@ When(/I set the var(?:iable)? "([^"]+)" to "([^"]+)"/, { timeout: -1 }, async (
|
|
|
769
894
|
* 1. I set the var "rent_interval" to "weekly"
|
|
770
895
|
*/
|
|
771
896
|
return wrapPromiseWithTimeout(
|
|
772
|
-
scope.steps.set_regular_var( scope, var_name,
|
|
897
|
+
scope.steps.set_regular_var( scope, var_name, answer ),
|
|
773
898
|
scope.timeout
|
|
774
899
|
);
|
|
775
900
|
});
|
|
@@ -935,8 +1060,22 @@ After(async function(scenario) {
|
|
|
935
1060
|
});
|
|
936
1061
|
} else {
|
|
937
1062
|
// Save/download a picture of the screen that's showing during the unexpected status
|
|
938
|
-
|
|
939
|
-
await scope.
|
|
1063
|
+
// Save one copy in the outer-most artifact folder
|
|
1064
|
+
let scenario_filename = await scope.getSafeScenarioFilename( scope, { prefix: `error_on` });
|
|
1065
|
+
await scope.page.screenshot({
|
|
1066
|
+
path: `${ scope.paths.artifacts }/${ scenario_filename }.jpg`,
|
|
1067
|
+
type: `jpeg`,
|
|
1068
|
+
fullPage: true
|
|
1069
|
+
});
|
|
1070
|
+
// Save another copy in the artifact's Scenario folder
|
|
1071
|
+
let screenshot_name = `error_on`;
|
|
1072
|
+
let { id } = await scope.examinePageID( scope, 'none to match' );
|
|
1073
|
+
screenshot_name += `-${ id }`;
|
|
1074
|
+
await scope.page.screenshot({
|
|
1075
|
+
path: `${ scope.paths.scenario }/${ screenshot_name }.jpg`,
|
|
1076
|
+
type: `jpeg`,
|
|
1077
|
+
fullPage: true
|
|
1078
|
+
});
|
|
940
1079
|
} // ends if scope.disable_error_screenshot
|
|
941
1080
|
} // ends if scope.page exists
|
|
942
1081
|
|
|
@@ -991,6 +1130,13 @@ After(async function(scenario) {
|
|
|
991
1130
|
await scope.page.close();
|
|
992
1131
|
scope.page = null;
|
|
993
1132
|
} // ends if scope.page
|
|
1133
|
+
|
|
1134
|
+
// Add report text to Scenario folder after everything has been added to the report
|
|
1135
|
+
let current_report_obj = scope.report.get( scope.scenario_id );
|
|
1136
|
+
let scenario_report_obj = [ scope.scenario_id, current_report_obj ]; // Mimic how loop works with `Map`
|
|
1137
|
+
let report = await scope.getPrintableScenario( scope, { scenario: scenario_report_obj });
|
|
1138
|
+
// Save the report as in the Scenario folder
|
|
1139
|
+
fs.writeFileSync( scope.paths.scenario_report, report );
|
|
994
1140
|
});
|
|
995
1141
|
|
|
996
1142
|
AfterAll(async function() {
|
|
@@ -1000,7 +1146,7 @@ AfterAll(async function() {
|
|
|
1000
1146
|
console.log( `\n\n${ report }` );
|
|
1001
1147
|
|
|
1002
1148
|
// Save/download the report as an artifact
|
|
1003
|
-
fs.writeFileSync(
|
|
1149
|
+
fs.writeFileSync( scope.paths.report, report );
|
|
1004
1150
|
|
|
1005
1151
|
// If there is a browser open, then close it
|
|
1006
1152
|
if (scope.browser) {
|
|
@@ -2,22 +2,28 @@
|
|
|
2
2
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const log = require('./log');
|
|
5
|
+
const session_vars = require('./session_vars');
|
|
5
6
|
|
|
6
7
|
// This is hardcoded information from `cucumber.js`. Once we move to cucumber 8, we should
|
|
7
|
-
// change that the cucumber.json and actually parse the info from it.
|
|
8
|
+
// change that the cucumber.json and actually parse the info from it.
|
|
9
|
+
// The file won't be used for anything other than detecting and removing color codes
|
|
8
10
|
let summary_file_name = 'cucumber-report.txt';
|
|
9
11
|
fs.readFile(summary_file_name, 'utf8', (err, data) => {
|
|
10
12
|
if (err) {
|
|
11
13
|
console.error(err);
|
|
12
14
|
return;
|
|
13
15
|
}
|
|
16
|
+
|
|
14
17
|
// Replace terminal color codes, if present
|
|
15
18
|
// https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797#colors--graphics-mode
|
|
16
19
|
data = data.replace(/\x1b\[[0-9][0-9]?[0-9]?m/g, '');
|
|
17
|
-
|
|
20
|
+
|
|
21
|
+
// Put it in the correct file in the correct folder
|
|
22
|
+
let artifacts_path = session_vars.get_artifacts_path_name();
|
|
23
|
+
fs.appendFile( `${ artifacts_path }/${ log.debug_log_file }`, data, err => {
|
|
18
24
|
if (err) {
|
|
19
25
|
console.error(err);
|
|
20
26
|
return;
|
|
21
27
|
}
|
|
22
|
-
});
|
|
28
|
+
}); // Ends appendFileSync
|
|
23
29
|
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const safe_filename = require('sanitize-filename');
|
|
3
|
+
|
|
4
|
+
let files = {};
|
|
5
|
+
|
|
6
|
+
files.readable_date = function() {
|
|
7
|
+
/* Return the current timestamp in a human-readable filename-safe format to
|
|
8
|
+
* match the workflow artifact date format. */
|
|
9
|
+
let date = new Date(); // now
|
|
10
|
+
let str = date.toLocaleString('en-GB', { timeZone: 'UTC' });
|
|
11
|
+
let fancy_str = str.replace(/\//g, '-').replace(',', ' at').replace(':', 'hrs ').replace(':', 'mins ') + 'secs UTC';
|
|
12
|
+
return fancy_str;
|
|
13
|
+
}; // Ends files.readable_date()
|
|
14
|
+
|
|
15
|
+
files.make_artifacts_folder = function (folder_name) {
|
|
16
|
+
/** Makes a folder in the root of the project, either with the given name
|
|
17
|
+
* or with a default name.
|
|
18
|
+
*
|
|
19
|
+
* Works for local development as well, unlike action.yml or the workflow file.
|
|
20
|
+
*/
|
|
21
|
+
if (folder_name) {
|
|
22
|
+
folder_name = safe_filename( folder_name );
|
|
23
|
+
} else {
|
|
24
|
+
folder_name = `alkiln_tests_output-${ files.readable_date() }`
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
fs.mkdirSync( folder_name );
|
|
28
|
+
return folder_name;
|
|
29
|
+
}; // Ends files.make_artifacts_folder()
|
|
30
|
+
|
|
31
|
+
module.exports = files;
|
|
32
|
+
|
|
@@ -21,9 +21,11 @@ const session_vars = {};
|
|
|
21
21
|
module.exports = session_vars;
|
|
22
22
|
|
|
23
23
|
// These default to null
|
|
24
|
+
// TODO: How to isolate debug elsewhere so this file can use the logger?
|
|
24
25
|
session_vars.get_debug = function () { return process.env.DEBUG || null; };
|
|
25
26
|
session_vars.get_dev_api_key = function () { return process.env.DOCASSEMBLE_DEVELOPER_API_KEY || null; };
|
|
26
27
|
session_vars.get_repo_url = function () { return process.env.REPO_URL || null; };
|
|
28
|
+
session_vars.is_dev_env = function () { return process.env.DEV || null; }
|
|
27
29
|
|
|
28
30
|
// More complex logic
|
|
29
31
|
session_vars.get_setup_timeout_ms = function () {
|
|
@@ -80,9 +82,10 @@ session_vars.get_languages = function () {
|
|
|
80
82
|
}; // Ends session_vars.get_languages()
|
|
81
83
|
|
|
82
84
|
|
|
83
|
-
const
|
|
85
|
+
const runtime_config_path = `runtime_config.json`;
|
|
86
|
+
const project_name_key = `da_project_name`;
|
|
84
87
|
session_vars.save_project_name = function ( project_name ) {
|
|
85
|
-
/* Saves the name of the project to a
|
|
88
|
+
/* Saves the name of the project to a json obj so deletion can use it later.
|
|
86
89
|
* Built for local as well as remote testing. Assumes a kosher string.
|
|
87
90
|
* We avoided a list because of concerns over getting out of date.
|
|
88
91
|
* Should we try to prevent someone overwriting a previous project name?
|
|
@@ -90,16 +93,23 @@ session_vars.save_project_name = function ( project_name ) {
|
|
|
90
93
|
* @param project_name { string } - purely alphanumeric string */
|
|
91
94
|
|
|
92
95
|
// Warn local developers if file already exists
|
|
93
|
-
if ( fs.existsSync(
|
|
96
|
+
if ( fs.existsSync( runtime_config_path ) ) {
|
|
94
97
|
let old_project_name = session_vars.get_project_name();
|
|
95
98
|
let session_project_already_exists_msg = `ALKiln WARNING: `
|
|
96
99
|
+ `This session had a project name already: ${ old_project_name }. `
|
|
97
100
|
+ `A new project has now been created called ${ project_name }. `
|
|
98
101
|
+ `Remember to delete ${ old_project_name }`;
|
|
99
102
|
console.warn( session_project_already_exists_msg );
|
|
103
|
+
} else {
|
|
104
|
+
// If the file doesn't exist, make one because next we need to read it
|
|
105
|
+
fs.writeFileSync( runtime_config_path, JSON.stringify( {}, null, 2 ) );
|
|
100
106
|
}
|
|
101
107
|
|
|
102
|
-
|
|
108
|
+
// Get the json, changing it, and re-write the file from scratch
|
|
109
|
+
let json = JSON.parse( fs.readFileSync( runtime_config_path ) );
|
|
110
|
+
json[ project_name_key ] = project_name;
|
|
111
|
+
let file = fs.writeFileSync( runtime_config_path, JSON.stringify( json, null, 2 ) );
|
|
112
|
+
|
|
103
113
|
if ( session_vars.get_debug() ) {
|
|
104
114
|
console.log( `ALKiln debug: Stored name of Project "${ project_name }" locally.` );
|
|
105
115
|
}
|
|
@@ -107,26 +117,59 @@ session_vars.save_project_name = function ( project_name ) {
|
|
|
107
117
|
}; // Ends save_project_name()
|
|
108
118
|
|
|
109
119
|
session_vars.get_project_name = function () {
|
|
110
|
-
/* Get the name of the current
|
|
111
|
-
let
|
|
112
|
-
|
|
120
|
+
/* Get the name of the current docassemble Project */
|
|
121
|
+
let json = JSON.parse( fs.readFileSync( runtime_config_path ));
|
|
122
|
+
let project_name = json[ project_name_key ] || null;
|
|
123
|
+
if ( session_vars.get_debug() ) { console.log( `ALKiln debug: Project name from file is "${ project_name }".` ); }
|
|
113
124
|
return project_name;
|
|
114
125
|
}; // Ends get_project_name()
|
|
115
126
|
|
|
116
127
|
session_vars.delete_project_name = function () {
|
|
117
|
-
/*
|
|
118
|
-
// Avoid race conditions possibly caused by checking for existence first
|
|
119
|
-
// Delete file if possible
|
|
128
|
+
/* Empty the key storing the name of the docassemble Project */
|
|
120
129
|
try {
|
|
121
|
-
|
|
122
|
-
|
|
130
|
+
// Get the json, changing it, and re-write the file from scratch
|
|
131
|
+
let json = JSON.parse( fs.readFileSync( runtime_config_path ));
|
|
132
|
+
json[ project_name_key ] = ``;
|
|
133
|
+
console.log( `ALKiln: Deleted the data that stored the name of the Project.` );
|
|
134
|
+
fs.writeFileSync( runtime_config_path, JSON.stringify( json, null, 2 ) );
|
|
123
135
|
return true;
|
|
124
136
|
} catch ( error ) {
|
|
125
|
-
console.warn( `ALKiln WARNING: Could not delete the Project name
|
|
137
|
+
console.warn( `ALKiln WARNING: Could not delete the Project name data. Error: ${ error }.` );
|
|
126
138
|
return false;
|
|
127
139
|
}
|
|
128
140
|
};
|
|
129
141
|
|
|
142
|
+
// The file storing the artifacts path contains the name of the current artifacts folder.
|
|
143
|
+
// The directory name it contains will be created or changed with each run of all the tests.
|
|
144
|
+
// const file_storing_artifact_path = `_alkiln_test_artifacts_dir_name.json`;
|
|
145
|
+
const artifacts_path_key = `artifacts_path`;
|
|
146
|
+
session_vars.save_artifacts_path_name = function ( path_name ) {
|
|
147
|
+
/* Save a key with the name of the current artifacts folder in case it doesn't exist. */
|
|
148
|
+
|
|
149
|
+
// Get the json, changing it, and re-write the file from scratch
|
|
150
|
+
let json = JSON.parse( fs.readFileSync( runtime_config_path ) );
|
|
151
|
+
json[ artifacts_path_key ] = path_name;
|
|
152
|
+
let file = fs.writeFileSync( runtime_config_path, JSON.stringify( json, null, 2 ) );
|
|
153
|
+
|
|
154
|
+
if ( session_vars.get_debug() ) {
|
|
155
|
+
console.log( `ALKiln debug: Stored name of artifacts directory "${ path_name }" locally.` );
|
|
156
|
+
}
|
|
157
|
+
return file;
|
|
158
|
+
}; // Ends get_project_name()
|
|
159
|
+
|
|
160
|
+
session_vars.get_artifacts_path_name = function () {
|
|
161
|
+
/* Get the name of the current artifacts path. */
|
|
162
|
+
try {
|
|
163
|
+
let json = JSON.parse( fs.readFileSync( runtime_config_path ));
|
|
164
|
+
let path_name = json[ artifacts_path_key ];
|
|
165
|
+
|
|
166
|
+
if ( session_vars.get_debug() ) { console.log( `ALKiln debug: Artifacts directory is "${ path_name }".` ); }
|
|
167
|
+
return path_name;
|
|
168
|
+
} catch ( error ) {
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
}; // Ends get_project_name()
|
|
172
|
+
|
|
130
173
|
/**
|
|
131
174
|
* Ensure all required environment variables exist. Add each missing variable
|
|
132
175
|
* to an error that will be thrown at the end.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@suffolklitlab/alkiln",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.7.0",
|
|
4
4
|
"description": "Integrated automated end-to-end testing with docassemble, puppeteer, and cucumber.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@axe-core/puppeteer": "4.4.2",
|
|
39
39
|
"@cucumber/cucumber": "7.3.2",
|
|
40
|
+
"@faker-js/faker": "^7.3.0",
|
|
40
41
|
"axios": "0.24.0",
|
|
41
42
|
"chai": "4.2.0",
|
|
42
43
|
"cheerio": "1.0.0-rc.10",
|
|
@@ -4,7 +4,7 @@ Feature: Interactive steps
|
|
|
4
4
|
# In tag names, 'i' is for 'interactive'
|
|
5
5
|
|
|
6
6
|
@slow @i1
|
|
7
|
-
Scenario: I set
|
|
7
|
+
Scenario: I set various values
|
|
8
8
|
Given I start the interview at "all_tests"
|
|
9
9
|
Then the question id should be "upload files"
|
|
10
10
|
When I set the var "upload_files_visible" to "some_png_1.png, some_png_2.png"
|
|
@@ -87,6 +87,10 @@ Scenario: I set text-type values
|
|
|
87
87
|
Then the question id should be "button event action"
|
|
88
88
|
And I tap to continue
|
|
89
89
|
# Next page
|
|
90
|
+
Then the question id should be "single-dropdown-field"
|
|
91
|
+
And I set the var "single_dropdown_field" to "email"
|
|
92
|
+
And I tap to continue
|
|
93
|
+
# Next page
|
|
90
94
|
Then the question id should be "the end"
|
|
91
95
|
|
|
92
96
|
@fast @i2 @secret
|
|
@@ -127,4 +131,9 @@ Scenario: tap element with an error
|
|
|
127
131
|
is there a typo?
|
|
128
132
|
"""
|
|
129
133
|
Given I start the interview at "test_taps"
|
|
130
|
-
And I tap the "Tests-not_there-tab" tab
|
|
134
|
+
And I tap the "Tests-not_there-tab" tab
|
|
135
|
+
|
|
136
|
+
@i5 @random
|
|
137
|
+
Scenario: I answer randomly till the end
|
|
138
|
+
Given I start the interview at "all_tests"
|
|
139
|
+
And I answer randomly for at most 50 pages
|
|
@@ -98,7 +98,7 @@ Scenario: Test "Then I don’t continue" with an apostrophe
|
|
|
98
98
|
Then I don’t continue
|
|
99
99
|
And I will be told an answer is invalid
|
|
100
100
|
|
|
101
|
-
@fast @o9 @table
|
|
101
|
+
@fast @o9 @table @json
|
|
102
102
|
Scenario: I can match JSON page var to str
|
|
103
103
|
Given I start the interview at "all_tests.yml"
|
|
104
104
|
And I get to "showifs" with this data:
|
|
@@ -123,7 +123,7 @@ Scenario: I get the page's JSON
|
|
|
123
123
|
Given I start the interview at "all_tests"
|
|
124
124
|
Then I get the page's JSON variables and values
|
|
125
125
|
|
|
126
|
-
@fast @o11
|
|
126
|
+
@fast @o11 @screenshot
|
|
127
127
|
Scenario: I take a screenshot
|
|
128
128
|
Given I start the interview at "all_tests"
|
|
129
129
|
Then I take a screenshot
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
@random_input
|
|
2
|
+
Feature: Assembly Line package-specific Steps
|
|
3
|
+
|
|
4
|
+
# In tag names, 'ri' is for 'random input'
|
|
5
|
+
|
|
6
|
+
@slow @ri1 @random
|
|
7
|
+
Scenario: I fill in random input till the end
|
|
8
|
+
Given I start the interview at "test_random_input"
|
|
9
|
+
And I answer randomly for at most 20 pages
|
|
10
|
+
Then the question id should be "end"
|
|
11
|
+
|
|
12
|
+
@slow @ri2 @random
|
|
13
|
+
Scenario: I fill in random input for 1 page
|
|
14
|
+
Given I start the interview at "test_random_input"
|
|
15
|
+
And I answer randomly for at most 1 page
|
|
@@ -68,6 +68,7 @@ Covers story table tests for:
|
|
|
68
68
|
| signature_1 | | |
|
|
69
69
|
| signature_2 | | |
|
|
70
70
|
| single_quote_dict['single_quote_key']['sq_two'] | true | |
|
|
71
|
+
| single_dropdown_field | email | |
|
|
71
72
|
| x[i].name.first | Proxyname1 | proxy_list[0].name.first |
|
|
72
73
|
| x[i].name.first | Proxyname2 | proxy_list[1].name.first |
|
|
73
74
|
| x.target_number | 2 | proxy_list.target_number |
|
|
@@ -6,14 +6,11 @@ const scope = require(`../../lib/scope.js`);
|
|
|
6
6
|
const getSafeScenarioBaseFilename = scope.getSafeScenarioBaseFilename;
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
let mock_scenario = function ( description
|
|
9
|
+
let mock_scenario = function ( description ) {
|
|
10
10
|
/** Mock the complex structure of a Scenario object */
|
|
11
11
|
let scenario = {
|
|
12
|
-
pickle: { name: description
|
|
12
|
+
pickle: { name: description }
|
|
13
13
|
};
|
|
14
|
-
for ( let tag of tag_names ) {
|
|
15
|
-
scenario.pickle.tags.push({ name: tag });
|
|
16
|
-
}
|
|
17
14
|
return scenario;
|
|
18
15
|
}; // Ends mock_scenario();
|
|
19
16
|
|
|
@@ -23,39 +20,31 @@ describe(`When I use scope.getSafeScenarioBaseFilename()`, function() {
|
|
|
23
20
|
scope.language = undefined;
|
|
24
21
|
});
|
|
25
22
|
|
|
26
|
-
// No language
|
|
23
|
+
// No language
|
|
27
24
|
it(`preserves spaces`, async function() {
|
|
28
|
-
let scenario = mock_scenario( names.with_spaces
|
|
25
|
+
let scenario = mock_scenario( names.with_spaces );
|
|
29
26
|
let result = await getSafeScenarioBaseFilename( scope, { scenario });
|
|
30
27
|
expect( result ).to.equal( names.with_spaces );
|
|
31
28
|
});
|
|
32
29
|
|
|
33
30
|
it(`preserves non-english characters`, async function() {
|
|
34
|
-
let scenario = mock_scenario( names.non_english_chars
|
|
31
|
+
let scenario = mock_scenario( names.non_english_chars );
|
|
35
32
|
let result = await getSafeScenarioBaseFilename( scope, { scenario });
|
|
36
33
|
expect( result ).to.equal( names.non_english_chars );
|
|
37
34
|
});
|
|
38
35
|
|
|
39
36
|
it(`replaces invalid characters with "_"`, async function() {
|
|
40
|
-
let scenario = mock_scenario( names.colon_input
|
|
37
|
+
let scenario = mock_scenario( names.colon_input );
|
|
41
38
|
let result = await getSafeScenarioBaseFilename( scope, { scenario });
|
|
42
39
|
expect( result ).to.equal( names.colon_output );
|
|
43
40
|
});
|
|
44
41
|
|
|
45
|
-
// language
|
|
46
|
-
it(`adds a language
|
|
42
|
+
// language
|
|
43
|
+
it(`adds a language correctly to a description`, async function() {
|
|
47
44
|
scope.language = names.non_english_chars;
|
|
48
|
-
let scenario = mock_scenario( names.with_spaces
|
|
45
|
+
let scenario = mock_scenario( names.with_spaces );
|
|
49
46
|
let result = await getSafeScenarioBaseFilename( scope, { scenario });
|
|
50
|
-
let expected = `${ names.non_english_chars }-${ names.with_spaces }
|
|
51
|
-
expect( result ).to.equal( expected );
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
// 2 tags
|
|
55
|
-
it(`adds 2 tags correctly, preserving numbers`, async function() {
|
|
56
|
-
let scenario = mock_scenario( names.with_spaces, [ names.tag1, names.tag2 ] );
|
|
57
|
-
let result = await getSafeScenarioBaseFilename( scope, { scenario });
|
|
58
|
-
let expected = `${ names.with_spaces }-${ names.tag1 }-${ names.tag2 }`;
|
|
47
|
+
let expected = `${ names.non_english_chars }-${ names.with_spaces }`;
|
|
59
48
|
expect( result ).to.equal( expected );
|
|
60
49
|
});
|
|
61
50
|
|
|
@@ -8,9 +8,12 @@
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
let test_filename = function ( expected_prefix, result ) {
|
|
11
|
-
|
|
12
|
-
let expected_name_regex_str = `^${ expected_prefix }
|
|
13
|
-
|
|
11
|
+
/* Test a name to see if it's valid output with a language defined. */
|
|
12
|
+
let expected_name_regex_str = `^${ expected_prefix }-${ names.base_filename }-\.{37}$`;
|
|
13
|
+
if ( expected_prefix == `` ) {
|
|
14
|
+
expected_name_regex_str = `^${ names.base_filename }-\.{37}$`;
|
|
15
|
+
}
|
|
16
|
+
let regex = new RegExp( expected_name_regex_str );
|
|
14
17
|
|
|
15
18
|
// Log more info if it failed
|
|
16
19
|
let found_match = regex.test( result );
|