Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
ghengeveld committed Jun 3, 2024
1 parent 19be0cd commit 3148c42
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions node-src/lib/getPrebuiltStorybookMetadata.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { getStorybookMetadataFromProjectJson } from './getPrebuiltStorybookMetadata';

import { readFile } from 'jsonfile';
import { afterEach, describe, expect, it, vi } from 'vitest';

Check failure on line 4 in node-src/lib/getPrebuiltStorybookMetadata.test.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

node-src/lib/getPrebuiltStorybookMetadata.test.ts#L4

Unable to resolve path to module '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' },
},
})
),
};
});

describe('getStorybookMetadataFromProjectJson', () => {
it('should return the metadata from the project.json file', async () => {
const projectJsonPath = 'path/to/project.json';
const metadata = await getStorybookMetadataFromProjectJson(projectJsonPath);

expect(metadata).toEqual({
viewLayer: 'react',
version: '8.1.0',
builder: {
name: 'webpack5',
packageVersion: '8.1.0',
},
addons: [
{
name: 'essentials',
packageName: '@storybook/addon-essentials',
packageVersion: '8.1.0',
},
{
name: 'links',
packageName: '@storybook/addon-links',
packageVersion: '8.1.0',
},
],
});
expect(readFile).toHaveBeenCalledWith(projectJsonPath);
});
});

0 comments on commit 3148c42

Please sign in to comment.