|
| 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 |
0 commit comments