Skip to content

Commit 693fa63

Browse files
authored
✨ Add VIZZLY_BUILD_NAME environment variable support (#195)
## Summary - Add `VIZZLY_BUILD_NAME` environment variable for setting build names in CI without CLI flags - Makes CI configuration cleaner - no need to interpolate values in CLI args ## Changes - Add `getBuildName()` function to `environment-config.js` - Wire into `config-loader.js` to set `config.build.name` from environment - Add tests for new functionality - Update CLAUDE.md documentation ## Usage ```bash # Instead of vizzly run "npm test" --build-name "PR #${PR_NUMBER} - ${BRANCH_NAME}" # You can now use export VIZZLY_BUILD_NAME="PR #${PR_NUMBER} - ${BRANCH_NAME}" vizzly run "npm test" ``` ## Test plan - [x] Unit tests pass for environment-config.js - [x] Unit tests pass for config-loader.js - [x] Lint passes
1 parent 2bf8c37 commit 693fa63

5 files changed

Lines changed: 56 additions & 1 deletion

File tree

CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ The React-based reporter works in two modes:
175175
- `VIZZLY_TOKEN` - API authentication token
176176
- `VIZZLY_API_URL` - API base URL (default: https://app.vizzly.dev)
177177
- `VIZZLY_LOG_LEVEL` - Logging level (debug|info|warn|error)
178+
- `VIZZLY_BUILD_NAME` - Custom build name (useful in CI for dynamic naming)
178179
- `VIZZLY_PARALLEL_ID` - Parallel build identifier
179180
- `VIZZLY_ENABLED` - Enable/disable SDK (default: auto-detect)
180181
- `VIZZLY_SERVER_URL` - Screenshot server URL for client

src/utils/config-loader.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { resolve } from 'node:path';
22
import { cosmiconfigSync } from 'cosmiconfig';
33
import { validateVizzlyConfigWithDefaults } from './config-schema.js';
4-
import { getApiToken, getApiUrl, getParallelId } from './environment-config.js';
4+
import {
5+
getApiToken,
6+
getApiUrl,
7+
getBuildName,
8+
getParallelId,
9+
} from './environment-config.js';
510
import { getProjectMapping } from './global-config.js';
611
import * as output from './output.js';
712

@@ -105,13 +110,18 @@ export async function loadConfig(configPath = null, cliOverrides = {}) {
105110
// 4. Override with environment variables (higher priority than fallbacks)
106111
const envApiKey = getApiToken();
107112
const envApiUrl = getApiUrl();
113+
const envBuildName = getBuildName();
108114
const envParallelId = getParallelId();
109115

110116
if (envApiKey) {
111117
config.apiKey = envApiKey;
112118
output.debug('config', 'using token from environment');
113119
}
114120
if (envApiUrl !== 'https://app.vizzly.dev') config.apiUrl = envApiUrl;
121+
if (envBuildName) {
122+
config.build.name = envBuildName;
123+
output.debug('config', 'using build name from environment');
124+
}
115125
if (envParallelId) config.parallelId = envParallelId;
116126

117127
// 5. Apply CLI overrides (highest priority)

src/utils/environment-config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ export function getParallelId() {
7777
return process.env.VIZZLY_PARALLEL_ID;
7878
}
7979

80+
/**
81+
* Get build name from environment
82+
* @returns {string|undefined} Build name
83+
*/
84+
export function getBuildName() {
85+
return process.env.VIZZLY_BUILD_NAME;
86+
}
87+
8088
/**
8189
* Check if TDD mode is enabled
8290
* @returns {boolean} Whether TDD mode is enabled
@@ -107,6 +115,7 @@ export function getAllEnvironmentConfig() {
107115
enabled: isVizzlyEnabled(),
108116
serverUrl: getServerUrl(),
109117
buildId: getBuildId(),
118+
buildName: getBuildName(),
110119
parallelId: getParallelId(),
111120
tddMode: isTddMode(),
112121
};

tests/utils/config-loader.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,14 @@ describe('utils/config-loader', () => {
5454
originalEnv = {
5555
VIZZLY_TOKEN: process.env.VIZZLY_TOKEN,
5656
VIZZLY_API_URL: process.env.VIZZLY_API_URL,
57+
VIZZLY_BUILD_NAME: process.env.VIZZLY_BUILD_NAME,
5758
VIZZLY_PARALLEL_ID: process.env.VIZZLY_PARALLEL_ID,
5859
VIZZLY_HOME: process.env.VIZZLY_HOME,
5960
};
6061

6162
// Clean env
6263
delete process.env.VIZZLY_TOKEN;
64+
delete process.env.VIZZLY_BUILD_NAME;
6365
delete process.env.VIZZLY_PARALLEL_ID;
6466

6567
// Create test directory
@@ -135,6 +137,22 @@ describe('utils/config-loader', () => {
135137
assert.strictEqual(config.parallelId, 'parallel-123');
136138
});
137139

140+
it('applies VIZZLY_BUILD_NAME environment variable', async () => {
141+
process.env.VIZZLY_BUILD_NAME = 'CI Build #123';
142+
143+
let config = await loadConfig();
144+
145+
assert.strictEqual(config.build.name, 'CI Build #123');
146+
});
147+
148+
it('CLI buildName overrides VIZZLY_BUILD_NAME', async () => {
149+
process.env.VIZZLY_BUILD_NAME = 'env-build-name';
150+
151+
let config = await loadConfig(null, { buildName: 'cli-build-name' });
152+
153+
assert.strictEqual(config.build.name, 'cli-build-name');
154+
});
155+
138156
it('CLI token overrides env token', async () => {
139157
process.env.VIZZLY_TOKEN = 'env-token';
140158

tests/utils/environment-config.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
getApiToken,
66
getApiUrl,
77
getBuildId,
8+
getBuildName,
89
getLogLevel,
910
getParallelId,
1011
getServerUrl,
@@ -30,6 +31,7 @@ describe('utils/environment-config', () => {
3031
'VIZZLY_ENABLED',
3132
'VIZZLY_SERVER_URL',
3233
'VIZZLY_BUILD_ID',
34+
'VIZZLY_BUILD_NAME',
3335
'VIZZLY_PARALLEL_ID',
3436
'VIZZLY_TDD',
3537
];
@@ -156,6 +158,18 @@ describe('utils/environment-config', () => {
156158
});
157159
});
158160

161+
describe('getBuildName', () => {
162+
it('returns undefined when not set', () => {
163+
assert.strictEqual(getBuildName(), undefined);
164+
});
165+
166+
it('returns VIZZLY_BUILD_NAME when set', () => {
167+
process.env.VIZZLY_BUILD_NAME = 'My CI Build';
168+
169+
assert.strictEqual(getBuildName(), 'My CI Build');
170+
});
171+
});
172+
159173
describe('isTddMode', () => {
160174
it('returns false when not set', () => {
161175
assert.strictEqual(isTddMode(), false);
@@ -213,6 +227,7 @@ describe('utils/environment-config', () => {
213227
enabled: false,
214228
serverUrl: undefined,
215229
buildId: undefined,
230+
buildName: undefined,
216231
parallelId: undefined,
217232
tddMode: false,
218233
});
@@ -227,6 +242,7 @@ describe('utils/environment-config', () => {
227242
process.env.VIZZLY_ENABLED = 'true';
228243
process.env.VIZZLY_SERVER_URL = 'http://server';
229244
process.env.VIZZLY_BUILD_ID = 'build';
245+
process.env.VIZZLY_BUILD_NAME = 'My Build';
230246
process.env.VIZZLY_PARALLEL_ID = 'parallel';
231247
process.env.VIZZLY_TDD = 'true';
232248

@@ -241,6 +257,7 @@ describe('utils/environment-config', () => {
241257
enabled: true,
242258
serverUrl: 'http://server',
243259
buildId: 'build',
260+
buildName: 'My Build',
244261
parallelId: 'parallel',
245262
tddMode: true,
246263
});

0 commit comments

Comments
 (0)