Skip to content

Commit

Permalink
chore(W-15263489): improve unit test performance (#2716)
Browse files Browse the repository at this point in the history
  • Loading branch information
justinwilaby authored Mar 18, 2024
1 parent d23407c commit 7428df0
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
11 changes: 7 additions & 4 deletions packages/cli/src/global_telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ const {version} = require('../package.json')

const root = path.resolve(__dirname, '../package.json')
const isDev = process.env.IS_DEV_ENVIRONMENT === 'true'
const config = new Config({root})
const heroku = new APIClient(config)
const token = heroku.auth

function getToken() {
const config = new Config({root})
const heroku = new APIClient(config)
return heroku.auth
}

const debug = require('debug')('global_telemetry')

Expand Down Expand Up @@ -44,7 +47,7 @@ const provider = new NodeTracerProvider({
resource,
})

const headers = {Authorization: `Bearer ${token}`}
const headers = {Authorization: `Bearer ${process.env.IS_HEROKU_TEST_ENV !== 'true' ? getToken() : ''}`}

const exporter = new OTLPTraceExporter({
url: isDev ? 'https://backboard-staging.herokuapp.com/otel/v1/traces' : 'https://backboard.heroku.com/otel/v1/traces',
Expand Down
10 changes: 6 additions & 4 deletions packages/cli/src/hooks/postrun/performance_analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import * as telemetry from '../../global_telemetry'
declare const global: telemetry.TelemetryGlobal

const performance_analytics: Hook<'postrun'> = async function () {
if (global.cliTelemetry) {
const cmdStartTime = global.cliTelemetry.commandRunDuration
global.cliTelemetry.commandRunDuration = telemetry.computeDuration(cmdStartTime)
global.cliTelemetry.lifecycleHookCompletion.postrun = true
if (process.env.IS_HEROKU_TEST_ENV === 'true' || !global.cliTelemetry) {
return
}

const cmdStartTime = global.cliTelemetry.commandRunDuration
global.cliTelemetry.commandRunDuration = telemetry.computeDuration(cmdStartTime)
global.cliTelemetry.lifecycleHookCompletion.postrun = true
}

export default performance_analytics
4 changes: 4 additions & 0 deletions packages/cli/src/hooks/prerun/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import * as telemetry from '../../global_telemetry'
declare const global: telemetry.TelemetryGlobal

const analytics: Hook<'prerun'> = async function (options) {
if (process.env.IS_HEROKU_TEST_ENV === 'true') {
return
}

global.cliTelemetry = telemetry.setupTelemetry(this.config, options)
const analytics = new Analytics(this.config)
await analytics.record(options)
Expand Down
1 change: 0 additions & 1 deletion packages/cli/test/acceptance/smoke.acceptance.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// tslint:disable no-console

import * as fs from 'fs-extra'
import {expect} from 'chai'
import * as path from 'path'
Expand Down
8 changes: 8 additions & 0 deletions packages/cli/test/helpers/init.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
const path = require('path')

globalThis.setInterval = () => ({unref: () => {}})
const tm = globalThis.setTimeout
globalThis.setTimeout = cb => {
return tm(cb)
}

process.env.TS_NODE_PROJECT = path.resolve('test/tsconfig.json')
process.env.IS_HEROKU_TEST_ENV = 'true'

let nock = require('nock')
nock.disableNetConnect()
Expand Down

0 comments on commit 7428df0

Please sign in to comment.