-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: downgrade jest types #1442
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,22 @@ | ||
/* eslint-disable compat/compat */ | ||
import { v4 } from 'uuid' | ||
import { createPosthogInstance } from '../src/__tests__/helpers/posthog-instance' | ||
import { waitFor } from '@testing-library/dom' | ||
import { getRequests, resetRequests } from './mock-server' | ||
import { uuidv7 } from '../src/uuidv7' | ||
|
||
async function shortWait() { | ||
// no need to worry about ie11 compat in tests | ||
// eslint-disable-next-line compat/compat | ||
await new Promise<void>((resolve: () => void) => setTimeout(resolve, 500)) | ||
} | ||
|
||
describe('FunctionalTests / Feature Flags', () => { | ||
let token: string | ||
|
||
beforeEach(() => { | ||
token = uuidv7() | ||
}) | ||
|
||
test('person properties set in identify() with new distinct_id are sent to decide', async () => { | ||
const token = v4() | ||
const posthog = await createPosthogInstance(token, { advanced_disable_decide: false }) | ||
|
||
const anonymousId = posthog.get_distinct_id() | ||
|
@@ -25,14 +35,14 @@ describe('FunctionalTests / Feature Flags', () => { | |
resetRequests(token) | ||
|
||
// wait for decide callback | ||
await new Promise<void>((resolve: () => void) => setTimeout(resolve, 500)) | ||
await shortWait() | ||
|
||
// Person properties set here should also be sent to the decide endpoint. | ||
posthog.identify('test-id', { | ||
email: '[email protected]', | ||
}) | ||
|
||
await new Promise((resolve: () => void) => setTimeout(resolve, 500)) | ||
await shortWait() | ||
|
||
await waitFor(() => { | ||
expect(getRequests(token)['/decide/']).toEqual([ | ||
|
@@ -52,7 +62,6 @@ describe('FunctionalTests / Feature Flags', () => { | |
}) | ||
|
||
test('person properties set in identify() with the same distinct_id are sent to decide', async () => { | ||
const token = v4() | ||
const posthog = await createPosthogInstance(token, { advanced_disable_decide: false }) | ||
|
||
const anonymousId = posthog.get_distinct_id() | ||
|
@@ -71,8 +80,7 @@ describe('FunctionalTests / Feature Flags', () => { | |
resetRequests(token) | ||
|
||
// wait for decide callback | ||
// eslint-disable-next-line compat/compat | ||
await new Promise((resolve: () => void) => setTimeout(resolve, 500)) | ||
await shortWait() | ||
|
||
// First we identify with a new distinct_id but with no properties set | ||
posthog.identify('test-id') | ||
|
@@ -111,7 +119,6 @@ describe('FunctionalTests / Feature Flags', () => { | |
}) | ||
|
||
test('identify() triggers new request in queue after first request', async () => { | ||
const token = v4() | ||
const posthog = await createPosthogInstance(token, { advanced_disable_decide: false }) | ||
|
||
const anonymousId = posthog.get_distinct_id() | ||
|
@@ -139,8 +146,7 @@ describe('FunctionalTests / Feature Flags', () => { | |
}) | ||
|
||
// wait for decide callback | ||
// eslint-disable-next-line compat/compat | ||
await new Promise((resolve: () => void) => setTimeout(resolve, 500)) | ||
await shortWait() | ||
|
||
// now second call should've fired | ||
await waitFor(() => { | ||
|
@@ -157,7 +163,6 @@ describe('FunctionalTests / Feature Flags', () => { | |
}) | ||
|
||
test('identify() does not trigger new request in queue after first request for loaded callback', async () => { | ||
const token = v4() | ||
await createPosthogInstance(token, { | ||
advanced_disable_decide: false, | ||
bootstrap: { distinctID: 'anon-id' }, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,24 @@ | ||
import 'regenerator-runtime/runtime' | ||
import { waitFor } from '@testing-library/dom' | ||
import { v4 } from 'uuid' | ||
import { getRequests } from './mock-server' | ||
import { createPosthogInstance } from '../src/__tests__/helpers/posthog-instance' | ||
import { logger } from '../src/utils/logger' | ||
import { uuidv7 } from '../src/uuidv7' | ||
import { PostHog } from '../src/posthog-core' | ||
jest.mock('../src/utils/logger') | ||
|
||
describe('FunctionalTests / Identify', () => { | ||
test('identify sends a identify event', async () => { | ||
const token = v4() | ||
const posthog = await createPosthogInstance(token) | ||
|
||
const anonymousId = posthog.get_distinct_id() | ||
let token: string | ||
let posthog: PostHog | ||
let anonymousId: string | ||
|
||
beforeEach(async () => { | ||
token = uuidv7() | ||
posthog = await createPosthogInstance(token) | ||
anonymousId = posthog.get_distinct_id() | ||
}) | ||
Comment on lines
+11
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same same, a little tidying since we're removing uuid from here |
||
|
||
test('identify sends a identify event', async () => { | ||
posthog.identify('test-id') | ||
|
||
await waitFor(() => | ||
|
@@ -34,11 +40,6 @@ describe('FunctionalTests / Identify', () => { | |
test('identify sends an engage request if identify called twice with the same distinct id and with $set/$set_once', async () => { | ||
// The intention here is to reduce the number of unncecessary $identify | ||
// requests to process. | ||
const token = v4() | ||
const posthog = await createPosthogInstance(token) | ||
|
||
const anonymousId = posthog.get_distinct_id() | ||
|
||
// The first time we identify, it calls the /e/ endpoint with an $identify | ||
posthog.identify('test-id', { email: '[email protected]' }, { location: 'first' }) | ||
|
||
|
@@ -82,11 +83,6 @@ describe('FunctionalTests / Identify', () => { | |
|
||
test('identify sends an $set event if identify called twice with a different distinct_id', async () => { | ||
// This is due to $identify only being called for anonymous users. | ||
const token = v4() | ||
const posthog = await createPosthogInstance(token) | ||
|
||
const anonymousId = posthog.get_distinct_id() | ||
|
||
// The first time we identify, it calls the /e/ endpoint with an $identify | ||
posthog.identify('test-id', { email: '[email protected]' }, { location: 'first' }) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,18 +58,16 @@ | |
"@rrweb/types": "2.0.0-alpha.13", | ||
"@sentry/types": "8.7.0", | ||
"@testing-library/dom": "^9.3.0", | ||
"@testing-library/jest-dom": "^6.4.5", | ||
"@testing-library/jest-dom": "^6.5.0", | ||
"@testing-library/preact": "^3.2.4", | ||
"@types/eslint": "^8.44.6", | ||
"@types/jest": "^29.5.1", | ||
"@types/jest": "^27.5.1", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the fix we came here to make |
||
"@types/node": "^22.5.0", | ||
"@types/react-dom": "^18.0.10", | ||
"@types/sinon": "^17.0.1", | ||
"@types/uuid": "^9.0.1", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. was weird that we were importing a function from a types package anyway |
||
"@types/web": "^0.0.154", | ||
"@typescript-eslint/eslint-plugin": "^8.2.0", | ||
"@typescript-eslint/parser": "^8.2.0", | ||
"babel-eslint": "10.1.0", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clearly not using this |
||
"babel-jest": "^26.6.3", | ||
"compare-versions": "^6.1.0", | ||
"cypress": "13.6.3", | ||
|
@@ -79,7 +77,7 @@ | |
"eslint-config-posthog-js": "link:eslint-rules", | ||
"eslint-config-prettier": "^8.5.0", | ||
"eslint-plugin-compat": "^4.1.4", | ||
"eslint-plugin-jest": "^28.8.0", | ||
"eslint-plugin-jest": "^28.8.3", | ||
"eslint-plugin-no-only-tests": "^3.1.0", | ||
"eslint-plugin-posthog-js": "link:eslint-rules", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a little tidying while we're in here