Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(flow): Fixed new flow-check errors detected by flow 0.108.0 #1718

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/util/promisify.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/util/temp-dir.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
8 changes: 8 additions & 0 deletions tests/unit/test-firefox/test.remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand All @@ -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);
Expand Down Expand Up @@ -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');
Expand All @@ -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));

Expand Down
7 changes: 5 additions & 2 deletions tests/unit/test-util/test.promisify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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);

Expand Down