Skip to content

Commit 13291f4

Browse files
committed
🐛 Preserve cloud build context in CLI runs
1 parent 0579c16 commit 13291f4

3 files changed

Lines changed: 41 additions & 5 deletions

File tree

clients/storybook/src/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export async function run(storybookPath, options = {}, context = {}) {
128128
branch = gitInfo.branch;
129129
commit = gitInfo.commit;
130130
message = gitInfo.message;
131-
buildName = gitInfo.buildName;
131+
buildName = vizzlyConfig?.build?.name || gitInfo.buildName;
132132
pullRequestNumber = gitInfo.prNumber;
133133
} else {
134134
// Fallback for older CLI versions - use environment variables
@@ -138,7 +138,8 @@ export async function run(storybookPath, options = {}, context = {}) {
138138
branch = process.env.VIZZLY_BRANCH || 'main';
139139
commit = process.env.VIZZLY_COMMIT_SHA || undefined;
140140
message = process.env.VIZZLY_COMMIT_MESSAGE || undefined;
141-
buildName = `Storybook ${new Date().toISOString()}`;
141+
buildName =
142+
vizzlyConfig?.build?.name || `Storybook ${new Date().toISOString()}`;
142143
pullRequestNumber = process.env.VIZZLY_PR_NUMBER
143144
? parseInt(process.env.VIZZLY_PR_NUMBER, 10)
144145
: undefined;

src/services/test-runner.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { VizzlyError } from '../errors/vizzly-error.js';
1818
import {
1919
cancelTests,
2020
createBuild,
21+
fetchBuildUrl,
2122
finalizeBuild,
2223
initializeDaemon,
2324
runTests,
@@ -95,26 +96,44 @@ export class TestRunner extends EventEmitter {
9596
}
9697

9798
async createBuild(options, tdd) {
99+
let createdApiBuild = null;
98100
let buildId = await createBuild({
99101
runOptions: options,
100102
tdd,
101103
config: this.config,
102104
deps: {
103105
buildManager: this.buildManager,
104106
createApiClient: this.deps.createApiClient,
105-
createApiBuild: this.deps.createApiBuild,
107+
createApiBuild: async (client, payload) => {
108+
createdApiBuild = await this.deps.createApiBuild(client, payload);
109+
return createdApiBuild;
110+
},
106111
output: this.deps.output,
107112
},
108113
});
109114

110115
if (!tdd && buildId) {
116+
let buildUrl =
117+
createdApiBuild?.url ||
118+
(await fetchBuildUrl({
119+
buildId,
120+
config: this.config,
121+
deps: {
122+
createApiClient: this.deps.createApiClient,
123+
getBuild: this.deps.getBuild,
124+
output: this.deps.output,
125+
},
126+
}));
127+
111128
let writeSession = this.deps.writeSession || defaultWriteSession;
112129
writeSession({
113130
buildId,
114131
branch: options?.branch,
115132
commit: options?.commit,
116133
parallelId: options?.parallelId,
117134
});
135+
136+
this.emit('build-created', { buildId, url: buildUrl });
118137
}
119138

120139
return buildId;

tests/services/test-runner.test.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,14 @@ function createDeps(overrides = {}) {
88
throw new Error('spawn should not be called in createBuild tests');
99
},
1010
createApiClient: () => ({}),
11-
createApiBuild: async () => ({ id: 'api-build-123' }),
12-
getBuild: async () => ({ id: 'api-build-123' }),
11+
createApiBuild: async () => ({
12+
id: 'api-build-123',
13+
url: 'https://app.vizzly.dev/org/project/builds/api-build-123',
14+
}),
15+
getBuild: async () => ({
16+
id: 'api-build-123',
17+
url: 'https://app.vizzly.dev/org/project/builds/api-build-123',
18+
}),
1319
finalizeApiBuild: async () => {},
1420
output: {
1521
debug: () => {},
@@ -42,6 +48,10 @@ describe('services/test-runner', () => {
4248
{},
4349
{ deps }
4450
);
51+
let buildEvents = [];
52+
testRunner.on('build-created', event => {
53+
buildEvents.push(event);
54+
});
4555

4656
let buildId = await testRunner.createBuild(
4757
{
@@ -54,6 +64,12 @@ describe('services/test-runner', () => {
5464
);
5565

5666
assert.strictEqual(buildId, 'api-build-123');
67+
assert.deepStrictEqual(buildEvents, [
68+
{
69+
buildId: 'api-build-123',
70+
url: 'https://app.vizzly.dev/org/project/builds/api-build-123',
71+
},
72+
]);
5773
assert.deepStrictEqual(writtenSessions, [
5874
{
5975
buildId: 'api-build-123',

0 commit comments

Comments
 (0)