Skip to content

Commit 18e4306

Browse files
committed
temp
1 parent b8bfdfb commit 18e4306

File tree

6 files changed

+78
-109
lines changed

6 files changed

+78
-109
lines changed

vscode/extension/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ node_modules
22
dist
33
out
44
.vscode-test
5+
.test_setup
56
*.vsix
67
LICENSE
78
src_react
Binary file not shown.

vscode/extension/playwright-report/index.html

Lines changed: 0 additions & 77 deletions
This file was deleted.

vscode/extension/playwright.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export default defineConfig({
66
retries: process.env.CI ? 1 : 0,
77
workers: 1,
88
reporter: [['html', { outputFolder: 'playwright-report' }], ['list']],
9+
globalSetup: './tests/global-setup.ts',
910
projects: [
1011
{
1112
name: 'electron-vscode',
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { execSync } from 'child_process'
2+
import path from 'path'
3+
import fs from 'fs-extra'
4+
5+
async function globalSetup() {
6+
console.log('Setting up extension for Playwright tests...')
7+
8+
const extensionDir = path.join(__dirname, '..')
9+
const testSetupDir = path.join(extensionDir, '.test_setup')
10+
const extensionsDir = path.join(testSetupDir, 'extensions')
11+
12+
// Clean up any existing test setup directory
13+
await fs.remove(testSetupDir)
14+
await fs.ensureDir(extensionsDir)
15+
16+
// Get the extension version from package.json
17+
const packageJson = JSON.parse(
18+
fs.readFileSync(path.join(extensionDir, 'package.json'), 'utf-8'),
19+
)
20+
const version = packageJson.version
21+
const extensionName = packageJson.name || 'sqlmesh'
22+
23+
// Look for the specific version .vsix file
24+
const vsixFileName = `${extensionName}-${version}.vsix`
25+
const vsixPath = path.join(extensionDir, vsixFileName)
26+
27+
if (!fs.existsSync(vsixPath)) {
28+
throw new Error(
29+
`Extension file ${vsixFileName} not found. Run "pnpm run vscode:package" first.`,
30+
)
31+
}
32+
33+
console.log(`Installing extension: ${vsixFileName}`)
34+
35+
// Create a temporary user data directory for the installation
36+
const tempUserDataDir = await fs.mkdtemp(
37+
path.join(require('os').tmpdir(), 'vscode-test-install-user-data-'),
38+
)
39+
40+
try {
41+
execSync(
42+
`pnpm run code-server --user-data-dir "${tempUserDataDir}" --extensions-dir "${extensionsDir}" --install-extension "${vsixPath}"`,
43+
{
44+
stdio: 'inherit',
45+
cwd: extensionDir,
46+
},
47+
)
48+
console.log('Extension installed successfully to .test_setup/extensions')
49+
} finally {
50+
// Clean up temporary user data directory
51+
await fs.remove(tempUserDataDir)
52+
}
53+
}
54+
55+
export default globalSetup

vscode/extension/tests/utils_code_server.ts

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,23 @@ export interface CodeServerContext {
1010
defaultPythonInterpreter: string
1111
}
1212

13+
/**
14+
* Get the path to the extensions directory set up by global setup
15+
* @returns The extensions directory path
16+
*/
17+
function getExtensionsDir(): string {
18+
const extensionDir = path.join(__dirname, '..')
19+
const extensionsDir = path.join(extensionDir, '.test_setup', 'extensions')
20+
21+
if (!fs.existsSync(extensionsDir)) {
22+
throw new Error(
23+
`Extensions directory not found at ${extensionsDir}. Make sure global setup has run.`,
24+
)
25+
}
26+
27+
return extensionsDir
28+
}
29+
1330
/**
1431
* @param tempDir - The temporary directory to use for the code-server instance
1532
* @param placeFileWithPythonInterpreter - Whether to place a vscode/settings.json file in the temp directory that points to the python interpreter of the environmen the test is running in.
@@ -22,6 +39,9 @@ export async function startCodeServer({
2239
tempDir: string
2340
placeFileWithPythonInterpreter?: boolean
2441
}): Promise<CodeServerContext> {
42+
// Get the extensions directory set up by global setup
43+
const extensionsDir = getExtensionsDir()
44+
2545
// Find an available port
2646
const codeServerPort = Math.floor(Math.random() * 10000) + 50000
2747
const defaultPythonInterpreter = path.join(
@@ -60,38 +80,7 @@ export async function startCodeServer({
6080
)
6181
}
6282

63-
// Get the extension version from package.json
64-
const extensionDir = path.join(__dirname, '..')
65-
const packageJson = JSON.parse(
66-
fs.readFileSync(path.join(extensionDir, 'package.json'), 'utf-8'),
67-
)
68-
const version = packageJson.version
69-
const extensionName = packageJson.name || 'sqlmesh'
70-
71-
// Look for the specific version .vsix file
72-
const vsixFileName = `${extensionName}-${version}.vsix`
73-
const vsixPath = path.join(extensionDir, vsixFileName)
74-
75-
if (!fs.existsSync(vsixPath)) {
76-
throw new Error(
77-
`Extension file ${vsixFileName} not found. Run "pnpm run vscode:package" first.`,
78-
)
79-
}
80-
81-
console.log(`Using extension: ${vsixFileName}`)
82-
83-
// Install the extension first
84-
const extensionsDir = path.join(tempDir, 'extensions')
85-
console.log('Installing extension...')
86-
execSync(
87-
`pnpm run code-server --user-data-dir "${userDataDir}" --extensions-dir "${extensionsDir}" --install-extension "${vsixPath}"`,
88-
{
89-
stdio: 'inherit',
90-
cwd: path.join(__dirname, '..'),
91-
},
92-
)
93-
94-
// Start code-server instance
83+
// Start code-server instance using the shared extensions directory
9584
const codeServerProcess = spawn(
9685
'pnpm',
9786
[

0 commit comments

Comments
 (0)