Skip to content

Commit

Permalink
Run ts on test files
Browse files Browse the repository at this point in the history
  • Loading branch information
robbie-c committed Aug 13, 2024
1 parent 19ca9dd commit 331201f
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 19 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
"lint": "eslint src && eslint cypress",
"prettier": "prettier --write src/ functional_tests/",
"prepublishOnly": "pnpm lint && pnpm test && pnpm build && pnpm test:react",
"test": "pnpm test:unit && pnpm test:custom-eslint-rules && pnpm test:functional",
"test": "pnpm typecheck && pnpm test:unit && pnpm test:custom-eslint-rules && pnpm test:functional",
"test:unit": "jest src",
"test:custom-eslint-rules": "jest eslint-rules",
"test:react": "cd react; pnpm test",
"test:functional": "jest functional_tests",
"test-watch": "jest --watch src",
"typecheck": "tsc --noEmit --project tsconfig.test.json",
"cypress": "cypress open",
"prepare": "husky install",
"deprecate-old-versions": "node scripts/deprecate-old-versions.mjs"
Expand Down
5 changes: 4 additions & 1 deletion src/__tests__/autocapture-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
} from '../autocapture-utils'
import { document } from '../utils/globals'
import { makeMouseEvent } from './autocapture.test'
import { AutocaptureConfig } from '../types'

describe(`Autocapture utility functions`, () => {
afterEach(() => {
Expand Down Expand Up @@ -252,7 +253,9 @@ describe(`Autocapture utility functions`, () => {
true,
],
])('correctly respects the allow list: %s', (_, clickTarget, autoCaptureConfig, shouldCapture) => {
expect(shouldCaptureDomEvent(clickTarget, makeMouseEvent({}), autoCaptureConfig)).toBe(shouldCapture)
expect(
shouldCaptureDomEvent(clickTarget, makeMouseEvent({}), autoCaptureConfig as AutocaptureConfig)
).toBe(shouldCapture)
})
})
})
Expand Down
8 changes: 0 additions & 8 deletions src/__tests__/autocapture.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,6 @@ describe('Autocapture system', () => {
it('should capture copy', () => {
const fakeEvent = makeCopyEvent({
target: elTarget,
clientX: 5,
clientY: 5,
})

setWindowTextSelection('copy this test')
Expand All @@ -417,8 +415,6 @@ describe('Autocapture system', () => {
it('should capture cut', () => {
const fakeEvent = makeCutEvent({
target: elTarget,
clientX: 5,
clientY: 5,
})

setWindowTextSelection('cut this test')
Expand All @@ -435,8 +431,6 @@ describe('Autocapture system', () => {
it('ignores empty selection', () => {
const fakeEvent = makeCopyEvent({
target: elTarget,
clientX: 5,
clientY: 5,
})

setWindowTextSelection('')
Expand All @@ -450,8 +444,6 @@ describe('Autocapture system', () => {
it('runs selection through the safe text before capture', () => {
const fakeEvent = makeCopyEvent({
target: elTarget,
clientX: 5,
clientY: 5,
})

// oh no, a social security number!
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/featureflags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ jest.useFakeTimers()
jest.spyOn(global, 'setTimeout')

describe('featureflags', () => {
let instance
let featureFlags
let instance: any
let featureFlags: any

const config = {
token: 'random fake token',
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/posthog-core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('posthog core', () => {
})

// act
const actual = posthog._calculate_event_properties(eventName, eventProperties)
const actual = posthog._calculate_event_properties(eventName, eventProperties, new Date())

// assert
expect(actual['event']).toBe('prop')
Expand Down
13 changes: 8 additions & 5 deletions src/__tests__/posthog-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ describe('posthog core', () => {
_send_request: jest.fn(),
}

const posthogWith = (config: Partial<PostHogConfig>, overrides?: Partial<PostHog>) => {
const posthogWith = (config: Partial<PostHogConfig>, overrides?: Partial<PostHog>): PostHog => {
const posthog = defaultPostHog().init('testtoken', config, uuidv7())
if (!posthog) {
throw new Error('PostHog failed to initialize')
}
return Object.assign(posthog, overrides || {})
}

Expand All @@ -47,7 +50,7 @@ describe('posthog core', () => {
})

it('adds system time to events', () => {
const captureData = posthogWith(defaultConfig, defaultOverrides).capture(eventName, {}, {})
const captureData = posthogWith(defaultConfig, defaultOverrides).capture(eventName, {}, {})!

expect(captureData).toHaveProperty('timestamp')
// timer is fixed at 2020-01-01
Expand All @@ -59,7 +62,7 @@ describe('posthog core', () => {
eventName,
{},
{ timestamp: new Date(2020, 0, 2, 12, 34) }
)
)!
expect(captureData).toHaveProperty('timestamp')
expect(captureData.timestamp).toEqual(new Date(2020, 0, 2, 12, 34))
expect(captureData.properties['$event_time_override_provided']).toEqual(true)
Expand Down Expand Up @@ -115,8 +118,8 @@ describe('posthog core', () => {

posthog.capture(eventName, {}, {})

expect(posthog.sessionPersistence.update_campaign_params).toHaveBeenCalled()
expect(posthog.sessionPersistence.update_referrer_info).toHaveBeenCalled()
expect(posthog.sessionPersistence?.update_campaign_params).toHaveBeenCalled()
expect(posthog.sessionPersistence?.update_referrer_info).toHaveBeenCalled()
})

it('errors with undefined event name', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/autocapture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class Autocapture {
return config
}

private _addDomEventHandlers(): void {
_addDomEventHandlers(): void {
if (!this.isBrowserSupported()) {
logger.info('Disabling Automatic Event Collection because this browser is not supported')
return
Expand Down
2 changes: 2 additions & 0 deletions src/posthog-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ class DeprecatedWebPerformanceObserver {
export class PostHog {
__loaded: boolean
config: PostHogConfig
lib_version: string

rateLimiter: RateLimiter
scrollManager: ScrollManager
Expand Down Expand Up @@ -285,6 +286,7 @@ export class PostHog {
this.__request_queue = []
this.__loaded = false
this.analyticsDefaultEndpoint = '/e/'
this.lib_version = Config.LIB_VERSION

this.featureFlags = new PostHogFeatureFlags(this)
this.toolbar = new Toolbar(this)
Expand Down
9 changes: 9 additions & 0 deletions tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"strict": false,
"noImplicitAny": false
},
"include": ["src/**/*.ts*", "src/__tests__/**/*.ts*"],
"exclude": []
}

0 comments on commit 331201f

Please sign in to comment.