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: migrated test/message to JS fixture tests #47868

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

Conversation

projectnoa
Copy link

test: migrated tests/message to JS fixture tests

Migrated all test located in the test/message directory to the fixtures structure and verified the output to fit the .snapshot representation. All tests passed, except for the following, which were not touched. Documentation has been updated to not reference test/message as an example to run test and has been changed to test/report.

Failing tests:
out/Release/node --expose-internals /home/upx/Documents/Development/Javascript/node/test/parallel/test-fs-copyfile.js
out/Release/node /home/upx/Documents/Development/Javascript/node/test/parallel/test-fs-cp.mjs

Fixes: #47707
Refs: https://eslint.org/docs/rules/space-in-parens.html

@nodejs-github-bot nodejs-github-bot added dependencies Pull requests that update a dependency file. needs-ci PRs that need a full CI run. zlib Issues and PRs related to the zlib subsystem. labels May 5, 2023
@GeoffreyBooth GeoffreyBooth added the test Issues and PRs related to the tests. label May 5, 2023
deps/zlib/zconf.h.included Outdated Show resolved Hide resolved
Copy link
Member

@MoLow MoLow left a comment

Choose a reason for hiding this comment

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

  1. please remove the changed zlib file inside dpes
  2. nothing requires these added fixtures. a test file must execute them using common.assertSnapshot - see https://github.com/nodejs/node/blob/bd913bee367e1ecd308bb7a3e5f6869813add31e/test/parallel/test-node-output-console.mjs and the other tests added in test: migrate message tests to use assertSnapshot #47498

@projectnoa projectnoa changed the title #47707 migrated test/message to JS fixture tests test: migrated test/message to JS fixture tests May 5, 2023
@projectnoa
Copy link
Author

projectnoa commented May 6, 2023

Hi @MoLow,

As requested, I reverted the changes to the zlib files and added the test runner files in the /parallel directory.

  • test-node-output-assertion.mjs
  • test-node-output-map.mjs
  • test-node-output-promise.mjs
  • test-node-output-tick.mjs

Additionally, I modified the test-node-output-console.mjs and test-node-output-errors.mjs to run some of the tests there. Of course, I made sure that the .snapshot files are congruent with the test output and all test succeed.

I was, however, unable to figure out how to make the test util-inspect-error-cause.js evaluate correctly with the snapshot since the output seems to have some special characters that don't play well with RegEx.

Here's an example:

`My attempts to turn the following:

    at Object.<anonymous> \x1B[90m(/\x1B[39mtest*util-inspect-error-cause.js:*:*\x1B[90m)\x1B[39m
\x1B[90m    at Module._compile (node:internal*modules*cjs*loader:*:*)\x1B[39m
\x1B[90m    at Module._extensions..js (node:internal*modules*cjs*loader:*:*)\x1B[39m
\x1B[90m    at Module.load (node:internal*modules*cjs*loader:*:*)\x1B[39m
\x1B[90m    at Module._load (node:internal*modules*cjs*loader:*:*)\x1B[39m
\x1B[90m    at Function.executeUserEntryPoint [as runMain] (node:internal*modules*run_main:*:*)\x1B[39m
\x1B[90m   at node:internal*main*run_main_module:*:*\x1B[39m

into:

    at *
*[90m    at *[39m
*[90m    at *[39m
*[90m    at *[39m
*[90m    at *[39m
*[90m    at *[39m
*[90m    at *[39m

where not successful.`

This is the RegEx I was using:

`
const regex = /(\x1B[\d+m|(.)|<.>|/|\w+:)(?=[\n])/g;
const outputString = inputString.replace(regex, '
');

console.log(outputString);
`

I would appreciate the input and help.

Thanks!

Screenshot 2023-05-05 at 5 09 00 PM

@projectnoa projectnoa requested a review from MoLow May 6, 2023 00:34
@projectnoa projectnoa requested a review from MoLow May 8, 2023 17:59
@targos
Copy link
Member

targos commented May 9, 2023

I don't know what should be the prefix of the test file names, but test-node- doesn't seem right.

@projectnoa
Copy link
Author

I don't know what should be the prefix of the test file names, but test-node- doesn't seem right.

I totally agree, but I couldn't figure out a clear pattern or methodology for naming all these diverse tests. Open to suggestions. Thanks @targos!

@MoLow
Copy link
Member

MoLow commented May 10, 2023

perhaps test-output , or test-message or test-snapshot?

@projectnoa
Copy link
Author

@MoLow Test runner name prefix changed to test-output.

Let me know of any other observations.

Thanks!

@MoLow
Copy link
Member

MoLow commented May 16, 2023

Let me know of any other observations.

see comment: https://github.com/nodejs/node/pull/47868/files#r1187744266
lets keep this PR lean with a minimal diff

Copy link
Member

Choose a reason for hiding this comment

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

please revert all deleted files

@MoLow
Copy link
Member

MoLow commented May 17, 2023

this PR will need to be squashed / remove all merge commits

@projectnoa
Copy link
Author

this PR will need to be squashed / remove all merge commits

Apologies @MoLow but I am not versed enough in git to figure out how to squash the commits when there's a merge in between.

Could anybody help me here?

Appreciate the help and I'm sorry for my ignorance.

Thanks!

@MoLow
Copy link
Member

MoLow commented May 18, 2023

You would probably want to:

git fetch upstream main
git rebase upstream/main 
git reset --soft upstream/main
git add .
git commit -m "test: migrate message tests to js fixtures"

@projectnoa
Copy link
Author

You would probably want to:

git fetch upstream main
git rebase upstream/main 
git reset --soft upstream/main
git add .
git commit -m "test: migrate message tests to js fixtures"

@MoLow I ran the commands and merged the changes. I don't believe the squashing of the commits was achieved tho. I'm struggling to figure this out. I'm holding back this PR with my lack of experience with git.

@projectnoa
Copy link
Author

@MoLow

Should I discard this PR and create a new one with only the changes in one commit?

@MoLow
Copy link
Member

MoLow commented May 23, 2023

either that, or squash this PR into a commit with no merge commits, and no conflicts

@projectnoa projectnoa force-pushed the enhancement/message-tests-can-be-migrated-from-python-to-JS-#47707 branch from 33591bb to 555b9fc Compare May 23, 2023 19:25
test: migrate message tests to js fixtures squashed

Add test runners to /parallel dir and fix snapshot

Update test/parallel/test-node-output-tick.mjs

Co-authored-by: Moshe Atlow <[email protected]>

Update test/parallel/test-node-output-promise.mjs

Co-authored-by: Moshe Atlow <[email protected]>

Update test/parallel/test-node-output-assertion.mjs

Co-authored-by: Moshe Atlow <[email protected]>

Update test/parallel/test-node-output-map.mjs

Co-authored-by: Moshe Atlow <[email protected]>

fixed snapshot discrepancy with output-errors.mjs

Corrected test runner name prefix

Removing snapshots that show as 'new' on git diff

Restored deleted files

Deleted files restored
@projectnoa projectnoa force-pushed the enhancement/message-tests-can-be-migrated-from-python-to-JS-#47707 branch from 555b9fc to 2df37de Compare May 23, 2023 19:26
@projectnoa
Copy link
Author

either that, or squash this PR into a commit with no merge commits, and no conflicts

Figured out how to properly squash the PR commits. Apologies for the hassle.

@projectnoa
Copy link
Author

@MoLow let me know of any other observations.

Thanks!

@projectnoa projectnoa requested a review from MoLow May 31, 2023 03:56
@@ -0,0 +1,10 @@
node:punycode:*
Copy link
Member

Choose a reason for hiding this comment

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

@projectnoa there are still many files that do not appear as moved

@projectnoa
Copy link
Author

Hi @MoLow,

Could you please provide some guidance?

I really appreciate your help.

Thanks!

@MoLow
Copy link
Member

MoLow commented Jun 7, 2023

Could you please provide some guidance?

Sure, you should go over the diff of this PR and undo any changes to files that are not marked as moved

@projectnoa
Copy link
Author

projectnoa commented Jun 7, 2023

Could you please provide some guidance?

Sure, you should go over the diff of this PR and undo any changes to files that are not marked as moved

@MoLow
Won't this break the tests? Some files will not have the changes that are needed for the new tests to work.

@MoLow
Copy link
Member

MoLow commented Jun 7, 2023

if it brakes tests, lets revert that as well.
I think this PR should have a minimal diff

@projectnoa
Copy link
Author

if it brakes tests, lets revert that as well.
I think this PR should have a minimal diff

So, if I understand correctly.

  1. All .out files that were moved into fixtures as a .snapshot file must have the original content (I must not regenerate or modify these outputs).
  2. Any .js files that cannot validate this original output must be reverted and left on the messages directory.
  3. All .mjs files that run the tests don't apply to the previous rules since they are new.

Is this correct @MoLow ?

@MoLow
Copy link
Member

MoLow commented Jun 15, 2023

All .out files that were moved into fixtures as a .snapshot file must have the original content (I must not regenerate or modify these outputs).

I don't think having the original content is a must. I only asked the diff to be small enough for git to detect it as a file rename

Any .js files that cannot validate this original output must be reverted and left on the messages directory.

for this phase, yes - then we can iterate in smaller PR's that can be reviewed more carfully

All .mjs files that run the tests don't apply to the previous rules since they are new.

correct. they also do not have to be mjs files, that was just done for convenience

@projectnoa
Copy link
Author

Hello @MoLow, @NiharPhansalkar,

I did my best to restore the .snapshots to their original state so they show as Edited and not New. Additionally, I restored the original Python tests in the message directory. I was unable to make the following test pass (stdin_messages.js, eval_messages.js, core_line_numbers.js, util-inspect-error-cause.js) since the contents of some of the .out files is just too different to the output produced by the tests. In the end I was just bending over backwards to twist the code to validate the test, which defeats the purpose of tests.

If anybody is smart enough to figure where I went wrong and want to fix this PR, please do so. Otherwise, this is where I end my journey with this contribution, for my sanity's sake.

I apologize for not being able to figure this out and make a proper contribution.

Feel free to discard this PR if the effort of fixing it is not worth it.

Thanks

@MoLow
Copy link
Member

MoLow commented Jul 12, 2023

I don't think we should make the tests reduce the diff. just ship a first PR where all diffs are minimal, excluding tests that are more complicated. then in follow-up PRS - we can handle those tests with a bigger diff

require('../../common');
require('../source-map/uglify-throw');
require('../common');
require('../fixtures/source-map/uglify-throw');
Copy link
Member

Choose a reason for hiding this comment

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

I think in general we want all files to end with a newline.


Node.js *
Node.js *
Copy link
Member

Choose a reason for hiding this comment

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

Why are all these files not ending with newlines? Aren’t they autogenerated?

Comment on lines +6 to +13
at new Script (node:vm:*:*)
at createScript (node:vm:*:*)
at Object.runInThisContext (node:vm:*:*)
at node:internal/process/execution:*:*
at [eval]-wrapper:*:*
at runScript (node:internal/process/execution:*:*)
at evalScript (node:internal/process/execution:*:*)
at node:internal/main/eval_string:*:*
Copy link
Member

Choose a reason for hiding this comment

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

This stack trace is a step backward; this test will break if this call path ever changes, which isn’t something that should be breaking a test. Can we eliminate this from the snapshot, perhaps by updating the snapshot generation script if necessary?

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

Successfully merging this pull request may close these issues.

message tests can be migrated from python to JS
5 participants