Skip to content

Angular: Fix custom paths for stats.json on angular#34551

Merged
valentinpalkovic merged 12 commits into
nextfrom
bill/fix-stats-json
May 19, 2026
Merged

Angular: Fix custom paths for stats.json on angular#34551
valentinpalkovic merged 12 commits into
nextfrom
bill/fix-stats-json

Conversation

@mrginglymus
Copy link
Copy Markdown
Contributor

@mrginglymus mrginglymus commented Apr 15, 2026

Closes #

What I did

Running the angular builder with `--stats-json=` seems to be parsed as `false`. This means the chromatic will fail to run turbosnap, as it will not generate a stats file.

I'm not sure how long this has been the case, but I suspect it might be 'forever', and only recently a change to chromatic cli has made it stricter about the presence of the stats file.

It seems to stem from the angular schema being defined as `["boolean", "string"]`, and presumably angular attempting to parse them in order - and seeing as `` isn't `true` it must be `false`. Swapping the order fixes the problem.

Tests are now unskipped and passing after modernising the mocking approach.

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

  1. Generate an Angular sandbox: `yarn task sandbox --template angular-cli/default-ts --start-from auto`
  2. In the sandbox, run `yarn build-storybook --stats-json ./custom-stats.json`
  3. Confirm that `./custom-stats.json` is generated — before this fix it would not be generated because the path string was coerced to `false`.
  4. Alternatively, confirm the unit tests pass: `yarn vitest run code/frameworks/angular/src/builders/build-storybook/index.spec.ts code/frameworks/angular/src/builders/start-storybook/index.spec.ts`

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add `ci:normal`, `ci:merged` or `ci:daily` GH label to it to run a specific set of sandboxes.
  • Make sure this PR contains one of the labels below: bug, maintenance, dependencies, build, cleanup, documentation, feature request, BREAKING CHANGE, other.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 15, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 18cf6093-1ec7-4080-a168-8074c0c719b9

📥 Commits

Reviewing files that changed from the base of the PR and between ebc6514 and 5a92ef8.

📒 Files selected for processing (2)
  • code/frameworks/angular/src/builders/build-storybook/index.spec.ts
  • code/frameworks/angular/src/builders/start-storybook/index.spec.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • code/frameworks/angular/src/builders/build-storybook/index.spec.ts
  • code/frameworks/angular/src/builders/start-storybook/index.spec.ts

📝 Walkthrough

Walkthrough

Reorder JSON-schema type arrays for webpackStatsJson and statsJson in two Angular schema files; refactor two Angular builder test suites to register builders directly, migrate to module-level mocks, update assertions, and add a test verifying statsJson forwards string values.

Changes

Schema Type Reordering

Layer / File(s) Summary
Schema change
code/frameworks/angular/build-schema.json, code/frameworks/angular/start-schema.json
Changed type arrays for webpackStatsJson and statsJson from ["boolean","string"] to ["string","boolean"]. No other schema fields or constraints were modified.

Build-storybook tests

Layer / File(s) Summary
Test harness / registration
code/frameworks/angular/src/builders/build-storybook/index.spec.ts
Stop using package-based addBuilderFromPackage; manually register the builder on the Architect host via architectHost.addBuilder(...) with buildSchema and local handler.
Mocking changes
code/frameworks/angular/src/builders/build-storybook/index.spec.ts
Move Storybook internals mocks to top-level vi.mock and centralize mockRunScript; mock storybook/internal/core-server and storybook/internal/node-logger (spinner executed synchronously).
Behavioral tests
code/frameworks/angular/src/builders/build-storybook/index.spec.ts
Rename stats test to stats.json; keep statsJson: true expectation and add a test asserting statsJson: './custom-stats.json' forwards the exact string to buildStaticStandalone; adjust compodoc and angularBuilderOptions assertions to use object shapes/expect.objectContaining.
Failure handling
code/frameworks/angular/src/builders/build-storybook/index.spec.ts
Simplify rejection test to await expect(run.result).rejects.toThrow(...).

Start-storybook tests

Layer / File(s) Summary
Test harness / registration
code/frameworks/angular/src/builders/start-storybook/index.spec.ts
Manually register the builder via architectHost.addBuilder(...) with start-schema.json and local handler instead of addBuilderFromPackage.
Mocking changes
code/frameworks/angular/src/builders/start-storybook/index.spec.ts
Switch to module-level vi.mock with factory overrides for storybook/internal/core-server, storybook/internal/common, and storybook/internal/node-logger (run spinners synchronously).
Behavioral tests
code/frameworks/angular/src/builders/start-storybook/index.spec.ts
Update expectations for buildDevStandalone calls (argument shapes, angularBrowserTarget undefined vs null), adjust compodoc invocation assertion to { args, cwd }, and refine assertions around package manager runPackageCommand.
Failure handling
code/frameworks/angular/src/builders/start-storybook/index.spec.ts
Use await expect(run.result).rejects.toThrow(...) for error test.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot]

This comment was marked as resolved.

@valentinpalkovic valentinpalkovic moved this from Empathy Queue (prioritized) to In Progress in Core Team Projects Apr 16, 2026
@valentinpalkovic valentinpalkovic changed the title Fix custom paths for stats.json on angular Angular: Fix custom paths for stats.json on angular Apr 16, 2026
@valentinpalkovic valentinpalkovic self-assigned this Apr 16, 2026
@valentinpalkovic
Copy link
Copy Markdown
Contributor

Hi @mrginglymus, could you please fix the TypeScript issues?

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
code/frameworks/angular/src/builders/start-storybook/index.spec.ts (1)

127-245: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Add a regression test for string-valued stats options.

The start-storybook builder forwards both statsJson and webpackStatsJson to buildDevStandalone, but the test suite never schedules the builder with these set to a string value. Since this PR reorders schema unions specifically to preserve string paths for stats options, add a test that verifies the string value is correctly passed through—similar to the coverage already present in the build-storybook spec (lines 181, 201).

Test shape
+  it('should forward string statsJson values', async () => {
+    const run = await architect.scheduleBuilder('@storybook/angular:start-storybook', {
+      tsConfig: 'path/to/tsConfig.json',
+      port: 4400,
+      compodoc: false,
+      statsJson: './custom-stats.json',
+    });
+
+    const output = await run.result;
+
+    await run.stop();
+
+    expect(output.success).toBeTruthy();
+    expect(buildDevStandalone).toHaveBeenCalledWith(
+      expect.objectContaining({
+        statsJson: './custom-stats.json',
+      })
+    );
+  });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@code/frameworks/angular/src/builders/start-storybook/index.spec.ts` around
lines 127 - 245, Add a regression test that schedules the
'@storybook/angular:start-storybook' builder with string-valued stats options
and asserts they are forwarded to buildDevStandalone; specifically, create a new
it block (mirroring existing tests like "should start storybook with tsConfig")
that calls architect.scheduleBuilder with statsJson: 'path/to/stats.json' and
webpackStatsJson: 'path/to/webpack-stats.json', awaits run.result, stops the
run, and then expects buildDevStandalone toHaveBeenCalledWith an
objectContaining where statsJson and webpackStatsJson equal those string paths
(use the existing test patterns and mocks such as buildDevStandalone,
mockRunScript, and expect.objectContaining to locate the assertion).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@code/frameworks/angular/src/builders/start-storybook/index.spec.ts`:
- Around line 127-245: Add a regression test that schedules the
'@storybook/angular:start-storybook' builder with string-valued stats options
and asserts they are forwarded to buildDevStandalone; specifically, create a new
it block (mirroring existing tests like "should start storybook with tsConfig")
that calls architect.scheduleBuilder with statsJson: 'path/to/stats.json' and
webpackStatsJson: 'path/to/webpack-stats.json', awaits run.result, stops the
run, and then expects buildDevStandalone toHaveBeenCalledWith an
objectContaining where statsJson and webpackStatsJson equal those string paths
(use the existing test patterns and mocks such as buildDevStandalone,
mockRunScript, and expect.objectContaining to locate the assertion).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c89c2b6f-74d4-4497-9292-02fabe923b47

📥 Commits

Reviewing files that changed from the base of the PR and between 67659ce and ebc6514.

📒 Files selected for processing (1)
  • code/frameworks/angular/src/builders/start-storybook/index.spec.ts

@storybook-app-bot
Copy link
Copy Markdown

storybook-app-bot Bot commented May 19, 2026

Package Benchmarks

Commit: 5a92ef8, ran on 19 May 2026 at 09:37:34 UTC

No significant changes detected, all good. 👏

…tart-storybook

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@valentinpalkovic valentinpalkovic merged commit db04b12 into next May 19, 2026
142 checks passed
@valentinpalkovic valentinpalkovic deleted the bill/fix-stats-json branch May 19, 2026 09:58
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Core Team Projects May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants