@suffolklitlab/alkiln 5.13.4 → 5.15.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.
Files changed (44) hide show
  1. package/.github/workflows/github_server.yml +1 -1
  2. package/.github/workflows/playground.yml +2 -1
  3. package/.github/workflows/unit_tests.yml +1 -1
  4. package/CHANGELOG.md +40 -0
  5. package/action.yml +26 -10
  6. package/action_for_github_server/action.yml +31 -27
  7. package/docs/4_environments.md +2 -2
  8. package/docs/artifacts_folder_name.md +121 -71
  9. package/docs/constrained_random_tests.md +220 -289
  10. package/docs/decisions/move_runtime_config_to_sources_folder.md +3 -1
  11. package/docs/prioritize_constrained_random_tests.md +35 -76
  12. package/lib/docassemble/server_install.js +0 -2
  13. package/lib/docassemble/setup.js +1 -3
  14. package/lib/docassemble/takedown.js +2 -2
  15. package/lib/globals.js +10 -0
  16. package/lib/run_cucumber.js +40 -53
  17. package/lib/scope.js +44 -1
  18. package/lib/setup/TestGenerator.js +1757 -0
  19. package/lib/setup/artifacts.js +20 -0
  20. package/lib/setup/generate.js +42 -0
  21. package/lib/setup/get_Gherkin_AST.js +26 -0
  22. package/lib/setup/validate.js +89 -0
  23. package/lib/steps.js +101 -42
  24. package/lib/utils/Log.js +317 -165
  25. package/lib/utils/_alkiln-constrained_random_tests_old.js +1776 -0
  26. package/lib/utils/get_error_stacks.js +16 -0
  27. package/lib/utils/reports.js +44 -22
  28. package/lib/utils/session_vars.js +77 -57
  29. package/lib/utils/set_sources_paths.js +98 -0
  30. package/package.json +18 -7
  31. package/tests/log_codes/check_codes.sh +17 -13
  32. package/tests/log_codes/log_code_expected_instances.txt +58 -0
  33. package/tests/unit_tests/constrained_random_answers/invalid.fixtures.js +178 -0
  34. package/tests/unit_tests/constrained_random_answers/invalid.test.js +251 -0
  35. package/tests/unit_tests/constrained_random_answers/valid.fixtures.js +957 -0
  36. package/tests/unit_tests/constrained_random_answers/valid.test.js +563 -0
  37. package/tests/unit_tests/example_of_chai_test_lifecycle.js +78 -0
  38. package/tests/unit_tests/log.test.js +17 -41
  39. package/docs/seprate_file_generation_GitHub_action.md +0 -11
  40. package/lib/parse.js +0 -36
  41. package/lib/utils/get_sources_paths.js +0 -162
  42. package/lib/utils/parse.js +0 -1
  43. package/lib/utils/proccess_command_line_args.js +0 -267
  44. /package/docs/{expected_inernal_results.md → expected_internal_results.md} +0 -0
@@ -0,0 +1,178 @@
1
+ /** Actual and expected values for INvalid constrained random answer tests. */
2
+
3
+ module.exports = fixts = {};
4
+
5
+ /** Research notes
6
+ *
7
+ * Valid: A feature is valid without a description
8
+ * Valid: A scenario is valid without a description
9
+ *
10
+ * TODO
11
+ * Research: Can we get back null or undefined without syntax errors? (unlikely)
12
+ * Research: Can a feature.children item exist without having a `.scenario`
13
+ * prop? (unlikely)
14
+ * */
15
+
16
+ fixts.generator_missing_Feature = {};
17
+ fixts.generator_missing_Feature.arg = `Scenario: Invalid feature file`;
18
+ fixts.generator_missing_Feature.expected = null;
19
+ fixts.generator_missing_Feature.error_codes = [ `ALK0232` ];
20
+ fixts.generator_missing_Feature.log_codes = [ `ALK0232` ];
21
+
22
+ fixts.generator_missing_contents = {};
23
+ fixts.generator_missing_contents.arg = ``;
24
+ fixts.generator_missing_contents.expected = null;
25
+ fixts.generator_missing_contents.error_codes = [ `ALK0233` ];
26
+ fixts.generator_missing_contents.log_codes = [ `ALK0233` ];
27
+
28
+ fixts.generator_0_Scenarios = {};
29
+ fixts.generator_0_Scenarios.arg = `Feature: No scenarios`;
30
+ fixts.generator_0_Scenarios.expected = null;
31
+ fixts.generator_0_Scenarios.error_codes = [ `ALK0235` ];
32
+ fixts.generator_0_Scenarios.log_codes = [ `ALK0235` ];
33
+
34
+
35
+ /**
36
+ * Missing fore_Step keywords
37
+ * Missing constraints Step keywords
38
+ * */
39
+
40
+ fixts.missing_fore_Step_keywords = {};
41
+ fixts.missing_fore_Step_keywords.arg =
42
+ `Feature: I generate constrained random tests
43
+
44
+ Scenario: I fail with missing keywords for a fore Step
45
+ Given ALKiln makes 2
46
+ Given the final Scenario status should be "failed"
47
+ Given I start the interview at "test_kickout"
48
+ And ALKiln tests get to "end" with:
49
+ | var | possible_values |
50
+ | user_choice | correct;; wrong |
51
+ `;
52
+ fixts.missing_fore_Step_keywords.expected = null;
53
+ fixts.missing_fore_Step_keywords.error_codes = [ `ALK0242`, `ALK0263` ];
54
+ fixts.missing_fore_Step_keywords.log_codes = [
55
+ `ALK0237`,
56
+ `ALK0242`,
57
+ `ALK0263`,
58
+ ];
59
+
60
+
61
+ fixts.missing_constraints_Step_keywords = {};
62
+ fixts.missing_constraints_Step_keywords.arg =
63
+ `Feature: I generate constrained random tests
64
+
65
+ Scenario: I fail with missing keywords for a constraints Step
66
+ Given ALKiln makes 2 constrained random answers tests
67
+ Given the final Scenario status should be "failed"
68
+ Given I start the interview at "test_kickout"
69
+ And tests get to "end" with:
70
+ | var | possible_values |
71
+ | user_choice | correct;; wrong |
72
+ `;
73
+ fixts.missing_constraints_Step_keywords.expected = null;
74
+ fixts.missing_constraints_Step_keywords.error_codes = [ `ALK0256`, `ALK0263` ];
75
+ fixts.missing_constraints_Step_keywords.log_codes = [
76
+ `ALK0237`, `ALK0243`, `ALK0244`,
77
+ `ALK0245`, `ALK0248`, `ALK0249`,
78
+ `ALK0256`,
79
+ `ALK0263`,
80
+ ];
81
+
82
+
83
+ fixts.missing_table = {};
84
+ fixts.missing_table.arg =
85
+ `Feature: I generate constrained random tests
86
+
87
+ Scenario: I fail with the first missing table
88
+ Given ALKiln makes 2 constrained random answers tests
89
+ Given the final Scenario status should be "failed"
90
+ Given I start the interview at "test_kickout"
91
+ And ALKiln tests get to "end" with:
92
+ And ALKiln tests get to "end" with:
93
+ `;
94
+ // ======= ENDS ARG ======= //
95
+ fixts.missing_table.expected = null;
96
+ fixts.missing_table.error_codes = [ `ALK0251`, `ALK0263` ];
97
+ fixts.missing_table.log_codes = [
98
+ `ALK0237`, `ALK0243`, `ALK0244`,
99
+ `ALK0245`, `ALK0248`, `ALK0249`, `ALK0246`,
100
+ `ALK0251`,
101
+ `ALK0263`,
102
+ ];
103
+
104
+
105
+ fixts.missing_ids = {};
106
+ fixts.missing_ids.arg =
107
+ `Feature: I generate constrained random tests
108
+
109
+ Scenario: I fail with missing quoted ids in constrained random answers
110
+ Given ALKiln makes 2 constrained random answers tests
111
+ Given the final Scenario status should be "failed"
112
+ Given I start the interview at "test_kickout"
113
+ And ALKiln will get to end with:
114
+ | var | possible_values |
115
+ | user_choice | correct;; wrong |
116
+ `;
117
+ // ======= ENDS ARG ======= //
118
+ fixts.missing_ids.expected = null;
119
+ fixts.missing_ids.error_codes = [ `ALK0250`, `ALK0263` ];
120
+ fixts.missing_ids.log_codes = [
121
+ `ALK0237`, `ALK0243`, `ALK0244`,
122
+ `ALK0245`, `ALK0248`, `ALK0249`, `ALK0246`,
123
+ `ALK0250`,
124
+ `ALK0263`,
125
+ ];
126
+
127
+
128
+ // A valid generator Scenario, but an erroring test when run in cucumber, so it
129
+ // will error here instead
130
+ fixts.only_row_is_header = {};
131
+ fixts.only_row_is_header.arg =
132
+ `Feature: I generate constrained random tests
133
+
134
+ Scenario: Non-table row after table header
135
+ Given ALKiln makes 2 constrained random answers tests
136
+ Given the final Scenario status should be "failed"
137
+ Given I start the interview at "test_kickout"
138
+ And ALKiln will get to "end" with:
139
+ | var | possible_values |
140
+ Then non-table line
141
+ | user_choice | correct;; wrong |
142
+ `;
143
+ fixts.only_row_is_header.expected = null;
144
+ fixts.only_row_is_header.error_codes = [`ALK0252`, `ALK0263`];
145
+ fixts.only_row_is_header.log_codes = [
146
+ `ALK0237`, `ALK0243`, `ALK0244`,
147
+ `ALK0245`, `ALK0248`, `ALK0249`, `ALK0246`,
148
+ `ALK0252`,
149
+ `ALK0263`,
150
+ ];
151
+
152
+ /**
153
+ * No test for a table interrupted in the middle of regular rows (the parser
154
+ * can't detect it)
155
+ * */
156
+
157
+
158
+ fixts.multiple_scenarios = {};
159
+ fixts.multiple_scenarios.arg =
160
+ `Feature: It is invalid to have multiple Scenarios in one generator file
161
+
162
+ Scenario: The first of 2 Scenarios
163
+ Given ALKiln makes 1 constrained random answers tests
164
+ Given I start the interview at "test_kickout"
165
+ And ALKiln will get to "end" with:
166
+ | var | possible_values |
167
+ | user_choice | correct;; wrong |
168
+
169
+ Scenario: The second of 2 Scenarios
170
+ Given ALKiln makes 1 constrained random answers tests
171
+ Given I start the interview at "test_kickout"
172
+ And ALKiln will get to "end" with:
173
+ | var | possible_values |
174
+ | user_choice | correct;; wrong |
175
+ `;
176
+ fixts.multiple_scenarios.expected = null;
177
+ fixts.multiple_scenarios.error_codes = [`ALK0236`];
178
+ fixts.multiple_scenarios.log_codes = [`ALK0236`];
@@ -0,0 +1,251 @@
1
+ const chai = require(`chai`);
2
+ const expect = chai.expect;
3
+
4
+ const TestGenerator = require(`../../../lib/setup/TestGenerator.js`);
5
+ const Log = require(`../../../lib/utils/Log.js`);
6
+ const fixtures = require(`./invalid.fixtures.js`);
7
+
8
+
9
+ function get_error_codes({ errors }) {
10
+ /** Returns a list of ALKiln ALK#### codes from Error stacks
11
+ *
12
+ * @param {object} obj - Named arguments
13
+ * @param {[Error]} obj.errors - List of Error instances
14
+ *
15
+ * @returns {[str]} - List of ALKiln log codes in the errors
16
+ * */
17
+ let codes = [];
18
+ for ( let error of errors ) {
19
+ let matches = error.stack.match(/ALK\d\d\d\d/gm);
20
+ if ( matches ) {
21
+ codes.push( ...matches );
22
+ }
23
+ }
24
+
25
+ return codes;
26
+ };
27
+
28
+
29
+ function get_log_codes({ logger }) {
30
+ /** Returns a list of ALKiln codes from arguments sent to a Log instance
31
+ *
32
+ * @params {object} obj - Named arguments
33
+ * @params {Log} obj.logger - An instance of Log
34
+ * @params {object} obj.logger.opts - Options passed to the Log instance
35
+ * @params {str} obj.logger.opts.code - ALK#### formatted log code
36
+ * @params {[str]} obj.logger.logs - Additional messages to be logged
37
+ *
38
+ * @returns {[str]} - List of ALKiln log codes in the collection of logs
39
+ * */
40
+ let codes = [];
41
+
42
+ for ( let record of logger.internal_log_records ) {
43
+ codes.push( record.opts.code );
44
+ }
45
+
46
+ return codes;
47
+ }
48
+
49
+ /** Variables that will change their values for each `it()` */
50
+ const logger = new Log({ context: `invalid generators unit tests` });
51
+ let fixture = null;
52
+ let new_contents = null;
53
+ let errors = null;
54
+ let actual = null;
55
+ function mutate_globals_with({ testing_vals }) {
56
+ /** Set up values for parsing, parse, record values. Mutates in-scope
57
+ * variables in a way that helps chaijs (mocha really) get the right
58
+ * values to the right places.
59
+ *
60
+ * @params {object} testing_vals - Arguments to pass to the function and
61
+ * expected values
62
+ *
63
+ * @returns {undefined}
64
+ * */
65
+ // Reset log codes
66
+ logger.clear_internal_log_records();
67
+
68
+ // Fresh namespace
69
+ let generator = new TestGenerator();
70
+ // Mutates `fixture`
71
+ fixture = testing_vals;
72
+ // Mutates `new_contents` and `error`
73
+ ({ new_contents, errors } = generator.parse_file({
74
+ file_text: fixture.arg,
75
+ generator_path: `used_in_warning_logs`,
76
+ logger
77
+ }) );
78
+ };
79
+
80
+ describe(`Constrained random answers parser,`, function () {
81
+
82
+ describe(`when given a missing Feature keyword`, function () {
83
+
84
+ before(function () { mutate_globals_with({ testing_vals: fixtures.generator_missing_Feature }); });
85
+
86
+ let outer = fixtures.generator_missing_Feature;
87
+
88
+ it(`returns \`null\` for contents value`, function () {
89
+ expect( new_contents ).to.equal( fixture.expected );
90
+ });
91
+ it(`has these exact error codes: ${ JSON.stringify( outer.error_codes )}`, function () {
92
+ expect( get_error_codes({ errors: errors }) )
93
+ .to.have.all.members( fixture.error_codes );
94
+ });
95
+ it(`has these exact _log_ codes: ${ JSON.stringify( outer.log_codes )}`, function () {
96
+ expect( get_log_codes({ logger }) ).to.have.all.members( fixture.log_codes );
97
+ });
98
+
99
+ });
100
+
101
+ describe(`when given an empty string`, function () {
102
+
103
+ before(function () { mutate_globals_with({ testing_vals: fixtures.generator_missing_contents }); });
104
+
105
+ let outer = fixtures.generator_missing_contents;
106
+
107
+ it(`returns \`null\` for contents value`, function () {
108
+ expect( new_contents ).to.equal( fixture.expected );
109
+ });
110
+ it(`has these exact error codes: ${ JSON.stringify( outer.error_codes )}`, function () {
111
+ expect( get_error_codes({ errors: errors }) )
112
+ .to.have.all.members( fixture.error_codes );
113
+ });
114
+ it(`has these exact _log_ codes: ${ JSON.stringify( outer.log_codes )}`, function () {
115
+ expect( get_log_codes({ logger }) ).to.have.all.members( fixture.log_codes );
116
+ });
117
+
118
+ });
119
+
120
+ describe(`when given generator text missing Scenarios`, function () {
121
+
122
+ before(function () { mutate_globals_with({ testing_vals: fixtures.generator_0_Scenarios }); });
123
+
124
+ let outer = fixtures.generator_0_Scenarios;
125
+
126
+ it(`returns \`null\` for contents value`, function () {
127
+ expect( new_contents ).to.equal( fixture.expected );
128
+ });
129
+ it(`has these exact error codes: ${ JSON.stringify( outer.error_codes )}`, function () {
130
+ expect( get_error_codes({ errors: errors }) )
131
+ .to.have.all.members( fixture.error_codes );
132
+ });
133
+ it(`has these exact _log_ codes: ${ JSON.stringify( outer.log_codes )}`, function () {
134
+ expect( get_log_codes({ logger }) ).to.have.all.members( fixture.log_codes );
135
+ });
136
+
137
+ });
138
+
139
+ describe(`when given an invalid generator Scenario`, function () {
140
+
141
+ describe(`where a num tests fore Step is missing keywords,`, function () {
142
+
143
+ before(function () { mutate_globals_with({ testing_vals: fixtures.missing_fore_Step_keywords }); });
144
+
145
+ let outer = fixtures.missing_fore_Step_keywords;
146
+
147
+ it(`returns \`null\` for contents value`, function () {
148
+ expect( new_contents ).to.equal( fixture.expected );
149
+ });
150
+ it(`has these exact error codes: ${ JSON.stringify( outer.error_codes )}`, function () {
151
+ expect( get_error_codes({ errors: errors }) ).to.have.all.members( fixture.error_codes );
152
+ });
153
+ it(`has these exact _log_ codes: ${ JSON.stringify( outer.log_codes )}`, function () {
154
+ expect( get_log_codes({ logger }) ).to.have.all.members( fixture.log_codes );
155
+ });
156
+
157
+ });
158
+
159
+ describe(`where a constraints Step is missing keywords,`, function () {
160
+
161
+ before(function () { mutate_globals_with({ testing_vals: fixtures.missing_constraints_Step_keywords }); });
162
+
163
+ let outer = fixtures.missing_constraints_Step_keywords;
164
+
165
+ it(`returns \`null\` for contents value`, function () {
166
+ expect( new_contents ).to.equal( fixture.expected );
167
+ });
168
+ it(`has these exact error codes: ${ JSON.stringify( outer.error_codes )}`, function () {
169
+ expect( get_error_codes({ errors: errors }) ).to.have.all.members( fixture.error_codes );
170
+ });
171
+ it(`has these exact _log_ codes: ${ JSON.stringify( outer.log_codes )}`, function () {
172
+ expect( get_log_codes({ logger }) ).to.have.all.members( fixture.log_codes );
173
+ });
174
+
175
+ });
176
+
177
+ describe(`that is missing a table,`, function () {
178
+
179
+ before(function () { mutate_globals_with({ testing_vals: fixtures.missing_table }); });
180
+
181
+ let outer = fixtures.missing_table;
182
+
183
+ it(`returns \`null\` for contents value`, function () {
184
+ expect( new_contents ).to.equal( fixture.expected );
185
+ });
186
+ it(`has these exact error codes: ${ JSON.stringify( outer.error_codes )}`, function () {
187
+ expect( get_error_codes({ errors: errors }) ).to.have.all.members( fixture.error_codes );
188
+ });
189
+ it(`has these exact _log_ codes: ${ JSON.stringify( outer.log_codes )}`, function () {
190
+ expect( get_log_codes({ logger }) ).to.have.all.members( fixture.log_codes );
191
+ });
192
+
193
+ });
194
+
195
+ describe(`that has no quoted ids,`, function () {
196
+
197
+ before(function () { mutate_globals_with({ testing_vals: fixtures.missing_ids }); });
198
+
199
+ let outer = fixtures.missing_ids;
200
+
201
+ it(`returns \`null\` for contents value`, function () {
202
+ expect( new_contents ).to.equal( fixture.expected );
203
+ });
204
+ it(`has these exact error codes: ${ JSON.stringify( outer.error_codes )}`, function () {
205
+ expect( get_error_codes({ errors: errors }) ).to.have.all.members( fixture.error_codes );
206
+ });
207
+ it(`has these exact _log_ codes: ${ JSON.stringify( outer.log_codes )}`, function () {
208
+ expect( get_log_codes({ logger }) ).to.have.all.members( fixture.log_codes );
209
+ });
210
+
211
+ });
212
+
213
+ describe(`that has no header row,`, function () {
214
+
215
+ before(function () { mutate_globals_with({ testing_vals: fixtures.only_row_is_header }); });
216
+
217
+ let outer = fixtures.only_row_is_header;
218
+
219
+ it(`returns \`null\` for contents value`, function () {
220
+ expect( new_contents ).to.equal( fixture.expected );
221
+ });
222
+ it(`has these exact error codes: ${ JSON.stringify( outer.error_codes )}`, function () {
223
+ expect( get_error_codes({ errors: errors }) ).to.have.all.members( fixture.error_codes );
224
+ });
225
+ it(`has these exact _log_ codes: ${ JSON.stringify( outer.log_codes )}`, function () {
226
+ expect( get_log_codes({ logger }) ).to.have.all.members( fixture.log_codes );
227
+ });
228
+
229
+ });
230
+
231
+ describe(`that has multiple Scenarios,`, function () {
232
+
233
+ before(function () { mutate_globals_with({ testing_vals: fixtures.multiple_scenarios }); });
234
+
235
+ let outer = fixtures.multiple_scenarios;
236
+
237
+ it(`returns \`null\` for contents value`, function () {
238
+ expect( new_contents ).to.equal( fixture.expected );
239
+ });
240
+ it(`has these exact error codes: ${ JSON.stringify( outer.error_codes )}`, function () {
241
+ expect( get_error_codes({ errors: errors }) ).to.have.all.members( fixture.error_codes );
242
+ });
243
+ it(`has these exact _log_ codes: ${ JSON.stringify( outer.log_codes )}`, function () {
244
+ expect( get_log_codes({ logger }) ).to.have.all.members( fixture.log_codes );
245
+ });
246
+
247
+ });
248
+
249
+ });
250
+
251
+ });