Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: migrate message util tests from Python to JS #49721 #50333

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

jahjahLemonade
Copy link
Contributor

@jahjahLemonade jahjahLemonade commented Oct 23, 2023

Migrate the remaining util tests in the test/message folder from Python to JS.

Fixes: #47707

Migrated tests:

util/
	util-inspect-error-cause.js
	util-inspect-error-cause.out
	util_inspect_error.js
	util_inspect_error.out

Screenshot 2023-10-22 at 10 03 16 PM

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. test Issues and PRs related to the tests. labels Oct 23, 2023
Comment on lines 105 to 110
 at Module._compile (node:internal*modules*cjs*loader**)
 at Module._extensions..js (node:internal*modules*cjs*loader**)
 at Module.load (node:internal*modules*cjs*loader**)
 at Module._load (node:internal*modules*cjs*loader**)
 at Function.executeUserEntryPoint [as runMain] (node:internal*modules*run_main**)
 at node:internal*main*run_main_module**
Copy link
Member

Choose a reason for hiding this comment

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

We don’t want these internals in the snapshots. Renaming a method within the module loader shouldn’t break this unrelated test.

Copy link
Contributor Author

@jahjahLemonade jahjahLemonade Oct 30, 2023

Choose a reason for hiding this comment

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

Hey @GeoffreyBooth or @MoLow , I have a question. I'm making my edits in this PR after realizing I was going about it the wrong way. I'm having a hard time knowing when it's okay to edit the snapshot in order to get the tests to pass. I'm using past commits as a reference. But my question is, for the following, can I edit the snapshot to take " * " or should I edit my JS file to replace " * " with "90m" and "39m"?

+ actual - expected

      'RangeError: New Stack Frames\n' +
      '    at *\n' +
  +   '*[*m    at  *[*m {\n' +
  -   '*[90m    at *[39m {\n' +

Copy link
Member

Choose a reason for hiding this comment

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

You should not edit the snapshots manually, use NODE_REGENERATE_SNAPSHOTS=1 for regenerating snapshots.
you can probably remove colors from the snapshot
str = str.replace(/[^\x00-\x7F]/g, '').replace(/\u001b\[\d+m/g, '')

Copy link
Contributor Author

@jahjahLemonade jahjahLemonade Nov 30, 2023

Choose a reason for hiding this comment

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

@MoLow The linter don't like the control characters.

  22:12  error  Unexpected control character(s) in regular expression: \x00  no-control-regex
  23:12  error  Unexpected control character(s) in regular expression: \x1b  no-control-regex

✖ 2 problems (2 errors, 0 warnings)

Comment on lines 1 to 9
Error: Number error cause
at *
at *
at *
at *
at *
at *
at * {
[cause]: 42
Copy link
Member

Choose a reason for hiding this comment

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

Add Error.stackTraceLimit = 0 (or 1) before the test is run to remove these call stack lines that we don’t care about. Search for Error.stackTraceLimit in other tests to see examples.

Copy link
Contributor Author

@jahjahLemonade jahjahLemonade Oct 23, 2023

Choose a reason for hiding this comment

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

@GeoffreyBooth

Added the following in the .js file locally

Error.stackTraceLimit = 7;

and it worked for me

Copy link
Member

Choose a reason for hiding this comment

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

Using 0 instead of 7 should help suppress the stack trace lines that show the module internals (my other note).

Copy link
Contributor Author

@jahjahLemonade jahjahLemonade Oct 25, 2023

Choose a reason for hiding this comment

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

@GeoffreyBooth I'm assuming I should be adding the line in my test-node-output-util.js file and not the files under fixtures/util? I ran into issues doing that, but not when adding the line to my file under parallel.

Copy link
Member

Choose a reason for hiding this comment

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

I don’t remember. If you search for Error.stackTraceLimit = 0 in the other test files you can copy the pattern they use.

@jahjahLemonade jahjahLemonade marked this pull request as draft October 30, 2023 18:11
@jahjahLemonade jahjahLemonade marked this pull request as ready for review November 30, 2023 00:39
Comment on lines +57 to +63
at Object.<anonymous> *[*m(**[*mtest*fixtures*util*util-inspect-error-cause.js:*:**[*m)*[*m
*[*m at Module._compile (node:internal*modules*cjs*loader:*:*)*[*m
*[*m at Module._extensions..js (node:internal*modules*cjs*loader:*:*)*[*m
*[*m at Module.load (node:internal*modules*cjs*loader:*:*)*[*m
*[*m at Module._load (node:internal*modules*cjs*loader:*:*)*[*m
*[*m at Function.executeUserEntryPoint [as runMain] (node:internal*modules*run_main:*:*)*[*m
*[*m at *[*m
Copy link
Member

Choose a reason for hiding this comment

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

None of these functions should be in the stack trace. I should be able to refactor the internals of the CommonJS loader without breaking unrelated tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-ci PRs that need a full CI run. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

message tests can be migrated from python to JS
4 participants