From 2a581726c667121ebfa8a014bcefca3e608f6200 Mon Sep 17 00:00:00 2001 From: bcheidemann Date: Sat, 20 Feb 2021 02:38:43 +0000 Subject: [PATCH 01/24] feat: add shims for file system providers --- shims/providers/default.js | 2 ++ shims/providers/indexeddb.js | 2 ++ shims/providers/memory.js | 2 ++ 3 files changed, 6 insertions(+) create mode 100644 shims/providers/default.js create mode 100644 shims/providers/indexeddb.js create mode 100644 shims/providers/memory.js diff --git a/shims/providers/default.js b/shims/providers/default.js new file mode 100644 index 0000000..2ba8094 --- /dev/null +++ b/shims/providers/default.js @@ -0,0 +1,2 @@ +const { Default } = require('../../src/providers/index'); +module.exports = Default; \ No newline at end of file diff --git a/shims/providers/indexeddb.js b/shims/providers/indexeddb.js new file mode 100644 index 0000000..6e01dc1 --- /dev/null +++ b/shims/providers/indexeddb.js @@ -0,0 +1,2 @@ +const IndexedDB = require('../../src/providers/indexeddb'); +module.exports = IndexedDB; \ No newline at end of file diff --git a/shims/providers/memory.js b/shims/providers/memory.js new file mode 100644 index 0000000..c33cc34 --- /dev/null +++ b/shims/providers/memory.js @@ -0,0 +1,2 @@ +const Memory = require('../../src/providers/memory'); +module.exports = Memory; \ No newline at end of file From ceed84f3770786d8d603edf94c6c2bfb3181ac91 Mon Sep 17 00:00:00 2001 From: bcheidemann Date: Sat, 20 Feb 2021 02:43:21 +0000 Subject: [PATCH 02/24] feat: add shim for fs --- shims/fs.js | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 shims/fs.js diff --git a/shims/fs.js b/shims/fs.js new file mode 100644 index 0000000..832847a --- /dev/null +++ b/shims/fs.js @@ -0,0 +1,56 @@ +const { FileSystem } = require('../src/index'); + +let Provider; +try { + Provider = require('fsprovider'); +} +catch { + Provider = require('./providers/default'); +} + +const provider = new Provider(); + +let onFsReady; +let onFsError; + +let fsReady = new Promise((resolve, reject) => { + onFsReady = resolve; + onFsError = reject; +}); + +var fsInstance = new FileSystem({ provider }, (err) => { + if (err) { + onFsError(err); + } else { + onFsReady(true); + } +}); + +const fsPromises = new Proxy(fsInstance.promises, { + get(target, prop) { + return async (...args) => { + await fsReady; + return await target[prop](...args); + }; + }, +}); + +const fs = new Proxy(fsInstance, { + get(target, prop) { + if (prop === 'promises') { + return fsPromises; + } + + return (...args) => { + (async () => { + await fsReady; + target[prop](...args); + })(); + }; + }, +}); + +module.exports = { + __esModule: true, + default: fs, +}; From 128e10dc1372e2f5c496605c9b92258b197d3393 Mon Sep 17 00:00:00 2001 From: bcheidemann Date: Sat, 20 Feb 2021 03:36:34 +0000 Subject: [PATCH 03/24] docs: add webpack section to README.md --- README.md | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/README.md b/README.md index 61e72bc..1554ed4 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,75 @@ requirejs(['filer'], function(Filer) {...} var Filer = window.Filer; ``` +### Webpack + +Filer can be used as a drop-in replacement for the node.js [fs module](http://nodejs.org/api/fs.html) using webpack. + +In order to use filer in place of fs, insert the following into your webpack config: + +```javascript +// webpack.config.js +module.exports = { + resolve: { + alias: { + 'fs': 'filer/shims/fs.js', + } + } +} +``` + +You can then import the node.js [fs module](http://nodejs.org/api/fs.html) as normal +and the shim will ensure that calls to fs are appropriately handled by filer. + +```javascript +import fs from 'fs'; +``` + +If any calls are made to fs or fs.promises methods before the file system has been +initialised, the shim will automatically delay the call until the file system is ready. + +If you're using filer in a typescript project, the fs shim has the added +benefit of allowing you to use the types for the node.js [fs module](http://nodejs.org/api/fs.html), +which filer tries to match as closely as possible. Note that some methods from fs are +not available, even though typescript will tell you that they are! See [Getting Started](#getting-started) +for more details on filers limitations. + +If you wish to use an alternative file sytem in place of the default (IndexedDB), you must also +include an alias for this in your webpack config. For example, if you wish to use an "in memory" +file system, configure webpack as shown below. + +```javascript +// webpack.config.js +module.exports = { + resolve: { + alias: { + 'fsprovider': 'filer/shims/providers/memory.js', + 'fs': 'filer/shims/fs.js', + } + } +} +``` + +The current options for file system providers are: + +* Default (IndexedDB) - filer/shims/providers/default.js +* IndexedDB - filer/shims/providers/default.js +* Memory - filer/shims/providers/memory.js + +The node.js [path module](http://nodejs.org/api/path.html) also has a shim available, which can +be applied in a similar manner to the node.js [fs module](http://nodejs.org/api/fs.html) shim. + +```javascript +// webpack.config.js +module.exports = { + resolve: { + alias: { + 'path': 'filer/shims/path.js', + } + } +} +``` + ### Getting Started Filer is as close to the node.js [fs module](http://nodejs.org/api/fs.html) as possible, From f12f01dca040cc0652ab0dba09a0edb2f0cfd734 Mon Sep 17 00:00:00 2001 From: bcheidemann Date: Sat, 20 Feb 2021 03:38:52 +0000 Subject: [PATCH 04/24] feat: add path shim --- shims/path.js | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 shims/path.js diff --git a/shims/path.js b/shims/path.js new file mode 100644 index 0000000..ffd0088 --- /dev/null +++ b/shims/path.js @@ -0,0 +1,6 @@ +const path = require("./path.js"); + +module.exports = { + __esModule: true, + default: path, +}; From 4d4b6bf3f3db57743a8a08d6b494ed6919d7f423 Mon Sep 17 00:00:00 2001 From: bcheidemann Date: Sat, 20 Feb 2021 03:54:01 +0000 Subject: [PATCH 05/24] docs: add recommendation to use fsprovider alias in README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 1554ed4..038dceb 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,9 @@ The current options for file system providers are: * IndexedDB - filer/shims/providers/default.js * Memory - filer/shims/providers/memory.js +Though it's technically optional, it is recommended to include an alias for fsprovider in your +webpack config. This will prevent webpack from logging unnecessary warnings. + The node.js [path module](http://nodejs.org/api/path.html) also has a shim available, which can be applied in a similar manner to the node.js [fs module](http://nodejs.org/api/fs.html) shim. From 417a4e97dd2de8a8f203676260574dd8c8aa492f Mon Sep 17 00:00:00 2001 From: bcheidemann Date: Sat, 20 Feb 2021 04:04:37 +0000 Subject: [PATCH 06/24] docs: --- README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/README.md b/README.md index 038dceb..a3ff64a 100644 --- a/README.md +++ b/README.md @@ -112,6 +112,24 @@ The current options for file system providers are: Though it's technically optional, it is recommended to include an alias for fsprovider in your webpack config. This will prevent webpack from logging unnecessary warnings. +If you wish to use your own file system provider with the node.js [fs module](http://nodejs.org/api/fs.html) +shim, it will be necessary to include an alias for fsprovider which points to your providers implementation. +This can be done as follows: + +```javascript +// webpack.config.js +const path = require('path'); + +module.exports = { + resolve: { + alias: { + 'fsprovider': path.resolve(__dirname, 'example/dir/provider.js'), + 'fs': 'filer/shims/fs.js', + } + } +} +``` + The node.js [path module](http://nodejs.org/api/path.html) also has a shim available, which can be applied in a similar manner to the node.js [fs module](http://nodejs.org/api/fs.html) shim. @@ -126,6 +144,13 @@ module.exports = { } ``` +You can then import the node.js [path module](http://nodejs.org/api/path.html) as normal and the +shim will ensure that calls to path are appropriately handled by filer. + +```javascript +import path from 'path'; +``` + ### Getting Started Filer is as close to the node.js [fs module](http://nodejs.org/api/fs.html) as possible, From 9d03788c1cab1ea056645a53d28ed34bad170336 Mon Sep 17 00:00:00 2001 From: bcheidemann Date: Sat, 20 Feb 2021 04:14:24 +0000 Subject: [PATCH 07/24] docs: add own name to authors file --- AUTHORS | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index e40f820..8d0f59f 100644 --- a/AUTHORS +++ b/AUTHORS @@ -5,4 +5,5 @@ Barry Tulchinsky (@btulchinsky) Kieran Sedgwick (@sedge) Yoav Gurevich Gideon Thomas -Abdirahman Guled \ No newline at end of file +Abdirahman Guled +Ben Heidemann \ No newline at end of file From 9c669564b2aa3c9066ea2e48d2d69ad9e187fc96 Mon Sep 17 00:00:00 2001 From: bcheidemann Date: Sun, 21 Feb 2021 00:19:17 +0000 Subject: [PATCH 08/24] refactor: change fsprovider to fsProvider --- README.md | 8 ++++---- shims/fs.js | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a3ff64a..74f3a5a 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ file system, configure webpack as shown below. module.exports = { resolve: { alias: { - 'fsprovider': 'filer/shims/providers/memory.js', + 'fsProvider': 'filer/shims/providers/memory.js', 'fs': 'filer/shims/fs.js', } } @@ -109,11 +109,11 @@ The current options for file system providers are: * IndexedDB - filer/shims/providers/default.js * Memory - filer/shims/providers/memory.js -Though it's technically optional, it is recommended to include an alias for fsprovider in your +Though it's technically optional, it is recommended to include an alias for fsProvider in your webpack config. This will prevent webpack from logging unnecessary warnings. If you wish to use your own file system provider with the node.js [fs module](http://nodejs.org/api/fs.html) -shim, it will be necessary to include an alias for fsprovider which points to your providers implementation. +shim, it will be necessary to include an alias for fsProvider which points to your providers implementation. This can be done as follows: ```javascript @@ -123,7 +123,7 @@ const path = require('path'); module.exports = { resolve: { alias: { - 'fsprovider': path.resolve(__dirname, 'example/dir/provider.js'), + 'fsProvider': path.resolve(__dirname, 'example/dir/provider.js'), 'fs': 'filer/shims/fs.js', } } diff --git a/shims/fs.js b/shims/fs.js index 832847a..a9efa56 100644 --- a/shims/fs.js +++ b/shims/fs.js @@ -2,10 +2,10 @@ const { FileSystem } = require('../src/index'); let Provider; try { - Provider = require('fsprovider'); + Provider = require('fsProvider'); } catch { - Provider = require('./providers/default'); + Provider = require('./providers/default'); } const provider = new Provider(); From 986ad37597b0dc2be02cbbc5bfd8ee43dd856d16 Mon Sep 17 00:00:00 2001 From: bcheidemann Date: Sun, 21 Feb 2021 00:21:20 +0000 Subject: [PATCH 09/24] refactor: get reference to error in catch block fixes red squigle for unexpected { --- shims/fs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shims/fs.js b/shims/fs.js index a9efa56..d60986f 100644 --- a/shims/fs.js +++ b/shims/fs.js @@ -4,7 +4,7 @@ let Provider; try { Provider = require('fsProvider'); } -catch { +catch (err) { Provider = require('./providers/default'); } From 7415e45867d35bc2cf8494c51f56333c2cae8208 Mon Sep 17 00:00:00 2001 From: bcheidemann Date: Sun, 21 Feb 2021 00:24:19 +0000 Subject: [PATCH 10/24] docs: fix typo in README.md replace 'alternative file sytem' with 'alternative file system provider' --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 74f3a5a..5965163 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ which filer tries to match as closely as possible. Note that some methods from f not available, even though typescript will tell you that they are! See [Getting Started](#getting-started) for more details on filers limitations. -If you wish to use an alternative file sytem in place of the default (IndexedDB), you must also +If you wish to use an alternative file system provider in place of the default (IndexedDB), you must also include an alias for this in your webpack config. For example, if you wish to use an "in memory" file system, configure webpack as shown below. From a2f7ee044b04c913ad789ea69c0f3193b79a764f Mon Sep 17 00:00:00 2001 From: bcheidemann Date: Sun, 21 Feb 2021 10:18:57 +0000 Subject: [PATCH 11/24] chore: show console logs when running tests --- karma.conf.js | 1 + 1 file changed, 1 insertion(+) diff --git a/karma.conf.js b/karma.conf.js index 231678d..3944bc9 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -6,6 +6,7 @@ module.exports = function(config) { frameworks: ['mocha', 'chai'], reporters: ['mocha', 'summary'], client: { + captureConsole: true, mocha: { ui: 'bdd', timeout: 5000, From 7ec1fed51f9bc6f9f3e19e212d0ca50bcaf77008 Mon Sep 17 00:00:00 2001 From: bcheidemann Date: Sun, 21 Feb 2021 10:21:03 +0000 Subject: [PATCH 12/24] chore: use regenerator runtime in tests for async/await --- karma.conf.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/karma.conf.js b/karma.conf.js index 3944bc9..aa7d677 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -2,7 +2,10 @@ module.exports = function(config) { config.set({ singleRun: true, basePath: '', - files: ['tests/dist/index.js'], + files: [ + 'node_modules/regenerator-runtime/runtime.js', + 'tests/dist/index.js' + ], frameworks: ['mocha', 'chai'], reporters: ['mocha', 'summary'], client: { From 0f5fe64ae8e5e1271a71a939c42d13a49a6c44c2 Mon Sep 17 00:00:00 2001 From: bcheidemann Date: Sun, 21 Feb 2021 10:25:43 +0000 Subject: [PATCH 13/24] chore: npm install regenerator-runtime --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 21d612b..d5584da 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "minimatch": "^3.0.4" }, "devDependencies": { + "regenerator-runtime": "^0.13.7", "chai": "^4.2.0", "chai-datetime": "^1.5.0", "eslint": "^6.8.0", From ce809c4ac93d01a360d35f41d34963ed2bf3f67e Mon Sep 17 00:00:00 2001 From: bcheidemann Date: Sun, 7 Mar 2021 14:58:09 +0000 Subject: [PATCH 14/24] feat: add buffer shim --- shims/buffer.js | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 shims/buffer.js diff --git a/shims/buffer.js b/shims/buffer.js new file mode 100644 index 0000000..746e7eb --- /dev/null +++ b/shims/buffer.js @@ -0,0 +1,7 @@ +const { Buffer } = require('filer'); + +module.exports = { + __esModule: true, + default: Buffer, + Buffer, +}; From d264113e0ddd4ebdb4c8816673ec920cf580e2b0 Mon Sep 17 00:00:00 2001 From: bcheidemann Date: Sun, 7 Mar 2021 14:58:35 +0000 Subject: [PATCH 15/24] docs: add documentation for use of buffer shim to README.md --- README.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/README.md b/README.md index 5965163..6a64714 100644 --- a/README.md +++ b/README.md @@ -151,6 +151,51 @@ shim will ensure that calls to path are appropriately handled by filer. import path from 'path'; ``` +It may be necessary in certain cases to shim the node.js [Buffer object](http://nodejs.org/api/buffer.html). This can be impoerted as follows: + +```javascript +import path from 'path'; +``` + +As such it can be shimmed in much the same way as path and fs: + +```javascript +// webpack.config.js +module.exports = { + resolve: { + alias: { + 'buffer': 'filer/shims/buffer.js', + } + } +} +``` + +However, the Buffer object is globally defined in a node environment and many third party libraries will not import (or require) it. +Using the resolve alias alone will be ineffective in such cases. Instead we must expand our webpack config to use webpacks +[provide plugin](https://webpack.js.org/plugins/provide-plugin/), which will automatically load the module without the need for an import +or require. This can be implemented as follows: + +```javascript +// webpack.config.js +const webpack = require('webpack'); + +module.exports = { + resolve: { + alias: { + 'buffer': 'filer/shims/buffer.js', + } + }, + plugins: [ + new webpack.ProvidePlugin({ + Buffer: 'buffer', + }), + ] +} +``` + +This will, in effect, make the Buffer object shim globally available in the same way that the node.js +[Buffer object](http://nodejs.org/api/buffer.html) is in a node environment. + ### Getting Started Filer is as close to the node.js [fs module](http://nodejs.org/api/fs.html) as possible, From aa152955b50f9a8450f4a458b634f24c57ff79fe Mon Sep 17 00:00:00 2001 From: bcheidemann Date: Sun, 7 Mar 2021 15:01:05 +0000 Subject: [PATCH 16/24] refactor: use correct path import in shim --- shims/path.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shims/path.js b/shims/path.js index ffd0088..46dd292 100644 --- a/shims/path.js +++ b/shims/path.js @@ -1,4 +1,4 @@ -const path = require("./path.js"); +const { path } = require('../src/index'); module.exports = { __esModule: true, From da65e06e3c841b9d9bec400dd17a75d74feeb774 Mon Sep 17 00:00:00 2001 From: bcheidemann Date: Sun, 7 Mar 2021 15:01:51 +0000 Subject: [PATCH 17/24] test: run fs shim spec test --- tests/index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/index.js b/tests/index.js index beb517f..a0f6e3b 100644 --- a/tests/index.js +++ b/tests/index.js @@ -3,6 +3,9 @@ * get them running by default. */ +// Shims +require('./spec/shims/fs.spec'); + // Filer require('./spec/filer.spec'); require('./spec/filer.buffer.spec.js'); From d6b29226aa37559fceeadb6641ec045fd195893b Mon Sep 17 00:00:00 2001 From: bcheidemann Date: Sun, 7 Mar 2021 15:02:29 +0000 Subject: [PATCH 18/24] refactor: return result of fn when wrapping in utils.shimIndexDB --- tests/lib/test-utils.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/lib/test-utils.js b/tests/lib/test-utils.js index 2c58bb3..fd4461a 100644 --- a/tests/lib/test-utils.js +++ b/tests/lib/test-utils.js @@ -52,11 +52,13 @@ function shimIndexedDB(fn) { global.indexedDB = require('fake-indexeddb'); } - fn(); + var result = fn(); if(addShim) { delete global.indexedDB; } + + return result; } function setup(callback) { From 8b57d299f4c0e276f59c2f7644119cb58e147b91 Mon Sep 17 00:00:00 2001 From: bcheidemann Date: Sun, 7 Mar 2021 15:05:18 +0000 Subject: [PATCH 19/24] test: add test for fs shim --- tests/spec/shims/fs.spec.js | 44 +++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tests/spec/shims/fs.spec.js diff --git a/tests/spec/shims/fs.spec.js b/tests/spec/shims/fs.spec.js new file mode 100644 index 0000000..d8fb5a4 --- /dev/null +++ b/tests/spec/shims/fs.spec.js @@ -0,0 +1,44 @@ +'use strict'; +const expect = require('chai').expect; +const utils = require('../../lib/test-utils'); +const fs = utils.shimIndexedDB(() => require('../../../shims/fs').default); + +describe.only('fs shim', () => { + it('should be defined', () => { + expect(fs).to.not.be.undefined; + }); + + it('should be an object', () => { + expect(typeof fs).to.equal('object'); + }); + + it('should return a function when accessing fs.writeFile', () => { + expect(typeof fs.writeFile).to.equal('function'); + }); + + it('should call callback when calling fs.writeFile', (done) => { + fs.writeFile('/test.txt', 'test', function(err) { + if(err) throw err; + + done(); + }); + }); + + it('should return an object when accessing fs.promises', () => { + expect(typeof fs.promises).to.equal('object'); + }); + + it('should return a function when accessing fs.promises.writeFile', () => { + expect(typeof fs.promises.writeFile).to.equal('function'); + }); + + it('should return a promise which resolves when calling fs.promises.writeFile', (done) => { + const writeFilePromise = fs.promises.writeFile('/test2.txt', ''); + expect(writeFilePromise instanceof Promise).to.equal(true); + writeFilePromise.then(() => { + done(); + }).catch((err) => { + done(err); + }); + }); +}); From 6027376efaa3f6a8bed2e5908d7cf53feebd5386 Mon Sep 17 00:00:00 2001 From: bcheidemann Date: Sun, 7 Mar 2021 15:20:58 +0000 Subject: [PATCH 20/24] refactor: use correct import for Buffer in buffer shim --- shims/buffer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shims/buffer.js b/shims/buffer.js index 746e7eb..8b15727 100644 --- a/shims/buffer.js +++ b/shims/buffer.js @@ -1,4 +1,4 @@ -const { Buffer } = require('filer'); +const { Buffer } = require('../src/index'); module.exports = { __esModule: true, From 15be384940da87d2ecb7d2488791ed9553925426 Mon Sep 17 00:00:00 2001 From: bcheidemann Date: Sun, 7 Mar 2021 15:21:11 +0000 Subject: [PATCH 21/24] test: run tests for path and buffer --- tests/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/index.js b/tests/index.js index a0f6e3b..e9245e6 100644 --- a/tests/index.js +++ b/tests/index.js @@ -5,6 +5,8 @@ // Shims require('./spec/shims/fs.spec'); +require('./spec/shims/path.spec'); +require('./spec/shims/buffer.spec'); // Filer require('./spec/filer.spec'); From 3a8a59d362af1c3f616be56cb6c89629a0576ede Mon Sep 17 00:00:00 2001 From: bcheidemann Date: Sun, 7 Mar 2021 15:21:28 +0000 Subject: [PATCH 22/24] test: add spec for buffer shim --- tests/spec/shims/buffer.spec.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 tests/spec/shims/buffer.spec.js diff --git a/tests/spec/shims/buffer.spec.js b/tests/spec/shims/buffer.spec.js new file mode 100644 index 0000000..888207a --- /dev/null +++ b/tests/spec/shims/buffer.spec.js @@ -0,0 +1,23 @@ +'use strict'; +const expect = require('chai').expect; +const bufferDefault = require('../../../shims/buffer').default; +const bufferNamed = require('../../../shims/buffer').Buffer; +const bufferActual = require('../../../src/index').Buffer; + +describe.only('path shim', () => { + it('default export should be defined', () => { + expect(bufferDefault).to.not.be.undefined; + }); + + it('named export should be defined', () => { + expect(bufferNamed).to.not.be.undefined; + }); + + it('default export should be re-exposing Buffer', () => { + expect(bufferDefault).to.equal(bufferActual); + }); + + it('named export should be re-exposing Buffer', () => { + expect(bufferNamed).to.equal(bufferActual); + }); +}); From a2151cab25b48471770a2a3e3b6c958cdfbb1d95 Mon Sep 17 00:00:00 2001 From: bcheidemann Date: Sun, 7 Mar 2021 15:21:39 +0000 Subject: [PATCH 23/24] test: add spec for path shim --- tests/spec/shims/path.spec.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 tests/spec/shims/path.spec.js diff --git a/tests/spec/shims/path.spec.js b/tests/spec/shims/path.spec.js new file mode 100644 index 0000000..0432aca --- /dev/null +++ b/tests/spec/shims/path.spec.js @@ -0,0 +1,14 @@ +'use strict'; +const expect = require('chai').expect; +const path = require('../../../shims/path').default; +const pathActual = require('../../../src/index').path; + +describe.only('path shim', () => { + it('should be defined', () => { + expect(path).to.not.be.undefined; + }); + + it('should be re-exposing path', () => { + expect(path).to.equal(pathActual); + }); +}); From 887ed9318a5bf9d4d60f9e1ae2c049283a76130d Mon Sep 17 00:00:00 2001 From: bcheidemann Date: Sun, 7 Mar 2021 15:25:52 +0000 Subject: [PATCH 24/24] docs: fix buffer import example in README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6a64714..e1e73d5 100644 --- a/README.md +++ b/README.md @@ -154,7 +154,7 @@ import path from 'path'; It may be necessary in certain cases to shim the node.js [Buffer object](http://nodejs.org/api/buffer.html). This can be impoerted as follows: ```javascript -import path from 'path'; +import { Buffer } from 'buffer'; ``` As such it can be shimmed in much the same way as path and fs: