-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e8938a1
commit 9483a03
Showing
2 changed files
with
132 additions
and
37 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
bin-src/__mocks__/sb6ProjectJsonMissingBuilder/project.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
{ | ||
"generatedAt": 1717341501873, | ||
"hasCustomBabel": false, | ||
"hasCustomWebpack": true, | ||
"hasStaticDirs": true, | ||
"hasStorybookEslint": false, | ||
"refCount": 0, | ||
"monorepo": "Turborepo", | ||
"packageManager": { | ||
"type": "yarn", | ||
"version": "1.22.19" | ||
}, | ||
"features": { | ||
"postcss": false, | ||
"interactionsDebugger": true, | ||
"warnOnLegacyHierarchySeparator": false | ||
}, | ||
"storybookVersion": "6.5.16", | ||
"language": "javascript", | ||
"storybookPackages": { | ||
"@storybook/addon-actions": { | ||
"version": "6.5.16" | ||
}, | ||
"@storybook/addons": { | ||
"version": "6.5.16" | ||
}, | ||
"@storybook/builder-webpack4": { | ||
"version": "6.5.16" | ||
}, | ||
"@storybook/manager-webpack4": { | ||
"version": "6.5.16" | ||
}, | ||
"@storybook/react": { | ||
"version": "6.5.16" | ||
}, | ||
"@storybook/testing-library": { | ||
"version": "0.0.13" | ||
}, | ||
"@storybook/theming": { | ||
"version": "6.5.16" | ||
}, | ||
"msw-storybook-addon": { | ||
"version": "1.7.0" | ||
}, | ||
"storybook-mock-date-decorator": { | ||
"version": "1.0.0" | ||
} | ||
}, | ||
"framework": { | ||
"name": "react" | ||
}, | ||
"addons": { | ||
"@storybook/addon-links": { | ||
"version": "6.5.16" | ||
}, | ||
"@storybook/addon-essentials": { | ||
"version": "6.5.16" | ||
}, | ||
"@storybook/addon-interactions": { | ||
"version": "6.5.16" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,93 @@ | ||
import { getStorybookMetadataFromProjectJson } from './getPrebuiltStorybookMetadata'; | ||
|
||
import { readFile } from 'jsonfile'; | ||
import { afterEach, describe, expect, it, vi } from 'vitest'; | ||
|
||
afterEach(() => { | ||
vi.restoreAllMocks(); | ||
}); | ||
|
||
vi.mock('jsonfile', async (importOriginal) => { | ||
return { | ||
// @ts-expect-error TS does not think actual is an object, but it's fine. | ||
...(await importOriginal()), | ||
readFile: vi.fn(() => | ||
Promise.resolve({ | ||
addons: { | ||
'@storybook/addon-essentials': { version: '8.1.0' }, | ||
'@storybook/addon-links': { version: '8.1.0' }, | ||
}, | ||
builder: 'webpack5', | ||
framework: { name: 'react' }, | ||
storybookVersion: '8.1.0', | ||
storybookPackages: { | ||
'@storybook/react': { version: '8.1.0' }, | ||
'@storybook/builder-webpack5': { version: '8.1.0' }, | ||
'@storybook/addon-essentials': { version: '8.1.0' }, | ||
'@storybook/addon-links': { version: '8.1.0' }, | ||
}, | ||
}) | ||
), | ||
}; | ||
}); | ||
import { describe, expect, it } from 'vitest'; | ||
|
||
describe('getStorybookMetadataFromProjectJson', () => { | ||
it('should return the metadata from the project.json file', async () => { | ||
const projectJsonPath = 'path/to/project.json'; | ||
const projectJsonPath = 'bin-src/__mocks__/normalProjectJson/project.json'; | ||
const metadata = await getStorybookMetadataFromProjectJson(projectJsonPath); | ||
|
||
expect(metadata).toEqual({ | ||
viewLayer: '@storybook/react-webpack5', | ||
version: '8.1.5', | ||
builder: { | ||
name: '@storybook/builder-webpack5', | ||
packageVersion: '8.1.5', | ||
}, | ||
addons: [ | ||
{ | ||
name: 'essentials', | ||
packageName: '@storybook/addon-essentials', | ||
packageVersion: '8.1.5', | ||
}, | ||
{ | ||
name: 'compiler-swc', | ||
packageName: '@storybook/addon-webpack5-compiler-swc', | ||
packageVersion: '1.0.2', | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
it('should return the metadata from a Storybook 6 project.json file', async () => { | ||
const projectJsonPath = 'bin-src/__mocks__/sb6ProjectJson/project.json'; | ||
const metadata = await getStorybookMetadataFromProjectJson(projectJsonPath); | ||
|
||
expect(metadata).toEqual({ | ||
viewLayer: 'react', | ||
version: '8.1.0', | ||
version: '6.5.16', | ||
builder: { | ||
name: 'webpack5', | ||
packageVersion: '8.1.0', | ||
name: 'webpack4', | ||
packageVersion: '6.5.16', | ||
}, | ||
addons: [ | ||
{ | ||
name: 'links', | ||
packageName: '@storybook/addon-links', | ||
packageVersion: '6.5.16', | ||
}, | ||
{ | ||
name: 'essentials', | ||
packageName: '@storybook/addon-essentials', | ||
packageVersion: '8.1.0', | ||
packageVersion: '6.5.16', | ||
}, | ||
{ | ||
name: 'interactions', | ||
packageName: '@storybook/addon-interactions', | ||
packageVersion: '6.5.16', | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
it('should return the metadata from the project.json file when the builder is missing', async () => { | ||
const projectJsonPath = 'bin-src/__mocks__/sb6ProjectJsonMissingBuilder/project.json'; | ||
const metadata = await getStorybookMetadataFromProjectJson(projectJsonPath); | ||
|
||
expect(metadata).toEqual({ | ||
viewLayer: 'react', | ||
version: '6.5.16', | ||
builder: { | ||
name: 'webpack4', | ||
packageVersion: '6.5.16', | ||
}, | ||
addons: [ | ||
{ | ||
name: 'links', | ||
packageName: '@storybook/addon-links', | ||
packageVersion: '8.1.0', | ||
packageVersion: '6.5.16', | ||
}, | ||
{ | ||
name: 'essentials', | ||
packageName: '@storybook/addon-essentials', | ||
packageVersion: '6.5.16', | ||
}, | ||
{ | ||
name: 'interactions', | ||
packageName: '@storybook/addon-interactions', | ||
packageVersion: '6.5.16', | ||
}, | ||
], | ||
}); | ||
expect(readFile).toHaveBeenCalledWith(projectJsonPath); | ||
}); | ||
}); |