:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(autoresearch): speed up SQL editor Jest tests (#94730)
Paul D'Ambra5cc536ba79df
diff --git a/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.test.ts b/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.test.tsindex 23312ed40561..3d4801fb9b58 100644--- a/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.test.ts+++ b/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.test.ts@@ -12,8 +12,6 @@ import { insightsApi } from 'scenes/insights/utils/api'import { getMarkdownNotebookMarkdown } from 'scenes/notebooks/Notebook/markdownNotebookV2'import { NotebookNodeType } from 'scenes/notebooks/types'import { defaultNotebookContent } from 'scenes/notebooks/utils'-import { sceneLogic } from 'scenes/sceneLogic'-import { teamLogic } from 'scenes/teamLogic'import { urls } from 'scenes/urls'import { useMocks } from '~/mocks/jest'@@ -216,6 +214,16 @@ function createMonacoWithModel(model: any): any {return monaco}+async function runDebouncedAction(action: () => void): Promise<void> {+ jest.useFakeTimers()+ try {+ action()+ await jest.advanceTimersByTimeAsync(600)+ } finally {+ jest.useRealTimers()+ }+}+describe('sqlEditorLogic', () => {let logic: ReturnType<typeof sqlEditorLogic.build>let editorRootLogic: ReturnType<typeof editorSceneLogic.build> | undefined@@ -295,11 +303,8 @@ describe('sqlEditorLogic', () => {})initKeaTests()- teamLogic.mount()- sceneLogic.mount()databaseLogic = databaseTableListLogic()databaseLogic.mount()- await expectLogic(teamLogic).toFinishAllListeners()})afterEach(() => {@@ -1514,8 +1519,7 @@ describe('sqlEditorLogic', () => {outputActiveTab: OutputTab.Visualization,})- logic.actions.setQueryInput('SELECT 2')- await new Promise((resolve) => setTimeout(resolve, 600))+ await runDebouncedAction(() => logic.actions.setQueryInput('SELECT 2'))expect(router.values.hashParams.q).toEqual('SELECT 2')expect(router.values.hashParams.output_tab).toEqual(OutputTab.Visualization)@@ -2009,8 +2013,7 @@ describe('sqlEditorLogic', () => {await expectLogic(logic).toDispatchActions(['setEditorSource', 'createTab', 'updateTab'])- logic.actions.setQueryInput('SELECT 2')- await new Promise((resolve) => setTimeout(resolve, 600))+ await runDebouncedAction(() => logic.actions.setQueryInput('SELECT 2'))expect(router.values.searchParams.source).toBeUndefined()expect(router.values.hashParams.q).toEqual('SELECT 2')@@ -2051,8 +2054,7 @@ describe('sqlEditorLogic', () => {await expectLogic(logic).toDispatchActions(['setEditorSource', 'createTab', 'updateTab'])- logic.actions.setQueryInput('SELECT 2')- await new Promise((resolve) => setTimeout(resolve, 600))+ await runDebouncedAction(() => logic.actions.setQueryInput('SELECT 2'))expect(router.values.searchParams.source).toBeUndefined()expect(router.values.hashParams.q).toEqual('SELECT 2')@@ -2117,8 +2119,7 @@ describe('sqlEditorLogic', () => {expect(logic.values.sourceQuery.source.connectionId).toEqual('conn-123')expect(router.values.hashParams.c).toEqual('conn-123')- logic.actions.setQueryInput('SELECT 2')- await new Promise((resolve) => setTimeout(resolve, 600))+ await runDebouncedAction(() => logic.actions.setQueryInput('SELECT 2'))expect(router.values.hashParams.q).toEqual('SELECT 2')expect(router.values.hashParams.c).toEqual('conn-123')@@ -2140,8 +2141,7 @@ describe('sqlEditorLogic', () => {expect(logic.values.sendRawQueryEnabled).toEqual(true)expect(String(router.values.hashParams.raw)).toEqual('1')- logic.actions.setQueryInput('SELECT 2')- await new Promise((resolve) => setTimeout(resolve, 600))+ await runDebouncedAction(() => logic.actions.setQueryInput('SELECT 2'))expect(router.values.hashParams.q).toEqual('SELECT 2')expect(router.values.hashParams.c).toEqual('conn-123')