@suffolklitlab/alkiln 5.13.0-logs3 → 5.13.1

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.
@@ -1,5 +1,5 @@
1
1
  const _da_REST = require('./docassemble_api_REST');
2
- const Log = require('../utils/log');
2
+ const log = require('../utils/log');
3
3
  const session_vars = require('../utils/session_vars' );
4
4
  const time = require('../utils/time');
5
5
 
@@ -61,10 +61,6 @@ const time = require('../utils/time');
61
61
  let da_i = {};
62
62
  module.exports = da_i;
63
63
 
64
- const artifacts_path = session_vars.get_artifacts_path_name();
65
- const log = new Log({ path: artifacts_path, context: `api` });
66
- const context = `da api`;
67
-
68
64
 
69
65
  // Constants
70
66
  const DEFAULT_MAX_REQUEST_MS = session_vars.get_setup_timeout_ms();
@@ -96,9 +92,7 @@ da_i.throw_an_error_if_server_is_not_responding = async function ( options ) {
96
92
 
97
93
  // Defaults
98
94
  let { timeout } = options || { timeout: DEFAULT_MAX_REQUEST_MS };
99
- log.info({ code: `ALK0166`, context: `da api`, },
100
- `Waiting for the docassemble server to respond. Will wait for ${ timeout/1000 } seconds at most.`
101
- );
95
+ log.info({ type: `da api`, code: `ALK0166`, pre: `Waiting for the docassemble server to respond. Will wait for ${ timeout/1000 } seconds at most.` });
102
96
 
103
97
  try {
104
98
  let start_time = Date.now()
@@ -106,9 +100,7 @@ da_i.throw_an_error_if_server_is_not_responding = async function ( options ) {
106
100
  let response = await _da_REST.get_dev_id( timeout );
107
101
  let end_time = Date.now()
108
102
  if ( response && response.data && response.data.id ) {
109
- log.info({ code: `ALK0167`, context: `da api`, },
110
- `The docassemble server responded after ${ (end_time - start_time)/1000 } seconds.`
111
- );
103
+ log.info({ type: `da api`, code: `ALK0167`, pre: `The docassemble server responded after ${ (end_time - start_time)/1000 } seconds.` });
112
104
  return false;
113
105
  }
114
106
 
@@ -117,16 +109,17 @@ da_i.throw_an_error_if_server_is_not_responding = async function ( options ) {
117
109
  if ( is_timeout_error( error ) ) {
118
110
  // Anything that's waiting for the server to not be busy does not want
119
111
  // to move forward without a free server.
120
- log.info({ code: `ALK0168`, context: `da api`, },
121
- `The docassemble server was still busy after ${ timeout/1000 } seconds.`
122
- );
112
+ log.info({ type: `da api`, code: `ALK0168`, pre: `The docassemble server was still busy after ${ timeout/1000 } seconds.` });
123
113
  } else {
124
114
  // Not sure what to do for other errors. It could be a server
125
115
  // error, like an 'Access Denied' error, which should be handled.
126
- log.warning({ code: `ALK0169`, context: `da api` },
127
- `Checked if the server was busy and ran into a different error`,
128
- error
129
- );
116
+ log.error({
117
+ type: `da api`,
118
+ code: `ALK0169`,
119
+ pre: `Tried to check if the docassemble server was busy, but `
120
+ + `ran into an unexpected error. The error didn't indicate a busy server, though. Error message:\n`
121
+ + error
122
+ });
130
123
  }
131
124
 
132
125
  throw error;
@@ -239,12 +232,8 @@ da_i.get_api_key_access_status = async function ({ timeout = null, api_key = nul
239
232
  } // ends try
240
233
  } // ends auth_data.codes only has the first code
241
234
 
242
- // log.debug({ type: `da api info`, code: `ALKx0202`,
243
- // pre: `API key authentication info`, data: auth_data });
244
- log.debug({ code: `ALK0202`, context: `da api`, },
245
- `API key authentication info`,
246
- auth_data
247
- );
235
+ log.debug({ type: `da api info`, code: `ALK0202`,
236
+ pre: `API key authentication info`, data: auth_data });
248
237
 
249
238
  return auth_data;
250
239
  }; // Ends da_i.get_api_key_access_status()
@@ -258,20 +247,16 @@ da_i.delete_project = async function ( delete_options ) {
258
247
  let { timeout } = delete_options || { timeout: DEFAULT_MAX_REQUEST_MS };
259
248
 
260
249
  let project_name = session_vars.get_project_name()
261
- log.info({ code: `ALK0170`, context: `da api`, },
262
- `Trying to delete Project ${ project_name }`
263
- );
250
+ log.info({ type: `da api`, code: `ALK0170`, pre: `Trying to delete Project ${ project_name }` });
264
251
 
265
252
  try {
266
253
  let response = await _da_REST.delete_project( timeout );
267
- log.info({ code: `ALK0171`, context: `da api`, },
268
- `Deleted Project "${ project_name }"`
269
- );
254
+ log.info({ type: `da api`, code: `ALK0171`, pre: `Deleted Project "${ project_name }"` });
270
255
  } catch ( error ) {
271
- log.throw({ code: `ALK0172`, context: `da api`, error: error },
272
- `Ran into an error when deleting Project "${ project_name }". See https://docassemble.org/docs/api.html#playground_delete_project.`
273
- );
274
- // throw error;
256
+ let msg = `Ran into an error when deleting Project "${ project_name }". See https://docassemble.org/docs/api.html#playground_delete_project.`
257
+ log.error({ type: `da api`, code: `ALK0172`, pre: msg });
258
+ log.debug({ type: `da api`, code: `ALK0173`, pre: msg });
259
+ throw error;
275
260
  }
276
261
 
277
262
  }; // Ends da_i.delete_project()
@@ -295,9 +280,7 @@ da_i.quietly_try_to_delete_interviews = async function ({ interviews = {}, api_k
295
280
  });
296
281
  responses.push( sub_responses );
297
282
  } else {
298
- log.debug({ code: `ALK0191`, context: `da api` },
299
- `There is no interview to delete.`
300
- );
283
+ log.debug({ type: `da api info`, code: `ALK0191`, pre: `There is no interview to delete.` });
301
284
  }
302
285
  }
303
286
  return responses;
@@ -312,9 +295,9 @@ da_i.quietly_delete_one_interview = async function ( timeout, { interview = {},
312
295
  let responses = [];
313
296
  for ( let api_key of api_keys ) {
314
297
  try {
315
- log.debug({ code: `ALK0188`, context: `da api` },
316
- `Trying to delete the interview with the id ${ interview.uid } and an API key.`
317
- );
298
+ log.debug({ type: `da api info`, code: `ALK0188`,
299
+ pre: `Trying to delete the interview with the id ${ interview.uid } and an API key.`
300
+ });
318
301
 
319
302
  // Actual work:
320
303
  let response = await _da_REST.delete_interview( timeout, {
@@ -323,15 +306,13 @@ da_i.quietly_delete_one_interview = async function ( timeout, { interview = {},
323
306
  });
324
307
  responses.push( response );
325
308
 
326
- log.debug({ code: `ALK0189`, context: `da api` },
327
- `No error when trying to delete interview ${ interview.uid } at ${ interview.i }.`
328
- );
309
+ log.debug({ type: `da api info`, code: `ALK0189`,
310
+ pre: `No error when trying to delete interview ${ interview.uid } at ${ interview.i }.`
311
+ });
329
312
  } catch ( error ) {
330
313
  error.interview = interview;
331
- log.debug({ code: `ALK0190`, context: `da api` },
332
- `Error when deleting the interview. See https://docassemble.org/docs/api.html#session_delete.`,
333
- error
334
- );
314
+ let msg = `Error when deleting the interview. See https://docassemble.org/docs/api.html#session_delete.`
315
+ log.debug({ type: `da api info`, code: `ALK0190`, pre: msg, data: error });
335
316
  }
336
317
  } // ends for api keys
337
318
  return responses;
@@ -366,9 +347,7 @@ da_i.get_interview = async function ({ interview = {}, api_keys = [], options =
366
347
  if ( interview && interview.uid ) {
367
348
  for ( let api_key of api_keys ) {
368
349
  try {
369
- log.debug({ code: `ALK0192`, context: `da api` },
370
- `Trying to get the interview with the id ${ interview.uid } and an API key.`
371
- );
350
+ log.debug({ type: `da api info`, code: `ALK0192`, pre: `Trying to get the interview with the id ${ interview.uid } and an API key.` });
372
351
 
373
352
  // Actual work:
374
353
  let response = await _da_REST.get_interview( timeout, {
@@ -377,28 +356,20 @@ da_i.get_interview = async function ({ interview = {}, api_keys = [], options =
377
356
  });
378
357
 
379
358
  if ( response && response.data && response.data.items && response.data.items[0] && response.data.items[0].session ) {
380
- log.debug({ code: `ALK0193`, context: `da api` },
381
- `Status ${ response.status }. Got ${ response.data.items[0].session }.`
382
- );
359
+ log.debug({ type: `da api info`, code: `ALK0193`, pre: `Status ${ response.status }. Got ${ response.data.items[0].session }.`});
383
360
  return response.data.items[0];
384
361
  } else {
385
- log.debug({ code: `ALK0194`, context: `da api` },
386
- `Status ${ response.status }. Cannot find ${ interview.uid }`
387
- );
362
+ log.debug({ type: `da api info`, code: `ALK0194`, pre: `Status ${ response.status }. Cannot find ${ interview.uid }`});
388
363
  }
389
364
 
390
365
  } catch ( error ) {
391
366
  error.interview = interview;
392
- log.debug({ code: `ALK0195`, context: `da api` },
393
- `${ error.status || `No error.status.` } ${ error.statusText || error.data || `No error.statusText.` } Ran into an error when getting the interview ${ interview.uid }. See https://docassemble.org/docs/api.html#interviews.`,
394
- error
395
- );
367
+ let msg = `${ error.status || `No error.status.` } ${ error.statusText || error.data || `No error.statusText.` } Ran into an error when getting the interview ${ interview.uid }. See https://docassemble.org/docs/api.html#interviews.`
368
+ log.debug({ type: `da api info`, code: `ALK0195`, pre: msg, data: error });
396
369
  }
397
370
  } // ends for api_keys
398
371
  } else {
399
- log.debug({ code: `ALK0196`, context: `da api` },
400
- `There is no interview to get.`
401
- );
372
+ log.debug({ type: `da api info`, code: `ALK0196`, pre: `There is no interview to get.` });
402
373
  }
403
374
 
404
375
  return null;
@@ -1,11 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  const session_vars = require('../utils/session_vars');
4
- const Log = require('../utils/log');
4
+ const log = require('../utils/log');
5
5
  const fg = require('fast-glob');
6
6
 
7
7
  const server_install = async () => {
8
- /** Finds out where in this directory the package's folders are. */
9
8
  session_vars.save_install_method(`server`);
10
9
 
11
10
  // Get path to folders inside repo main "docassemble" folder
@@ -24,33 +23,20 @@ const server_install = async () => {
24
23
  // Get names of all folders in repo "docassemble" folder
25
24
  let chosen_folder = folders[0];
26
25
  if ( folders.length === 0 ) {
27
- let msg = `ALKiln cannot find the package's files. There are 0 folders at "${ path }". Stopping tests.`;
28
- log.throw({ code: `ALK0044`, context: `server_install`,
29
- error: new ReferenceError( msg ) // no logs
30
- });
26
+ let msg = `There are 0 folders at ${path}. Stopping tests.`;
27
+ log.error({ type: `setup`, code: `ALK0044`, data: msg })
28
+ throw new ReferenceError( msg );
31
29
  }
32
30
 
33
31
  if ( folders.length > 1 ) {
34
- log.warn({ code: `ALK0045`, context: `setup`, },
35
- `There are ${ folders.length } folders at "${ path }": "${ folders.join('", "') }". ALKiln chose to use the folder "${ chosen_folder }".`
36
- );
37
- } else {
38
- log.info({ code: `ALK0218`, context: `setup`, },
39
- `ALKiln found the package folder at "${ chosen_folder }".`
40
- );
32
+ log.warn({
33
+ type: `setup`,
34
+ code: `ALK0045`,
35
+ data: `There are ${folders.length} folders at ${path}: "${folders.join('", "')}". ALKiln chose to use the folder "${chosen_folder}".`
36
+ })
41
37
  }
42
38
 
43
39
  session_vars.save_repo_folder_name( chosen_folder );
44
40
  }; // Ends server_install();
45
41
 
46
- // 1. session_vars - make sure all the required env vars exist
47
- session_vars.validateEnvironment();
48
-
49
- // 2. Prepare logs
50
- // Local devs: This will be separate from your test paths
51
- // unless you pass a `path` argument into the cucumber run command
52
- const argv = require(`minimist`)(process.argv.slice(2));
53
- const log = new Log({ path: argv.path, context: `server_install` });
54
-
55
- // 3. run
56
42
  server_install();
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ // TODO: Rename to playground_install?
4
+
3
5
  const child_process = require(`child_process`);
4
6
 
5
- const Log = require(`../utils/log`);
7
+ const log = require(`../utils/log`);
6
8
  const session_vars = require(`../utils/session_vars` );
7
- const files = require(`../utils/files` );
8
- const time = require(`../utils/time` );
9
9
 
10
10
  const setup = async () => {
11
11
  /** In the docassemble testing account identified by the
@@ -18,14 +18,9 @@ const setup = async () => {
18
18
  let project_name = session_vars.get_project_base_name().replace(/[^A-Za-z0-9]/g, '') + `${Date.now()}`;
19
19
  session_vars.save_project_name( project_name );
20
20
 
21
- const starting_msg = `Starting to upload this package to `
21
+ log.info({ type: `setup`, code: `ALK0046`, pre: `Starting to upload this package to `
22
22
  + `a new Project called ${project_name} in the Playground `
23
- + `of your server's testing account. It may take a couple of minutes.`;
24
- log.info({ code: `ALK0046`, context: `setup` },
25
- starting_msg
26
- );
27
-
28
- // TODO: 1. Start listening to the normal console here (for debug logging)
23
+ + `of your server's testing account. It may take a couple of minutes.` });
29
24
 
30
25
  // dainstall . --apiurl https://site.org --apikey $API_KEY --playground --project=name
31
26
  // I think this won't run on windows? Why do I think this? Where on the
@@ -39,37 +34,29 @@ const setup = async () => {
39
34
  `--playground`, `--project=${ project_name }`
40
35
  ],
41
36
  // Prints messages from the process to the console while it's running
42
- // result.stderr, result.stdout, etc. will be `null`
43
37
  { stdio: 'inherit', }
44
38
  );
45
39
 
46
- // TODO: 2. Stop listening to the normal console here
47
-
48
40
  // 403 is invalid API key, but I'm not sure how to output
49
- // the response to find out the error code. stderr is `null`.
41
+ // the response to find out the error code
42
+
50
43
  if ( result.status !== 0 ) {
51
- const install_err_msg = `Status code ${ result.status }. Could not `
52
- + `dainstall this package on your server. See above for more details.`;
53
- log.throw({ code: `ALK0047`, context: `setup`,
54
- before: `☝️ ☝️ ☝️ Error data ☝️ ☝️ ☝️\n`,
55
- error: `Error while installing project` },
56
- install_err_msg
57
- );
44
+ log.error({
45
+ type: `setup`,
46
+ code: `ALK0047`,
47
+ pre: `Status code ${ result.status }. Could not dainstall this package on your server. See above for more details.`
48
+ });
49
+ throw(result.stderr);
58
50
  }
59
51
 
60
- log.success({ code: `ALK0048`, context: `setup`, },
61
- `ALKiln created a Project in your Playground named "${ project_name }"!`
62
- );
52
+ log.success({
53
+ type: `setup`,
54
+ code: `ALK0048`,
55
+ pre: `ALKiln created a Project in your Playground named "${ project_name }"!`
56
+ });
63
57
  }; // Ends setup();
64
58
 
65
- // 1. session_vars - make sure all the required env vars exist
66
- session_vars.validateEnvironment();
67
-
68
- // 2. Prepare logs
69
- // Local devs: This will be separate from your test paths
70
- // unless you pass a `path` argument into the cucumber run command
71
- const argv = require(`minimist`)(process.argv.slice(2));
72
- const log = new Log({ path: argv.path, context: `setup` });
73
59
 
74
- // 3. run
60
+ // Before everything, make sure all the required env vars exist
61
+ session_vars.validateEnvironment();
75
62
  setup();
@@ -1,46 +1,26 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  const da_i = require('./docassemble_api_interface');
4
- const session_vars = require('../utils/session_vars');
5
- const Log = require('../utils/log');
4
+ const log = require('../utils/log');
5
+ const session_vars = require('../utils/session_vars' );
6
6
 
7
7
  const takedown = async () => {
8
- /** In the docassemble testing account identified by the
8
+ /* In the docassemble testing account identified by the
9
9
  * DOCASSEMBLE_DEVELOPER_API_KEY secret, delete the
10
10
  * Project created for this test.
11
11
  * For local development, clean up project name file. */
12
- log.info({ code: `ALK0177`, context: `takedown`, },
13
- `Trying to remove the docassemble Project from the testing account.`
14
- );
12
+ log.info({ type: `takedown`, code: `ALK0177`, pre: `Trying to remove the docassemble Project from the testing account.` });
15
13
  // Explicit try-catch prevents "Unhandled promise rejection error"
16
14
  // avoids showing confusing node errors to users that they shouldn't have to fix
17
15
  try {
18
16
  await da_i.delete_project();
19
17
  session_vars.delete_project_name();
20
- log.info({ code: `ALK0178`, context: `takedown`, },
21
- `Test takedown finished successfully!`
22
- );
18
+ log.success({ type: `takedown`, code: `ALK0178`, pre: `Test takedown has finished successfully!` });
23
19
  } catch (error) {
24
- log.throw({ code: `ALK0179`, context: `takedown`, error: error },
25
- `Unable to delete project`,
26
- );
27
- // we don't re-throw the exception, so make sure to exit
28
- // with 1 to let GitHub Actions know the script failed
20
+ log.error({type: `takedown`, code: `ALK0179`, 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
29
22
  process.exitCode = 1;
30
23
  }
31
-
32
- // TODO: ? Build the final setup, run, & takedown verbose log
33
- // file in here. Add to it in the GitHub action ?
34
24
  };
35
25
 
36
- // 1. session_vars - make sure all the required env vars exist
37
- session_vars.validateEnvironment();
38
-
39
- // 2. Prepare logs
40
- // Local devs: This will be separate from your test artifacts paths
41
- // unless you pass a `path` argument into the `cucumber` run command
42
- const argv = require(`minimist`)( process.argv.slice(2) );
43
- const log = new Log({ path: argv.path, context: `takedown` });
44
-
45
- // 3. run
46
26
  takedown();
@@ -1,10 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  const fs = require('fs');
4
- const path = require(`path`);
5
4
  const cucumber_api = require('@cucumber/cucumber/api');
6
5
 
7
- const Log = require('./utils/log');
6
+ const log = require('./utils/log'); // These always log in the console
8
7
  const session_vars = require('./utils/session_vars');
9
8
 
10
9
  const SUMMARY_FILENAME = `cucumber-report.txt`;
@@ -54,14 +53,11 @@ function build_config( command_args ) {
54
53
  }; // Ends build_config()
55
54
 
56
55
 
57
- async function main() {
56
+ (async function main() {
58
57
  /** Create the cucumber config, run the tests, create and
59
58
  * manipluate the output. */
60
-
61
59
  const environment = { cwd: process.cwd() };
62
- log.info({ code: `ALK0049`, context: `pre_run environment` },
63
- environment
64
- );
60
+ log.info({ type: `run`, code: `ALK0049`, pre: `environment`, data: environment });
65
61
 
66
62
  // We'll use the user info to construct the possible paths to /sources
67
63
  let id = session_vars.get_user_id();
@@ -69,9 +65,8 @@ async function main() {
69
65
  let project = session_vars.get_user_project_name();
70
66
 
71
67
  // process.argv is a list of strings of commands and args.
72
- // If using `npm run cucumber` (as opposed to the bin commands),
73
- // use `--` before `--sources=./foo`
74
- const argv = require(`minimist`)( process.argv.slice(2), {
68
+ // If using `npm run cucumber`, use `--` before `--sources=./foo`
69
+ let argv = require(`minimist`)( process.argv.slice(2), {
75
70
  default: {
76
71
  sources: [
77
72
  `./docassemble/*/data/sources`, // In GitHub folder
@@ -90,45 +85,35 @@ async function main() {
90
85
  let one_dir_exists = session_vars.set_sources_paths( sources_list );
91
86
  if ( !one_dir_exists ) {
92
87
  // If we don't throw, it'll be more confusing when no tests run
93
- log.throw({ code: `ALK0050`, context: `pre_run`,
94
- error: new ReferenceError(
95
- `ALKiln can't find your "sources" folder(s). See above for details.`
96
- ),
97
- });
88
+ let msg = `ALKiln can't find your "sources" folder(s). See above for details.`;
89
+ let code = `ALK0050`
90
+ log.error({ type: `run`, code: code, pre: msg });
91
+ throw new ReferenceError(`🤕 ${ code } run ERROR: ${ msg }`);
98
92
  }
99
93
 
100
94
  const { runConfiguration } = await cucumber_api.loadConfiguration({
101
95
  provided: build_config( argv ),
102
96
  }, environment);
103
- log.info({ code: `ALK0051`, context: `pre_run config`, },
104
- runConfiguration
105
- );
106
-
107
- const codeDir = path.dirname(require.main.filename);
108
- log.info({ code: `ALK0052`, context: `pre_run directory`, },
109
- codeDir, `\n\n`
110
- );
97
+
98
+ log.info({ type: `run`, code: `ALK0051`, pre: `runConfiguration`, data: runConfiguration });
99
+
100
+ var path = require(`path`);
101
+ var codeDir = path.dirname(require.main.filename);
102
+ log.info({ type: `run`, code: `ALK0052`, pre: `working directory`, data: codeDir });
111
103
  const support = await cucumber_api.loadSupport({ support: {
112
104
  requireModules: [ `${ codeDir }/index.js` ],
113
105
  requirePaths: [ `${ codeDir }/index.js` ],
114
106
  importPaths: [],
115
107
  }, sources: {paths: []}}, environment);
116
108
 
117
- // ====================
118
- // Run
119
- // ====================
120
- const { success } = await cucumber_api.runCucumber({...runConfiguration, support});
121
- // ====================
109
+ log.info({ type: `run`, code: `ALK0053`, pre: `working directory`, data: codeDir });
110
+ log.info({ type: `plain`, pre: `\n\n` });
122
111
 
112
+ const { success } = await cucumber_api.runCucumber({...runConfiguration, support});
123
113
  if ( success ) {
124
- log.success({ code: `ALK0054`, context: `post_run`, },
125
- `Tests succeeded!`
126
- );
114
+ log.success({ type: `run`, code: `ALK0054`, pre: `Tests succeeded!` });
127
115
  } else {
128
- // Don't want to throw error here, so don't pass error object
129
- log.warn({ code: `ALK0055`, context: `post_run`, },
130
- `The tests ran into something unexpected. Look above for more details.`
131
- );
116
+ log.error({ type: `run`, code: `ALK0055`, pre: `The test run ran into something unexpected. Look above for more details.` });
132
117
  }
133
118
  // Custom exit code. May overlap with other systems.
134
119
  // Best info I've found via stack overflow: https://tldp.org/LDP/abs/html/exitcodes.html
@@ -138,64 +123,31 @@ async function main() {
138
123
  // This is hardcoded information from `provide_config` above.
139
124
  // This code isn't used for anything other than detecting and removing color codes.
140
125
  let summary_file_name = SUMMARY_FILENAME;
141
- fs.readFile(summary_file_name, 'utf8', (read_error, text) => {
142
- if ( read_error ) {
126
+ fs.readFile(summary_file_name, 'utf8', (err, text) => {
127
+ if (err) {
143
128
  // Something else will probably show an error that's more relevant
144
- log.warn({ code: `ALK0056`, context: `post_run error`, },
145
- `Failed to read cucumber report`, read_error
146
- );
129
+ log.info({ type: `run`, code: `ALK0056`, pre: `Failed to read cucumber report`, data: err });
147
130
  return;
148
131
  }
149
132
 
150
133
  // Replace terminal color codes, if present
151
134
  // https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797#colors--graphics-mode
152
135
  text = text.replace(/\x1b\[[0-9][0-9]?[0-9]?m/g, '');
153
- // Add to the debug file
136
+
137
+ // Put it in the correct file in the correct folder
138
+ let artifacts_path = session_vars.get_artifacts_path_name();
154
139
  try {
155
- // fs.appendFileSync( `${ artifacts_path }/${ log.debug_log_file }`, `\n\n${text}`);
156
- log.debug({ code: `ALK0216`, context: `post_run`, },
157
- `\n\n`, text
158
- );
140
+ fs.appendFileSync( `${ artifacts_path }/${ log.debug_log_file }`, `\n\n${text}`);
159
141
  } catch ( error ) {
160
- log.warn({ code: `ALK0182`, context: `post_run error`, },
161
- `Something probably went wrong earlier. Look above for more details. Problem when writing to ${ log.path }/${ log.debug_log_filename }.`,
162
- error
163
- );
142
+ log.info({ type: `run`, code: `ALK0182`, pre: `Something probably went wrong earlier. Look above for more details, but here is more information just in case: ALKiln was unable to write to ${ artifacts_path }/${ log.debug_log_file }.`, data: error });
164
143
  }
165
-
166
- // Add to the non-passed test output file
167
144
  try {
168
- // Save only non-passing test output to cut out cruft.
169
- // cucumber only outputs non-success details anyway.
170
- // Our reports only non-passing tests to this file.
145
+ // Add to a unexpected results file when tests themselves fail
171
146
  if ( exitCode === 50 ) {
172
- // fs.appendFileSync( `${ log.path }/${ Log.unexpected_filename }`, `\n\n${ text }` );
173
- log.unexpected({ text });
147
+ fs.appendFileSync( `${ artifacts_path }/${ log.unexpected_filename }`, `\n\n${ text }` );
174
148
  }
175
- } catch ( unexpected_file_error ) {
176
- console.warn(
177
- `🔎 ALK0181 internal WARNING: Something probably went wrong earlier. Problem when writing to ${ log.path }/${ log.unexpected_filename }`,
178
- unexpected_file_error
179
- );
149
+ } catch ( error ) {
150
+ log.info({ type: `run`, code: `ALK0181`, pre: `Something probably went wrong earlier. Look above for more details, but here is more information just in case: ALKiln was unable to write to ${ artifacts_path }/${ log.unexpected_filename }.`, data: error });
180
151
  }
181
-
182
- return;
183
152
  });
184
- }
185
-
186
-
187
- // 1. session_vars - make sure all the required env vars exist
188
- session_vars.validateEnvironment();
189
-
190
- // 2. Prepare logs
191
- // process.argv is a list of strings of commands and args.
192
- // If using `npm run cucumber` (as opposed to the bin commands),
193
- // use `--` before `--sources=./foo`
194
- const argv = require(`minimist`)( process.argv.slice(2) );
195
- // The artifacts folder might be getting created for the first
196
- // time right here. The tests themselves should avoid creating
197
- // their own file.
198
- const log = new Log({ path: argv.path, context: `run` });
199
-
200
- // 3. run
201
- main();
153
+ })();