From 8bf8eb8171ad2bd4d8f6a0fb0a9755d3a2b6f99b Mon Sep 17 00:00:00 2001 From: Ryan Zimmerman Date: Mon, 13 May 2019 12:53:26 -0400 Subject: [PATCH 1/5] Add support for fs.realpath.native in envs that support it --- lib/fs/__tests__/realpath.test.js | 24 ++++++++++++++++++++++++ lib/fs/index.js | 5 +++++ 2 files changed, 29 insertions(+) create mode 100644 lib/fs/__tests__/realpath.test.js diff --git a/lib/fs/__tests__/realpath.test.js b/lib/fs/__tests__/realpath.test.js new file mode 100644 index 00000000..c3374bb7 --- /dev/null +++ b/lib/fs/__tests__/realpath.test.js @@ -0,0 +1,24 @@ +'use strict' + +const fs = require('fs') +const fse = require('../..') +const assert = require('assert') + +/* eslint-env mocha */ + +// fs.realpath.native only available in Node v9.2+ +if (typeof fs.realpath.native === 'function') { + describe('realpath.native', () => { + it('works with callbacks', () => { + fse.realpath.native(__dirname, (err, path) => { + assert.ifError(err) + assert.equal(path, __dirname) + }) + }) + + it('works with promises', async () => { + const path = await fse.realpath.native(__dirname) + assert.equal(path, __dirname) + }) + }) +} diff --git a/lib/fs/index.js b/lib/fs/index.js index 8ffdf7b0..a7b22922 100644 --- a/lib/fs/index.js +++ b/lib/fs/index.js @@ -102,3 +102,8 @@ exports.write = function (fd, buffer, ...args) { }) }) } + +// fs.realpath.native only available in Node v9.2+ +if (typeof fs.realpath.native === 'function') { + exports.realpath.native = u(fs.realpath.native) +} From 4585044278bb35ff88da3c313cc1ef7de1d97c14 Mon Sep 17 00:00:00 2001 From: Ryan Zimmerman Date: Mon, 13 May 2019 12:57:43 -0400 Subject: [PATCH 2/5] Fix syntax for Node 6 --- lib/fs/__tests__/realpath.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fs/__tests__/realpath.test.js b/lib/fs/__tests__/realpath.test.js index c3374bb7..80d10ba7 100644 --- a/lib/fs/__tests__/realpath.test.js +++ b/lib/fs/__tests__/realpath.test.js @@ -16,7 +16,7 @@ if (typeof fs.realpath.native === 'function') { }) }) - it('works with promises', async () => { + it('works with promises', async function () { const path = await fse.realpath.native(__dirname) assert.equal(path, __dirname) }) From 2a5ec0446b4695f1b72e7bd481e77fe11078b597 Mon Sep 17 00:00:00 2001 From: Ryan Zimmerman Date: Mon, 13 May 2019 13:06:31 -0400 Subject: [PATCH 3/5] Don't use async/await --- lib/fs/__tests__/realpath.test.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/fs/__tests__/realpath.test.js b/lib/fs/__tests__/realpath.test.js index 80d10ba7..96a84016 100644 --- a/lib/fs/__tests__/realpath.test.js +++ b/lib/fs/__tests__/realpath.test.js @@ -16,9 +16,13 @@ if (typeof fs.realpath.native === 'function') { }) }) - it('works with promises', async function () { - const path = await fse.realpath.native(__dirname) - assert.equal(path, __dirname) + it('works with promises', (done) => { + fse.realpath.native(__dirname) + .then(path => { + assert.equal(path, __dirname) + done() + }) + .catch(done) }) }) } From cb8d327ce4d13617cbf53c8a543221e5b123bbc8 Mon Sep 17 00:00:00 2001 From: Ryan Zimmerman Date: Mon, 13 May 2019 13:55:59 -0400 Subject: [PATCH 4/5] Add test for realpathSync.native --- lib/fs/__tests__/realpath.test.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/fs/__tests__/realpath.test.js b/lib/fs/__tests__/realpath.test.js index 96a84016..1322b8ea 100644 --- a/lib/fs/__tests__/realpath.test.js +++ b/lib/fs/__tests__/realpath.test.js @@ -24,5 +24,10 @@ if (typeof fs.realpath.native === 'function') { }) .catch(done) }) + + it('works with sync version', () => { + const path = fse.realpathSync.native(__dirname) + assert.equal(path, __dirname) + }) }) } From 889361713e3fccc9b6ee878cd20e505d6a443306 Mon Sep 17 00:00:00 2001 From: Ryan Zimmerman Date: Tue, 14 May 2019 07:08:44 -0400 Subject: [PATCH 5/5] assert.equal -> assert.strictEqual --- lib/fs/__tests__/realpath.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/fs/__tests__/realpath.test.js b/lib/fs/__tests__/realpath.test.js index 1322b8ea..59ee6fa3 100644 --- a/lib/fs/__tests__/realpath.test.js +++ b/lib/fs/__tests__/realpath.test.js @@ -12,14 +12,14 @@ if (typeof fs.realpath.native === 'function') { it('works with callbacks', () => { fse.realpath.native(__dirname, (err, path) => { assert.ifError(err) - assert.equal(path, __dirname) + assert.strictEqual(path, __dirname) }) }) it('works with promises', (done) => { fse.realpath.native(__dirname) .then(path => { - assert.equal(path, __dirname) + assert.strictEqual(path, __dirname) done() }) .catch(done) @@ -27,7 +27,7 @@ if (typeof fs.realpath.native === 'function') { it('works with sync version', () => { const path = fse.realpathSync.native(__dirname) - assert.equal(path, __dirname) + assert.strictEqual(path, __dirname) }) }) }