fix: some APIs modified for ASAR support cannot be util.promisify'ed (#13845)
This commit is contained in:
parent
eb79ad4dab
commit
c52b3d921e
2 changed files with 123 additions and 5 deletions
|
@ -2,6 +2,7 @@ const assert = require('assert')
|
|||
const ChildProcess = require('child_process')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const util = require('util')
|
||||
const {closeWindow} = require('./window-helpers')
|
||||
|
||||
const nativeImage = require('electron').nativeImage
|
||||
|
@ -549,6 +550,60 @@ describe('asar package', function () {
|
|||
})
|
||||
})
|
||||
|
||||
describe('fs.exists', function () {
|
||||
it('handles an existing file', function (done) {
|
||||
var p = path.join(fixtures, 'asar', 'a.asar', 'file1')
|
||||
// eslint-disable-next-line
|
||||
fs.exists(p, function (exists) {
|
||||
assert.equal(exists, true)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('handles a non-existent file', function (done) {
|
||||
var p = path.join(fixtures, 'asar', 'a.asar', 'not-exist')
|
||||
// eslint-disable-next-line
|
||||
fs.exists(p, function (exists) {
|
||||
assert.equal(exists, false)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('promisified version handles an existing file', (done) => {
|
||||
var p = path.join(fixtures, 'asar', 'a.asar', 'file1')
|
||||
// eslint-disable-next-line
|
||||
util.promisify(fs.exists)(p).then(exists => {
|
||||
assert.equal(exists, true)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('promisified version handles a non-existent file', function (done) {
|
||||
var p = path.join(fixtures, 'asar', 'a.asar', 'not-exist')
|
||||
// eslint-disable-next-line
|
||||
util.promisify(fs.exists)(p).then(exists => {
|
||||
assert.equal(exists, false)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('fs.existsSync', function () {
|
||||
it('handles an existing file', function () {
|
||||
var p = path.join(fixtures, 'asar', 'a.asar', 'file1')
|
||||
assert.doesNotThrow(function () {
|
||||
assert.equal(fs.existsSync(p), true)
|
||||
})
|
||||
})
|
||||
|
||||
it('handles a non-existent file', function () {
|
||||
var p = path.join(fixtures, 'asar', 'a.asar', 'not-exist')
|
||||
assert.doesNotThrow(function () {
|
||||
assert.equal(fs.existsSync(p), false)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('fs.access', function () {
|
||||
it('accesses a normal file', function (done) {
|
||||
var p = path.join(fixtures, 'asar', 'a.asar', 'file1')
|
||||
|
@ -644,6 +699,12 @@ describe('asar package', function () {
|
|||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('can be promisified', () => {
|
||||
return util.promisify(ChildProcess.exec)('echo ' + echo + ' foo bar').then(({ stdout }) => {
|
||||
assert.equal(stdout.toString().replace(/\r/g, ''), echo + ' foo bar\n')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('child_process.execSync', function () {
|
||||
|
@ -680,6 +741,12 @@ describe('asar package', function () {
|
|||
var output = execFileSync(echo, ['test'])
|
||||
assert.equal(String(output), 'test\n')
|
||||
})
|
||||
|
||||
it('can be promisified', () => {
|
||||
return util.promisify(ChildProcess.execFile)(echo, ['test']).then(({ stdout }) => {
|
||||
assert.equal(stdout, 'test\n')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('internalModuleReadJSON', function () {
|
||||
|
@ -700,6 +767,18 @@ describe('asar package', function () {
|
|||
})
|
||||
})
|
||||
|
||||
describe('util.promisify', function () {
|
||||
it('can promisify all fs functions', function () {
|
||||
const originalFs = require('original-fs')
|
||||
|
||||
for (const key in originalFs) {
|
||||
if (originalFs[key][util.promisify.custom] && !fs[key][util.promisify.custom]) {
|
||||
assert(false, `fs.${key}[util.promisify.custom] missing`)
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('process.noAsar', function () {
|
||||
var errorName = process.platform === 'win32' ? 'ENOENT' : 'ENOTDIR'
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue