Skip to content

Commit

Permalink
Fixed tests to refer to v5 except for special v4 test
Browse files Browse the repository at this point in the history
  • Loading branch information
shilman committed May 24, 2024
1 parent da79c3d commit ad20171
Show file tree
Hide file tree
Showing 11 changed files with 169 additions and 121 deletions.
28 changes: 14 additions & 14 deletions code/lib/core-server/src/utils/summarizeIndex.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('summarizeIndex', () => {
it('example stories', () => {
expect(
summarizeIndex({
v: 4,
v: 5,
entries: {
'example-introduction--docs': {
id: 'example-introduction--docs',
Expand Down Expand Up @@ -146,14 +146,14 @@ describe('summarizeIndex', () => {
"playStoryCount": 0,
"storiesMdxCount": 0,
"storyCount": 0,
"version": 4,
"version": 5,
}
`);
});
it('onboarding stories', () => {
expect(
summarizeIndex({
v: 4,
v: 5,
entries: {
'example-introduction--docs': {
id: 'example-introduction--docs',
Expand Down Expand Up @@ -204,14 +204,14 @@ describe('summarizeIndex', () => {
"playStoryCount": 0,
"storiesMdxCount": 0,
"storyCount": 0,
"version": 4,
"version": 5,
}
`);
});
it('user stories', () => {
expect(
summarizeIndex({
v: 4,
v: 5,
entries: {
'stories-renderers-react-errors--story-contains-unrenderable': {
id: 'stories-renderers-react-errors--story-contains-unrenderable',
Expand Down Expand Up @@ -260,14 +260,14 @@ describe('summarizeIndex', () => {
"playStoryCount": 0,
"storiesMdxCount": 0,
"storyCount": 4,
"version": 4,
"version": 5,
}
`);
});
it('pages', () => {
expect(
summarizeIndex({
v: 4,
v: 5,
entries: {
'example-page--logged-out': {
id: 'example-page--logged-out',
Expand Down Expand Up @@ -317,14 +317,14 @@ describe('summarizeIndex', () => {
"playStoryCount": 1,
"storiesMdxCount": 0,
"storyCount": 1,
"version": 4,
"version": 5,
}
`);
});
it('storiesMdx', () => {
expect(
summarizeIndex({
v: 4,
v: 5,
entries: {
'stories-renderers-react-react-mdx--docs': {
id: 'stories-renderers-react-react-mdx--docs',
Expand Down Expand Up @@ -374,14 +374,14 @@ describe('summarizeIndex', () => {
"playStoryCount": 0,
"storiesMdxCount": 1,
"storyCount": 3,
"version": 4,
"version": 5,
}
`);
});
it('autodocs', () => {
expect(
summarizeIndex({
v: 4,
v: 5,
entries: {
'example-button--docs': {
id: 'example-button--docs',
Expand Down Expand Up @@ -432,14 +432,14 @@ describe('summarizeIndex', () => {
"playStoryCount": 0,
"storiesMdxCount": 0,
"storyCount": 0,
"version": 4,
"version": 5,
}
`);
});
it('mdx', () => {
expect(
summarizeIndex({
v: 4,
v: 5,
entries: {
'example-introduction--docs': {
id: 'example-introduction--docs',
Expand Down Expand Up @@ -483,7 +483,7 @@ describe('summarizeIndex', () => {
"playStoryCount": 0,
"storiesMdxCount": 0,
"storyCount": 0,
"version": 4,
"version": 5,
}
`);
});
Expand Down
67 changes: 65 additions & 2 deletions code/lib/manager-api/src/lib/stories.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { describe, it, expect } from 'vitest';
import type { StoryIndexV2, StoryIndexV3 } from '@storybook/types';
import { transformStoryIndexV2toV3, transformStoryIndexV3toV4 } from './stories';
import type { StoryIndexV2, StoryIndexV3, API_PreparedStoryIndex } from '@storybook/types';
import {
transformStoryIndexV2toV3,
transformStoryIndexV3toV4,
transformStoryIndexV4toV5,
} from './stories';
import { mockEntries } from '../tests/mockStoriesEntries';

const baseV2: StoryIndexV2['stories'][0] = {
id: '1',
Expand Down Expand Up @@ -151,3 +156,61 @@ describe('transformStoryIndexV3toV4', () => {
`);
});
});

describe('transformStoryIndexV4toV5', () => {
it('transforms a StoryIndexV4 to an API_PreparedStoryIndex correctly', () => {
const indexV4: API_PreparedStoryIndex = {
v: 4,
entries: mockEntries,
};

expect(transformStoryIndexV4toV5(indexV4)).toMatchInlineSnapshot(`
{
"entries": {
"component-a--docs": {
"id": "component-a--docs",
"importPath": "./path/to/component-a.ts",
"name": "Docs",
"storiesImports": [],
"tags": [
"dev",
],
"title": "Component A",
"type": "docs",
},
"component-a--story-1": {
"id": "component-a--story-1",
"importPath": "./path/to/component-a.ts",
"name": "Story 1",
"tags": [
"dev",
],
"title": "Component A",
"type": "story",
},
"component-a--story-2": {
"id": "component-a--story-2",
"importPath": "./path/to/component-a.ts",
"name": "Story 2",
"tags": [
"dev",
],
"title": "Component A",
"type": "story",
},
"component-b--story-3": {
"id": "component-b--story-3",
"importPath": "./path/to/component-b.ts",
"name": "Story 3",
"tags": [
"dev",
],
"title": "Component B",
"type": "story",
},
},
"v": 5,
}
`);
});
});
2 changes: 1 addition & 1 deletion code/lib/manager-api/src/lib/stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const transformSetStoriesStoryDataToPreparedStoryIndex = (
{} as API_PreparedStoryIndex['entries']
);

return { v: 4, entries };
return { v: 5, entries };
};

export const transformStoryIndexV2toV3 = (index: StoryIndexV2): StoryIndexV3 => {
Expand Down
26 changes: 13 additions & 13 deletions code/lib/manager-api/src/tests/refs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ describe('Refs API', () => {
setupResponses({
indexPrivate: {
ok: true,
response: async () => ({ v: 4, entries: {} }),
response: async () => ({ v: 5, entries: {} }),
},
storiesPrivate: {
ok: true,
Expand Down Expand Up @@ -506,7 +506,7 @@ describe('Refs API', () => {
"index": {},
"internal_index": {
"entries": {},
"v": 4,
"v": 5,
},
"title": "Fake",
"type": "lazy",
Expand All @@ -524,7 +524,7 @@ describe('Refs API', () => {
"index": {},
"internal_index": {
"entries": {},
"v": 4,
"v": 5,
},
"title": "Fake",
"type": "lazy",
Expand All @@ -542,7 +542,7 @@ describe('Refs API', () => {
setupResponses({
indexPrivate: {
ok: true,
response: async () => ({ v: 4, entries: {} }),
response: async () => ({ v: 5, entries: {} }),
},
storiesPrivate: {
ok: true,
Expand Down Expand Up @@ -603,7 +603,7 @@ describe('Refs API', () => {
"index": {},
"internal_index": {
"entries": {},
"v": 4,
"v": 5,
},
"title": "Fake",
"type": "lazy",
Expand All @@ -622,7 +622,7 @@ describe('Refs API', () => {
setupResponses({
indexPrivate: {
ok: true,
response: async () => ({ v: 4, entries: {} }),
response: async () => ({ v: 5, entries: {} }),
},
storiesPrivate: {
ok: true,
Expand Down Expand Up @@ -684,7 +684,7 @@ describe('Refs API', () => {
"index": {},
"internal_index": {
"entries": {},
"v": 4,
"v": 5,
},
"title": "Fake",
"type": "lazy",
Expand Down Expand Up @@ -781,7 +781,7 @@ describe('Refs API', () => {
setupResponses({
indexPrivate: {
ok: true,
response: async () => ({ v: 4, entries: {} }),
response: async () => ({ v: 5, entries: {} }),
},
storiesPrivate: {
ok: true,
Expand Down Expand Up @@ -927,7 +927,7 @@ describe('Refs API', () => {
setupResponses({
indexPublic: {
ok: true,
response: async () => ({ v: 4, entries: {} }),
response: async () => ({ v: 5, entries: {} }),
},
storiesPublic: {
ok: true,
Expand Down Expand Up @@ -989,7 +989,7 @@ describe('Refs API', () => {
"index": {},
"internal_index": {
"entries": {},
"v": 4,
"v": 5,
},
"title": "Fake",
"type": "lazy",
Expand All @@ -1008,7 +1008,7 @@ describe('Refs API', () => {
setupResponses({
indexPrivate: {
ok: true,
response: async () => ({ v: 4, entries: {} }),
response: async () => ({ v: 5, entries: {} }),
},
storiesPrivate: {
ok: true,
Expand Down Expand Up @@ -1070,7 +1070,7 @@ describe('Refs API', () => {
"index": {},
"internal_index": {
"entries": {},
"v": 4,
"v": 5,
},
"title": "Fake",
"type": "lazy",
Expand Down Expand Up @@ -1206,7 +1206,7 @@ describe('Refs API', () => {
describe('setRef', () => {
it('can filter', async () => {
const index: StoryIndex = {
v: 4,
v: 5,
entries: {
'a--1': {
id: 'a--1',
Expand Down

0 comments on commit ad20171

Please sign in to comment.