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
'@typescript-eslint/camelcase': 0, // disabled until ??
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/no-floating-promises': 2,
'@typescript-eslint/no-non-null-assertion': 0,
'@typescript-eslint/no-unused-vars': [
2,

View file

@ -27,11 +27,16 @@ jest.mock('../../../lib/platform');
jest.mock('../../../lib/datasource/docker');
jest.mock('../../../lib/util/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;
describe('bundler.updateArtifacts()', () => {
beforeEach(() => {
beforeEach(async () => {
jest.resetAllMocks();
jest.resetModules();
@ -44,7 +49,7 @@ describe('bundler.updateArtifacts()', () => {
env.getChildProcessEnv.mockReturnValue(envMock.basic);
bundlerHostRules.findAllAuthenticatable.mockReturnValue([]);
resetPrefetchedImages();
setUtilConfig(config);
await setUtilConfig(config);
});
it('returns null by default', async () => {
expect(
@ -114,8 +119,8 @@ describe('bundler.updateArtifacts()', () => {
expect(execSnapshots).toMatchSnapshot();
});
describe('Docker', () => {
beforeEach(() => {
setUtilConfig({ ...config, binarySource: BinarySource.Docker });
beforeEach(async () => {
await setUtilConfig({ ...config, binarySource: BinarySource.Docker });
});
it('.ruby-version', async () => {
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 env = mocked(_env);
const platform = mocked(_platform);
jest.mock('../../util/exec/docker/index', () =>
require('../../../test/util').mockPartial('../../util/exec/docker/index', {
removeDanglingContainers: jest.fn(),
})
);
const config = {
// `join` fixes Windows CI
@ -26,12 +31,12 @@ const config = {
};
describe('.updateArtifacts()', () => {
beforeEach(() => {
beforeEach(async () => {
jest.resetAllMocks();
jest.resetModules();
env.getChildProcessEnv.mockReturnValue(envMock.basic);
setExecConfig(config);
await setExecConfig(config);
resetPrefetchedImages();
});
it('returns null if no Cargo.lock found', async () => {
@ -86,7 +91,7 @@ describe('.updateArtifacts()', () => {
expect(execSnapshots).toMatchSnapshot();
});
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');
const execSnapshots = mockExecAll(exec);
fs.readFile.mockResolvedValueOnce('New Cargo.lock' as any);

View file

@ -28,10 +28,10 @@ const config = {
};
describe('.updateArtifacts()', () => {
beforeEach(() => {
beforeEach(async () => {
jest.resetAllMocks();
env.getChildProcessEnv.mockReturnValue(envMock.basic);
setExecConfig(config);
await setExecConfig(config);
datasource.getReleases.mockResolvedValue({
releases: [
@ -114,7 +114,7 @@ describe('.updateArtifacts()', () => {
});
it('returns updated Podfile', async () => {
const execSnapshots = mockExecAll(exec);
setExecConfig({ ...config, binarySource: BinarySource.Docker });
await setExecConfig({ ...config, binarySource: BinarySource.Docker });
platform.getFile.mockResolvedValueOnce('Old Podfile');
platform.getRepoStatus.mockResolvedValueOnce({
modified: ['Podfile.lock'],
@ -132,7 +132,7 @@ describe('.updateArtifacts()', () => {
});
it('returns updated Podfile and Pods files', async () => {
const execSnapshots = mockExecAll(exec);
setExecConfig({ ...config, binarySource: BinarySource.Docker });
await setExecConfig({ ...config, binarySource: BinarySource.Docker });
platform.getFile.mockResolvedValueOnce('Old Podfile');
platform.getFile.mockResolvedValueOnce('Old Manifest.lock');
platform.getRepoStatus.mockResolvedValueOnce({
@ -185,7 +185,7 @@ describe('.updateArtifacts()', () => {
it('dynamically selects Docker image tag', async () => {
const execSnapshots = mockExecAll(exec);
setExecConfig({
await setExecConfig({
...config,
binarySource: 'docker',
dockerUser: 'ubuntu',
@ -210,7 +210,7 @@ describe('.updateArtifacts()', () => {
it('falls back to the `latest` Docker image tag', async () => {
const execSnapshots = mockExecAll(exec);
setExecConfig({
await setExecConfig({
...config,
binarySource: 'docker',
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 env = mocked(_env);
const platform = mocked(_platform);
jest.mock('../../util/exec/docker/index', () =>
require('../../../test/util').mockPartial('../../util/exec/docker/index', {
removeDanglingContainers: jest.fn(),
})
);
const config = {
// `join` fixes Windows CI
@ -31,11 +36,11 @@ const config = {
};
describe('.updateArtifacts()', () => {
beforeEach(() => {
beforeEach(async () => {
jest.resetAllMocks();
jest.resetModules();
env.getChildProcessEnv.mockReturnValue(envMock.basic);
setUtilConfig(config);
await setUtilConfig(config);
resetPrefetchedImages();
});
it('returns if no composer.lock found', async () => {
@ -124,7 +129,7 @@ describe('.updateArtifacts()', () => {
expect(execSnapshots).toMatchSnapshot();
});
it('supports docker mode', async () => {
setUtilConfig({ ...config, binarySource: BinarySource.Docker });
await setUtilConfig({ ...config, binarySource: BinarySource.Docker });
platform.getFile.mockResolvedValueOnce('Current composer.lock');
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 env = mocked(_env);
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
@ -49,13 +54,13 @@ const goEnv = {
};
describe('.updateArtifacts()', () => {
beforeEach(() => {
beforeEach(async () => {
jest.resetAllMocks();
jest.resetModules();
delete process.env.GOPATH;
env.getChildProcessEnv.mockReturnValue({ ...envMock.basic, ...goEnv });
setUtilConfig(config);
await setUtilConfig(config);
resetPrefetchedImages();
});
it('returns if no go.sum found', async () => {
@ -104,7 +109,7 @@ describe('.updateArtifacts()', () => {
expect(execSnapshots).toMatchSnapshot();
});
it('supports docker mode without credentials', async () => {
setUtilConfig({ ...config, binarySource: BinarySource.Docker });
await setUtilConfig({ ...config, binarySource: BinarySource.Docker });
platform.getFile.mockResolvedValueOnce('Current go.sum');
const execSnapshots = mockExecAll(exec);
platform.getRepoStatus.mockResolvedValueOnce({
@ -145,7 +150,7 @@ describe('.updateArtifacts()', () => {
expect(execSnapshots).toMatchSnapshot();
});
it('supports docker mode with credentials', async () => {
setUtilConfig({ ...config, binarySource: BinarySource.Docker });
await setUtilConfig({ ...config, binarySource: BinarySource.Docker });
hostRules.find.mockReturnValueOnce({
token: 'some-token',
});
@ -169,7 +174,7 @@ describe('.updateArtifacts()', () => {
expect(execSnapshots).toMatchSnapshot();
});
it('supports docker mode with credentials and appMode enabled', async () => {
setUtilConfig({ ...config, binarySource: BinarySource.Docker });
await setUtilConfig({ ...config, binarySource: BinarySource.Docker });
hostRules.find.mockReturnValueOnce({
token: 'some-token',
});

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,3 +1,4 @@
import * as upath from 'upath';
import { platform as _platform } from '../lib/platform';
import { getConfig } from '../lib/config/defaults';
import { RenovateConfig as _RenovateConfig } from '../lib/config';
@ -10,6 +11,27 @@ export function mocked<T>(module: T): jest.Mocked<T> {
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.
* @param obj Object to cast to final type

View file

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

View file

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

View file

@ -21,7 +21,7 @@ shell.echo(`Publishing version: ${version}`);
// 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();
// if (err) {