Skip to content

Commit fa661f3

Browse files
authored
Add support for fs.realpath.native in envs that support it (#682)
* Add support for fs.realpath.native in envs that support it * Add test for realpathSync.native * assert.equal -> assert.strictEqual
1 parent 32a65ff commit fa661f3

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

lib/fs/__tests__/realpath.test.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'use strict'
2+
3+
const fs = require('fs')
4+
const fse = require('../..')
5+
const assert = require('assert')
6+
7+
/* eslint-env mocha */
8+
9+
// fs.realpath.native only available in Node v9.2+
10+
if (typeof fs.realpath.native === 'function') {
11+
describe('realpath.native', () => {
12+
it('works with callbacks', () => {
13+
fse.realpath.native(__dirname, (err, path) => {
14+
assert.ifError(err)
15+
assert.strictEqual(path, __dirname)
16+
})
17+
})
18+
19+
it('works with promises', (done) => {
20+
fse.realpath.native(__dirname)
21+
.then(path => {
22+
assert.strictEqual(path, __dirname)
23+
done()
24+
})
25+
.catch(done)
26+
})
27+
28+
it('works with sync version', () => {
29+
const path = fse.realpathSync.native(__dirname)
30+
assert.strictEqual(path, __dirname)
31+
})
32+
})
33+
}

lib/fs/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,8 @@ exports.write = function (fd, buffer, ...args) {
102102
})
103103
})
104104
}
105+
106+
// fs.realpath.native only available in Node v9.2+
107+
if (typeof fs.realpath.native === 'function') {
108+
exports.realpath.native = u(fs.realpath.native)
109+
}

0 commit comments

Comments
 (0)