Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Conversation

@OmarTawfik
Copy link

Identify the Bug

When trying to write jest tests for a library built on top of oniguruma, tests often failed with the error:

TypeError: Cannot redefine property: length

Which I tracked to this line:

Object.defineProperty(OnigString.prototype, 'length', {

This line adds some additional functionality to the native library imported, before exporting the result. It does so by directly modifying the prototype chain of the native types. If this module is evaluated once, that behavior is safe. But in case where the module cache is updated/modified as the tests are running, reevaluating that module will fail the process.

Description of the Change

To fix this, and enable using this library safely when writing tests, I propose updating the binding to export child types with the augmented functionality. Not only it is more readable, it guards against such failures, by exporting a new type every time.

Possible Drawbacks

First time contibutor, so I'd welcome guidance here.

Verification Process

npm test

Release Notes

N/A - a refactor with no user-facing changes.

@OmarTawfik
Copy link
Author

cc @sadick254

@OmarTawfik
Copy link
Author

I see this is also mentioned in #113
@sadick254 can you please tell me if this is something you are planning on supporting?

@OmarTawfik
Copy link
Author

Closing this as the project doesn't seem actively maintained. Feel free to reopen or ping me if you decide to take this on.

@OmarTawfik OmarTawfik closed this Jan 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant