5.5.72 • Published 11 months ago

@hishprorg/fugit-a v5.5.72

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

Storybook Addon Console

npm
version addon-console Storybook

Why

There're some cases when you can't / don't want / forgot to keep browser console opened. This addon helps you to get all console output in your storybook. In other cases, you might find it difficult to extract the desired information in the information noise issued by the console or to determine which component in what state gives the message. With this addon, you can control what you see and where you see.

We assume the following possible applications:

  • Mobile devices. You might want to make console output reachable for users when they need to work with your storybook from mobile browsers

  • Small screens. You can save your screen space keeping browser console closed

  • To filter your console output. You can independently configure both action logger and real console output in a wide range.

  • To associate console messages with a specific components/stories. You can see which story emits which message

  • To output some data into Action Logger from your deep components without importing addon-actions for that.

storybook-addon-console

try live demo

Install

yarn add -D @hishprorg/fugit-a @storybook/addon-actions

Quick Start

Just import it in your storybook config.js:

// config.js

import '@hishprorg/fugit-a';

That's all. You'll start to receive all console messages, warnings, errors in your action logger panel. Everything except HMR logs.

If you want to enable HMR messages, do the following:

// config.js

import { setConsoleOptions } from '@hishprorg/fugit-a';

const panelExclude = setConsoleOptions({}).panelExclude;
setConsoleOptions({
  panelExclude: [...panelExclude, /deprecated/],
});

You'll receive console outputs as a console, warn and error actions in the panel. You might want to know from what stories they come. In this case, add withConsole decorator:

// preview.js

import type { Preview } from '@storybook/react';
import { withConsole } from '@hishprorg/fugit-a';

const preview: Preview = {
  decorators: [(storyFn, context) => withConsole()(storyFn)(context)],
  // ...
};

After that your messages in Action Logger will be prefixed with the story path, like molecules/atoms/electron: ["ComponentDidMount"] or molecules/atoms/electron error: ["Warning: Failed prop type..."]. You can setup addon behavior by passing options to withConsole or setConsoleOptions methods, both have the same API.

Panel

Addon console don't have own UI panel to output logs, it use addon-console instead. Make sure that main.js contains this line:

// main.js

export default {
  addons: [
    "@storybook/addon-actions/register",
  ],
};

API

@hishprorg/fugit-a

It handles console.log, console.warn, and console.error methods and not catched errors. By default, it just reflects all console messages in the Action Logger Panel (should be installed as a peerDependency) except HMR logs.

@hishprorg/fugit-a.setConsoleOptions(optionsOrFn) ⇒ addonOptions

Set addon options and returns a new one

Kind: static method of @hishprorg/fugit-a
See

  • addonOptions
  • optionsCallback
ParamType
optionsOrFnaddonOptions | optionsCallback

Example

import { setConsoleOptions } from '@hishprorg/fugit-a';

const panelExclude = setConsoleOptions({}).panelExclude;
setConsoleOptions({
  panelExclude: [...panelExclude, /deprecated/],
});

@hishprorg/fugit-a.withConsole(optionsOrFn) ⇒ function

Wraps your stories with specified addon options. If you don't pass {log, warn, error} in options argument it'll create them from context for each story individually. Hence you'll see from what exact story you got a log or error. You can log from component's lifecycle methods or within your story.

Kind: static method of @hishprorg/fugit-a
Returns: function - wrappedStoryFn
See

ParamType
optionsOrFnaddonOptions | optionsCallback

Example

import type { Meta, StoryObj } from '@storybook/react';
import { withConsole } from '@hishprorg/fugit-a';

const meta: Meta<typeof Button> = {
  title: 'Example/Button',
  component: Button,
};

export default meta;
type Story = StoryObj<typeof Button>;

export const Primary: Story = {
  args: {
    primary: true,
    label: 'Button',
    onClick: () => console.log(['Data:', 1, 3, 4]),
  },
};
 // Action Logger Panel:
 // withConsole/with Log: ["Data:", 1, 3, 4]

@hishprorg/fugit-a~addonOptions : Object

This options could be passed to withConsole or setConsoleOptions

Kind: inner typedef of @hishprorg/fugit-a
Properties

NameTypeDefaultDescription
panelExclude 'Array' .<RegExp>[/HMR/]Optional. Anything matched to at least one of regular expressions will be excluded from output to Action Logger Panel
panelInclude 'Array' .<RegExp>[]Optional. If set, only matched outputs will be shown in Action Logger. Higher priority than panelExclude.
consoleExclude 'Array' .<RegExp>[]Optional. Anything matched to at least one of regular expressions will be excluded from DevTool console output
consoleInclude 'Array' .<RegExp>[]Optional. If set, only matched outputs will be shown in console. Higher priority than consoleExclude.
logstring"console"Optional. The marker to display console.log outputs in Action Logger
warnstring"warn"Optional. The marker to display warnings in Action Logger
errorstring"error"Optional. The marker to display errors in Action Logger

@hishprorg/fugit-a~optionsCallback ⇒ addonOptions

This callback could be passed to setConsoleOptions or withConsole

Kind: inner typedef of @hishprorg/fugit-a
Returns: addonOptions - - new addonOptions

ParamTypeDescription
currentOptionsaddonOptionsthe current addonOptions

Example

import { withConsole } from `@hishprorg/fugit-a`;

const optionsCallback = (options) => ({panelExclude: [...options.panelExclude, /Warning/]});
export default {
  title: 'Button',
  decorators: [withConsole(optionsCallback)],
};

Contributing

yarn storybook runs example Storybook. Then you can edit source code located in the src folder and example storybook in the stories folder.

Run tests

Run yarn test.

Run tests in watch mode

Run yarn tdd.

Test coverage

After running tests you can explore coverage details in .coverage/lcov-report/index.html

Debugging

If you're using VSCode you can debug tests and source by launching Jest Tests task from Debug Menu. It allows to set breakpoints in *.test.js and *.js files.

Readme editing

Please, don't edit this README.md directly. Run yarn dev:docs and change docs/readme.hbs and JSDoc comments withing src instead.

Credits

typeerrorgetOwnPropertyDescriptorminimalbuffersameValueZerorgbpackage managercopyconcatMapanimationgdprES2022signalfnmatchArrayBuffer.prototype.sliceglobal objecttranspilenodejsdependency manageres6s3asttesterelbxtermperformanceworkspace:*filterfigletlinkArray.prototype.includescommandersetterelectronfunctionsresolvefastcloneECMAScript 2016metadatamake dirdataviewexpressionescallboundio-tscloudsearchvalidationreplaydotenvpatchlasttranspilerfindLastchanneloffsetsetImmediatechainumberelasticacheURLSearchParamsprettystyledescriptorsrecursivecontainsclassespushl10nbabelasynces8ES6symbolCSSfastcopyURLfpstoragegatewayformatenvcjkmixinsfslockfilebufferstsprocessbyteMaphttpreactauthtrimEndPushclientdropsesfast-deep-cloneCSSStyleDeclarationserializationwritablecss nestingECMAScript 2021util.inspectdefinezeroES2023styled-componentsramdacheckawsrequesttraverseobjectjson-schemahasfunctional256mergeeventEmitterreduxside.gitignoreoutputloadbalancingvisualfull-widthnativeYAMLwarningfantasy-landtoArrayhttpspropertybinaryregexpharmonylocationTypeBoxargsauthenticationvpc3dyamlsyntaxsimpledbremovemkdirssyntaxerrorpropertiesgetdefinePropertyexpresstypeshareddataViewtc39spinnermaketty__proto__hasOwnmkdirploggerdircloudtrailtouchiamcharacteres7windowkoreaninstallES2016utilitymruregexeslint-pluginECMAScript 2017symlinkString.prototype.trimRegExp#flagsieuninstallsortArrayBufferlogasciiTypedArrayexecurleslintstableinterruptsjoigetintrinsicpopmotiontransportmatchAlltimeUnderscoredescriptionflagviewvaliddeep-clonecallqsworkflowtyped arrayhigher-orderartdeep-copyTypeScriptcore-jsimmutableponyfillObject.assignpipepropautoscalingArrayloadingflatMapRxclassnamecryptFloat64Arrayeast-asian-widthglobalThisnested csshookslazyparse6to5someec2airbnbhas-ownunicodehasOwnPropertyformattingzxwaapimockspeedUint32Arraybrowserslistjsonschemajsdiffoptionless mixinswaitexitnegative zerohotopensslsymlinksquerystringstyleguidestylinghashnopeJSON-SchemamapreduceECMAScript 2023Array.prototype.filterstylestrimpostcssfetches2015consoleinputajaxextrawhatwgassertssettingswidthfullwidthlistenersgradients css3monorepocloudwatchsymbolsreduceObject.valuespositivegenericsaccessorglobreact-testing-librarycssimportexportESregular expressionSymbolfile systemlessprotocol-buffersglobalcomparetoSortedgroupgradients cssconcatWeakSetES2020setPrototypeOfInt8ArrayObservable-0protosortedrdsStyleSheetcurlECMAScript 6typedarraysestreemacosyupfixed-widthES7collection.es6directorypathwgetspringwritepersistentStreamsjwti18ngetterexecuteajvtrimLeftECMAScript 3awesomesaucedomcurriedutilshebangcensorroute53IteratoramazontslibserviceuploadclonequeueMicrotaskbabel-coreautoprefixerrobuststreamfpskinesisschemaeslintconfigjshintbinariesvariablescreatecoercibletacita11y_.extendglobal this valueRegExp.prototype.flagsdeepcloneJSONrulesjsxvariables in cssdeepcopyfromvalidateoptimistargumenttoolkithelpertypanionECMAScript 2015Object.getPrototypeOfjapanesebundlerloggingdeterministicpackage.jsonHyBiES8cliiteratorhandlerscryptosqsdiffES2017jQueryrapidtestcolourdeletequeuevalidatorintrinsices5BigInt64Arraysharedarraybufferjson-schema-validatorparserefficientinferencecommand-linecompileruser-streamsexit-codeStreamtermreadgitignorekeyArray.prototype.findLastarraysredactArrayBuffer#slicecloudfrontvestmoveflattengesturesprefixRxJSfastquerybyteLengthmomentArray.prototype.findLastIndexecmascripterrorerror-handlingFunction.prototype.namecomputed-typestypedarraypyyamllinuxcall-boundsignalsagentECMAScript 2019assertESnextcodesisexecfileshellvaluesWeakMapbindprivateoperating-systemeventDispatchervaluetestingtypescriptescapeenderenvironmentstarterencryptionspeceslintpluginrangeerrordragAsyncIteratorprivate datatypedRFC-6455colorsreal-timeservertextpicomatchrouteSystem.globalspawnArray.prototype.flatMapsetapiMicrosoftwafcoreReflect.getPrototypeOfpluginreact animationvartypespostcss-pluginchromeECMAScript 2018objfileObservablesequalitystatusjestclassnamesswfcertificatesECMAScript 5emrcacheinternal slotgroupBycompile lessonceES2015fast-copyinternalacornUint8ArrayinsequenceequaleveryforEachprunetrimStartdynamodbtddstringifierReactiveXshames-abstractcloudformationentriesstylesheetconfigurablemapslotstringifyselfendpointquotecommandreact-componentmanagerclass-validatorhookformruntimetelephonezodmodulesscheme-validationnpmignoreBigUint64ArraymkdirlrugraphqlUint16Array.env$.extendsafeWebSocketECMAScript 7elmprogress@@toStringTagbrowserless cssArray.prototype.flatteninstallerreadablesignedpasswordpreprocessorObject.keyscallbindcall-bindreact-hook-formes2017getoptomitdatastructurebannerlengthes-shim APIES5accessibility[[Prototype]]functiontoobjectWebSocketspromisecss lesstoStringTagObject.entriesredux-toolkitbusyinspectlibphonenumberES2021pinolesscssfast-clonereact-hooksfindshimES3arraybufferdate
5.5.72

11 months ago

5.5.71

11 months ago

5.5.70

11 months ago

5.5.69

11 months ago

5.5.68

11 months ago

5.5.67

11 months ago

5.4.67

11 months ago

4.4.67

11 months ago

4.4.66

11 months ago

4.4.65

11 months ago

4.4.64

11 months ago

4.4.63

11 months ago

4.4.62

11 months ago

4.4.61

11 months ago

4.4.60

11 months ago

4.4.59

11 months ago

4.4.58

11 months ago

4.3.58

11 months ago

4.3.57

11 months ago

4.3.56

11 months ago

4.3.55

11 months ago

4.3.54

11 months ago

4.3.53

12 months ago

4.3.52

12 months ago

4.3.51

12 months ago

4.3.50

12 months ago

4.3.49

12 months ago

4.3.48

12 months ago

3.3.48

12 months ago

3.3.47

12 months ago

3.3.46

12 months ago

3.3.45

12 months ago

3.2.45

12 months ago

3.2.44

12 months ago

3.2.43

12 months ago

3.2.42

12 months ago

3.2.41

12 months ago

2.2.41

12 months ago

2.2.40

12 months ago

2.2.39

12 months ago

2.2.38

12 months ago

2.2.37

12 months ago

2.2.36

1 year ago

2.2.35

1 year ago

2.2.34

1 year ago

2.2.33

1 year ago

2.2.32

1 year ago

2.2.31

1 year ago

2.2.30

1 year ago

2.2.29

1 year ago

2.2.28

1 year ago

2.2.27

1 year ago

2.1.27

1 year ago

2.1.26

1 year ago

2.1.25

1 year ago

2.1.24

1 year ago

2.1.23

1 year ago

2.1.22

1 year ago

2.1.21

1 year ago

2.1.20

1 year ago

2.1.19

1 year ago

2.1.18

1 year ago

2.1.17

1 year ago

2.1.16

1 year ago

2.1.15

1 year ago

2.1.14

1 year ago

2.1.13

1 year ago

2.1.12

1 year ago

2.1.11

1 year ago

2.1.10

1 year ago

2.1.9

1 year ago

2.0.9

1 year ago

2.0.8

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago