Skip to content

Commit bfcf6e4

Browse files
authored
fix(cli): dry run migrations updating stories (#324)
Fixes WDX-162 Fixes #323
1 parent 948ce49 commit bfcf6e4

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

packages/cli/src/commands/migrations/run/index.test.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,15 @@ vi.mock('../../../utils', async () => {
2323
};
2424
});
2525

26-
// Mock the actions
27-
vi.mock('./actions', () => ({
28-
readMigrationFiles: vi.fn(),
29-
getMigrationFunction: vi.fn(),
30-
}));
26+
// Mock actions
27+
vi.mock('./actions', async () => {
28+
const actual = await vi.importActual<typeof import('./actions')>('./actions');
29+
return {
30+
applyMigrationToAllBlocks: actual.applyMigrationToAllBlocks,
31+
readMigrationFiles: vi.fn(),
32+
getMigrationFunction: vi.fn(),
33+
};
34+
});
3135

3236
vi.mock('../../stories/actions', () => ({
3337
fetchStories: vi.fn(),
@@ -170,16 +174,12 @@ describe('migrations run command - streaming approach', () => {
170174
// Verify that getMigrationFunction was called
171175
expect(getMigrationFunction).toHaveBeenCalledWith('migration-component.js', '12345', undefined);
172176

173-
// In the new streaming approach, updateStory is only called if the migration actually changes content
174-
// Since our mock migration function doesn't actually change the content hash, updateStory won't be called
175-
// This is the correct behavior - only stories with actual changes should be updated
176-
177177
// Verify that progress bars were displayed (konsola.info should be called for summaries)
178178
expect(konsola.info).toHaveBeenCalledWith(
179179
expect.stringContaining('Migration Results:'),
180180
);
181181
expect(konsola.info).toHaveBeenCalledWith(
182-
expect.stringContaining('No stories required updates'),
182+
expect.stringContaining('Update Results: 1 stories updated.'),
183183
);
184184
});
185185

@@ -309,6 +309,9 @@ describe('migrations run command - streaming approach', () => {
309309
// Verify that getMigrationFunction was called
310310
expect(getMigrationFunction).toHaveBeenCalledWith('migration-component.js', '12345', undefined);
311311

312+
expect(konsola.warn).toHaveBeenCalledWith(
313+
expect.stringContaining('DRY RUN MODE ENABLED: No changes will be made.'),
314+
);
312315
// Verify that updateStory was NOT called (since it's a dry run)
313316
expect(updateStory).not.toHaveBeenCalled();
314317

packages/cli/src/commands/migrations/run/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ migrationsCommand.command('run [componentName]')
2525
.option('--publish <publish>', 'Options for publication mode: all | published | published-with-changes')
2626
.action(async (componentName: string | undefined, options: MigrationsRunOptions) => {
2727
konsola.title(`${commands.MIGRATIONS}`, colorPalette.MIGRATIONS, componentName ? `Running migrations for component ${componentName}...` : 'Running migrations...');
28+
if (options.dryRun) {
29+
konsola.warn(`DRY RUN MODE ENABLED: No changes will be made.\n`);
30+
}
2831

2932
// Global options
3033
const verbose = program.opts().verbose;

packages/cli/src/commands/migrations/run/streams/update-stream.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ export class UpdateStream extends Writable {
8989
payload.publish = 1;
9090
}
9191

92-
const updatedStory = await updateStory(this.options.space, storyId, payload);
93-
94-
if (updatedStory) {
92+
const updatedStory = !this.options.dryRun && await updateStory(this.options.space, storyId, payload);
93+
const isStoryUpdated = Boolean(updatedStory);
94+
if (isStoryUpdated || this.options.dryRun) {
9595
this.results.successful.push({ storyId, name: storyName });
9696
this.results.totalProcessed++;
9797
this.options.onProgress?.(this.results.totalProcessed);

0 commit comments

Comments
 (0)