Skip to content

Commit 5399797

Browse files
committed
chore: speed up tests when running locally
- when running the tests one by one in vscode for example - this skips the step of installation if already installed making the tests run faster
1 parent 68eec22 commit 5399797

2 files changed

Lines changed: 99 additions & 13 deletions

File tree

vscode/extension/tests/broken_project.spec.ts

Lines changed: 69 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { test } from '@playwright/test'
1+
import { test, expect } from '@playwright/test'
22
import fs from 'fs-extra'
33
import os from 'os'
44
import path from 'path'
@@ -95,18 +95,59 @@ test('working project, then broken through adding double model, then refixed', a
9595
await saveFile(page)
9696

9797
// Wait for the error to appear
98-
// TODO: Selector doesn't work in the linage view
99-
// await window.waitForSelector('text=Error')
98+
const iframes = page.locator('iframe')
99+
const iframeCount = await iframes.count()
100+
let errorCount = 0
101+
102+
for (let i = 0; i < iframeCount; i++) {
103+
const iframe = iframes.nth(i)
104+
const contentFrame = iframe.contentFrame()
105+
if (contentFrame) {
106+
const activeFrame = contentFrame.locator('#active-frame').contentFrame()
107+
if (activeFrame) {
108+
try {
109+
await activeFrame
110+
.getByText('Error: Failed to load model')
111+
.waitFor({ timeout: 1000 })
112+
errorCount++
113+
} catch {
114+
// Continue to next iframe if this one doesn't have the error
115+
continue
116+
}
117+
}
118+
}
119+
}
120+
expect(errorCount).toBeGreaterThan(0)
100121

101122
// Remove the duplicated model to fix the project
102123
await fs.remove(path.join(tempDir, 'models', 'customers_duplicated.sql'))
103124

104125
// Save again to refresh the context
105126
await saveFile(page)
106127

107-
// Wait for the error to go away and context to reload
108-
// TODO: Selector doesn't work in the linage view
109-
// await page.waitForSelector('text=raw.demographics')
128+
const iframes2 = page.locator('iframe')
129+
const iframeCount2 = await iframes2.count()
130+
let raw_demographicsCount = 0
131+
132+
for (let i = 0; i < iframeCount2; i++) {
133+
const iframe = iframes2.nth(i)
134+
const contentFrame = iframe.contentFrame()
135+
if (contentFrame) {
136+
const activeFrame = contentFrame.locator('#active-frame').contentFrame()
137+
if (activeFrame) {
138+
try {
139+
await activeFrame
140+
.getByText('raw.demographics')
141+
.waitFor({ timeout: 1000 })
142+
raw_demographicsCount++
143+
} catch {
144+
// Continue to next iframe if this one doesn't have the error
145+
continue
146+
}
147+
}
148+
}
149+
}
150+
expect(raw_demographicsCount).toBeGreaterThan(0)
110151
} finally {
111152
await stopCodeServer(context)
112153
}
@@ -158,8 +199,28 @@ test('bad project, double model, then fixed', async ({ page }) => {
158199
await openLineageView(page)
159200

160201
// Wait for the error to go away
161-
// TODO: Selector doesn't work in the linage view
162-
// await page.waitForSelector('text=raw.demographics')
202+
const iframes = page.locator('iframe')
203+
const iframeCount = await iframes.count()
204+
let raw_demographicsCount = 0
205+
206+
for (let i = 0; i < iframeCount; i++) {
207+
const iframe = iframes.nth(i)
208+
const contentFrame = iframe.contentFrame()
209+
if (contentFrame) {
210+
const activeFrame = contentFrame.locator('#active-frame').contentFrame()
211+
if (activeFrame) {
212+
try {
213+
await activeFrame
214+
.getByText('sushi.customers')
215+
.waitFor({ timeout: 1000 })
216+
raw_demographicsCount++
217+
} catch {
218+
continue
219+
}
220+
}
221+
}
222+
}
223+
expect(raw_demographicsCount).toBeGreaterThan(0)
163224
} finally {
164225
await stopCodeServer(context)
165226
}

vscode/extension/tests/global-setup.ts

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { execSync } from 'child_process'
22
import path from 'path'
33
import fs from 'fs-extra'
4+
import { createHash } from 'crypto'
45

56
async function globalSetup() {
67
console.log('Setting up extension for Playwright tests...')
@@ -10,8 +11,6 @@ async function globalSetup() {
1011
const extensionsDir = path.join(testSetupDir, 'extensions')
1112

1213
// Clean up any existing test setup directory
13-
await fs.remove(testSetupDir)
14-
await fs.ensureDir(extensionsDir)
1514

1615
// Get the extension version from package.json
1716
const packageJson = JSON.parse(
@@ -30,26 +29,52 @@ async function globalSetup() {
3029
)
3130
}
3231

33-
console.log(`Installing extension: ${vsixFileName}`)
34-
3532
// Create a temporary user data directory for the installation
3633
const tempUserDataDir = await fs.mkdtemp(
3734
path.join(require('os').tmpdir(), 'vscode-test-install-user-data-'),
3835
)
3936

4037
try {
38+
// Check if in .test_setup there is a extension hash file which contains the hash of the extension
39+
// If it does, check if the hash is the same as the hash of the extension in the vsix file
40+
// If it is, skip the installation
41+
// If it is not, remove the extension hash file and install the extension
42+
const extensionHashFile = path.join(testSetupDir, 'extension-hash.txt')
43+
console.log('extensionHashFile', extensionHashFile)
44+
if (fs.existsSync(extensionHashFile)) {
45+
const extensionHash = fs.readFileSync(extensionHashFile, 'utf-8')
46+
const vsixHash = await hashFile(vsixPath)
47+
if (extensionHash === vsixHash) {
48+
console.log('Extension already installed')
49+
return
50+
}
51+
}
52+
53+
await fs.remove(testSetupDir)
54+
await fs.ensureDir(testSetupDir)
55+
await fs.ensureDir(extensionsDir)
56+
57+
console.log(`Installing extension: ${vsixFileName}`)
4158
execSync(
4259
`pnpm run code-server --user-data-dir "${tempUserDataDir}" --extensions-dir "${extensionsDir}" --install-extension "${vsixPath}"`,
4360
{
4461
stdio: 'inherit',
4562
cwd: extensionDir,
4663
},
4764
)
48-
console.log('Extension installed successfully to .test_setup/extensions')
65+
66+
// Write the hash of the extension to the extension hash file
67+
const extensionHash = await hashFile(vsixPath)
68+
await fs.writeFile(extensionHashFile, extensionHash)
4969
} finally {
5070
// Clean up temporary user data directory
5171
await fs.remove(tempUserDataDir)
5272
}
5373
}
5474

75+
async function hashFile(filePath: string): Promise<string> {
76+
const fileBuffer = await fs.readFile(filePath)
77+
return createHash('sha256').update(fileBuffer).digest('hex')
78+
}
79+
5580
export default globalSetup

0 commit comments

Comments
 (0)