@suffolklitlab/alkiln 5.13.4 → 5.14.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.
@@ -250,21 +250,23 @@ reports.getPrintableScenario = function( scenario ) {
250
250
  return report;
251
251
  }; // Ends reports.getPrintableScenario()
252
252
 
253
- let getLineText = function ({ type=`no type`, code=`ALK00rl`, value=`` }) {
253
+ let getLineText = function ({ from_log, type=`no type`, code=`ALK00rl`, value=`` }) {
254
254
  let start = ``;
255
255
  if ( type.includes(`page_id`) ) { start += `screen id: `; }
256
256
  else if ( type.includes(`outcome`) ) { start += `\n`; } // extra new line
257
- else if ( type.includes(`warning`) ) { start += `šŸ”Ž ${ code } WARNING: `; }
258
- else if ( type.includes(`error`) ) { start += `\nšŸ¤• ${ code } ERROR: `; } // extra new line
257
+ else if ( type.includes(`warning`) && !from_log ) { start += `šŸ”Ž ${ code } WARNING: `; }
258
+ else if ( type.includes(`error`) && !from_log ) { start += `\nšŸ¤• ${ code } ERROR: `; } // extra new line
259
259
  return `${ start }${ value }`;
260
260
  }; // Ends getLine()
261
261
 
262
- let getDebugLine = function ({ type=``, code=`ALK00rd`, value=`` }) {
263
- /** In debug log lines, include all the information possible. */
262
+ let getDebugLine = function ({ from_log, type=``, code=`ALK00rd`, value=`` }) {
263
+ /** In lines for the debug file, include all the information possible. */
264
264
 
265
265
  // `plain` is usually used for visual clarity and shouldn't have
266
266
  // codes and such associated with it. Return right away.
267
267
  if ( type.includes(`plain`) ) { return value; }
268
+ // Discuss: How to prevent saving in the debug log twice
269
+ if ( from_log ) { return value; }
268
270
 
269
271
  let start = ``;
270
272
 
@@ -291,7 +293,7 @@ let getDebugLine = function ({ type=``, code=`ALK00rd`, value=`` }) {
291
293
  if ( type.includes(`warning`) ) { description_parts.push( `WARNING` ); }
292
294
  if ( type.includes(`error`) ) { description_parts.push( `ERROR` ); }
293
295
  // Default
294
- if ( description_parts.length <= 0 ) { description_parts.push( `UNKNOWN` ); }
296
+ if ( description_parts.length <= 0 ) { description_parts.push( `UNKNOWN LOG TYPE` ); }
295
297
 
296
298
  start = [ start, ...description_parts ].join(` `);
297
299
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suffolklitlab/alkiln",
3
- "version": "5.13.4",
3
+ "version": "5.14.0",
4
4
  "description": "Integrated automated end-to-end testing with docassemble, puppeteer, and cucumber.",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -0,0 +1,78 @@
1
+ const chai = require(`chai`);
2
+
3
+ describe('chaijs before hooks', function () {
4
+ console.log(1);
5
+ before(() => console.log('--top-level before()'));
6
+ console.log(2);
7
+ beforeEach(() => console.log('--top-level beforeEach()'));
8
+ console.log(3);
9
+ describe('nesting 1', function () {
10
+ console.log(4);
11
+ before(() => console.log('--1. nested before()'));
12
+ console.log(5);
13
+ beforeEach(() => console.log('--1. nested beforeEach()'));
14
+ console.log(6);
15
+ it('is 1st nested spec', () => { console.log(7); return true; });
16
+ console.log(8);
17
+ it('is 2nd nested spec', () => { console.log(9); return true; });
18
+ console.log(10);
19
+ });
20
+ console.log(11);
21
+ describe('nesting 2', function () {
22
+ console.log(12);
23
+ before(() => console.log('--2. nested before()'));
24
+ console.log(13);
25
+ beforeEach(() => console.log('--2. nested beforeEach()'));
26
+ console.log(14);
27
+ it('is 1st nested spec', () => { console.log(15); return true; });
28
+ console.log(16);
29
+ it('is 2nd nested spec', () => { console.log(17); return true; });
30
+ console.log(18);
31
+ });
32
+ console.log(19);
33
+ });
34
+
35
+ /** Result:
36
+ 1
37
+ 2
38
+ 3
39
+ 4
40
+ 5
41
+ 6
42
+ 8
43
+ 10
44
+ 11
45
+ 12
46
+ 13
47
+ 14
48
+ 16
49
+ 18
50
+ 19
51
+
52
+
53
+ chaijs before hooks
54
+ --top-level before()
55
+ nesting 1
56
+ --1. nested before()
57
+ --top-level beforeEach()
58
+ --1. nested beforeEach()
59
+ 7
60
+ āœ“ is 1st nested spec
61
+ --top-level beforeEach()
62
+ --1. nested beforeEach()
63
+ 9
64
+ āœ“ is 2nd nested spec
65
+ nesting 2
66
+ --2. nested before()
67
+ --top-level beforeEach()
68
+ --2. nested beforeEach()
69
+ 15
70
+ āœ“ is 1st nested spec
71
+ --top-level beforeEach()
72
+ --2. nested beforeEach()
73
+ 17
74
+ āœ“ is 2nd nested spec
75
+
76
+
77
+ 4 passing (6ms)
78
+ * */
@@ -1,11 +0,0 @@
1
- Pros for separate action:
2
-
3
- - Reflects nature of process - generating files is inherently separate.
4
- - Potentially cleaner separation conceptually for us.
5
-
6
- Cons:
7
-
8
- - Main beef: Developing and maintaining GitHub actions is hard
9
- - Authors have more in their workflow file
10
- - Need to update existing workflows
11
- - Need to update ALKilnSetup interview
package/lib/parse.js DELETED
@@ -1,36 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- let log = `log`;
4
- let args = get_command_line_args();
5
- let sources_paths = get_sources_paths( args );
6
- let feature_files_paths = get_feature_files( sources_paths );
7
-
8
- let all_errors = [];
9
- // Just see if any error when Gherkin parses them
10
- for ( let file_path of feature_files_paths ) {
11
- try {
12
- Gherkin.parse( file_path );
13
- } catch ( error ) {
14
- all_errors.push( error );
15
- }
16
- }
17
- // let generated_files_paths = constrained_random_answer_tests.generate();
18
- // // Just see if any error when Gherkin parses them
19
- // for ( let generated_path of generated_files_paths ) {
20
- // try {
21
- // Gherkin.parse( generated_path );
22
- // } catch ( error ) {
23
- // all_errors.push( error );
24
- // }
25
- // }
26
-
27
- let generator_errors = constrained_random_answer_tests.generate();
28
- all_errors = [ ...all_errors, ...generator_errors ];
29
-
30
- if ( all_errors.length > 0 ) {
31
- // Use the Log class in here
32
- for ( let one_error of all_errors ) {
33
- console.log( `An error:`, one_error );
34
- }
35
- throw new Error( `ALKiln ran into an error when parsing the test files. See above for more details` );
36
- }
@@ -1,162 +0,0 @@
1
- /**
2
- fast_glob (fast glob)
3
-
4
- files
5
- session_vars
6
- */
7
-
8
-
9
- // let log = null;
10
-
11
- // function set_log ( artifacts_path ) {
12
- // log = Log( artifacts_path );
13
- // }
14
-
15
- // TODO: Remove after merging Log class PR
16
- let artifacts_path = files.make_artifacts_folder();
17
- session_vars.save_artifacts_path_name( artifacts_path );
18
-
19
-
20
- function proccess_command_line_args({ log }) {
21
-
22
- // Discuss: Wouldn't have to use log if we moved this up.
23
- const environment = { cwd: process.cwd() };
24
- log.info({ type: `run`, code: `ALK0049`, pre: `environment`, data: environment });
25
-
26
- // We'll use the user info to construct the possible paths to /sources
27
- let id = session_vars.get_user_id();
28
- // `project` is the name in the server docassemble "Project" page
29
- let project = session_vars.get_user_project_name();
30
-
31
- // process.argv is a list of strings of commands and args.
32
- // Internal note: If using `npm run cucumber`, use `--` before
33
- // `--sources=./foo`
34
- let command_line_args = require(`minimist`)( process.argv.slice(2), {
35
- default: {
36
- sources: [
37
- `./docassemble/*/data/sources`, // In GitHub folder
38
- `/usr/share/docassemble/files/playgroundsources/${id}/${project}/*.feature`, // From playground without S3
39
- `/tmp/playgroundsources/${id}/${project}/*.feature` // From playground with S3
40
- ],
41
- }
42
- });
43
-
44
- let processed = {};
45
- processed.sources = get_sources_paths({ command_line_args });
46
- let tags = get_tags({ command_line_args });
47
-
48
- return command_line_args;
49
- }
50
-
51
-
52
- function get_sources_paths({ command_line_args }) {
53
-
54
- // Make sure `sources` is always a list
55
- let sources_list = command_line_args.sources;
56
- if ( typeof command_line_args.sources === `string` ) {
57
- sources_list = [ command_line_args.sources ];
58
- }
59
-
60
- // Check every path, tracking which exist and which are missing
61
- let existing_paths = [];
62
- let missing_paths = [];
63
- for ( let path of paths ) {
64
- let dirs = fast_glob.sync(
65
- [ path ],
66
- { onlyFiles: false, suppressErrors: true }
67
- );
68
-
69
- if ( dirs.length > 0 ) {
70
- existing_paths.push( ...dirs );
71
- } else {
72
- missing_paths.push( path );
73
- }
74
- }
75
-
76
- // If no paths were valid
77
- if ( existing_paths.length <= 0 ) {
78
- // session_vars.set_sources_paths( null );
79
-
80
- // Discuss: Wouldn't have to use log if we moved this up.
81
- // If we don't throw, it'll be more confusing when no tests run
82
- let msg = `ALKiln can't find your "sources" folder(s). See above for details.`;
83
- let code = `ALK0050`
84
- log.error({ type: `run`, code: code, pre: msg });
85
- // pass error up instead?
86
- throw new ReferenceError(`šŸ¤• ${ code } run ERROR: ${ msg }`);
87
- }
88
-
89
- // TODO: move this out a level
90
- console.info(
91
- `lightbulb ALK0042 INFO: Did find "sources" file(s) at "${ existing_paths.join('", "') }".`
92
- )
93
-
94
- // session_vars.set_sources_paths( existing_paths );
95
- return existing_paths;
96
- }
97
-
98
-
99
- function get_tags({ command_line_args }) {
100
- // Normalize tag expressions, if there are any Joining and splitting handles
101
- // both tags surrounded with `""` or those without `""`
102
- let tags = command_line_args[`_`].join(` `).split(` `);
103
- // If there was no tag expression, `tags` is ['']. Remove that item.
104
- tags = tags.filter(function(entry) { return entry !== ""; })
105
- if ( tags.length > 0 ) {
106
- let joined_tags = '';
107
- // Cucumber expects tags in boolean expressions, like (@a0 or @a1) and
108
- // @random. If we get a list of only tags, then "or" them all together
109
- if (tags.every((val) => val.startsWith(`@`))) {
110
- joined_tags = tags.join(` or `);
111
- }
112
- // If we get a list of seemingly no tags, assume they meant to use tags
113
- else if (tags.every((val) => !val.startsWith(`@`))) {
114
- joined_tags = tags.map((val) => `@` + val).join(` or `);
115
- }
116
- // If it's a mix of tags and no tags, it's probably a boolean expression!
117
- else {
118
- joined_tags = tags.join(` `);
119
- }
120
-
121
- // config.tags = joined_tags;
122
- return joined_tags;
123
- }
124
-
125
- return null;
126
- }
127
-
128
-
129
- /**
130
- * get sources paths
131
- * generate feature files
132
- * try to parse everything
133
- * pass on the feature files?
134
- *
135
- * When running run_cucumber, pass whether files have yet been parsed
136
- * Alternatively, have 2 setup steps? The second one parses before run_cucumber
137
- * That seems maybe better...? Have to pass on the feature files somehow, though
138
- *
139
- * setup_server_stuff
140
- * get_feature_files
141
- * run_cucumber(with files list somehow... runtime_config?)
142
- * */
143
-
144
- function get_feature_paths() {
145
- // Turn all the paths to the sources folders into paths to the feature files
146
- let sources_paths = session_vars.get_sources_paths();
147
- let feature_paths = [];
148
-
149
- // Get all the paths for the right feature files (for cucumber to use)
150
- for ( let sources_path of sources_paths ) {
151
- const generators_prefix = `alkiln_random`;
152
- constrained_random_tests.create({ generators_prefix, sources_path });
153
- // Ignore feature files that we parsed ourselves
154
- let glob = fast_glob.sync(
155
- `${ sources_path }/**/*.feature`,
156
- { ignore: [`${ sources_path }/${ generators_prefix }*.feature`] }
157
- );
158
- feature_paths.push( ...glob );
159
- }
160
- }
161
-
162
-
@@ -1 +0,0 @@
1
- parse.js
@@ -1,267 +0,0 @@
1
- /**
2
- * before everything else
3
- * error if there are generator errors
4
- *
5
- * problem:
6
- *
7
- * because of the 3 (4) env of ALKiln, have to be able to generate and error in
8
- * 2 places: run_cucumber, at the start of the GitHub action
9
- *
10
- * If there's an error, no problem (nothing will run twice)
11
- *
12
- * Otherwise (success, warnings, etc.), generation/parsing will be run 2x. Do we
13
- * care?
14
- *
15
- * Note that generation cleans out its folder before generating.
16
- *
17
- * Warnings are the problem if we log them at the top (not if we log them along
18
- * with the other test errors/warnings).
19
- *
20
- * Error:
21
- * Action: Errors, nothing else is run
22
- * Local/Playground: Errors, nothing else is run
23
- * TODO: Need to generate error files?
24
- *
25
- * Success:
26
- * Action: Generate twice
27
- * Local/Playground: Generate once
28
- *
29
- * Warnings (same warnings):
30
- * Action: Generate, warn?, generate, warn?, warn at end of test run
31
- * Do we need a "dry run" env var?
32
- * Local/Playground: Generate, warn, warn at end of test run
33
- *
34
- * Maybe run_cucumber needs an idea of whether it's running as the first
35
- * operation or as a follow-up
36
- * `is_followup` (general state of affairs)
37
- * `don't_generate` (a command of a specific action to take)
38
- * previous_steps = [`pre_parse`, `server_setup`/`github_playground_setup`]
39
- *
40
- * Maybe do this completely separately and call it in different places in
41
- * different processes.
42
- *
43
- *
44
- * action needs:
45
- * pre-setup needs:
46
- * `generate` which needs:
47
- * (really??) trigger_any_parsing_errors which needs:
48
- * feature files list/glob which needs:
49
- * sources paths which needs
50
- * command line args
51
- * and
52
- * prints environment PROBLEM TO REPEAT
53
- * potentially errors
54
- * and
55
- * potentially errors
56
- *
57
- * run_cucumber needs
58
- * pre-setup
59
- * (maybe) generate which needs:
60
- * (maybe) trigger_any_parsing_errors etc.
61
- * (maybe) trigger_any_parsing_errors which needs:
62
- * feature files, etc.
63
- *
64
- * feature files list/glob which needs:
65
- * sources paths which needs
66
- * command line args
67
- * and
68
- * prints environment PROBLEM TO REPEAT
69
- * potentially errors (not a problem. won't run if the other errors)
70
- * tags needs
71
- * command line args
72
- *
73
- * ## Problem 1 - printing environment in 2 places
74
- * Fix: Move print environment into run_cucumber
75
- *
76
- * ====
77
- *
78
- * ## Problem 2 - parsing in both places.
79
- * Parsing errors will prevent duplicate parsing.
80
- * What about when there are no errors?
81
- * Fix: I guess we can check for parsing errors again without harm, though it'll
82
- * take an extra second. Errors will only be parsed once because they'll
83
- * prevent execution.
84
- *
85
- * ## Problem 3 - generating in both places
86
- * Fix: flag? Or maybe re-generating isn't a problem if it doesn't take too long
87
- *
88
- * ## Problem 4
89
- * Parse before generating or after generating?
90
- * - Can generating create files that have parsing errors without already
91
- * having parsing errors? If so, parse before.
92
- * - Generating can create its own errors, though. So generate before?
93
- * - Also, errors for generated tests may be confusing because author may think,
94
- * "I didn't write those tests."
95
- * Maybe:
96
- * 1. test all files before generating
97
- * 2. generate (and pass back errors or just throw?)
98
- * 3. test generated files and throw just generator process errors and parsing
99
- * errors
100
- *
101
- * All:
102
- * 0. Get command line args
103
- * 1. Get sources
104
- * 2. Get feature files
105
- * 3. Parse all current (can throw) (accumulated errors?)
106
- * 4. Generate (with possible errors) (can throw accumulated errors)
107
- * 5. Parse generated (can throw)
108
- * Should those throw all together? Probably not. They can affect each other.
109
- *
110
- * run_cucumber also independently needs:
111
- * 1. sources
112
- * 2. feature files
113
- * */
114
-
115
- /**
116
- * get sources paths
117
- * generate feature files
118
- * try to parse everything
119
- * pass on the feature files?
120
- *
121
- * When running run_cucumber, pass whether files have yet been parsed
122
- * Alternatively, have 2 setup steps? The second one parses before run_cucumber
123
- * That seems maybe better...? Have to pass on the feature files somehow, though
124
- *
125
- * setup_server_stuff
126
- * get_feature_files
127
- * run_cucumber(with files list somehow... runtime_config?)
128
- * */
129
-
130
- /**
131
- fast_glob (fast glob)
132
-
133
- files
134
- session_vars
135
- */
136
-
137
- // let log = null;
138
-
139
- // function set_log ( artifacts_path ) {
140
- // log = Log( artifacts_path );
141
- // }
142
-
143
- // TODO: Remove after merging Log class PR
144
- let artifacts_path = files.make_artifacts_folder();
145
- session_vars.save_artifacts_path_name( artifacts_path );
146
-
147
- function get_command_line_args({ log }) {
148
-
149
- // We'll use the user info to construct the possible paths to /sources
150
- let id = session_vars.get_user_id();
151
- // `project` is the name in the author's server's docassemble "Project" page
152
- let project = session_vars.get_user_project_name();
153
-
154
- // process.argv is a list of strings of commands and args.
155
- // Internal note: If using `npm run cucumber`, use `--` before
156
- // `--sources=./foo`
157
- let command_line_args = require(`minimist`)( process.argv.slice(2), {
158
- default: {
159
- sources: [
160
- `./docassemble/*/data/sources`, // In GitHub folder
161
- `/usr/share/docassemble/files/playgroundsources/${id}/${project}/*.feature`, // From playground without S3
162
- `/tmp/playgroundsources/${id}/${project}/*.feature` // From playground with S3
163
- ],
164
- }
165
- });
166
-
167
- // let processed = {};
168
- // processed.sources = get_sources_paths({ command_line_args });
169
- // let tags = get_tags({ command_line_args });
170
-
171
- return command_line_args;
172
- }
173
-
174
-
175
- function get_sources_paths({ command_line_args }) {
176
-
177
- // Make sure `sources` is always a list
178
- let sources_list = command_line_args.sources;
179
- if ( typeof command_line_args.sources === `string` ) {
180
- sources_list = [ command_line_args.sources ];
181
- }
182
-
183
- // Check every path, tracking which exist and which are missing
184
- let existing_paths = [];
185
- let missing_paths = [];
186
- for ( let path of paths ) {
187
- let dirs = fast_glob.sync(
188
- [ path ],
189
- { onlyFiles: false, suppressErrors: true }
190
- );
191
-
192
- if ( dirs.length > 0 ) {
193
- existing_paths.push( ...dirs );
194
- } else {
195
- missing_paths.push( path );
196
- }
197
- }
198
-
199
- // If no paths were valid
200
- if ( existing_paths.length <= 0 ) {
201
- // session_vars.set_sources_paths( null );
202
-
203
- // Discuss: Wouldn't have to use log if we moved this up.
204
- // If we don't throw, it'll be more confusing when no tests run
205
- let msg = `ALKiln can't find your "sources" folder(s). See above for details.`;
206
- let code = `ALK0050`
207
- log.error({ type: `run`, code: code, pre: msg });
208
- // pass error up instead?
209
- throw new ReferenceError(`šŸ¤• ${ code } run ERROR: ${ msg }`);
210
- }
211
-
212
- // TODO: move this out a level
213
- console.info(
214
- `lightbulb ALK0042 INFO: Did find "sources" file(s) at "${ existing_paths.join('", "') }".`
215
- )
216
-
217
- // session_vars.set_sources_paths( existing_paths );
218
- return existing_paths;
219
- }
220
-
221
-
222
- function get_tags({ command_line_args }) {
223
- // Normalize tag expressions, if there are any Joining and splitting handles
224
- // both tags surrounded with `""` or those without `""`
225
- let tags = command_line_args[`_`].join(` `).split(` `);
226
- // If there was no tag expression, `tags` is ['']. Remove that item.
227
- tags = tags.filter(function(entry) { return entry !== ""; })
228
- if ( tags.length > 0 ) {
229
- let joined_tags = '';
230
- // Cucumber expects tags in boolean expressions, like (@a0 or @a1) and
231
- // @random. If we get a list of only tags, then "or" them all together
232
- if (tags.every((val) => val.startsWith(`@`))) {
233
- joined_tags = tags.join(` or `);
234
- }
235
- // If we get a list of seemingly no tags, assume they meant to use tags
236
- else if (tags.every((val) => !val.startsWith(`@`))) {
237
- joined_tags = tags.map((val) => `@` + val).join(` or `);
238
- }
239
- // If it's a mix of tags and no tags, it's probably a boolean expression!
240
- else {
241
- joined_tags = tags.join(` `);
242
- }
243
-
244
- // config.tags = joined_tags;
245
- return joined_tags;
246
- }
247
-
248
- return null;
249
- }
250
-
251
- function get_feature_paths() {
252
- // Turn all the paths to the sources folders into paths to the feature files
253
- let sources_paths = session_vars.get_sources_paths();
254
- let feature_paths = [];
255
-
256
- // Get all the paths for the right feature files (for cucumber to use)
257
- for ( let sources_path of sources_paths ) {
258
- const generators_prefix = `alkiln_random`;
259
- constrained_random_tests.create({ generators_prefix, sources_path });
260
- // Ignore feature files that we parsed ourselves
261
- let glob = fast_glob.sync(
262
- `${ sources_path }/**/*.feature`,
263
- { ignore: [`${ sources_path }/${ generators_prefix }*.feature`] }
264
- );
265
- feature_paths.push( ...glob );
266
- }
267
- }