Skip to content

Commit

Permalink
Fixing tests WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
shilman committed Jun 7, 2024
1 parent 61d6ee7 commit d89481e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
6 changes: 3 additions & 3 deletions code/lib/preview-api/src/modules/store/StoryStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class StoryStore<TRenderer extends Renderer> {
this.storyIndex = new StoryIndexStore(storyIndex);

this.projectAnnotations = normalizeProjectAnnotations(projectAnnotations);
const { initialGlobals, globalTypes } = projectAnnotations;
const { initialGlobals, globalTypes } = this.projectAnnotations;

this.args = new ArgsStore();
this.globals = new GlobalsStore({ globals: initialGlobals, globalTypes });
Expand All @@ -95,8 +95,8 @@ export class StoryStore<TRenderer extends Renderer> {
setProjectAnnotations(projectAnnotations: ProjectAnnotations<TRenderer>) {
// By changing `this.projectAnnotations, we implicitly invalidate the `prepareStoryWithCache`
this.projectAnnotations = normalizeProjectAnnotations(projectAnnotations);
const { globals, globalTypes } = projectAnnotations;
this.globals.set({ globals, globalTypes });
const { initialGlobals, globalTypes } = projectAnnotations;
this.globals.set({ globals: initialGlobals, globalTypes });
}

// This means that one of the CSF files has changed.
Expand Down
4 changes: 3 additions & 1 deletion code/lib/preview-api/src/modules/store/csf/composeConfigs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ export function composeConfigs<TRenderer extends Renderer>(
...allArgTypeEnhancers.filter((e) => !e.secondPass),
...allArgTypeEnhancers.filter((e) => e.secondPass),
],
globals: getObjectField(moduleExportList, 'globals'),
initialGlobals:
getObjectField(moduleExportList, 'initialGlobals') ??
getObjectField(moduleExportList, 'globals'),
globalTypes: getObjectField(moduleExportList, 'globalTypes'),
loaders: getArrayField(moduleExportList, 'loaders'),
beforeEach: getArrayField(moduleExportList, 'beforeEach'),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';

import { normalizeProjectAnnotations } from './normalizeProjectAnnotations';

describe('normalizeProjectAnnotations', () => {
describe('blah', () => {
beforeEach(() => {
const warnThatThrows = vi.mocked(console.warn).getMockImplementation();
vi.mocked(console.warn).mockImplementation(() => {});
return () => {
vi.mocked(console.warn).mockImplementation(warnThatThrows!);
};
});
it('normalizes globals to initialGlobals', () => {
expect(
normalizeProjectAnnotations({
globals: { a: 'b' },
})
).toMatchObject({
initialGlobals: { a: 'b' },
});
});
});
it('passes through initialGlobals', () => {
expect(
normalizeProjectAnnotations({
initialGlobals: { a: 'b' },
})
).toMatchObject({
initialGlobals: { a: 'b' },
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {
ProjectAnnotations,
NormalizedProjectAnnotations,
} from '@storybook/types';
import { once } from '@storybook/client-logger';
import { deprecate } from '@storybook/client-logger';
import { dedent } from 'ts-dedent';

import { inferArgTypes } from '../inferArgTypes';
Expand All @@ -24,7 +24,7 @@ export function normalizeProjectAnnotations<TRenderer extends Renderer>({
...annotations
}: ProjectAnnotations<TRenderer>): NormalizedProjectAnnotations<TRenderer> {
if (globals) {
once.warn(dedent`
deprecate(dedent`
The preview.js 'globals' field is deprecated and will be removed in Storybook 9.0.
Please use 'initialGlobals' instead. Learn more:
Expand Down

0 comments on commit d89481e

Please sign in to comment.