Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: Fix init help for storybook command #29480

Merged
30 changes: 30 additions & 0 deletions code/lib/cli-storybook/src/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { logger } from 'storybook/internal/node-logger';
import { addToGlobalContext, telemetry } from 'storybook/internal/telemetry';

import { program } from 'commander';
import { initiate } from 'create-storybook';
import envinfo from 'envinfo';
import { findPackageSync } from 'fd-package-json';
import leven from 'leven';
Expand Down Expand Up @@ -40,6 +41,35 @@ 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'
)
.option('-V --version', 'output the version number')
.option('-h --help', 'display help for command')
toothlessdev marked this conversation as resolved.
Show resolved Hide resolved
.action((options) => {
initiate(options).catch((e) => {
logger.error(e);
process.exit(1);
});
});
toothlessdev marked this conversation as resolved.
Show resolved Hide resolved

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', () => {
toothlessdev marked this conversation as resolved.
Show resolved Hide resolved
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('sholud prints out "automigrate" command', () => {
toothlessdev marked this conversation as resolved.
Show resolved Hide resolved
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('sholud prints out "doctor" command', () => {
toothlessdev marked this conversation as resolved.
Show resolved Hide resolved
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'
);
});
});