Skip to content

Commit 25e1fcf

Browse files
committed
fix(test): inject inlined env vars in test setup for e2e tests
The e2e tests were failing because they import source files that require build-time inlined environment variables (like INLINED_SOCKET_CLI_COANA_VERSION). These variables are normally set by esbuild during build, but e2e tests run from source. Updated test/setup.mts to load these variables from external-tools.json, which is the same source of truth used by the build system.
1 parent 4c7246b commit 25e1fcf

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

packages/cli/test/setup.mts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,56 @@
11
/** @fileoverview Vitest setup file for test utilities. */
22

3+
import { existsSync, readFileSync } from 'node:fs'
4+
import path from 'node:path'
5+
import { fileURLToPath } from 'node:url'
6+
37
// Disable debug output during tests
48
process.env.DEBUG = ''
59
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

Comments
 (0)