Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ describe('framework-preset-angular-cli', () => {
const browserTargetOptions = { a: 1, nested: { x: 10 } };
const storybookOptions = { b: 2, nested: { y: 20 } };

vi.mocked(mockBuilderContext.getTargetOptions).mockResolvedValue(browserTargetOptions);
vi.mocked(mockBuilderContext.getTargetOptions)
.mockResolvedValueOnce(browserTargetOptions)
.mockResolvedValueOnce(storybookOptions);

const options: PresetOptions = {
configType: 'DEVELOPMENT',
Expand Down Expand Up @@ -201,7 +203,7 @@ describe('framework-preset-angular-cli', () => {
const result = await getBuilderOptions(options, mockBuilderContext);

expect(mockedTargetFromTargetString).not.toHaveBeenCalled();
expect(mockBuilderContext.getTargetOptions).not.toHaveBeenCalled();
expect(mockBuilderContext.getTargetOptions).toHaveBeenCalledOnce();
Copy link
Member Author

Choose a reason for hiding this comment

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

fyi: since we now also use getTargetOptions for retrieving the builder options, it is always called once, and if theres a browserTarget, called twice

expect(result).toEqual({
tsConfig: '/test/tsconfig.json',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,19 @@ export async function getBuilderOptions(options: PresetOptions, builderContext:
browserTargetOptions = await builderContext.getTargetOptions(browserTarget);
}

// `options.angularBuilderOptions` implicitly adds all options a target can have
// To figure out what user-land actually has explicitly defined in their target options, we
// manually need to read them
const explicitAngularBuilderOptions = await builderContext.getTargetOptions(
builderContext.target
);

/**
* Merge target options from browser target options and from storybook options Use deep merge to
* preserve nested properties like stylePreprocessorOptions.includePaths when they exist in
* browserTarget but not in storybook options
*/
const builderOptions = deepMerge(browserTargetOptions, options.angularBuilderOptions || {});
const builderOptions = deepMerge(browserTargetOptions, explicitAngularBuilderOptions || {});

// Handle tsConfig separately to maintain existing logic
builderOptions.tsConfig =
Expand Down