Skip to content

Commit 7fd1a44

Browse files
committed
chore(vscode): add test for quickfix
1 parent 405155d commit 7fd1a44

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import fs from 'fs-extra'
2+
import path from 'path'
3+
import os from 'os'
4+
import { openProblemsView, SUSHI_SOURCE_PATH } from './utils'
5+
import { test, expect } from './fixtures'
6+
import { createPythonInterpreterSettingsSpecifier } from './utils_code_server'
7+
8+
test('noselectstar quickfix', async ({ page, sharedCodeServer }) => {
9+
// Base test setup
10+
const tempDir = await fs.mkdtemp(
11+
path.join(os.tmpdir(), 'vscode-test-tcloud-'),
12+
)
13+
await fs.copy(SUSHI_SOURCE_PATH, tempDir)
14+
await createPythonInterpreterSettingsSpecifier(tempDir)
15+
16+
// Override the settings for the linter
17+
const configPath = path.join(tempDir, 'config.py')
18+
const read = await fs.readFile(configPath, 'utf8')
19+
// Replace linter to be on
20+
const replaced = read.replace('enabled=False', 'enabled=True')
21+
const replacedTheOtherRules = replaced.replace(
22+
`rules=[
23+
"ambiguousorinvalidcolumn",
24+
"invalidselectstarexpansion",
25+
"noselectstar",
26+
"nomissingaudits",
27+
"nomissingowner",
28+
],`,
29+
`rules=[
30+
"noselectstar",
31+
],
32+
`,
33+
)
34+
await fs.writeFile(configPath, replacedTheOtherRules)
35+
// Replace the file to cause the error
36+
const modelPath = path.join(tempDir, 'models', 'latest_order.sql')
37+
const readModel = await fs.readFile(modelPath, 'utf8')
38+
// Replace the specific select with the select star
39+
const modelReplaced = readModel.replace(
40+
'SELECT id, customer_id, start_ts, end_ts, event_date',
41+
'SELECT *',
42+
)
43+
await fs.writeFile(modelPath, modelReplaced)
44+
45+
// Open the code server with the specified directory
46+
await page.goto(
47+
`http://127.0.0.1:${sharedCodeServer.codeServerPort}/?folder=${tempDir}`,
48+
)
49+
await page.waitForLoadState('networkidle')
50+
51+
// Open the file with the linter issue
52+
await page
53+
.getByRole('treeitem', { name: 'models', exact: true })
54+
.locator('a')
55+
.click()
56+
await page
57+
.getByRole('treeitem', { name: 'latest_order.sql', exact: true })
58+
.locator('a')
59+
.click()
60+
61+
await page.waitForSelector('text=Loaded SQLMesh context')
62+
63+
await openProblemsView(page)
64+
65+
await page.getByRole('button', { name: 'Show fixes' }).click()
66+
await page
67+
.getByRole('menuitem', { name: 'Replace SELECT * with' })
68+
.first()
69+
.click()
70+
71+
// Wait for the quick fix to be applied
72+
await page.waitForTimeout(2_000)
73+
74+
// Assert that the model no longer contains SELECT * but SELECT id, customer_id, waiter_id, start_ts, end_ts, event_date
75+
const readUpdatedFile = (await fs.readFile(modelPath)).toString('utf8')
76+
expect(readUpdatedFile).not.toContain('SELECT *')
77+
expect(readUpdatedFile).toContain(
78+
'SELECT id, customer_id, waiter_id, start_ts, end_ts, event_date',
79+
)
80+
})

0 commit comments

Comments
 (0)