Skip to content

Commit

Permalink
Change log methods signature, use fs.append, add stdout...
Browse files Browse the repository at this point in the history
- Add report_log.txt
- Implement action output (untested)
- Implement logs in unit tests

Co-authored-by: will-morningstar <mxwillmorningstar@gmail.com>
  • Loading branch information
plocket and will-morningstar committed Sep 6, 2024
1 parent a788b7e commit e2a3982
Show file tree
Hide file tree
Showing 9 changed files with 464 additions and 273 deletions.
12 changes: 12 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ outputs:
PATH_TO_REPORT_FILE:
description: 'An empty string ("") or the path to report.txt. Remember to check for the existence of the file before using it.'
value: ${{ steps.alkiln_outputs.outputs.PATH_TO_REPORT_FILE }}
PATH_TO_REPORT_LOG_FILE:
description: 'An empty string ("") or the path to report_log.txt. Remember to check for the existence of the file before using it.'
value: ${{ steps.alkiln_outputs.outputs.PATH_TO_REPORT_LOG_FILE }}
PATH_TO_UNEXPECTED_RESULTS_FILE:
description: 'An empty string ("") or the path to unexpected_results.txt. Remember to check for the existence of the file before using it.'
value: ${{ steps.alkiln_outputs.outputs.PATH_TO_UNEXPECTED_RESULTS_FILE }}
Expand Down Expand Up @@ -175,6 +178,7 @@ runs:
else
REPORT_PATH="${FOLDER}report.txt"
REPORT_LOG_PATH="${FOLDER}report_log.txt"
UNEXPECTED_RESULTS_PATH="${FOLDER}unexpected_results.txt"
DEBUG_LOG_PATH="${FOLDER}debug_log.txt"
Expand All @@ -185,6 +189,13 @@ runs:
REPORT_PATH=""
fi
if [ -f "$REPORT_LOG_PATH" ]; then
echo "$REPORT_LOG_PATH exists"
else
echo "$REPORT_LOG_PATH is missing"
REPORT_LOG_PATH=""
fi
if [ -f "$UNEXPECTED_RESULTS_PATH" ]; then
echo "$UNEXPECTED_RESULTS_PATH exists"
else
Expand All @@ -203,6 +214,7 @@ runs:
echo "PATH_TO_ARTIFACTS=$FOLDER" >> "$GITHUB_OUTPUT"
echo "PATH_TO_REPORT_FILE=$REPORT_PATH" >> "$GITHUB_OUTPUT"
echo "PATH_TO_REPORT_LOG_FILE=$REPORT_LOG_PATH" >> "$GITHUB_OUTPUT"
echo "PATH_TO_UNEXPECTED_RESULTS_FILE=$UNEXPECTED_RESULTS_PATH" >> "$GITHUB_OUTPUT"
echo "PATH_TO_DEBUG_LOG_FILE=$DEBUG_LOG_PATH" >> "$GITHUB_OUTPUT"
Expand Down
10 changes: 5 additions & 5 deletions lib/scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -2162,7 +2162,7 @@ module.exports = {
* @param ensure_all_vars_used {bool} [false] = Default false. If true, errors if any
* object in var_data is not used during running of this function.
*/
log.debug({ code: `ALK0219`, before: `~~~~~~~~~~~~~~`, },
log.debug({ code: `ALK0221`, before: `~~~~~~~~~~~~~~\n`, },
`scope.setFields()`
);

Expand Down Expand Up @@ -2208,7 +2208,7 @@ module.exports = {
// Accumulate number of times this row was used. Esp important for `.target_number`
await scope.increment_row_use( scope, { row: row_used });

process.stdout.write(`\x1b[36m${ '*' }\x1b[0m`); // assumes var was set if no error occurred
log.stdout({}, `\x1b[36m${ '*' }\x1b[0m`); // assumes var was set if no error occurred
}
} // ends for every non-submit-button field on the page
} // ends while fields are still being set
Expand Down Expand Up @@ -2253,7 +2253,7 @@ module.exports = {
// }

did_navigate = true;
process.stdout.write(`\x1b[36m${ 'v' }\x1b[0m`); // pressed button successfully
log.stdout({}, `\x1b[36m${ 'v' }\x1b[0m`); // pressed button successfully
break;

} // ends if row_used
Expand Down Expand Up @@ -2300,7 +2300,7 @@ module.exports = {
// }

did_navigate = true;
process.stdout.write(`\x1b[36m${ '>' }\x1b[0m`); // continued successfully
log.stdout({}, `\x1b[36m${ '>' }\x1b[0m`); // continued successfully
} // ends if !did_navigate && ensure_navigation

if ( did_navigate && scope.check_all_for_a11y ) {
Expand Down Expand Up @@ -3124,7 +3124,7 @@ module.exports = {
} else {
// Try to give a random answer for that element tag
await scope.set_random_input_for[ field.tag ]( scope, { field: field });
process.stdout.write(`\x1b[36m${ '*' }\x1b[0m`); // assumes var was set if no error occurred
log.stdout({}, `\x1b[36m${ '*' }\x1b[0m`); // assumes var was set if no error occurred
}

} // End for all page fields
Expand Down
46 changes: 31 additions & 15 deletions lib/steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const {
Given,
After,
Before,
AfterStep,
BeforeAll,
AfterAll,
setDefaultTimeout //,
Expand Down Expand Up @@ -84,7 +85,7 @@ let click_with = {

let log = null;

BeforeAll(async () => {
BeforeAll(async function() {
scope.showif_timeout = 600;
// TODO: Do these really need to be maps? As sets, they may make the output
// more predictable to the user, but they add complexity.
Expand All @@ -97,30 +98,29 @@ BeforeAll(async () => {
// Store path names for files and docs created for the tests
scope.paths = {};

// TODO: figure out how to test file and folder creation stuff,
// especially when setup is excluded from the flow.
// // Make the folder to store all the files for this run of the tests
// scope.paths.artifacts = files.make_artifacts_folder();
// // Save its name in a file. `session_vars` can get it back later.
// // The value we are saving is used by at least run_cucumber.js.

// Make the folder to store all the files for this run of the tests
scope.paths.artifacts = files.make_artifacts_folder();
// Save its name in a file. `session_vars` can get it back later.
// The value we are saving is used by at least run_cucumber.js.
session_vars.save_artifacts_path_name( scope.paths.artifacts );
// A little indirect, but the artifacts path should always have already been
// created by now, either by `run_cucumber.js` or the relevant test
scope.paths.artifacts = session_vars.get_artifacts_path_name();
log = new Log({ path: scope.paths.artifacts, context: `steps` });
scope.set_log({ log_obj: log });

scope.paths.report = `${ scope.paths.artifacts }/report.txt`;
scope.paths.failures = `${ scope.paths.artifacts }/${ log.unexpected_filename }`;
scope.paths.debug_log = `${ scope.paths.artifacts }/${ log.debug_log_filename }`;
fs.writeFileSync( scope.paths.debug_log, "" );
scope.paths.report_log = `${ scope.paths.artifacts }/${ log.report_log_filename }`;
scope.paths.report = `${ scope.paths.artifacts }/${ log.report_filename }`;
scope.paths.failures = `${ scope.paths.artifacts }/${ log.unexpected_filename }`;

reports.create( scope );
});

Before(async (scenario) => {

// Start the running "progress bar" for the Scenario
console.log(``); // New line (which stdout doesn't do)
log.stdout({ log: `Scenario: ${ scenario.pickle.name }: ` })
log.stdout({}, `\nScenario: ${ scenario.pickle.name }: `);

// Create browser, which can't be created in BeforeAll() where .driver doesn't exist for some reason
if (!scope.browser) {
Expand Down Expand Up @@ -973,7 +973,7 @@ When(/I answer randomly for at most ([0-9]+) (?:page(?:s)?|screen(?:s)?)/, { tim
} // ends if !has_content

if ( buttons_exist ) {
process.stdout.write(`\x1b[36m${ 'v' }\x1b[0m`); // pressed button
log.stdout({}, `\x1b[36m${ 'v' }\x1b[0m`); // pressed button
}

resolve();
Expand Down Expand Up @@ -1264,6 +1264,15 @@ Then(/I fail to delete (\d) detected interview(?:s)? and get no error __internal
//#####################################
//#####################################

AfterStep(async function({ result }) {
// TODO: Abstract this
if ( result.status === `PASSED` ) { log.stdout({ records_only: true }, `.`); }
else if ( result.status === `FAILED` ) { log.stdout({ records_only: true }, `F`); }
else if ( result.status === `UNDEFINED` ) { log.stdout({ records_only: true }, `U`); }
else if ( result.status === `SKIPPED` ) { log.stdout({ records_only: true }, `-`); }
else if ( result.status === `PENDING` ) { log.stdout({ records_only: true }, `P`); }
});

After(async function(scenario) {

// Log errors
Expand Down Expand Up @@ -1431,6 +1440,13 @@ After(async function(scenario) {
need_to_force_failed_status = true;
}

// Not sure if this is necessary
if ( changeable_test_status !== 'PASSED' ) {
log.stdout({ records_only: true }, changeable_test_status[0].toUpperCase() );
} else {
log.stdout({ records_only: true }, `.` );
}

let signout_succeeded = true;
let signout_error_msg = ``;
// If there is a page open, then sign out and close it
Expand Down Expand Up @@ -1526,7 +1542,7 @@ After(async function(scenario) {

// Find the race condition.
log.debug({ code: `ALK0100`, context: `scenario`, },
`Scenario AfterStep() message:`, scenario.result.message
`Scenario After() message:`, scenario.result.message
);

});
Expand Down
Loading

0 comments on commit e2a3982

Please sign in to comment.