@suffolklitlab/alkiln 5.1.0-sources-5 → 5.1.0-sources-6

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
@@ -41,7 +41,9 @@ Format:
41
41
  ### Internal
42
42
  -
43
43
  -->
44
- <!-- ## [Unreleased] -->
44
+ ## [Unreleased]
45
+ ### Added
46
+ - Can now take the location of the "sources" folder or folders as an argument in the command line. The formats are `npm run cucumber @tags -- --sources=./foo` and `alkiln-run @tags --sources=./foo`.
45
47
 
46
48
  ## [5.1.0] - 2023-08-12
47
49
  ### Added
@@ -6,18 +6,28 @@ const session_vars = require('./utils/session_vars');
6
6
 
7
7
  const cucumber_api = require('@cucumber/cucumber/api');
8
8
 
9
- function build_config(argv) {
10
- // The default provided config
11
- const provided_config = {
9
+ function build_config( command_args ) {
10
+ // Turn all the paths to the sources folders into paths to the feature files
11
+ let sources_paths = session_vars.get_sources_paths();
12
+ let feature_paths = [];
13
+ for ( let source of sources_paths ) {
14
+ feature_paths.push( `${ source }/*.feature` );
15
+ }
16
+
17
+ const config = {
12
18
  publishQuiet: true,
13
19
  require: `./lib/index.js`,
14
20
  format: [`progress`, `summary:cucumber-report.txt`],
15
- paths: [`${ argv.sources }/*.feature`],
21
+ paths: feature_paths,
16
22
  retry: 1,
17
23
  }
18
24
 
19
- let tags = argv[`_`];
20
- console.log(`tags: ${JSON.stringify(tags)}, ${tags.length}`);
25
+ // Normalize tag expressions, if there are any
26
+ let tags = command_args[`_`];
27
+ // Avoid breaking old versions of ALKilnInThePlayground
28
+ if ( tags.length === 0 && session_vars.get_origin() === `playground` ) {
29
+ tags = session_vars.get_tags();
30
+ }
21
31
  if (tags.length > 0) {
22
32
  let joined_tags = '';
23
33
  // Cucumber expects tags in boolean expressions, like (@a0 or @a1) and @random.
@@ -34,14 +44,10 @@ function build_config(argv) {
34
44
  joined_tags = tags.join(` `);
35
45
  }
36
46
 
37
- provided_config.tags = joined_tags;
38
- } //else {
39
- // provided_config.tags = ''
40
- // } // end if there are tags
41
-
42
- console.log(`provided_config.tags: ${provided_config.tags}`);
47
+ config.tags = joined_tags;
48
+ }
43
49
 
44
- return provided_config;
50
+ return config;
45
51
  }; // Ends build_config()
46
52
 
47
53
 
@@ -51,29 +57,31 @@ function build_config(argv) {
51
57
  const environment = { cwd: process.cwd() };
52
58
  console.log("alkiln-run: environment: %o", environment);
53
59
 
54
- console.log(`command: ${ process.argv }`);
55
-
56
60
  // process.argv is a list of strings of commands and args.
61
+ // If using `npm run cucumber`, use `--` before `--sources=./foo`
57
62
  let argv = require(`minimist`)( process.argv.slice(2), {
58
63
  default: {
59
64
  // Testing from GitHub. TODO: Do we want to allow multiple sources paths?
60
- sources: `./docassemble/*/data/sources`,
65
+ sources: [ `./docassemble/*/data/sources` ],
61
66
  // From playground: `/usr/share/docassemble/files/playgroundsources/<user_id>/<project>/*.feature`
62
67
  // From playground with S3: `/tmp/playgroundsources/<user_id>/<project>/*.feature`
63
68
  }
64
69
  });
70
+
71
+ // Make sure `sources` is always a list
72
+ let sources_list = argv.sources;
73
+ if ( typeof argv.sources === `string` ) {
74
+ sources_list = [ argv.sources ];
75
+ }
65
76
 
66
- let dir_exists = session_vars.set_sources_path( argv.sources );
67
- if ( !dir_exists ) {
77
+ let one_dir_exists = session_vars.set_sources_paths( sources_list );
78
+ if ( !one_dir_exists ) {
68
79
  // If we don't throw, it'll be more confusing when no tests run
69
- throw new ReferenceError( `No folder exists at "${ argv.sources }", where ALKiln looks for your \`.feature\` files.`)
80
+ throw new ReferenceError( `ALKiln ERROR: ALKiln can't find your "sources" folder(s). See above for details.`);
70
81
  }
71
-
72
- const provided_config = build_config( argv );
73
- console.log(`provided_config: ${provided_config}`);
74
-
82
+
75
83
  const { runConfiguration } = await cucumber_api.loadConfiguration({
76
- provided: provided_config
84
+ provided: build_config( argv ),
77
85
  }, environment);
78
86
 
79
87
  console.log("alkiln-run: runConfiguration: %o", runConfiguration);
package/lib/scope.js CHANGED
@@ -1794,16 +1794,23 @@ module.exports = {
1794
1794
  return false; // The row wasn't used
1795
1795
  }
1796
1796
 
1797
- let dir = session_vars.get_sources_path();
1797
+ let sources_dirs = session_vars.get_sources_paths();
1798
1798
  // Get the full paths of all the existing files
1799
1799
  let paths = [];
1800
1800
  let missing_files = []; // For any user warnings
1801
1801
  for ( let name of uploads_names ) {
1802
+
1802
1803
  let trimmed_name = name.trim();
1803
- let matching_paths = fg.sync(
1804
- [ `${ dir }/${ trimmed_name }` ],
1805
- { suppressErrors: true }
1806
- );
1804
+ let matching_paths = [];
1805
+ // Look for the file in all "sources" folders
1806
+ for ( let one_dir of sources_dirs ) {
1807
+ let new_paths = fg.sync(
1808
+ [ `${ one_dir }/${ trimmed_name }` ],
1809
+ { suppressErrors: true }
1810
+ );
1811
+ matching_paths.push( ...new_paths );
1812
+ }
1813
+
1807
1814
  if ( matching_paths.length === 0 ) {
1808
1815
  missing_files.push( trimmed_name );
1809
1816
  } else {
@@ -1814,7 +1821,7 @@ module.exports = {
1814
1821
  if ( missing_files.length > 0 ) {
1815
1822
  await scope.addToReport( scope, {
1816
1823
  type: `warning`,
1817
- value: `ALKiln could not find "${ missing_files.join('", "') }" in "${ dir }".`
1824
+ value: `ALKiln could not find "${ missing_files.join('", "') }" in the folder(s) at "${ sources_dirs.join('", "') }".`
1818
1825
  });
1819
1826
  }
1820
1827
 
@@ -2046,7 +2053,7 @@ module.exports = {
2046
2053
  }
2047
2054
  if ( num_unused_rows > 0 ) {
2048
2055
  let { id } = await scope.examinePageID( scope, 'none to match' );
2049
- let msg = `Missing variable or variables on page "${id}"`;
2056
+ let msg = `Error on page "${id}". See screenshot and see text above for more details.`;
2050
2057
  await scope.addToReport(scope, { type: `error`, value: msg });
2051
2058
  expect( num_unused_rows, msg ).to.equal( 0 );
2052
2059
  }
@@ -38,6 +38,14 @@ session_vars.get_origin = function () {
38
38
  };
39
39
  session_vars.get_user_project_name = function () { return process.env._PROJECT_NAME || null; };
40
40
  session_vars.get_user_id = function () { return process.env._USER_ID || null; };
41
+ // Avoid breaking old versions of ALKilnInThePlayground
42
+ session_vars.get_tags = function () {
43
+ if ( process.env._TAGS ) {
44
+ return process.env._TAGS.split(` `);
45
+ } else {
46
+ return [];
47
+ }
48
+ };
41
49
 
42
50
  // More complex logic
43
51
  session_vars.get_server_reload_timeout = function () {
@@ -204,37 +212,59 @@ session_vars.get_artifacts_path_name = function () {
204
212
  }
205
213
  }; // Ends get_artifacts_path_name()
206
214
 
207
- session_vars.set_sources_path = function ( path ) {
208
- /** Returns whether the given path exists or not. If it does, store
209
- * the path to the sources folder. Can be used for getting, e.g
210
- * .feature files, files to upload, etc. May be annoying repetition
211
- * for some local testing.
215
+ session_vars.set_sources_paths = function ( paths ) {
216
+ /** Returns whether at least one of the given path exists. Store
217
+ * a list of the existing paths. Warn of any missing paths. Can be
218
+ * used for getting, e.g .feature files, files to upload, etc.
212
219
  *
213
- * Our code should ensure this gets run before cucumber gets triggered.
220
+ * Our code should ensure this gets run before cucumber tests get triggered.
214
221
  *
215
- * @returns bool */
222
+ * @param paths { [str] } List of paths to the 'sources' folder.
223
+ *
224
+ * @returns bool
225
+ */
216
226
 
217
- let sources = fg.sync(
218
- [ path ],
219
- { onlyFiles: false, suppressErrors: true }
220
- );
227
+ // Check every path, tracking which exist and which are missing
228
+ let existing_paths = [];
229
+ let missing_paths = [];
230
+ for ( let path of paths ) {
231
+ let dirs = fg.sync(
232
+ [ path ],
233
+ { onlyFiles: false, suppressErrors: true }
234
+ );
235
+
236
+ if ( dirs.length > 0 ) {
237
+ existing_paths.push( ...dirs );
238
+ } else {
239
+ missing_paths.push( path );
240
+ }
241
+ }
221
242
 
222
- if ( sources.length > 0 ) {
223
- session_vars._sources_path = path;
224
- return true;
225
- } else {
226
- session_vars._sources_path = null;
243
+ // Warn about missing paths
244
+ if ( missing_paths.length > 0 ) {
245
+ console.warn(
246
+ `ALKiln WARNING: ALKiln can't find folders at "${ paths.join(", ") }".`
247
+ );
248
+ }
249
+
250
+ // If no paths were valid
251
+ if ( existing_paths.length <= 0 ) {
252
+ session_vars._sources_paths = null;
227
253
  return false;
228
254
  }
255
+
256
+ // Otherwise, store valid paths
257
+ session_vars._sources_paths = existing_paths;
258
+ return true;
229
259
  };
230
260
 
231
- session_vars.get_sources_path = function () {
261
+ session_vars.get_sources_paths = function () {
232
262
  /** Get the "sources" folder path. Should never be undefined during
233
263
  * a run of the test. run_cucumber.js should make sure it has
234
264
  * a default value.
235
265
  *
236
266
  * @returns str || null */
237
- return session_vars._sources_path;
267
+ return session_vars._sources_paths;
238
268
  };
239
269
 
240
270
  session_vars.validateEnvironment = function() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suffolklitlab/alkiln",
3
- "version": "5.1.0-sources-5",
3
+ "version": "5.1.0-sources-6",
4
4
  "description": "Integrated automated end-to-end testing with docassemble, puppeteer, and cucumber.",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {