|
1 | 1 | /** @fileoverview Vitest setup file for test utilities. */ |
2 | 2 |
|
| 3 | +import { existsSync, readFileSync } from 'node:fs' |
| 4 | +import path from 'node:path' |
| 5 | +import { fileURLToPath } from 'node:url' |
| 6 | + |
3 | 7 | // Disable debug output during tests |
4 | 8 | process.env.DEBUG = '' |
5 | 9 | delete process.env.NODE_DEBUG |
| 10 | + |
| 11 | +// Load inlined environment variables from external-tools.json. |
| 12 | +// These are normally inlined at build time by esbuild, but tests run from source. |
| 13 | +const __dirname = path.dirname(fileURLToPath(import.meta.url)) |
| 14 | +const externalToolsPath = path.join(__dirname, '..', 'external-tools.json') |
| 15 | + |
| 16 | +if (existsSync(externalToolsPath)) { |
| 17 | + try { |
| 18 | + const externalTools = JSON.parse(readFileSync(externalToolsPath, 'utf8')) |
| 19 | + |
| 20 | + // Set inlined environment variables if not already set. |
| 21 | + const toolVersions: Record<string, string | undefined> = { |
| 22 | + INLINED_SOCKET_CLI_CDXGEN_VERSION: |
| 23 | + externalTools['@cyclonedx/cdxgen']?.version, |
| 24 | + INLINED_SOCKET_CLI_COANA_VERSION: |
| 25 | + externalTools['@coana-tech/cli']?.version, |
| 26 | + INLINED_SOCKET_CLI_CYCLONEDX_CDXGEN_VERSION: |
| 27 | + externalTools['@cyclonedx/cdxgen']?.version, |
| 28 | + INLINED_SOCKET_CLI_HOMEPAGE: 'https://github.com/SocketDev/socket-cli', |
| 29 | + INLINED_SOCKET_CLI_NAME: '@socketsecurity/cli', |
| 30 | + INLINED_SOCKET_CLI_OPENGREP_VERSION: externalTools['opengrep']?.version, |
| 31 | + INLINED_SOCKET_CLI_PUBLISHED_BUILD: '', |
| 32 | + INLINED_SOCKET_CLI_PYCLI_VERSION: |
| 33 | + externalTools['socketsecurity']?.version, |
| 34 | + INLINED_SOCKET_CLI_PYTHON_BUILD_TAG: externalTools['python']?.buildTag, |
| 35 | + INLINED_SOCKET_CLI_PYTHON_VERSION: externalTools['python']?.version, |
| 36 | + INLINED_SOCKET_CLI_SENTRY_BUILD: '', |
| 37 | + INLINED_SOCKET_CLI_SFW_VERSION: externalTools['sfw']?.version, |
| 38 | + INLINED_SOCKET_CLI_SOCKET_PATCH_VERSION: |
| 39 | + externalTools['socket-patch']?.version, |
| 40 | + INLINED_SOCKET_CLI_SYNP_VERSION: externalTools['synp']?.version, |
| 41 | + INLINED_SOCKET_CLI_TRIVY_VERSION: externalTools['trivy']?.version, |
| 42 | + INLINED_SOCKET_CLI_TRUFFLEHOG_VERSION: |
| 43 | + externalTools['trufflehog']?.version, |
| 44 | + INLINED_SOCKET_CLI_VERSION: '0.0.0-test', |
| 45 | + INLINED_SOCKET_CLI_VERSION_HASH: '0.0.0-test:abc1234:test', |
| 46 | + } |
| 47 | + |
| 48 | + for (const [key, value] of Object.entries(toolVersions)) { |
| 49 | + if (!process.env[key] && value) { |
| 50 | + process.env[key] = value |
| 51 | + } |
| 52 | + } |
| 53 | + } catch { |
| 54 | + // Ignore errors loading external-tools.json. |
| 55 | + } |
| 56 | +} |
0 commit comments