import nock from "nock" ; import env from "../../src/config/env" ; import "./matchers/to-have-sent-metrics" ; import "./matchers/nock" ; import "./matchers/to-promise" ; import statsd from "../../src/config/statsd" ; import { sequelize } from "../../src/models/sequelize" ; import InstallationTokenCache from "../../src/github/client/installation-token-cache" ; import AppTokenHolder from "../../src/github/client/app-token-holder" ; resetEnvVars ( ) ; function resetEnvVars ( ) { process . env = { ... process . env , ... env } ; } declare global { let jiraHost ; let jiraNock ; let githubNock ; let gheNock ; namespace NodeJS { interface Global { jiraHost : string ; jiraNock : nock . Scope ; githubNock : nock . Scope ; gheNock : nock . Scope ; } } } beforeEach ( ( ) => { resetEnvVars ( ) ; global . jiraHost = process . env . ATLASSIAN_URL || "" ; global . jiraNock = nock ( global . jiraHost ) ; global . githubNock = nock ( "https://api.github.com" ) ; global . gheNock = nock ( "http://github.mydomain.com" ) ; } ) ; afterEach ( ( ) => { try { expect ( nock ) . toBeDone ( ) ; } finally { InstallationTokenCache . getInstance ( ) . clear ( ) ; AppTokenHolder . getInstance ( ) . clear ( ) ; nock . cleanAll ( ) ; jest . resetAllMocks ( ) ; } } ) ; afterAll ( async ( ) => { await sequelize . close ( ) ; statsd . close ( ( ) => undefined ) ; } ) ;