diff --git a/lib/datasource/cargo/index.ts b/lib/datasource/cargo/index.ts index 9896a4f22a0f2332fb59b52c3a28a9147b04d8cc..570ffc18625174e313be6b72fadd98bb4cecb4c1 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 7fa0f6a3783be80549d0d5ea7e0294817579fa02..f4085325ce268f9cf87440540023735e63bc4654 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 cd66110c61677847d527de97f415730229fdafed..804a785ee201a70ee9cc6b00c872de7a527ae75f 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 865332ab486b0892558b8d349fcee0ca5e13bc52..08577dac58cc16b3e33ac7e5a0dba3977cb0613d 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 ce43de4e4caa2a44bef4b12d545aa5a75416427a..3fe9d274a64891be0e69e8a5f5384f57468a4714 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 e99fc5b14ed8301fc31648363c5bc8c0195fb0ff..182eff43a8e40a4883a6a9c9ca23ff6335f63585 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 8cc63f42d446bd91fcb9e683193aea10db524f35..cd11725d135f6b33c035c8a43190e3e9e409ead3 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 069c98bfc98666f07f3d850f91d645758660b023..f4d947950c8cc483951b2261b77b5caf6870c041 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 93e4e4aebd2402bc5b3032c6274e6b49ced22b0a..b33d320fd9a2f8245043d4e23b9e7ed40839f2bc 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 0000000000000000000000000000000000000000..dfa6d3e422fe678e14d22929bd2d0212935f1658 --- /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 61762f6837ac597b7eec31b84327f7396066ca0e..75e72a76666e3066fe662da9054e87efc998e01c 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 06a94285c2b92501fd42696cc8ce7433ba4b559c..0000000000000000000000000000000000000000 --- 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 0000000000000000000000000000000000000000..5bf9e47306fd70744c8bbb444c41e9ebf8e1bbfe --- /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 b577614f2dc5595ae254b6dfae5a73bbe77044e9..5b2eea2bfc1c8500111cb7bf45447c5dce4a3768 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 f04d5da553f2625656e2c9f54d0908e067b6e1cf..9e4826173be9ad006281265ad0c65d3e775935d3 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 0000000000000000000000000000000000000000..c3187b439ca4d98359c6e1b21440abfd560ff6c6 --- /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 5c7fb557bfe71de033d3e2e89c2aa563964ca091..789f9aeb000b562bf40422c2a668df71850db1cd 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 0329f22970a8b8633ddfb4e5917cac2737f142fe..dd50d4336628d41bb514cc45fd911d3c2df4d645 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 3c664cc816104922489df5e9f38af07e7fa7edca..23a4a3e6f471347f710508e4cd95208059d72ce2 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 e8d828b7aa53465f437b58f80911310c9e00de30..c852e3db1c17875e3c52256ecd69cc5172af469c 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 e467751d86c2a76a33da3a49cc6f77ce8d36625f..fc5226d048feeb9297b54775d8d492539f4ec43f 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 efca574cca48b3f6586cee81429a34cd06e57bb2..dc71575cb76a349ac883cd49a101552f4d9e1875 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 bd1e968aae11afc152262b040d437b87d7b2e09e..a0243a2cd87a0dc98367cd596fd55127790cc6b5 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 9c360672797a30e54d0ac3bf161a57b62984203e..bc121c209535ed6a90db9a8ac20e4af5b2323412 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 ceea2878168efc77f97a0364bbea6d6547ac43ee..4c17ae310e86f97cb01b8a3487dee6e3f8e6ff51 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 7cb4611edd35f5b4e8904ce281c5e9043b2ac00d..f264e355e900abf644043df78571d8e74633dae3 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 8a89d6c54d9e7f4eecb03f735732732eb6d83f40..f1466f0888840a942bd903e8c33a36db31d766c8 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 06cc5e01e9003188ab139546bed42987f2987f3d..597d758673843a21272b5f4263b870a4f1245344 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 790708144e880e792dd10106e6a99b4bc678bd6e..562b936d4be16898fc3247174afef36c6c5269cf 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 73c3d725cbbb0b5390f2ac07bc7669570b6e7ec3..4b78ce09898118e6a0866b8503b1fd8ad6eb2202 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 5ea848f84a03cb1f8d07e0c58c7ec067f5452edb..64b4d91859f2dfa15c349681331bb3616fd129cb 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 c5ed09400aebe9920e33cb29f1681c8f6a32a2f9..d80ae196729f233836a0852823c9e5cd08fed5cb 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 7ba8f439aa0a50480c5be44a8f22e008b76feff8..cdec753b5453c6c41d564c282407e82612d4e6e2 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 ea7f199dcfca3b4ed9718821bee28a1281f0dd2f..e918ba3c05af86a6ca7e15a98bff68fad0927ff3 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 e96c9aeff63c4358b0a06545ed9f0f964593b56e..3f6b1057b5cde074fabbfc40cea3325f06ba4e78 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 954b9735ea61c30ef6841c968f19c5edef02a12f..4ccabbfd77e8ced1077b991d95f3a499addaf8b7 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',