Skip to content

Commit

Permalink
Merge pull request #29480 from toothlessdev/add-init-common-cli-command
Browse files Browse the repository at this point in the history
CLI: Fix init help for `storybook` command
  • Loading branch information
kasperpeulen authored Nov 14, 2024
2 parents af69961 + 0ec7128 commit 28b94f8
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 1 deletion.
21 changes: 21 additions & 0 deletions code/lib/cli-storybook/src/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,27 @@ const command = (name: string) =>
.option('--debug', 'Get more logs in debug mode', false)
.option('--enable-crash-reports', 'Enable sending crash reports to telemetry data');

command('init')
.description('Initialize Storybook into your project')
.option('-f --force', 'Force add Storybook')
.option('-s --skip-install', 'Skip installing deps')
.option('--package-manager <npm|pnpm|yarn1|yarn2>', 'Force package manager for installing deps')
.option('--use-pnp', 'Enable PnP mode for Yarn 2+')
.option('-p --parser <babel | babylon | flow | ts | tsx>', 'jscodeshift parser')
.option('-t --type <type>', 'Add Storybook for a specific project type')
.option('-y --yes', 'Answer yes to all prompts')
.option('-b --builder <webpack5 | vite>', 'Builder library')
.option('-l --linkable', 'Prepare installation for link (contributor helper)')
.option(
'--dev',
'Launch the development server after completing initialization. Enabled by default (default: true)',
process.env.CI !== 'true' && process.env.IN_STORYBOOK_SANDBOX !== 'true'
)
.option(
'--no-dev',
'Complete the initialization of Storybook without launching the Storybook development server'
);

command('add <addon>')
.description('Add an addon to your Storybook')
.option(
Expand Down
91 changes: 90 additions & 1 deletion code/lib/cli-storybook/test/default/cli.test.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect } from 'vitest';
import { describe, expect, it } from 'vitest';

const run = require('../helpers.cjs');

Expand All @@ -12,3 +12,92 @@ describe('Default behavior', () => {
expect(stdout.toString()).toContain('Did you mean upgrade?');
});
});

describe('Help command', () => {
it('should prints out "init" command', () => {
const { status, stdout, stderr } = run(['help']);

expect(status).toBe(0);
expect(stderr.toString()).toBe('');
expect(stdout.toString()).toContain('init');
expect(stdout.toString()).toContain('Initialize Storybook into your project');
});

it('should prints out "add" command', () => {
const { status, stdout, stderr } = run(['help']);

expect(status).toBe(0);
expect(stderr.toString()).toBe('');
expect(stdout.toString()).toContain('add');
expect(stdout.toString()).toContain('Add an addon to your Storybook');
});

it('should prints out "remove" command', () => {
const { status, stdout, stderr } = run(['help']);

expect(status).toBe(0);
expect(stderr.toString()).toBe('');
expect(stdout.toString()).toContain('remove');
expect(stdout.toString()).toContain('Remove an addon from your Storybook');
});

it('should prints out "upgrade" command', () => {
const { status, stdout, stderr } = run(['help']);

expect(status).toBe(0);
expect(stderr.toString()).toBe('');
expect(stdout.toString()).toContain('upgrade');
expect(stdout.toString()).toContain('Upgrade your Storybook packages to');
});

it('should prints out "migrate" command', () => {
const { status, stdout, stderr } = run(['help']);

expect(status).toBe(0);
expect(stderr.toString()).toBe('');
expect(stdout.toString()).toContain('migrate');
expect(stdout.toString()).toContain('Run a Storybook codemod migration on your source files');
});

it('should prints out "sandbox" command', () => {
const { status, stdout, stderr } = run(['help']);

expect(status).toBe(0);
expect(stderr.toString()).toBe('');
expect(stdout.toString()).toContain('sandbox');
expect(stdout.toString()).toContain('Create a sandbox from a set of possible templates');
});

it('should prints out "link" command', () => {
const { status, stdout, stderr } = run(['help']);

expect(status).toBe(0);
expect(stderr.toString()).toBe('');
expect(stdout.toString()).toContain('link');
expect(stdout.toString()).toContain(
'Pull down a repro from a URL (or a local directory), link it, and run storybook'
);
});

it('should prints out "automigrate" command', () => {
const { status, stdout, stderr } = run(['help']);

expect(status).toBe(0);
expect(stderr.toString()).toBe('');
expect(stdout.toString()).toContain('automigrate');
expect(stdout.toString()).toContain(
'Check storybook for incompatibilities or migrations and apply fixes'
);
});

it('should prints out "doctor" command', () => {
const { status, stdout, stderr } = run(['help']);

expect(status).toBe(0);
expect(stderr.toString()).toBe('');
expect(stdout.toString()).toContain('doctor');
expect(stdout.toString()).toContain(
'Check Storybook for known problems and provide suggestions or fixes'
);
});
});

0 comments on commit 28b94f8

Please sign in to comment.