Skip to content

Commit

Permalink
Pass env vars as dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
robbie-c committed Aug 22, 2024
1 parent 4747ace commit 1e3655b
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions testcafe/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,29 @@ export const staticFilesMock = RequestMock()
})

export const initPosthog = (config) => {
return ClientFunction((configParams = {}) => {
let testSessionId = Math.round(Math.random() * 10000000000).toString()
let testSessionId = Math.round(Math.random() * 10000000000).toString()
if (BRANCH_NAME && RUN_ID && BROWSER) {
testSessionId = `${BRANCH_NAME} ${BROWSER} ${RUN_ID} ${testSessionId}`
}
// eslint-disable-next-line no-console
console.log('Initialized posthog with testSessionId', testSessionId)

if (BRANCH_NAME && RUN_ID && BROWSER) {
testSessionId = `${BRANCH_NAME} ${BROWSER} ${RUN_ID} ${testSessionId}`
}
configParams.debug = true
window.posthog.init(configParams.api_key, configParams)
window.posthog.register({
testSessionId,
})
// eslint-disable-next-line no-console
console.log('Initialized posthog with testSessionId', testSessionId)
return ClientFunction(
(configParams = {}) => {
configParams.debug = true
window.posthog.init(configParams.api_key, configParams)
window.posthog.register({
testSessionId,
})

return testSessionId
})({
return testSessionId
},
{
dependencies: {
testSessionId,
},
}
)({
...config,
api_host: POSTHOG_API_HOST,
api_key: POSTHOG_PROJECT_KEY,
Expand Down

0 comments on commit 1e3655b

Please sign in to comment.