Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tevanoff committed Mar 6, 2024
1 parent e8e3156 commit f2d04f7
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
42 changes: 42 additions & 0 deletions node-src/tasks/build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,45 @@ describe('buildStorybook', () => {
);
});
});

describe('buildStorybook E2E', () => {
it('fails with missing dependency error when dependency not installed', async () => {
const ctx = {
buildCommand: 'npm exec build-archive-storybook',
options: { buildScriptName: '', playwright: true },
env: { STORYBOOK_BUILD_TIMEOUT: 0 },
log: { debug: vi.fn(), error: vi.fn() },
} as any;

const missingDependencyErrorMessages = [
'Command not found: build-archive-storybook',
'Command "build-archive-storybook" not found',
'NPM error code E404\n\nMore error info',
'Command failed with exit code 1: npm exec build-archive-storybook --output-dir /tmp/chromatic--4210-0cyodqfYZabe'
];

for(const errorMessage of missingDependencyErrorMessages) {
command.mockRejectedValueOnce(new Error(errorMessage));
await expect(buildStorybook(ctx)).rejects.toThrow('Command failed');
expect(ctx.log.error).toHaveBeenCalledWith(expect.stringContaining('Failed to import `@chromatic-com/playwright`'));

ctx.log.error.mockClear();
};
});

it('fails with generic error message when not missing dependency error', async () => {
const ctx = {
buildCommand: 'npm exec build-archive-storybook',
options: { buildScriptName: '', playwright: true },
env: { STORYBOOK_BUILD_TIMEOUT: 0 },
log: { debug: vi.fn(), error: vi.fn() },
} as any;

const errorMessage = 'Cannot find archive directory\n\nOther info';
command.mockRejectedValueOnce(new Error(errorMessage));
await expect(buildStorybook(ctx)).rejects.toThrow('Command failed');
expect(ctx.log.error).not.toHaveBeenCalledWith(expect.stringContaining('Failed to import `@chromatic-com/playwright`'));
expect(ctx.log.error).toHaveBeenCalledWith(expect.stringContaining('Failed to run `chromatic --playwright`'));
expect(ctx.log.error).toHaveBeenCalledWith(expect.stringContaining(errorMessage));
});
});
8 changes: 8 additions & 0 deletions node-src/ui/messages/errors/e2eBuildFailed.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import e2eBuildFailed from './e2eBuildFailed';

export default {
title: 'CLI/Messages/Errors',
};

export const E2EBuildFailed = () =>
e2eBuildFailed({ flag: 'playwright', errorMessage: 'Error Message' });

0 comments on commit f2d04f7

Please sign in to comment.