Skip to content

test: improve test error message logs - #23694

Merged
clydin merged 1 commit into
angular:mainfrom
jbedard:e2e-error-stacks
Aug 9, 2022
Merged

test: improve test error message logs#23694
clydin merged 1 commit into
angular:mainfrom
jbedard:e2e-error-stacks

Conversation

@jbedard

@jbedard jbedard commented Aug 4, 2022

Copy link
Copy Markdown
Contributor

No description provided.

@@ -96,39 +96,47 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce
_processes.push(childProcess);

// Create the error here so the stack shows who called this function.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this wasn't actually done before? Creating the error with the stack trace at this point is the primary change. Otherwise the stack trace is always just the child_process exit/error stack which is useless.

// Return log info about the current process status
function envDump() {
return [
`ENV:${JSON.stringify(spawnOptions.env, null, 2)}`,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also changed but is a bit hard to see. It now outputs the env of the process being spawned, not the parent process - spawnOptions.env isntead of process.env. I think that is far more useful and probably the original intention?

Comment thread tests/legacy-cli/e2e/utils/process.ts Outdated
_processes.push(childProcess);

// Create the error here so the stack shows who called this function.
let error: Error;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't the below do the same?

Suggested change
let error: Error;
const error = new Error();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you're correct. I always thought the stack was where the error was thrown, but it's actually just where it was constructed?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is correct. Can also change the catch to which is more readable.

  }).catch((err) => {
    // Create the error here so the stack shows who called this function.
    return Promise.reject(new Error(err));
  });

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you do the new Error in the catch callback doesn't that mean the stack trace will be just the callback?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right

@jbedard
jbedard force-pushed the e2e-error-stacks branch 2 times, most recently from f1cdb91 to e5c5c4e Compare August 5, 2022 18:26
@jbedard
jbedard requested a review from alan-agius4 August 5, 2022 18:29
reject(
`Process output didn't match - "${cmd} ${args.join(' ')}": '${
options.waitForMatch
}': ${code}...\n\n${envDump()}\n`,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note both the code (formerly error) and the envDump() were not here previously.

@alan-agius4 alan-agius4 added target: patch This PR is targeted for the next patch release action: merge The PR is ready for merge by the caretaker labels Aug 8, 2022
@clydin
clydin merged commit 9171543 into angular:main Aug 9, 2022
@angular-automatic-lock-bot

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Sep 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants