Skip to content

Commit 352870a

Browse files
authored
fix(storybook-angular): add missing await to storybook-angular preset core (#2081)
1 parent b8016f5 commit 352870a

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

packages/storybook-angular/src/lib/preset.spec.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import { describe, it, expect, vi, beforeEach } from 'vitest';
88

99
// Stub out heavy dependencies so the module can be imported
1010
vi.mock('@storybook/angular/preset', () => ({
11-
core: () => ({ options: {} }),
11+
core: async () => ({
12+
options: {},
13+
channelOptions: { wsToken: 'mock-token' },
14+
}),
1215
addons: [],
1316
}));
1417

@@ -29,11 +32,14 @@ vi.mock('@analogjs/vite-plugin-angular', () => ({
2932

3033
// eslint-disable-next-line @typescript-eslint/no-explicit-any
3134
let viteFinal: any;
35+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
36+
let core: any;
3237

3338
beforeEach(async () => {
3439
vi.resetModules();
3540
const mod = await import('./preset');
3641
viteFinal = mod.viteFinal;
42+
core = mod.core;
3743
});
3844

3945
/**
@@ -43,7 +49,10 @@ beforeEach(async () => {
4349
*/
4450
const registerDependencyMocks = () => {
4551
vi.doMock('@storybook/angular/preset', () => ({
46-
core: () => ({ options: {} }),
52+
core: async () => ({
53+
options: {},
54+
channelOptions: { wsToken: 'mock-token' },
55+
}),
4756
addons: [],
4857
}));
4958
vi.doMock('storybook/internal/types', () => ({}));
@@ -72,6 +81,21 @@ const importWithAngularVersion = async (major: string) => {
7281
return mod.viteFinal;
7382
};
7483

84+
describe('core', () => {
85+
it('should await PresetCore and include channelOptions from resolved config', async () => {
86+
const result = await core({}, {});
87+
88+
expect(result.channelOptions?.wsToken).toBe('mock-token');
89+
});
90+
91+
it('should override builder with @storybook/builder-vite', async () => {
92+
const result = await core({}, {});
93+
94+
expect(result.builder).toBeDefined();
95+
expect(result.builder.name).toBeDefined();
96+
});
97+
});
98+
7599
describe('viteFinal', () => {
76100
const createMockOptions = (overrides = {}) => ({
77101
configDir: '.storybook',

packages/storybook-angular/src/lib/preset.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const previewAnnotations = async (entries = [], options) => {
2727
};
2828

2929
export const core = async (config, options) => {
30-
const presetCore = PresetCore(config, options);
30+
const presetCore = await PresetCore(config, options);
3131
return {
3232
...presetCore,
3333
builder: {

0 commit comments

Comments
 (0)