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

replace deprecated New Buffer() with Buffer.from() #3330

Merged
merged 1 commit into from
Apr 18, 2018

Conversation

harrysarson
Copy link
Contributor

Description of Change

new Buffer() is set to be run time deprecated in node v10 (see nodejs/node#19079 and https://nodejs.org/api/deprecations.html#deprecations_dep0005_buffer_constructor).

I swapped out the usage of new Buffer() for Buffer.from() in mocha's integration tests.

This should be semver patch.

@outsideris
Copy link
Contributor

outsideris commented Apr 18, 2018

Mocha still support node.js v4 and Buffer.from is introduced since v5.10.0.
Supporting node v4 will be drop soon.
This PR should be merged after dropping support node v4, I think.

@outsideris outsideris added the qa label Apr 18, 2018
@harrysarson
Copy link
Contributor Author

@outsideris Buffer.from is already used in mocha. I found it here:

expect(stringify(Buffer.from([0x01]))).to.equal('[\n 1\n]');

The tests pass on node 4 even with this change. It seems the buffer.from was actually added in node v4.5 despite what the docs say:

harry@home:~$ nvm use 4.4
Now using node v4.4.7 (npm v2.15.8)
harry@home:~$ node
> Buffer.from('hi')
TypeError: this is not a typed array.
    at Function.from (native)
    at repl:1:8
    at REPLServer.defaultEval (repl.js:262:27)
    at bound (domain.js:287:14)
    at REPLServer.runBound [as eval] (domain.js:300:12)
    at REPLServer.<anonymous> (repl.js:431:12)
    at emitOne (events.js:82:20)
    at REPLServer.emit (events.js:169:7)
    at REPLServer.Interface._onLine (readline.js:211:10)
    at REPLServer.Interface._line (readline.js:550:8)
> .exit
harry@home:~$ nvm use 4.5
Now using node v4.5.0 (npm v2.15.9)
harry@home:~$ node
> Buffer.from('hi')
<Buffer 68 69>

@boneskull boneskull added the semver-patch implementation requires increase of "patch" version number; "bug fixes" label Apr 18, 2018
@boneskull
Copy link
Contributor

LGTM. Buffer.from() in v4.x only accepts a single parameter, but it's still present in all v4.x versions.

Netlify failure unrelated.

@harrysarson Thanks!

@boneskull boneskull merged commit a6115ac into mochajs:master Apr 18, 2018
@boneskull boneskull added this to the next milestone Apr 18, 2018
@harrysarson harrysarson deleted the patch-1 branch April 18, 2018 17:53
@outsideris
Copy link
Contributor

@harrysarson My bad. I didn't know that node v4 support Buffer.from.

@harrysarson
Copy link
Contributor Author

No worries, the node docs are definately unclear about this.

@boneskull
Copy link
Contributor

Yeah, I had to dig into the commit history to figure it out 😝

wopian referenced this pull request in wopian/agc-assembly May 20, 2018
This Pull Request updates dependency [mocha](https://github.com/mochajs/mocha) from `~5.1.0` to `~5.2.0`



<details>
<summary>Release Notes</summary>

### [`v5.2.0`](https://github.com/mochajs/mocha/blob/master/CHANGELOG.md#&#8203;520--2018-05-18)
[Compare Source](mochajs/mocha@v5.1.1...v5.2.0)
#### 🎉 Enhancements

- [#&#8203;3375]: Add support for comments in `mocha.opts` ([@&#8203;plroebuck])
#### 🐛 Fixes

- [#&#8203;3346]: Exit correctly from `before` hooks when using `--bail` ([@&#8203;outsideris])
#### 📖 Documentation

- [#&#8203;3328]: Mocha-flavored [API docs](https://mochajs.org/api/)! ([@&#8203;Munter])
#### 🔩 Other

- [#&#8203;3330]: Use `Buffer.from()` ([@&#8203;harrysarson])
- [#&#8203;3295]: Remove redundant folder ([@&#8203;DavNej])
- [#&#8203;3356](`https://github.com/mochajs/mocha/pull/3356`): Refactoring ([@&#8203;plroebuck])

[#&#8203;3375]: `https://github.com/mochajs/mocha/pull/3375`
[#&#8203;3346]: `https://github.com/mochajs/mocha/pull/3346`
[#&#8203;3328]: `https://github.com/mochajs/mocha/pull/3328`
[#&#8203;3330]: `https://github.com/mochajs/mocha/pull/3330`
[#&#8203;3295]: `https://github.com/mochajs/mocha/pull/3295`

[@&#8203;plroebuck]: https://github.com/plroebuck
[@&#8203;harrysarson]: https://github.com/harrysarson
[@&#8203;outsideris]: https://github.com/outsideris
[@&#8203;Munter]: https://github.com/Munter

---

</details>




---

This PR has been generated by [Renovate Bot](https://renovatebot.com).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-patch implementation requires increase of "patch" version number; "bug fixes"
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants