Skip to content

Commit 107fe25

Browse files
authored
chore(vscode): refactoring e2e tests (#4962)
1 parent 606b740 commit 107fe25

17 files changed

+115
-226
lines changed

vscode/extension/tests/bad_setup.spec.ts

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
createVirtualEnvironment,
77
openFile,
88
openLineageView,
9+
openServerPage,
910
pipInstall,
1011
REPO_ROOT,
1112
SUSHI_SOURCE_PATH,
@@ -41,21 +42,13 @@ test('missing LSP dependencies shows install prompt', async ({
4142
spaces: 2,
4243
})
4344

44-
await page.goto(
45-
`http://127.0.0.1:${sharedCodeServer.codeServerPort}/?folder=${tempDir}`,
46-
)
47-
48-
// Open a SQL file to trigger SQLMesh activation
49-
// Wait for the models folder to be visible
50-
await page.waitForSelector('text=models')
45+
await openServerPage(page, tempDir, sharedCodeServer)
5146

52-
// Click on the models folder
47+
// Open a top_waiters model to trigger SQLMesh activation
5348
await page
5449
.getByRole('treeitem', { name: 'models', exact: true })
5550
.locator('a')
5651
.click()
57-
58-
// Open the top_waiters model
5952
await page
6053
.getByRole('treeitem', { name: 'customers.sql', exact: true })
6154
.locator('a')
@@ -66,12 +59,7 @@ test('missing LSP dependencies shows install prompt', async ({
6659
expect(await page.locator('text=Install').count()).toBeGreaterThanOrEqual(1)
6760
})
6861

69-
test('lineage, no sqlmesh found', async ({
70-
page,
71-
sharedCodeServer,
72-
}, testInfo) => {
73-
testInfo.setTimeout(120_000) // 2 minutes for venv creation and package installation
74-
62+
test('lineage, no sqlmesh found', async ({ page, sharedCodeServer }) => {
7563
const tempDir = await fs.mkdtemp(
7664
path.join(os.tmpdir(), 'vscode-test-tcloud-'),
7765
)
@@ -92,12 +80,8 @@ test('lineage, no sqlmesh found', async ({
9280
})
9381

9482
// navigate to code-server instance
95-
await page.goto(
96-
`http://127.0.0.1:${sharedCodeServer.codeServerPort}/?folder=${tempDir}`,
97-
)
98-
await page.waitForLoadState('networkidle')
83+
await openServerPage(page, tempDir, sharedCodeServer)
9984

100-
// Open lineage view
10185
await openLineageView(page)
10286

10387
// Assert shows that sqlmesh is not installed
@@ -143,10 +127,7 @@ test.skip('check that the LSP runs correctly by opening lineage when looking at
143127
await fs.ensureDir(path.dirname(sqlFile))
144128
await fs.writeFile(sqlFile, 'SELECT 1')
145129

146-
await page.goto(
147-
`http://127.0.0.1:${sharedCodeServer.codeServerPort}/?folder=${tempDir}`,
148-
)
149-
await page.waitForLoadState('networkidle')
130+
await openServerPage(page, tempDir, sharedCodeServer)
150131

151132
// Open the SQL file from the other directory
152133
await openFile(page, sqlFile)

vscode/extension/tests/broken_project.spec.ts

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import os from 'os'
44
import path from 'path'
55
import {
66
openLineageView,
7+
openServerPage,
78
runCommand,
89
saveFile,
910
SUSHI_SOURCE_PATH,
@@ -29,9 +30,7 @@ test('bad project, double model', async ({ page, sharedCodeServer }) => {
2930
)
3031

3132
await createPythonInterpreterSettingsSpecifier(tempDir)
32-
await page.goto(
33-
`http://127.0.0.1:${sharedCodeServer.codeServerPort}/?folder=${tempDir}`,
34-
)
33+
await openServerPage(page, tempDir, sharedCodeServer)
3534

3635
await page.waitForSelector('text=models')
3736

@@ -60,9 +59,7 @@ test('working project, then broken through adding double model, then refixed', a
6059
await fs.copy(SUSHI_SOURCE_PATH, tempDir)
6160

6261
await createPythonInterpreterSettingsSpecifier(tempDir)
63-
await page.goto(
64-
`http://127.0.0.1:${sharedCodeServer.codeServerPort}/?folder=${tempDir}`,
65-
)
62+
await openServerPage(page, tempDir, sharedCodeServer)
6663
await page.waitForLoadState('networkidle')
6764

6865
// Open the lineage view to confirm it loads properly
@@ -170,13 +167,7 @@ test('bad project, double model, then fixed', async ({
170167
customersSql,
171168
)
172169

173-
await page.goto(
174-
`http://127.0.0.1:${sharedCodeServer.codeServerPort}/?folder=${tempDir}`,
175-
)
176-
await page.waitForLoadState('networkidle')
177-
await page.goto(
178-
`http://127.0.0.1:${sharedCodeServer.codeServerPort}/?folder=${tempDir}`,
179-
)
170+
await openServerPage(page, tempDir, sharedCodeServer)
180171

181172
await page.waitForSelector('text=models')
182173

@@ -245,10 +236,7 @@ test('bad project, double model, check lineage', async ({
245236
)
246237

247238
await createPythonInterpreterSettingsSpecifier(tempDir)
248-
await page.goto(
249-
`http://127.0.0.1:${sharedCodeServer.codeServerPort}/?folder=${tempDir}`,
250-
)
251-
await page.waitForLoadState('networkidle')
239+
await openServerPage(page, tempDir, sharedCodeServer)
252240

253241
// Open the lineage view
254242
await openLineageView(page)
@@ -273,9 +261,7 @@ test('bad model block, then fixed', async ({ page, sharedCodeServer }) => {
273261
'MODEL ( name sushi.bad_block, test); SELECT * FROM sushi.customers'
274262
await fs.writeFile(badModelPath, contents)
275263

276-
await page.goto(
277-
`http://127.0.0.1:${sharedCodeServer.codeServerPort}/?folder=${tempDir}`,
278-
)
264+
await openServerPage(page, tempDir, sharedCodeServer)
279265
await page.waitForLoadState('networkidle')
280266

281267
// Open the customers.sql model

vscode/extension/tests/completions.spec.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@ import { test, expect } from './fixtures'
22
import path from 'path'
33
import fs from 'fs-extra'
44
import os from 'os'
5-
import { SUSHI_SOURCE_PATH } from './utils'
5+
import { openServerPage, SUSHI_SOURCE_PATH } from './utils'
66
import { createPythonInterpreterSettingsSpecifier } from './utils_code_server'
77

88
test('Autocomplete for model names', async ({ page, sharedCodeServer }) => {
99
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'vscode-test-sushi-'))
1010
await fs.copy(SUSHI_SOURCE_PATH, tempDir)
1111

1212
await createPythonInterpreterSettingsSpecifier(tempDir)
13-
await page.goto(
14-
`http://127.0.0.1:${sharedCodeServer.codeServerPort}/?folder=${tempDir}`,
15-
)
13+
await openServerPage(page, tempDir, sharedCodeServer)
1614

1715
// Wait for the models folder to be visible
1816
await page.waitForSelector('text=models')
@@ -67,9 +65,7 @@ test.describe('Macro Completions', () => {
6765
await fs.copy(SUSHI_SOURCE_PATH, tempDir)
6866

6967
await createPythonInterpreterSettingsSpecifier(tempDir)
70-
await page.goto(
71-
`http://127.0.0.1:${sharedCodeServer.codeServerPort}/?folder=${tempDir}`,
72-
)
68+
await openServerPage(page, tempDir, sharedCodeServer)
7369

7470
// Wait for the models folder to be visible
7571
await page.waitForSelector('text=models')
@@ -119,10 +115,7 @@ test.describe('Macro Completions', () => {
119115
await fs.copy(SUSHI_SOURCE_PATH, tempDir)
120116

121117
await createPythonInterpreterSettingsSpecifier(tempDir)
122-
123-
await page.goto(
124-
`http://127.0.0.1:${sharedCodeServer.codeServerPort}/?folder=${tempDir}`,
125-
)
118+
await openServerPage(page, tempDir, sharedCodeServer)
126119

127120
// Wait for the models folder to be visible
128121
await page.waitForSelector('text=models')

vscode/extension/tests/diagnostics.spec.ts

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { expect, test } from './fixtures'
22
import path from 'path'
33
import fs from 'fs-extra'
44
import os from 'os'
5-
import { runCommand, SUSHI_SOURCE_PATH } from './utils'
5+
import { openServerPage, runCommand, SUSHI_SOURCE_PATH } from './utils'
66
import { createPythonInterpreterSettingsSpecifier } from './utils_code_server'
77
import { execAsync } from '../src/utilities/exec'
88
import yaml from 'yaml'
@@ -20,10 +20,7 @@ test('Workspace diagnostics show up in the diagnostics panel', async ({
2020
const updatedContent = configContent.replace('enabled=False', 'enabled=True')
2121
await fs.writeFile(configPath, updatedContent)
2222

23-
await page.goto(
24-
`http://127.0.0.1:${sharedCodeServer.codeServerPort}/?folder=${tempDir}`,
25-
)
26-
23+
await openServerPage(page, tempDir, sharedCodeServer)
2724
// Wait for the models folder to be visible
2825
await page.waitForSelector('text=models')
2926

@@ -70,10 +67,7 @@ test.describe('Bad config.py/config.yaml file issues', () => {
7067
// Write an invalid YAML to config.yaml
7168
await fs.writeFile(configYamlPath, 'invalid_yaml; asdfasudfy')
7269

73-
await page.goto(
74-
`http://127.0.0.1:${sharedCodeServer.codeServerPort}/?folder=${tempDir}`,
75-
)
76-
await page.waitForLoadState('networkidle')
70+
await openServerPage(page, tempDir, sharedCodeServer)
7771

7872
// Open full_model.sql model
7973
await page
@@ -116,10 +110,7 @@ test.describe('Bad config.py/config.yaml file issues', () => {
116110
// Write config to the yaml file
117111
await fs.writeFile(configYamlPath, yaml.stringify(config))
118112

119-
await page.goto(
120-
`http://127.0.0.1:${sharedCodeServer.codeServerPort}/?folder=${tempDir}`,
121-
)
122-
await page.waitForLoadState('networkidle')
113+
await openServerPage(page, tempDir, sharedCodeServer)
123114

124115
// Open full_model.sql model
125116
await page
@@ -158,10 +149,7 @@ test.describe('Bad config.py/config.yaml file issues', () => {
158149
// Write an invalid Python to config.py
159150
await fs.writeFile(configPyPath, 'config = {}')
160151

161-
await page.goto(
162-
`http://127.0.1:${sharedCodeServer.codeServerPort}/?folder=${tempDir}`,
163-
)
164-
await page.waitForLoadState('networkidle')
152+
await openServerPage(page, tempDir, sharedCodeServer)
165153

166154
// Open customers.sql model
167155
await page
@@ -197,10 +185,7 @@ test.describe('Bad config.py/config.yaml file issues', () => {
197185
// Write an invalid Python to config.py
198186
await fs.writeFile(configPyPath, 'invalid_python_code = [1, 2, 3')
199187

200-
await page.goto(
201-
`http://127.0.1:${sharedCodeServer.codeServerPort}/?folder=${tempDir}`,
202-
)
203-
await page.waitForLoadState('networkidle')
188+
await openServerPage(page, tempDir, sharedCodeServer)
204189

205190
// Open customers.sql model
206191
await page
@@ -242,10 +227,7 @@ test.describe('Diagnostics for bad SQLMesh models', () => {
242227
)
243228
await fs.copy(customersSqlPath, duplicatedCustomersSqlPath)
244229

245-
await page.goto(
246-
`http://127.0.0.1:${sharedCodeServer.codeServerPort}/?folder=${tempDir}`,
247-
)
248-
await page.waitForLoadState('networkidle')
230+
await openServerPage(page, tempDir, sharedCodeServer)
249231

250232
// Open full_model.sql model
251233
await page
@@ -334,10 +316,7 @@ test.describe('Diagnostics for bad audits', () => {
334316
await fs.writeFile(auditFilePath, updatedContent)
335317

336318
// Navigate to the code-server instance
337-
await page.goto(
338-
`http://127.0.1:${sharedCodeServer.codeServerPort}/?folder=${tempDir}`,
339-
)
340-
await page.waitForLoadState('networkidle')
319+
await openServerPage(page, tempDir, sharedCodeServer)
341320

342321
// Open a the customers.sql model
343322
await page

0 commit comments

Comments
 (0)