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

Fix napi_get_value_string_utf8 to match node #7175

Merged
merged 5 commits into from
Nov 17, 2023
Merged

Conversation

oguimbal
Copy link
Contributor

@oguimbal oguimbal commented Nov 17, 2023

closes #6949

What does this PR do?

As described in #6949, the napi_get_value_string_utf8 function does not match Nodejs NAPI behaviour.

This PR:

  • fixes this issue
  • adds unit testing to check that both node & bun behave the same

How did you verify your code works?

I believe NAPI is not unit tested at all.
In this PR, I'm proposing a way to test coherence between bun's NAPI & node's.

It consists of a NAPI node/bun application (in test/napi/napi-app) that can be called by unit tests.

When tests run, it:

  1. Builds the given api application
  2. Runs this application in node (with flags that depends on the test)
  3. Runs this application in bun (using the ./build/bun-debug executable)
  4. Compares both outputs to ensure they are the same.

This is obviously a very opiniated way of testing things, so I'd totaly understand if this not OK.

As a side-note, I did not check wether if this is OK with your build pipeline, as it requires both node and yarn to be available in path.

I ran those tests locally using bun run build && bun test test/napi.

Before fixes:

image

After fixes:
image

  • I included a test for the new code, or existing tests cover it
  • I ran my tests locally and they pass (bun-debug test test-file-name.test)


function checkSameOutput(test: string, args: any[]) {
const nodeResult = runOn("node", test, args).trim();
let bunResult = runOn(join(__dirname, "../../build/bun-debug"), test, args);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
let bunResult = runOn(join(__dirname, "../../build/bun-debug"), test, args);
let bunResult = runOn(bunExe(), test, args);

Copy link
Contributor Author

@oguimbal oguimbal Nov 17, 2023

Choose a reason for hiding this comment

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

If I do this locally, tests fail again as if it was run on the current bun version... is bunExe() supposed to refer to the version of bun built by the pipeline ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

hm. yes, is bun-debug available in $PATH?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, but it's available as bug-debug, not bun. Thus, these tests only pass locally if I run them via bun run build && bun-debug test test/napi (with a lot of noisy logs, obviously).

If that's the executable that runs on your test pipeline instead of the current version of bun, then fine, lets commit that 🙃

Copy link
Collaborator

Choose a reason for hiding this comment

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

The tests pass locally with process.execPath in use and they will not pass in CI without that.

autofix-ci bot and others added 4 commits November 17, 2023 12:21
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
@Jarred-Sumner
Copy link
Collaborator

Thank you for this. I'm going to merge it and then get it running in CI a follow-up PR.

@Jarred-Sumner Jarred-Sumner merged commit 6e7014c into oven-sh:main Nov 17, 2023
19 of 27 checks passed
@Jarred-Sumner Jarred-Sumner mentioned this pull request Nov 17, 2023
@oguimbal
Copy link
Contributor Author

Thanks !

ryoppippi pushed a commit to ryoppippi/bun that referenced this pull request Feb 1, 2024
* fix napi_get_value_string_utf8 to match node
closes oven-sh#6949

* [autofix.ci] apply automated fixes

* Update test/napi/napi.test.ts

Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>

* Update test/napi/napi.test.ts

Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NAPI: napi_get_value_string_utf8 does not behave like nodejs
2 participants