From f50d00abd6754db2ad2eb84a49369830ea7add2f Mon Sep 17 00:00:00 2001 From: Luca Greco Date: Fri, 27 Sep 2019 14:30:27 +0200 Subject: [PATCH] chore(flow): Fixed new flow-check errors detected by flow 0.108.0 --- src/util/promisify.js | 8 ++++++++ src/util/temp-dir.js | 4 ++-- tests/unit/test-firefox/test.remote.js | 8 ++++++++ tests/unit/test-util/test.promisify.js | 7 +++++-- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/util/promisify.js b/src/util/promisify.js index 311b16b257..c381dcde64 100644 --- a/src/util/promisify.js +++ b/src/util/promisify.js @@ -1,5 +1,13 @@ /* @flow */ +import {promisify} from 'util'; + +// promisify.custom is missing from the node types know to flow, +// and it triggers flow-check errors if used directly. +// By using the value exported here, flow-check passes successfully +// without using FLOW_IGNORE supress comments. +export const promisifyCustom = promisify.custom; + /* * A small promisify helper to make it easier to customize a * function promisified (using the 'util' module available in diff --git a/src/util/temp-dir.js b/src/util/temp-dir.js index ed7c32c74a..ea4ccf7ea9 100644 --- a/src/util/temp-dir.js +++ b/src/util/temp-dir.js @@ -4,13 +4,13 @@ import {promisify} from 'util'; import tmp from 'tmp'; import {createLogger} from './logger'; -import {multiArgsPromisedFn} from './promisify'; +import {multiArgsPromisedFn, promisifyCustom} from './promisify'; const log = createLogger(__filename); export type MakePromiseCallback = (tmpDir: TempDir) => any; -tmp.dir[promisify.custom] = multiArgsPromisedFn(tmp.dir); +tmp.dir[promisifyCustom] = multiArgsPromisedFn(tmp.dir); const createTempDir = promisify(tmp.dir); diff --git a/tests/unit/test-firefox/test.remote.js b/tests/unit/test-firefox/test.remote.js index 53ce8a11ca..5beb4bdc54 100644 --- a/tests/unit/test-firefox/test.remote.js +++ b/tests/unit/test-firefox/test.remote.js @@ -180,6 +180,7 @@ describe('firefox.remote', () => { const stubResponse = {requestTypes: ['reload']}; const conn = makeInstance(); + // $FLOW_IGNORE: allow overwrite not writable property for testing purpose. conn.addonRequest = sinon.spy(() => Promise.resolve(stubResponse)); const returnedAddon = await conn.checkForAddonReloading(addon); @@ -197,6 +198,7 @@ describe('firefox.remote', () => { const stubResponse = {requestTypes: ['install']}; const conn = makeInstance(); + // $FLOW_IGNORE: allow overwrite not writable property for testing purpose. conn.addonRequest = () => Promise.resolve(stubResponse); await conn.checkForAddonReloading(addon) @@ -210,6 +212,7 @@ describe('firefox.remote', () => { const addon = fakeAddon(); const conn = makeInstance(); + // $FLOW_IGNORE: allow overwrite not writable property for testing purpose. conn.addonRequest = sinon.spy(() => Promise.resolve({requestTypes: ['reload']})); const checkedAddon = await conn.checkForAddonReloading(addon); @@ -292,9 +295,12 @@ describe('firefox.remote', () => { const addon = fakeAddon(); const conn = makeInstance(); + // $FLOW_IGNORE: allow overwrite not writable property for testing purpose. conn.getInstalledAddon = sinon.spy(() => Promise.resolve(addon)); + // $FLOW_IGNORE: allow overwrite not writable property for testing purpose. conn.checkForAddonReloading = (addonToCheck) => Promise.resolve(addonToCheck); + // $FLOW_IGNORE: allow overwrite not writable property for testing purpose. conn.addonRequest = sinon.spy(() => Promise.resolve({})); await conn.reloadAddon('some-id'); @@ -311,7 +317,9 @@ describe('firefox.remote', () => { const addon = fakeAddon(); const conn = makeInstance(); + // $FLOW_IGNORE: allow overwrite not writable property for testing purpose. conn.getInstalledAddon = () => Promise.resolve(addon); + // $FLOW_IGNORE: allow overwrite not writable property for testing purpose. conn.checkForAddonReloading = sinon.spy((addonToCheck) => Promise.resolve(addonToCheck)); diff --git a/tests/unit/test-util/test.promisify.js b/tests/unit/test-util/test.promisify.js index 9f16af818b..9dbe6c0e9c 100644 --- a/tests/unit/test-util/test.promisify.js +++ b/tests/unit/test-util/test.promisify.js @@ -5,7 +5,10 @@ import {describe, it} from 'mocha'; import {assert} from 'chai'; import sinon from 'sinon'; -import {multiArgsPromisedFn} from '../../../src/util/promisify'; +import { + multiArgsPromisedFn, + promisifyCustom, +} from '../../../src/util/promisify'; describe('nodejs util.promisify', () => { it('wraps a nodejs callback-based function into a promised function', @@ -67,7 +70,7 @@ describe('web-ext util.promisify.multiArgsPromisedFn custom helper', () => { } }); - fnCallMultiArgs[promisify.custom] = multiArgsPromisedFn(fnCallMultiArgs); + fnCallMultiArgs[promisifyCustom] = multiArgsPromisedFn(fnCallMultiArgs); const promisedFnMultiArgs = promisify(fnCallMultiArgs);