diff options
author | Jordan Harband <ljharb@gmail.com> | 2021-02-09 00:49:04 +0300 |
---|---|---|
committer | Gar <gar+gh@danger.computer> | 2021-02-12 20:35:10 +0300 |
commit | 868954a72c06ff2210b35e1e75571f4ec3357c43 (patch) | |
tree | 6d4b502d156229ad7e18013dc6bf93dfa9bb19b4 /test | |
parent | 37e8cc507b2ce0b89f92e7e77b1d909d1bf5513f (diff) |
[fix] node v10.0 lacks `fs.promises`
In this node version, fall back to `util.promisify` of the callback version.
Maybe fixes https://github.com/npm/cli/issues/2623. Maybe fixes https://github.com/npm/cli/issues/2652. Maybe fixes https://github.com/npm/cli/issues/2625.
PR-URL: https://github.com/npm/cli/pull/2654
Credit: @ljharb
Close: #2654
Reviewed-by: @wraithgar, @ruyadorno
Diffstat (limited to 'test')
-rw-r--r-- | test/lib/shrinkwrap.js | 8 | ||||
-rw-r--r-- | test/lib/utils/reify-finish.js | 10 |
2 files changed, 17 insertions, 1 deletions
diff --git a/test/lib/shrinkwrap.js b/test/lib/shrinkwrap.js index 65b16b147..ed8fd329c 100644 --- a/test/lib/shrinkwrap.js +++ b/test/lib/shrinkwrap.js @@ -1,4 +1,5 @@ const t = require('tap') +const fs = require('fs') const requireInject = require('require-inject') const npm = { @@ -327,3 +328,10 @@ t.test('shrinkwrap --global', t => { t.end() }) }) + +t.test('works without fs.promises', async t => { + t.doesNotThrow(() => requireInject('../../lib/shrinkwrap.js', { + ...mocks, + fs: { ...fs, promises: null }, + })) +}) diff --git a/test/lib/utils/reify-finish.js b/test/lib/utils/reify-finish.js index d6c7d2e7b..39277f21a 100644 --- a/test/lib/utils/reify-finish.js +++ b/test/lib/utils/reify-finish.js @@ -20,7 +20,7 @@ let expectWrite = false const realFs = require('fs') const fs = { ...realFs, - promises: { + promises: realFs.promises && { ...realFs.promises, writeFile: async (path, data) => { if (!expectWrite) @@ -78,3 +78,11 @@ t.test('should write if everything above passes', async t => { const data = fs.readFileSync(`${path}/npmrc`, 'utf8').replace(/\r\n/g, '\n') t.matchSnapshot(data, 'written config') }) + +t.test('works without fs.promises', async t => { + t.doesNotThrow(() => requireInject('../../../lib/utils/reify-finish.js', { + fs: { ...fs, promises: null }, + '../../../lib/npm.js': npm, + '../../../lib/utils/reify-output.js': reifyOutput, + })) +}) |