Skip to content

Commit

Permalink
reduce code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhousley committed Mar 26, 2024
1 parent 1629922 commit 2573e7a
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 9 deletions.
3 changes: 3 additions & 0 deletions src/common/context/__mocks__/shared-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ export const SharedContext = jest.fn(function () {
agentIdentifier: 'abcd',
ee: {
on: jest.fn()
},
timeKeeper: {
now: jest.fn(() => performance.now())
}
}
})
8 changes: 3 additions & 5 deletions src/common/context/shared-context.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { warn } from '../util/console'
import { TimeKeeper } from '../timing/time-keeper'

const model = {
agentIdentifier: '',
ee: undefined
ee: undefined,
timeKeeper: undefined
}

export class SharedContext {
Expand All @@ -16,9 +16,7 @@ export class SharedContext {
if (Object.keys(model).includes(key)) this.sharedContext[key] = value
})
} catch (err) {
warn('An error occured while setting SharedContext', err)
warn('An error occurred while setting SharedContext', err)
}

this.timeKeeper = TimeKeeper.getTimeKeeperByAgentIdentifier(this.sharedContext.agentIdentifier)
}
}
2 changes: 1 addition & 1 deletion src/common/harvest/harvest.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export class Harvest extends SharedContext {
encodeParam('v', VERSION),
transactionNameParam(info),
encodeParam('ct', runtime.customTransaction),
'&rst=' + this.timeKeeper.now(),
'&rst=' + this.sharedContext.timeKeeper.now(),
'&ck=0', // ck param DEPRECATED - still expected by backend
'&s=' + (runtime.session?.state.value || '0'), // the 0 id encaps all untrackable and default traffic
encodeParam('ref', ref),
Expand Down
3 changes: 0 additions & 3 deletions src/common/harvest/harvest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ let harvestInstance

beforeEach(() => {
harvestInstance = new Harvest()
harvestInstance.timeKeeper = {
now: jest.fn(() => performance.now())
}
})

afterEach(() => {
Expand Down
Empty file added src/common/url/beacon.js
Empty file.

0 comments on commit 2573e7a

Please sign in to comment.