fix: add missing await statements (#5918)

Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
This commit is contained in:
Jamie Magee 2020-04-09 12:47:48 +02:00 committed by GitHub
parent faa2810f98
commit d4f6aa4bc5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 97 additions and 39 deletions

View file

@ -50,6 +50,7 @@ module.exports = {
// TODO: fix lint // TODO: fix lint
'@typescript-eslint/camelcase': 0, // disabled until ?? '@typescript-eslint/camelcase': 0, // disabled until ??
'@typescript-eslint/no-explicit-any': 0, '@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/no-floating-promises': 2,
'@typescript-eslint/no-non-null-assertion': 0, '@typescript-eslint/no-non-null-assertion': 0,
'@typescript-eslint/no-unused-vars': [ '@typescript-eslint/no-unused-vars': [
2, 2,

View file

@ -27,11 +27,16 @@ jest.mock('../../../lib/platform');
jest.mock('../../../lib/datasource/docker'); jest.mock('../../../lib/datasource/docker');
jest.mock('../../../lib/util/host-rules'); jest.mock('../../../lib/util/host-rules');
jest.mock('./host-rules'); jest.mock('./host-rules');
jest.mock('../../util/exec/docker/index', () =>
require('../../../test/util').mockPartial('../../util/exec/docker/index', {
removeDanglingContainers: jest.fn(),
})
);
let config; let config;
describe('bundler.updateArtifacts()', () => { describe('bundler.updateArtifacts()', () => {
beforeEach(() => { beforeEach(async () => {
jest.resetAllMocks(); jest.resetAllMocks();
jest.resetModules(); jest.resetModules();
@ -44,7 +49,7 @@ describe('bundler.updateArtifacts()', () => {
env.getChildProcessEnv.mockReturnValue(envMock.basic); env.getChildProcessEnv.mockReturnValue(envMock.basic);
bundlerHostRules.findAllAuthenticatable.mockReturnValue([]); bundlerHostRules.findAllAuthenticatable.mockReturnValue([]);
resetPrefetchedImages(); resetPrefetchedImages();
setUtilConfig(config); await setUtilConfig(config);
}); });
it('returns null by default', async () => { it('returns null by default', async () => {
expect( expect(
@ -114,8 +119,8 @@ describe('bundler.updateArtifacts()', () => {
expect(execSnapshots).toMatchSnapshot(); expect(execSnapshots).toMatchSnapshot();
}); });
describe('Docker', () => { describe('Docker', () => {
beforeEach(() => { beforeEach(async () => {
setUtilConfig({ ...config, binarySource: BinarySource.Docker }); await setUtilConfig({ ...config, binarySource: BinarySource.Docker });
}); });
it('.ruby-version', async () => { it('.ruby-version', async () => {
platform.getFile.mockResolvedValueOnce('Current Gemfile.lock'); platform.getFile.mockResolvedValueOnce('Current Gemfile.lock');

View file

@ -18,6 +18,11 @@ const fs: jest.Mocked<typeof _fs> = _fs as any;
const exec: jest.Mock<typeof _exec> = _exec as any; const exec: jest.Mock<typeof _exec> = _exec as any;
const env = mocked(_env); const env = mocked(_env);
const platform = mocked(_platform); const platform = mocked(_platform);
jest.mock('../../util/exec/docker/index', () =>
require('../../../test/util').mockPartial('../../util/exec/docker/index', {
removeDanglingContainers: jest.fn(),
})
);
const config = { const config = {
// `join` fixes Windows CI // `join` fixes Windows CI
@ -26,12 +31,12 @@ const config = {
}; };
describe('.updateArtifacts()', () => { describe('.updateArtifacts()', () => {
beforeEach(() => { beforeEach(async () => {
jest.resetAllMocks(); jest.resetAllMocks();
jest.resetModules(); jest.resetModules();
env.getChildProcessEnv.mockReturnValue(envMock.basic); env.getChildProcessEnv.mockReturnValue(envMock.basic);
setExecConfig(config); await setExecConfig(config);
resetPrefetchedImages(); resetPrefetchedImages();
}); });
it('returns null if no Cargo.lock found', async () => { it('returns null if no Cargo.lock found', async () => {
@ -86,7 +91,7 @@ describe('.updateArtifacts()', () => {
expect(execSnapshots).toMatchSnapshot(); expect(execSnapshots).toMatchSnapshot();
}); });
it('returns updated Cargo.lock with docker', async () => { it('returns updated Cargo.lock with docker', async () => {
setExecConfig({ ...config, binarySource: BinarySource.Docker }); await setExecConfig({ ...config, binarySource: BinarySource.Docker });
platform.getFile.mockResolvedValueOnce('Old Cargo.lock'); platform.getFile.mockResolvedValueOnce('Old Cargo.lock');
const execSnapshots = mockExecAll(exec); const execSnapshots = mockExecAll(exec);
fs.readFile.mockResolvedValueOnce('New Cargo.lock' as any); fs.readFile.mockResolvedValueOnce('New Cargo.lock' as any);

View file

@ -28,10 +28,10 @@ const config = {
}; };
describe('.updateArtifacts()', () => { describe('.updateArtifacts()', () => {
beforeEach(() => { beforeEach(async () => {
jest.resetAllMocks(); jest.resetAllMocks();
env.getChildProcessEnv.mockReturnValue(envMock.basic); env.getChildProcessEnv.mockReturnValue(envMock.basic);
setExecConfig(config); await setExecConfig(config);
datasource.getReleases.mockResolvedValue({ datasource.getReleases.mockResolvedValue({
releases: [ releases: [
@ -114,7 +114,7 @@ describe('.updateArtifacts()', () => {
}); });
it('returns updated Podfile', async () => { it('returns updated Podfile', async () => {
const execSnapshots = mockExecAll(exec); const execSnapshots = mockExecAll(exec);
setExecConfig({ ...config, binarySource: BinarySource.Docker }); await setExecConfig({ ...config, binarySource: BinarySource.Docker });
platform.getFile.mockResolvedValueOnce('Old Podfile'); platform.getFile.mockResolvedValueOnce('Old Podfile');
platform.getRepoStatus.mockResolvedValueOnce({ platform.getRepoStatus.mockResolvedValueOnce({
modified: ['Podfile.lock'], modified: ['Podfile.lock'],
@ -132,7 +132,7 @@ describe('.updateArtifacts()', () => {
}); });
it('returns updated Podfile and Pods files', async () => { it('returns updated Podfile and Pods files', async () => {
const execSnapshots = mockExecAll(exec); const execSnapshots = mockExecAll(exec);
setExecConfig({ ...config, binarySource: BinarySource.Docker }); await setExecConfig({ ...config, binarySource: BinarySource.Docker });
platform.getFile.mockResolvedValueOnce('Old Podfile'); platform.getFile.mockResolvedValueOnce('Old Podfile');
platform.getFile.mockResolvedValueOnce('Old Manifest.lock'); platform.getFile.mockResolvedValueOnce('Old Manifest.lock');
platform.getRepoStatus.mockResolvedValueOnce({ platform.getRepoStatus.mockResolvedValueOnce({
@ -185,7 +185,7 @@ describe('.updateArtifacts()', () => {
it('dynamically selects Docker image tag', async () => { it('dynamically selects Docker image tag', async () => {
const execSnapshots = mockExecAll(exec); const execSnapshots = mockExecAll(exec);
setExecConfig({ await setExecConfig({
...config, ...config,
binarySource: 'docker', binarySource: 'docker',
dockerUser: 'ubuntu', dockerUser: 'ubuntu',
@ -210,7 +210,7 @@ describe('.updateArtifacts()', () => {
it('falls back to the `latest` Docker image tag', async () => { it('falls back to the `latest` Docker image tag', async () => {
const execSnapshots = mockExecAll(exec); const execSnapshots = mockExecAll(exec);
setExecConfig({ await setExecConfig({
...config, ...config,
binarySource: 'docker', binarySource: 'docker',
dockerUser: 'ubuntu', dockerUser: 'ubuntu',

View file

@ -22,6 +22,11 @@ const fs: jest.Mocked<typeof _fs> = _fs as any;
const exec: jest.Mock<typeof _exec> = _exec as any; const exec: jest.Mock<typeof _exec> = _exec as any;
const env = mocked(_env); const env = mocked(_env);
const platform = mocked(_platform); const platform = mocked(_platform);
jest.mock('../../util/exec/docker/index', () =>
require('../../../test/util').mockPartial('../../util/exec/docker/index', {
removeDanglingContainers: jest.fn(),
})
);
const config = { const config = {
// `join` fixes Windows CI // `join` fixes Windows CI
@ -31,11 +36,11 @@ const config = {
}; };
describe('.updateArtifacts()', () => { describe('.updateArtifacts()', () => {
beforeEach(() => { beforeEach(async () => {
jest.resetAllMocks(); jest.resetAllMocks();
jest.resetModules(); jest.resetModules();
env.getChildProcessEnv.mockReturnValue(envMock.basic); env.getChildProcessEnv.mockReturnValue(envMock.basic);
setUtilConfig(config); await setUtilConfig(config);
resetPrefetchedImages(); resetPrefetchedImages();
}); });
it('returns if no composer.lock found', async () => { it('returns if no composer.lock found', async () => {
@ -124,7 +129,7 @@ describe('.updateArtifacts()', () => {
expect(execSnapshots).toMatchSnapshot(); expect(execSnapshots).toMatchSnapshot();
}); });
it('supports docker mode', async () => { it('supports docker mode', async () => {
setUtilConfig({ ...config, binarySource: BinarySource.Docker }); await setUtilConfig({ ...config, binarySource: BinarySource.Docker });
platform.getFile.mockResolvedValueOnce('Current composer.lock'); platform.getFile.mockResolvedValueOnce('Current composer.lock');
const execSnapshots = mockExecAll(exec); const execSnapshots = mockExecAll(exec);

View file

@ -22,6 +22,11 @@ const fs: jest.Mocked<typeof _fs> = _fs as any;
const exec: jest.Mock<typeof _exec> = _exec as any; const exec: jest.Mock<typeof _exec> = _exec as any;
const env = mocked(_env); const env = mocked(_env);
const platform = mocked(_platform); const platform = mocked(_platform);
jest.mock('../../util/exec/docker/index', () =>
require('../../../test/util').mockPartial('../../util/exec/docker/index', {
removeDanglingContainers: jest.fn(),
})
);
const gomod1 = `module github.com/renovate-tests/gomod1 const gomod1 = `module github.com/renovate-tests/gomod1
@ -49,13 +54,13 @@ const goEnv = {
}; };
describe('.updateArtifacts()', () => { describe('.updateArtifacts()', () => {
beforeEach(() => { beforeEach(async () => {
jest.resetAllMocks(); jest.resetAllMocks();
jest.resetModules(); jest.resetModules();
delete process.env.GOPATH; delete process.env.GOPATH;
env.getChildProcessEnv.mockReturnValue({ ...envMock.basic, ...goEnv }); env.getChildProcessEnv.mockReturnValue({ ...envMock.basic, ...goEnv });
setUtilConfig(config); await setUtilConfig(config);
resetPrefetchedImages(); resetPrefetchedImages();
}); });
it('returns if no go.sum found', async () => { it('returns if no go.sum found', async () => {
@ -104,7 +109,7 @@ describe('.updateArtifacts()', () => {
expect(execSnapshots).toMatchSnapshot(); expect(execSnapshots).toMatchSnapshot();
}); });
it('supports docker mode without credentials', async () => { it('supports docker mode without credentials', async () => {
setUtilConfig({ ...config, binarySource: BinarySource.Docker }); await setUtilConfig({ ...config, binarySource: BinarySource.Docker });
platform.getFile.mockResolvedValueOnce('Current go.sum'); platform.getFile.mockResolvedValueOnce('Current go.sum');
const execSnapshots = mockExecAll(exec); const execSnapshots = mockExecAll(exec);
platform.getRepoStatus.mockResolvedValueOnce({ platform.getRepoStatus.mockResolvedValueOnce({
@ -145,7 +150,7 @@ describe('.updateArtifacts()', () => {
expect(execSnapshots).toMatchSnapshot(); expect(execSnapshots).toMatchSnapshot();
}); });
it('supports docker mode with credentials', async () => { it('supports docker mode with credentials', async () => {
setUtilConfig({ ...config, binarySource: BinarySource.Docker }); await setUtilConfig({ ...config, binarySource: BinarySource.Docker });
hostRules.find.mockReturnValueOnce({ hostRules.find.mockReturnValueOnce({
token: 'some-token', token: 'some-token',
}); });
@ -169,7 +174,7 @@ describe('.updateArtifacts()', () => {
expect(execSnapshots).toMatchSnapshot(); expect(execSnapshots).toMatchSnapshot();
}); });
it('supports docker mode with credentials and appMode enabled', async () => { it('supports docker mode with credentials and appMode enabled', async () => {
setUtilConfig({ ...config, binarySource: BinarySource.Docker }); await setUtilConfig({ ...config, binarySource: BinarySource.Docker });
hostRules.find.mockReturnValueOnce({ hostRules.find.mockReturnValueOnce({
token: 'some-token', token: 'some-token',
}); });

View file

@ -26,8 +26,8 @@ async function resetTestFiles() {
} }
describe(getName(__filename), () => { describe(getName(__filename), () => {
beforeAll(() => { beforeAll(async () => {
setUtilConfig(config); await setUtilConfig(config);
}); });
beforeEach(() => { beforeEach(() => {
jest.resetAllMocks(); jest.resetAllMocks();

View file

@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-floating-promises */
import fs from 'fs-extra'; import fs from 'fs-extra';
import * as upath from 'upath'; import * as upath from 'upath';
import { exec as _exec } from 'child_process'; import { exec as _exec } from 'child_process';

View file

@ -15,6 +15,11 @@ jest.mock('fs-extra');
jest.mock('child_process'); jest.mock('child_process');
jest.mock('../../util/exec/env'); jest.mock('../../util/exec/env');
jest.mock('../../util/host-rules'); jest.mock('../../util/host-rules');
jest.mock('../../util/exec/docker/index', () =>
require('../../../test/util').mockPartial('../../util/exec/docker/index', {
removeDanglingContainers: jest.fn(),
})
);
const fs: jest.Mocked<typeof _fs> = _fs as any; const fs: jest.Mocked<typeof _fs> = _fs as any;
const exec: jest.Mock<typeof _exec> = _exec as any; const exec: jest.Mock<typeof _exec> = _exec as any;
@ -31,7 +36,7 @@ const config = {
const dockerConfig = { ...config, binarySource: BinarySource.Docker }; const dockerConfig = { ...config, binarySource: BinarySource.Docker };
describe('.updateArtifacts()', () => { describe('.updateArtifacts()', () => {
beforeEach(() => { beforeEach(async () => {
jest.resetAllMocks(); jest.resetAllMocks();
env.getChildProcessEnv.mockReturnValue({ env.getChildProcessEnv.mockReturnValue({
...envMock.basic, ...envMock.basic,
@ -39,7 +44,7 @@ describe('.updateArtifacts()', () => {
LC_ALL: 'en_US', LC_ALL: 'en_US',
}); });
setUtilConfig(config); await setUtilConfig(config);
resetPrefetchedImages(); resetPrefetchedImages();
}); });
@ -85,7 +90,7 @@ describe('.updateArtifacts()', () => {
expect(execSnapshots).toMatchSnapshot(); expect(execSnapshots).toMatchSnapshot();
}); });
it('supports docker mode', async () => { it('supports docker mode', async () => {
setUtilConfig(dockerConfig); await setUtilConfig(dockerConfig);
platform.getFile.mockResolvedValueOnce('Current Pipfile.lock'); platform.getFile.mockResolvedValueOnce('Current Pipfile.lock');
const execSnapshots = mockExecAll(exec); const execSnapshots = mockExecAll(exec);
platform.getRepoStatus.mockResolvedValue({ platform.getRepoStatus.mockResolvedValue({

View file

@ -12,6 +12,11 @@ import { resetPrefetchedImages } from '../../util/exec/docker';
jest.mock('fs-extra'); jest.mock('fs-extra');
jest.mock('child_process'); jest.mock('child_process');
jest.mock('../../util/exec/env'); jest.mock('../../util/exec/env');
jest.mock('../../util/exec/docker/index', () =>
require('../../../test/util').mockPartial('../../util/exec/docker/index', {
removeDanglingContainers: jest.fn(),
})
);
const fs: jest.Mocked<typeof _fs> = _fs as any; const fs: jest.Mocked<typeof _fs> = _fs as any;
const exec: jest.Mock<typeof _exec> = _exec as any; const exec: jest.Mock<typeof _exec> = _exec as any;
@ -22,10 +27,10 @@ const config = {
}; };
describe('.updateArtifacts()', () => { describe('.updateArtifacts()', () => {
beforeEach(() => { beforeEach(async () => {
jest.resetAllMocks(); jest.resetAllMocks();
env.getChildProcessEnv.mockReturnValue(envMock.basic); env.getChildProcessEnv.mockReturnValue(envMock.basic);
setExecConfig(config); await setExecConfig(config);
resetPrefetchedImages(); resetPrefetchedImages();
}); });
it('returns null if no poetry.lock found', async () => { it('returns null if no poetry.lock found', async () => {
@ -80,7 +85,7 @@ describe('.updateArtifacts()', () => {
expect(execSnapshots).toMatchSnapshot(); expect(execSnapshots).toMatchSnapshot();
}); });
it('returns updated poetry.lock using docker', async () => { it('returns updated poetry.lock using docker', async () => {
setExecConfig({ await setExecConfig({
...config, ...config,
binarySource: BinarySource.Docker, binarySource: BinarySource.Docker,
dockerUser: 'foobar', dockerUser: 'foobar',

View file

@ -48,8 +48,8 @@ describe('platform/azure', () => {
}); });
}); });
afterEach(() => { afterEach(async () => {
azure.cleanRepo(); await azure.cleanRepo();
}); });
// do we need the args? // do we need the args?

View file

@ -48,8 +48,8 @@ describe('platform/bitbucket', () => {
}); });
}); });
afterEach(() => { afterEach(async () => {
bitbucket.cleanRepo(); await bitbucket.cleanRepo();
}); });
async function mockedGet(path: string) { async function mockedGet(path: string) {

View file

@ -243,7 +243,7 @@ export async function initRepo({
}: RepoParams): Promise<RepoConfig> { }: RepoParams): Promise<RepoConfig> {
logger.debug(`initRepo("${repository}")`); logger.debug(`initRepo("${repository}")`);
// config is used by the platform api itself, not necessary for the app layer to know // config is used by the platform api itself, not necessary for the app layer to know
cleanRepo(); await cleanRepo();
// istanbul ignore if // istanbul ignore if
if (endpoint) { if (endpoint) {
// Necessary for Renovate Pro - do not remove // Necessary for Renovate Pro - do not remove

View file

@ -54,8 +54,8 @@ describe('platform/gitlab', () => {
}); });
}); });
afterEach(() => { afterEach(async () => {
gitlab.cleanRepo(); await gitlab.cleanRepo();
}); });
describe('initPlatform()', () => { describe('initPlatform()', () => {
@ -164,8 +164,8 @@ describe('platform/gitlab', () => {
}); });
}); });
describe('cleanRepo()', () => { describe('cleanRepo()', () => {
it('exists', () => { it('exists', async () => {
gitlab.cleanRepo(); await gitlab.cleanRepo();
}); });
}); });

View file

@ -5,6 +5,7 @@ import * as globalWorker from './workers/global';
proxy.bootstrap(); proxy.bootstrap();
// eslint-disable-next-line @typescript-eslint/no-floating-promises
(async (): Promise<void> => { (async (): Promise<void> => {
process.exitCode = await globalWorker.start(); process.exitCode = await globalWorker.start();
})(); })();

View file

@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-floating-promises */
import { import {
exec as _cpExec, exec as _cpExec,
ExecOptions as ChildProcessExecOptions, ExecOptions as ChildProcessExecOptions,

View file

@ -1,3 +1,4 @@
import * as upath from 'upath';
import { platform as _platform } from '../lib/platform'; import { platform as _platform } from '../lib/platform';
import { getConfig } from '../lib/config/defaults'; import { getConfig } from '../lib/config/defaults';
import { RenovateConfig as _RenovateConfig } from '../lib/config'; import { RenovateConfig as _RenovateConfig } from '../lib/config';
@ -10,6 +11,27 @@ export function mocked<T>(module: T): jest.Mocked<T> {
return module as never; return module as never;
} }
/**
* Partially mock a module, providing an object with explicit mocks
* @param moduleName The module to mock
* @param overrides An object containing the mocks
* @example
* jest.mock('../../util/exec/docker/index', () =>
* require('../../../test/util').mockPartial('../../util/exec/docker/index', {
* removeDanglingContainers: jest.fn(),
* })
* );
*/
export function mockPartial(moduleName: string, overrides?: object): unknown {
const absolutePath = upath.join(module.parent.filename, '../', moduleName);
const originalModule = jest.requireActual(absolutePath);
return {
__esModule: true,
...originalModule,
...overrides,
};
}
/** /**
* Simply wrapper to create partial mocks. * Simply wrapper to create partial mocks.
* @param obj Object to cast to final type * @param obj Object to cast to final type

View file

@ -1,5 +1,6 @@
import shell from 'shelljs'; import shell from 'shelljs';
// eslint-disable-next-line @typescript-eslint/no-floating-promises
(async () => { (async () => {
shell.echo('-n', 'Checking re2 ... '); shell.echo('-n', 'Checking re2 ... ');
try { try {

View file

@ -57,6 +57,7 @@ async function generate({
await updateFile(`lib/${path}/api.generated.ts`, code.replace(/^\s+/gm, '')); await updateFile(`lib/${path}/api.generated.ts`, code.replace(/^\s+/gm, ''));
} }
// eslint-disable-next-line @typescript-eslint/no-floating-promises
(async () => { (async () => {
try { try {
// datasources // datasources

View file

@ -21,7 +21,7 @@ shell.echo(`Publishing version: ${version}`);
// err = true; // err = true;
// } // }
// eslint-disable-next-line promise/valid-params // eslint-disable-next-line promise/valid-params,@typescript-eslint/no-floating-promises
import('./dispatch-release.mjs').catch(); import('./dispatch-release.mjs').catch();
// if (err) { // if (err) {