From 4c485b727a49ee8398f2f72b713351a1a0b4e3f1 Mon Sep 17 00:00:00 2001 From: Michael Kriese <michael.kriese@visualon.de> Date: Thu, 15 Aug 2019 08:26:21 +0200 Subject: [PATCH] feat(utils): convert to ts (#4237) --- lib/datasource/cargo/index.ts | 2 +- lib/datasource/docker/index.ts | 21 +++----- lib/datasource/github/index.ts | 4 +- lib/datasource/pypi/index.ts | 3 +- lib/datasource/rubygems/get.ts | 4 +- lib/platform/github/gh-got-wrapper.ts | 2 +- lib/util/{env.js => env.ts} | 12 ++--- lib/util/got/{auth.js => auth.ts} | 7 ++- lib/util/got/{cache-get.js => cache-get.ts} | 9 ++-- lib/util/got/common.ts | 30 +++++++++++ lib/util/got/{host-rules.js => host-rules.ts} | 9 ++-- lib/util/got/index.js | 23 --------- lib/util/got/index.ts | 25 +++++++++ .../{renovate-agent.js => renovate-agent.ts} | 4 +- lib/util/got/{stats.js => stats.ts} | 27 ++++++---- lib/util/got/util.ts | 13 +++++ lib/util/{ignore.js => ignore.ts} | 8 +-- lib/util/{mask.js => mask.ts} | 6 +-- .../{package-rules.js => package-rules.ts} | 51 +++++++++++++++---- test/datasource/dart.spec.ts | 2 +- test/datasource/github.spec.ts | 3 +- test/datasource/nuget.spec.ts | 4 +- test/datasource/packagist.spec.ts | 2 +- test/datasource/pypi.spec.ts | 4 +- test/datasource/rubygems/index.spec.ts | 4 +- test/datasource/terraform.spec.ts | 4 +- test/manager/gradle-wrapper/update.spec.ts | 2 +- test/manager/homebrew/update.spec.ts | 5 +- .../platform/bitbucket/bb-got-wrapper.spec.ts | 2 +- test/platform/github/gh-got-wrapper.spec.ts | 4 +- test/platform/gitlab/gl-got-wrapper.spec.ts | 4 +- ...s.spec.js.snap => host-rules.spec.ts.snap} | 0 ...pec.js.snap => package-rules.spec.ts.snap} | 0 test/util/{env.spec.js => env.spec.ts} | 2 +- ...{host-rules.spec.js => host-rules.spec.ts} | 2 +- test/util/{mask.spec.js => mask.spec.ts} | 2 +- ...ge-rules.spec.js => package-rules.spec.ts} | 2 +- .../pr/changelog/release-notes.spec.js | 11 ++-- 38 files changed, 200 insertions(+), 119 deletions(-) rename lib/util/{env.js => env.ts} (66%) rename lib/util/got/{auth.js => auth.ts} (87%) rename lib/util/got/{cache-get.js => cache-get.ts} (84%) create mode 100644 lib/util/got/common.ts rename lib/util/got/{host-rules.js => host-rules.ts} (85%) delete mode 100644 lib/util/got/index.js create mode 100644 lib/util/got/index.ts rename lib/util/got/{renovate-agent.js => renovate-agent.ts} (74%) rename lib/util/got/{stats.js => stats.ts} (64%) create mode 100644 lib/util/got/util.ts rename lib/util/{ignore.js => ignore.ts} (70%) rename lib/util/{mask.js => mask.ts} (70%) rename lib/util/{package-rules.js => package-rules.ts} (82%) rename test/util/__snapshots__/{host-rules.spec.js.snap => host-rules.spec.ts.snap} (100%) rename test/util/__snapshots__/{package-rules.spec.js.snap => package-rules.spec.ts.snap} (100%) rename test/util/{env.spec.js => env.spec.ts} (95%) rename test/util/{host-rules.spec.js => host-rules.spec.ts} (98%) rename test/util/{mask.spec.js => mask.spec.ts} (84%) rename test/util/{package-rules.spec.js => package-rules.spec.ts} (99%) diff --git a/lib/datasource/cargo/index.ts b/lib/datasource/cargo/index.ts index 9896a4f22a..570ffc1862 100644 --- a/lib/datasource/cargo/index.ts +++ b/lib/datasource/cargo/index.ts @@ -38,7 +38,7 @@ export async function getPkgReleases({ 'https://raw.githubusercontent.com/rust-lang/crates.io-index/master/'; const crateUrl = baseUrl + path; try { - let res = await got(crateUrl, { + let res: any = await got(crateUrl, { hostType: 'cargo', }); if (!res || !res.body) { diff --git a/lib/datasource/docker/index.ts b/lib/datasource/docker/index.ts index 7fa0f6a378..f4085325ce 100644 --- a/lib/datasource/docker/index.ts +++ b/lib/datasource/docker/index.ts @@ -3,6 +3,7 @@ import hasha from 'hasha'; import URL from 'url'; import parseLinkHeader from 'parse-link-header'; import wwwAuthenticate from 'www-authenticate'; +import { OutgoingHttpHeaders } from 'http'; import { logger } from '../../logger'; import got from '../../util/got'; import * as hostRules from '../../util/host-rules'; @@ -37,7 +38,10 @@ function getRegistryRepository(lookupName: string, registryUrls: string[]) { }; } -async function getAuthHeaders(registry: string, repository: string) { +async function getAuthHeaders( + registry: string, + repository: string +): Promise<OutgoingHttpHeaders> { try { const apiCheckUrl = `${registry}/v2/`; const apiCheckResponse = await got(apiCheckUrl, { throwHttpErrors: false }); @@ -293,18 +297,9 @@ async function getTags( } let page = 1; do { - interface DockerTagResult { - body: { - tags: string[]; - }; - headers: { - link: string; - }; - } - - const res: DockerTagResult = await got(url, { json: true, headers }); + const res = await got<{ tags: string[] }>(url, { json: true, headers }); tags = tags.concat(res.body.tags); - const linkHeader = parseLinkHeader(res.headers.link); + const linkHeader = parseLinkHeader(res.headers.link as string); url = linkHeader && linkHeader.next ? URL.resolve(url, linkHeader.next.url) @@ -431,7 +426,7 @@ async function getLabels( headers, hooks: { beforeRedirect: [ - options => { + (options: any) => { if ( options.search && options.search.indexOf('X-Amz-Algorithm') !== -1 diff --git a/lib/datasource/github/index.ts b/lib/datasource/github/index.ts index cd66110c61..804a785ee2 100644 --- a/lib/datasource/github/index.ts +++ b/lib/datasource/github/index.ts @@ -6,13 +6,13 @@ import { DigestConfig, } from '../common'; import { logger } from '../../logger'; -import got from '../../util/got'; +import got, { GotJSONOptions } from '../../util/got'; const ghGot = api.get; async function fetchJSONFile(repo: string, fileName: string): Promise<Preset> { const url = `https://api.github.com/repos/${repo}/contents/${fileName}`; - const opts = { + const opts: GotJSONOptions = { headers: { accept: global.appMode ? 'application/vnd.github.machine-man-preview+json' diff --git a/lib/datasource/pypi/index.ts b/lib/datasource/pypi/index.ts index 865332ab48..08577dac58 100644 --- a/lib/datasource/pypi/index.ts +++ b/lib/datasource/pypi/index.ts @@ -115,8 +115,7 @@ async function getSimpleDependency( const lookupUrl = url.resolve(hostUrl, `${depName}`); try { const dependency: ReleaseResult = { releases: null }; - const response: { body: string } = await got(url.parse(lookupUrl), { - json: false, + const response = await got<string>(url.parse(lookupUrl), { hostType: 'pypi', }); const dep = response && response.body; diff --git a/lib/datasource/rubygems/get.ts b/lib/datasource/rubygems/get.ts index ce43de4e4c..3fe9d274a6 100644 --- a/lib/datasource/rubygems/get.ts +++ b/lib/datasource/rubygems/get.ts @@ -46,7 +46,9 @@ const fetch = async ({ dependency, registry, path }) => { const name = `/${dependency}.json`; const baseUrl = `${registry}/${path}`; - const response = (await got(name, { retry, json, baseUrl, headers })) || {}; + const response = (await got(name, { retry, json, baseUrl, headers })) || { + body: undefined, + }; return response.body; }; diff --git a/lib/platform/github/gh-got-wrapper.ts b/lib/platform/github/gh-got-wrapper.ts index e99fc5b14e..182eff43a8 100644 --- a/lib/platform/github/gh-got-wrapper.ts +++ b/lib/platform/github/gh-got-wrapper.ts @@ -48,7 +48,7 @@ async function get( if (opts.paginate) { // Check if result is paginated const pageLimit = opts.pageLimit || 10; - const linkHeader = parseLinkHeader(res.headers.link); + const linkHeader = parseLinkHeader(res.headers.link as string); if (linkHeader && linkHeader.next && linkHeader.last) { let lastPage = +linkHeader.last.page; if (!process.env.RENOVATE_PAGINATE_ALL && opts.paginate !== 'all') { diff --git a/lib/util/env.js b/lib/util/env.ts similarity index 66% rename from lib/util/env.js rename to lib/util/env.ts index 8cc63f42d4..cd11725d13 100644 --- a/lib/util/env.js +++ b/lib/util/env.ts @@ -1,11 +1,7 @@ -/** - * - * @param {string[]} customEnvVars - * @returns {NodeJS.ProcessEnv} - */ -export function getChildProcessEnv(customEnvVars = []) { - /** @type NodeJS.ProcessEnv */ - const env = {}; +export function getChildProcessEnv( + customEnvVars: string[] = [] +): NodeJS.ProcessEnv { + const env: NodeJS.ProcessEnv = {}; if (global.trustLevel === 'high') { return Object.assign(env, process.env); } diff --git a/lib/util/got/auth.js b/lib/util/got/auth.ts similarity index 87% rename from lib/util/got/auth.js rename to lib/util/got/auth.ts index 069c98bfc9..f4d947950c 100644 --- a/lib/util/got/auth.js +++ b/lib/util/got/auth.ts @@ -1,9 +1,8 @@ -const got = require('got'); -const { logger } = require('../../logger'); +import { logger } from '../../logger'; +import { create } from './util'; // istanbul ignore next -// @ts-ignore -module.exports = got.create({ +export default create({ options: {}, handler: (options, next) => { if (options.auth || options.headers.authorization) { diff --git a/lib/util/got/cache-get.js b/lib/util/got/cache-get.ts similarity index 84% rename from lib/util/got/cache-get.js rename to lib/util/got/cache-get.ts index 93e4e4aebd..b33d320fd9 100644 --- a/lib/util/got/cache-get.js +++ b/lib/util/got/cache-get.ts @@ -1,14 +1,13 @@ -const crypto = require('crypto'); -const got = require('got'); +import crypto from 'crypto'; +import { create } from './util'; -const clone = input => JSON.parse(JSON.stringify(input)); +const clone = (input: any) => JSON.parse(JSON.stringify(input)); // global.repoCache is reset to {} every time a repository is initialized // With this caching, it means every GET request is cached during each repository run // istanbul ignore next -// @ts-ignore -module.exports = got.create({ +export default create({ options: {}, handler: (options, next) => { if (!global.repoCache) { diff --git a/lib/util/got/common.ts b/lib/util/got/common.ts new file mode 100644 index 0000000000..dfa6d3e422 --- /dev/null +++ b/lib/util/got/common.ts @@ -0,0 +1,30 @@ +import got from 'got'; +import { Url } from 'url'; + +export interface Options { + hostType?: string; + search?: string; +} + +export type GotJSONOptions = Options & got.GotJSONOptions; +export type GotStreamOptions = Options & got.GotOptions<string | null>; + +export type GotUrl = string | Url; + +export interface GotFn { + <T extends object = any>( + url: GotUrl, + options?: GotJSONOptions + ): got.GotPromise<T>; + + <T extends Buffer | string = any>( + url: GotUrl, + options?: Options & got.GotBodyOptions<string | null> + ): got.GotPromise<T>; +} + +export interface Got + extends GotFn, + Record<'get' | 'post' | 'put' | 'patch' | 'head' | 'delete', GotFn> { + stream(url: GotUrl, options?: GotStreamOptions): NodeJS.ReadableStream; +} diff --git a/lib/util/got/host-rules.js b/lib/util/got/host-rules.ts similarity index 85% rename from lib/util/got/host-rules.js rename to lib/util/got/host-rules.ts index 61762f6837..75e72a7666 100644 --- a/lib/util/got/host-rules.js +++ b/lib/util/got/host-rules.ts @@ -1,13 +1,12 @@ /* eslint-disable no-param-reassign */ -const got = require('got'); -const { logger } = require('../../logger'); -const hostRules = require('../host-rules'); +import { logger } from '../../logger'; +import * as hostRules from '../host-rules'; +import { create } from './util'; // Apply host rules to requests // istanbul ignore next -// @ts-ignore -module.exports = got.create({ +export default create({ options: {}, handler: (options, next) => { if (!options.hostname) { diff --git a/lib/util/got/index.js b/lib/util/got/index.js deleted file mode 100644 index 06a94285c2..0000000000 --- a/lib/util/got/index.js +++ /dev/null @@ -1,23 +0,0 @@ -const got = require('got'); -const cacheGet = require('./cache-get'); -const renovateAgent = require('./renovate-agent'); -const hostRules = require('./host-rules'); -const auth = require('./auth'); -const stats = require('./stats'); - -/* - * This is the default got instance for Renovate. - * - Set the user agent to be Renovate - * - Cache all GET requests for the lifetime of the repo - * - * Important: always put the renovateAgent one last, to make sure the correct user agent is used - */ - -// @ts-ignore -module.exports = got.mergeInstances( - cacheGet, - renovateAgent, - hostRules, - auth, - stats.instance -); diff --git a/lib/util/got/index.ts b/lib/util/got/index.ts new file mode 100644 index 0000000000..5bf9e47306 --- /dev/null +++ b/lib/util/got/index.ts @@ -0,0 +1,25 @@ +import cacheGet from './cache-get'; +import renovateAgent from './renovate-agent'; +import hostRules from './host-rules'; +import auth from './auth'; +import { instance } from './stats'; +import { mergeInstances } from './util'; + +export * from './common'; + +/* + * This is the default got instance for Renovate. + * - Set the user agent to be Renovate + * - Cache all GET requests for the lifetime of the repo + * + * Important: always put the renovateAgent one last, to make sure the correct user agent is used + */ +export const api = mergeInstances( + cacheGet, + renovateAgent, + hostRules, + auth, + instance +); + +export default api; diff --git a/lib/util/got/renovate-agent.js b/lib/util/got/renovate-agent.ts similarity index 74% rename from lib/util/got/renovate-agent.js rename to lib/util/got/renovate-agent.ts index b577614f2d..5b2eea2bfc 100644 --- a/lib/util/got/renovate-agent.js +++ b/lib/util/got/renovate-agent.ts @@ -1,8 +1,8 @@ -const got = require('got'); +import got from 'got'; // Sets the user agent to be Renovate -module.exports = got.extend({ +export default got.extend({ headers: { 'user-agent': process.env.RENOVATE_USER_AGENT || diff --git a/lib/util/got/stats.js b/lib/util/got/stats.ts similarity index 64% rename from lib/util/got/stats.js rename to lib/util/got/stats.ts index f04d5da553..9e4826173b 100644 --- a/lib/util/got/stats.js +++ b/lib/util/got/stats.ts @@ -1,19 +1,26 @@ -const got = require('got'); -const { logger } = require('../../logger'); +import { logger } from '../../logger'; +import { create } from './util'; -let stats = {}; +interface HostStats { + median?: number; + average?: number; + sum?: number; + requests?: number; +} + +let stats: Record<string, number[]> = {}; // istanbul ignore next -module.exports.resetStats = () => { +export const resetStats = () => { stats = {}; }; // istanbul ignore next -module.exports.printStats = () => { +export const printStats = () => { logger.trace({ stats }, 'Host transfer stats (milliseconds)'); - const hostStats = {}; + const hostStats: Record<string, HostStats> = {}; for (const [hostname, entries] of Object.entries(stats)) { - const res = {}; + const res: HostStats = {}; res.requests = entries.length; res.sum = 0; entries.forEach(entry => { @@ -26,15 +33,13 @@ module.exports.printStats = () => { logger.debug({ hostStats }, 'Host request stats (milliseconds)'); }; -// @ts-ignore -module.exports.instance = got.create({ +export const instance = create({ options: {}, handler: (options, next) => { const start = new Date(); const nextPromise = next(options); nextPromise.on('response', () => { - // @ts-ignore - const elapsed = new Date() - start; + const elapsed = new Date().getTime() - start.getTime(); stats[options.hostname] = stats[options.hostname] || []; stats[options.hostname].push(elapsed); }); diff --git a/lib/util/got/util.ts b/lib/util/got/util.ts new file mode 100644 index 0000000000..c3187b439c --- /dev/null +++ b/lib/util/got/util.ts @@ -0,0 +1,13 @@ +import got from 'got'; +import { Got } from './common'; + +// TODO: missing types +export const mergeInstances = (got as any).mergeInstances as ( + ...args: (got.GotInstance<any>)[] +) => Got; + +// TODO: missing types +export const create = (got as any).create as (defaults: { + options: any; + handler: Function; +}) => got.GotInstance; diff --git a/lib/util/ignore.js b/lib/util/ignore.ts similarity index 70% rename from lib/util/ignore.js rename to lib/util/ignore.ts index 5c7fb557bf..789f9aeb00 100644 --- a/lib/util/ignore.js +++ b/lib/util/ignore.ts @@ -1,10 +1,6 @@ -const { logger } = require('../logger'); +import { logger } from '../logger'; -module.exports = { - isSkipComment, -}; - -function isSkipComment(comment) { +export function isSkipComment(comment?: string): boolean { if (comment && comment.match(/^(renovate|pyup):/)) { const command = comment .split('#')[0] diff --git a/lib/util/mask.js b/lib/util/mask.ts similarity index 70% rename from lib/util/mask.js rename to lib/util/mask.ts index 0329f22970..dd50d43366 100644 --- a/lib/util/mask.js +++ b/lib/util/mask.ts @@ -1,4 +1,4 @@ -function maskToken(str) { +export function maskToken(str?: string): string { return str ? [ str.substring(0, 2), @@ -7,7 +7,3 @@ function maskToken(str) { ].join('') : str; } - -module.exports = { - maskToken, -}; diff --git a/lib/util/package-rules.js b/lib/util/package-rules.ts similarity index 82% rename from lib/util/package-rules.js rename to lib/util/package-rules.ts index 3c664cc816..23a4a3e6f4 100644 --- a/lib/util/package-rules.js +++ b/lib/util/package-rules.ts @@ -1,14 +1,47 @@ -const minimatch = require('minimatch'); +import minimatch from 'minimatch'; +import { Range } from 'semver'; +import { logger } from '../logger'; +import * as versioning from '../versioning'; +import { mergeChildConfig } from '../config'; -const { logger } = require('../logger'); -const versioning = require('../versioning'); -const { mergeChildConfig } = require('../config'); +// TODO: move to `../config` +interface Config extends Record<string, any> { + versionScheme?: string; + packageFile?: string; + depType?: string; + depTypes?: string[]; + depName?: string; + currentValue?: string; + fromVersion?: string; + lockedVersion?: string; + updateType?: string; + isBump?: boolean; + sourceUrl?: string; + language?: string; + baseBranch?: string; + manager?: string; + datasource?: string; + packageRules?: (PackageRule & Config)[]; +} -module.exports = { - applyPackageRules, -}; +// TODO: move to `../config` +interface PackageRule { + paths?: string[]; + languages?: string[]; + baseBranchList?: string[]; + managers?: string[]; + datasources?: string[]; + depTypeList?: string[]; + packageNames?: string[]; + packagePatterns?: string[]; + excludePackageNames?: string[]; + excludePackagePatterns?: string[]; + matchCurrentVersion?: string | Range; + sourceUrlPrefixes?: string[]; + updateTypes?: string[]; +} -function matchesRule(inputConfig, packageRule) { +function matchesRule(inputConfig: Config, packageRule: PackageRule): boolean { const { versionScheme, packageFile, @@ -193,7 +226,7 @@ function matchesRule(inputConfig, packageRule) { return positiveMatch; } -function applyPackageRules(inputConfig) { +export function applyPackageRules(inputConfig: Config): Config { let config = { ...inputConfig }; const packageRules = config.packageRules || []; logger.trace( diff --git a/test/datasource/dart.spec.ts b/test/datasource/dart.spec.ts index e8d828b7aa..c852e3db1c 100644 --- a/test/datasource/dart.spec.ts +++ b/test/datasource/dart.spec.ts @@ -2,7 +2,7 @@ import fs from 'fs'; import _got from '../../lib/util/got'; import { getPkgReleases } from '../../lib/datasource/dart'; -const got = _got; +const got: any = _got; const body: any = JSON.parse( fs.readFileSync( diff --git a/test/datasource/github.spec.ts b/test/datasource/github.spec.ts index e467751d86..fc5226d048 100644 --- a/test/datasource/github.spec.ts +++ b/test/datasource/github.spec.ts @@ -2,13 +2,14 @@ import { api } from '../../lib/platform/github/gh-got-wrapper'; import * as datasource from '../../lib/datasource'; import * as github from '../../lib/datasource/github'; -import got from '../../lib/util/got'; +import _got from '../../lib/util/got'; import * as hostRules from '../../lib/util/host-rules'; jest.mock('../../lib/platform/github/gh-got-wrapper'); jest.mock('../../lib/util/got'); jest.mock('../../lib/util/host-rules'); +const got: any = _got; const ghGot: any = api.get; describe('datasource/github', () => { diff --git a/test/datasource/nuget.spec.ts b/test/datasource/nuget.spec.ts index efca574cca..dc71575cb7 100644 --- a/test/datasource/nuget.spec.ts +++ b/test/datasource/nuget.spec.ts @@ -1,10 +1,12 @@ import fs from 'fs'; -import got from '../../lib/util/got'; +import _got from '../../lib/util/got'; import * as datasource from '../../lib/datasource'; jest.mock('../../lib/util/got'); jest.mock('../../lib/util/host-rules'); +const got: any = _got; + const pkgListV3 = fs.readFileSync( 'test/datasource/nuget/_fixtures/nunitV3.json', 'utf8' diff --git a/test/datasource/packagist.spec.ts b/test/datasource/packagist.spec.ts index bd1e968aae..a0243a2cd8 100644 --- a/test/datasource/packagist.spec.ts +++ b/test/datasource/packagist.spec.ts @@ -6,7 +6,7 @@ import * as _hostRules from '../../lib/util/host-rules'; jest.mock('../../lib/util/got'); jest.mock('../../lib/util/host-rules'); -const got = _got; +const got: any = _got; const hostRules = _hostRules; const includesJson: any = fs.readFileSync( diff --git a/test/datasource/pypi.spec.ts b/test/datasource/pypi.spec.ts index 9c36067279..bc121c2095 100644 --- a/test/datasource/pypi.spec.ts +++ b/test/datasource/pypi.spec.ts @@ -1,9 +1,11 @@ import fs from 'fs'; -import got from '../../lib/util/got'; +import _got from '../../lib/util/got'; import * as datasource from '../../lib/datasource'; jest.mock('../../lib/util/got'); +const got: any = _got; + const res1: any = fs.readFileSync( 'test/datasource/pypi/_fixtures/azure-cli-monitor.json' ); diff --git a/test/datasource/rubygems/index.spec.ts b/test/datasource/rubygems/index.spec.ts index ceea287816..4c17ae310e 100644 --- a/test/datasource/rubygems/index.spec.ts +++ b/test/datasource/rubygems/index.spec.ts @@ -1,8 +1,10 @@ -import got from '../../../lib/util/got'; +import _got from '../../../lib/util/got'; import railsInfo from './_fixtures/rails/info.json'; import railsVersions from './_fixtures/rails/versions.json'; import * as rubygems from '../../../lib/datasource/rubygems'; +const got: any = _got; + const rubygemsOrgVersions = `created_at: 2017-03-27T04:38:13+00:00 --- - 1 05d0116933ba44b0b5d0ee19bfd35ccc diff --git a/test/datasource/terraform.spec.ts b/test/datasource/terraform.spec.ts index 7cb4611edd..f264e355e9 100644 --- a/test/datasource/terraform.spec.ts +++ b/test/datasource/terraform.spec.ts @@ -1,9 +1,11 @@ import fs from 'fs'; -import got from '../../lib/util/got'; +import _got from '../../lib/util/got'; import * as datasource from '../../lib/datasource'; jest.mock('../../lib/util/got'); +const got: any = _got; + const consulData: any = fs.readFileSync( 'test/datasource/terraform/_fixtures/registry-consul.json' ); diff --git a/test/manager/gradle-wrapper/update.spec.ts b/test/manager/gradle-wrapper/update.spec.ts index 8a89d6c54d..f1466f0888 100644 --- a/test/manager/gradle-wrapper/update.spec.ts +++ b/test/manager/gradle-wrapper/update.spec.ts @@ -1,6 +1,6 @@ import fs from 'fs'; import * as dcUpdate from '../../../lib/manager/gradle-wrapper'; -import * as _got from '../../../lib/util/got'; +import _got from '../../../lib/util/got'; jest.mock('../../../lib/util/got'); diff --git a/test/manager/homebrew/update.spec.ts b/test/manager/homebrew/update.spec.ts index 06cc5e01e9..597d758673 100644 --- a/test/manager/homebrew/update.spec.ts +++ b/test/manager/homebrew/update.spec.ts @@ -1,10 +1,11 @@ import fs from 'fs'; import { updateDependency } from '../../../lib/manager/homebrew/update'; - -const got = require('../../../lib/util/got'); +import _got from '../../../lib/util/got'; jest.mock('../../../lib/util/got'); +const got: any = _got; + const aide = fs.readFileSync('test/manager/homebrew/_fixtures/aide.rb', 'utf8'); const ibazel = fs.readFileSync( 'test/manager/homebrew/_fixtures/ibazel.rb', diff --git a/test/platform/bitbucket/bb-got-wrapper.spec.ts b/test/platform/bitbucket/bb-got-wrapper.spec.ts index 790708144e..562b936d4b 100644 --- a/test/platform/bitbucket/bb-got-wrapper.spec.ts +++ b/test/platform/bitbucket/bb-got-wrapper.spec.ts @@ -8,7 +8,7 @@ describe('platform/gl-got-wrapper', () => { // reset module jest.resetAllMocks(); jest.mock('../../../lib/util/got'); - got = require('../../../lib/util/got'); + got = require('../../../lib/util/got').api; hostRules = require('../../../lib/util/host-rules'); api = require('../../../lib/platform/bitbucket/bb-got-wrapper').api; diff --git a/test/platform/github/gh-got-wrapper.spec.ts b/test/platform/github/gh-got-wrapper.spec.ts index 73c3d725cb..4b78ce0989 100644 --- a/test/platform/github/gh-got-wrapper.spec.ts +++ b/test/platform/github/gh-got-wrapper.spec.ts @@ -1,11 +1,13 @@ import delay from 'delay'; import { Response } from 'got'; -import got from '../../../lib/util/got'; +import _got from '../../../lib/util/got'; import { api } from '../../../lib/platform/github/gh-got-wrapper'; jest.mock('../../../lib/util/got'); jest.mock('delay'); +const got: any = _got; + const get: <T extends object = any>( path: string, options?: any, diff --git a/test/platform/gitlab/gl-got-wrapper.spec.ts b/test/platform/gitlab/gl-got-wrapper.spec.ts index 5ea848f84a..64b4d91859 100644 --- a/test/platform/gitlab/gl-got-wrapper.spec.ts +++ b/test/platform/gitlab/gl-got-wrapper.spec.ts @@ -1,9 +1,11 @@ -import got from '../../../lib/util/got'; +import _got from '../../../lib/util/got'; import { api } from '../../../lib/platform/gitlab/gl-got-wrapper'; import * as hostRules from '../../../lib/util/host-rules'; jest.mock('../../../lib/util/got'); +const got: any = _got; + hostRules.add({ hostType: 'gitlab', token: 'abc123', diff --git a/test/util/__snapshots__/host-rules.spec.js.snap b/test/util/__snapshots__/host-rules.spec.ts.snap similarity index 100% rename from test/util/__snapshots__/host-rules.spec.js.snap rename to test/util/__snapshots__/host-rules.spec.ts.snap diff --git a/test/util/__snapshots__/package-rules.spec.js.snap b/test/util/__snapshots__/package-rules.spec.ts.snap similarity index 100% rename from test/util/__snapshots__/package-rules.spec.js.snap rename to test/util/__snapshots__/package-rules.spec.ts.snap diff --git a/test/util/env.spec.js b/test/util/env.spec.ts similarity index 95% rename from test/util/env.spec.js rename to test/util/env.spec.ts index c5ed09400a..d80ae19672 100644 --- a/test/util/env.spec.js +++ b/test/util/env.spec.ts @@ -1,4 +1,4 @@ -const { getChildProcessEnv } = require('../../lib/util/env'); +import { getChildProcessEnv } from '../../lib/util/env'; describe('getChildProcess environment when trustlevel set to low', () => { const envVars = ['HTTP_PROXY', 'HTTPS_PROXY', 'NO_PROXY', 'HOME', 'PATH']; diff --git a/test/util/host-rules.spec.js b/test/util/host-rules.spec.ts similarity index 98% rename from test/util/host-rules.spec.js rename to test/util/host-rules.spec.ts index 7ba8f439aa..cdec753b54 100644 --- a/test/util/host-rules.spec.js +++ b/test/util/host-rules.spec.ts @@ -1,4 +1,4 @@ -const { add, find, clear, hosts } = require('../../lib/util/host-rules'); +import { add, find, clear, hosts } from '../../lib/util/host-rules'; describe('util/host-rules', () => { beforeEach(() => { diff --git a/test/util/mask.spec.js b/test/util/mask.spec.ts similarity index 84% rename from test/util/mask.spec.js rename to test/util/mask.spec.ts index ea7f199dcf..e918ba3c05 100644 --- a/test/util/mask.spec.js +++ b/test/util/mask.spec.ts @@ -1,4 +1,4 @@ -const { maskToken } = require('../../lib/util/mask'); +import { maskToken } from '../../lib/util/mask'; describe('util/mask', () => { describe('.maskToken', () => { diff --git a/test/util/package-rules.spec.js b/test/util/package-rules.spec.ts similarity index 99% rename from test/util/package-rules.spec.js rename to test/util/package-rules.spec.ts index e96c9aeff6..3f6b1057b5 100644 --- a/test/util/package-rules.spec.js +++ b/test/util/package-rules.spec.ts @@ -1,4 +1,4 @@ -const { applyPackageRules } = require('../../lib/util/package-rules'); +import { applyPackageRules } from '../../lib/util/package-rules'; describe('applyPackageRules()', () => { const config1 = { diff --git a/test/workers/pr/changelog/release-notes.spec.js b/test/workers/pr/changelog/release-notes.spec.js index 954b9735ea..4ccabbfd77 100644 --- a/test/workers/pr/changelog/release-notes.spec.js +++ b/test/workers/pr/changelog/release-notes.spec.js @@ -1,10 +1,13 @@ -const fs = require('fs-extra'); -const ghGot = require('../../../../lib/util/got'); -const { +import fs from 'fs-extra'; +import got from '../../../../lib/util/got'; +import { addReleaseNotes, getReleaseNotes, getReleaseNotesMd, -} = require('../../../../lib/workers/pr/changelog/release-notes'); +} from '../../../../lib/workers/pr/changelog/release-notes'; + +/** @type any */ +const ghGot = got; const angularJsChangelogMd = fs.readFileSync( 'test/workers/pr/_fixtures/angular.js.md', -- GitLab