@@ -4,14 +4,17 @@ import os from 'os'
44import path from 'path'
55import {
66 createVirtualEnvironment ,
7+ openFile ,
78 openLineageView ,
89 pipInstall ,
910 REPO_ROOT ,
10- startVSCode ,
1111 SUSHI_SOURCE_PATH ,
1212} from './utils'
13+ import { startCodeServer , stopCodeServer } from './utils_code_server'
1314
14- test ( 'missing LSP dependencies shows install prompt' , async ( { } , testInfo ) => {
15+ test ( 'missing LSP dependencies shows install prompt' , async ( {
16+ page,
17+ } , testInfo ) => {
1518 testInfo . setTimeout ( 120_000 ) // 2 minutes for venv creation and package installation
1619 const tempDir = await fs . mkdtemp (
1720 path . join ( os . tmpdir ( ) , 'vscode-test-tcloud-' ) ,
@@ -26,6 +29,11 @@ test('missing LSP dependencies shows install prompt', async ({}, testInfo) => {
2629 const sqlmeshWithExtras = `${ REPO_ROOT } [bigquery]`
2730 await pipInstall ( pythonDetails , [ sqlmeshWithExtras , custom_materializations ] )
2831
32+ // Start VS Code
33+ const context = await startCodeServer ( {
34+ tempDir,
35+ } )
36+
2937 try {
3038 // Copy sushi project
3139 await fs . copy ( SUSHI_SOURCE_PATH , tempDir )
@@ -42,45 +50,45 @@ test('missing LSP dependencies shows install prompt', async ({}, testInfo) => {
4250 { spaces : 2 } ,
4351 )
4452
45- // Start VS Code
46- const { window, close } = await startVSCode ( tempDir )
53+ await page . goto ( `http://127.0.0.1:${ context . codeServerPort } ` )
4754
4855 // Open a SQL file to trigger SQLMesh activation
4956 // Wait for the models folder to be visible
50- await window . waitForSelector ( 'text=models' )
57+ await page . waitForSelector ( 'text=models' )
5158
5259 // Click on the models folder
53- await window
60+ await page
5461 . getByRole ( 'treeitem' , { name : 'models' , exact : true } )
5562 . locator ( 'a' )
5663 . click ( )
5764
5865 // Open the top_waiters model
59- await window
66+ await page
6067 . getByRole ( 'treeitem' , { name : 'customers.sql' , exact : true } )
6168 . locator ( 'a' )
6269 . click ( )
6370
6471 // Wait for the message to show that LSP extras need to be installed
65- await window . waitForSelector ( 'text=LSP dependencies missing' )
66- expect ( await window . locator ( 'text=Install' ) . count ( ) ) . toBeGreaterThanOrEqual (
67- 1 ,
68- )
69-
70- await close ( )
72+ await page . waitForSelector ( 'text=LSP dependencies missing' )
73+ expect ( await page . locator ( 'text=Install' ) . count ( ) ) . toBeGreaterThanOrEqual ( 1 )
7174 } finally {
72- // Clean up
73- await fs . remove ( tempDir )
75+ await stopCodeServer ( context )
7476 }
7577} )
7678
77- test ( 'lineage, no sqlmesh found' , async ( { } ) => {
79+ test ( 'lineage, no sqlmesh found' , async ( { page } , testInfo ) => {
80+ testInfo . setTimeout ( 120_000 ) // 2 minutes for venv creation and package installation
81+
7882 const tempDir = await fs . mkdtemp (
7983 path . join ( os . tmpdir ( ) , 'vscode-test-tcloud-' ) ,
8084 )
8185 const pythonEnvDir = path . join ( tempDir , '.venv' )
8286 const pythonDetails = await createVirtualEnvironment ( pythonEnvDir )
8387
88+ const context = await startCodeServer ( {
89+ tempDir,
90+ } )
91+
8492 try {
8593 // Copy sushi project
8694 await fs . copy ( SUSHI_SOURCE_PATH , tempDir )
@@ -97,25 +105,28 @@ test('lineage, no sqlmesh found', async ({}) => {
97105 { spaces : 2 } ,
98106 )
99107
100- const { window, close } = await startVSCode ( tempDir )
108+ // navigate to code-server instance
109+ await page . goto ( `http://127.0.0.1:${ context . codeServerPort } ` )
110+ await page . waitForLoadState ( 'networkidle' )
101111
102112 // Open lineage view
103- await openLineageView ( window )
113+ await openLineageView ( page )
104114
105115 // Assert shows that sqlmesh is not installed
106- await window . waitForSelector ( 'text=SQLMesh LSP not found' )
107-
108- await close ( )
116+ await page . waitForSelector ( 'text=SQLMesh LSP not found' )
109117 } finally {
110118 // Clean up
111- await fs . remove ( tempDir )
119+ await stopCodeServer ( context )
112120 }
113121} )
114122
115123// Checks that if you have another file open like somewhere else, it still checks the workspace first for a successful context
116124// it's very flaky but runs when debugging
117125// - the typing in of the file name is very flaky
118- test ( 'check that the LSP runs correctly by opening lineage when looking at another file before not in workspace' , async ( { } ) => {
126+ test ( 'check that the LSP runs correctly by opening lineage when looking at another file before not in workspace' , async ( {
127+ page,
128+ } , testInfo ) => {
129+ testInfo . setTimeout ( 120_000 ) // 2 minutes for venv creation and package installation
119130 const tempDir = await fs . mkdtemp (
120131 path . join ( os . tmpdir ( ) , 'vscode-test-tcloud-' ) ,
121132 )
@@ -133,7 +144,7 @@ test('check that the LSP runs correctly by opening lineage when looking at anoth
133144 // Configure VS Code settings to use our Python environment
134145 const settings = {
135146 'python.defaultInterpreterPath' : pythonDetails . pythonPath ,
136- 'sqlmesh.environmentPath' : pythonEnvDir ,
147+ 'sqlmesh.environmentPath' : tempDir ,
137148 }
138149 await fs . ensureDir ( path . join ( tempDir , '.vscode' ) )
139150 await fs . writeJson ( path . join ( tempDir , '.vscode' , 'settings.json' ) , settings , {
@@ -148,19 +159,18 @@ test('check that the LSP runs correctly by opening lineage when looking at anoth
148159 await fs . ensureDir ( path . dirname ( sqlFile ) )
149160 await fs . writeFile ( sqlFile , 'SELECT 1' )
150161
151- const { window, close } = await startVSCode ( tempDir )
162+ const context = await startCodeServer ( {
163+ tempDir,
164+ } )
152165 try {
166+ await page . goto ( `http://127.0.0.1:${ context . codeServerPort } ` )
167+ await page . waitForLoadState ( 'networkidle' )
168+
153169 // Open the SQL file from the other directory
154- await window . keyboard . press ( 'Meta+P' )
155- await window . waitForTimeout ( 100 )
156- await window . keyboard . type ( sqlFile . toString ( ) , { delay : 10 } )
157- await window . waitForTimeout ( 100 )
158- await window . keyboard . press ( 'Enter' )
159- await window . waitForTimeout ( 100 )
160-
161- await window . waitForSelector ( 'text=Loaded SQLMesh context' )
170+ await openFile ( page , sqlFile )
171+
172+ await page . waitForSelector ( 'text=Loaded SQLMesh context' )
162173 } finally {
163- await close ( )
164- await fs . remove ( tempDir )
174+ await stopCodeServer ( context )
165175 }
166176} )
0 commit comments