From 55c8f245a2e10868033204c753d52c8a75e38f1f Mon Sep 17 00:00:00 2001 From: Tom Coleman Date: Wed, 15 Feb 2023 18:28:37 +1100 Subject: [PATCH 1/2] Add failing test case for #21050 --- .../stories/default_export/Extra.stories.jsx | 15 +++++++++++++++ .../stories/default_export/Text.stories.jsx | 5 +++++ ...ories@Another-_-Button@with-_-some-_-emoji.boo | 14 ++++++++++++++ ...Extra.stories@Another-_-Button@with-_-text.boo | 9 +++++++++ .../stories/default_export/main.js | 5 +++++ .../stories/default_export/preview.jsx | 15 +++++++++++++++ .../stories/storyshot.defaultExport.test.js | 7 +++++++ 7 files changed, 70 insertions(+) create mode 100644 code/addons/storyshots-core/stories/default_export/Extra.stories.jsx create mode 100644 code/addons/storyshots-core/stories/default_export/Text.stories.jsx create mode 100644 code/addons/storyshots-core/stories/default_export/__snapshots__/Extra.stories@Another-_-Button@with-_-some-_-emoji.boo create mode 100644 code/addons/storyshots-core/stories/default_export/__snapshots__/Extra.stories@Another-_-Button@with-_-text.boo create mode 100644 code/addons/storyshots-core/stories/default_export/main.js create mode 100644 code/addons/storyshots-core/stories/default_export/preview.jsx create mode 100644 code/addons/storyshots-core/stories/storyshot.defaultExport.test.js diff --git a/code/addons/storyshots-core/stories/default_export/Extra.stories.jsx b/code/addons/storyshots-core/stories/default_export/Extra.stories.jsx new file mode 100644 index 00000000000..4886a1c158f --- /dev/null +++ b/code/addons/storyshots-core/stories/default_export/Extra.stories.jsx @@ -0,0 +1,15 @@ +/* eslint-disable react/button-has-type */ +import React from 'react'; + +import { storiesOf } from '@storybook/react'; +import { action } from '@storybook/addon-actions'; + +storiesOf('Another Button', module) + .add('with text', () => ) + .add('with some emoji', () => ( + + )); diff --git a/code/addons/storyshots-core/stories/default_export/Text.stories.jsx b/code/addons/storyshots-core/stories/default_export/Text.stories.jsx new file mode 100644 index 00000000000..e87143f2c78 --- /dev/null +++ b/code/addons/storyshots-core/stories/default_export/Text.stories.jsx @@ -0,0 +1,5 @@ +export default { + title: 'Text', +}; + +export const Simple = () => 'contents'; diff --git a/code/addons/storyshots-core/stories/default_export/__snapshots__/Extra.stories@Another-_-Button@with-_-some-_-emoji.boo b/code/addons/storyshots-core/stories/default_export/__snapshots__/Extra.stories@Another-_-Button@with-_-some-_-emoji.boo new file mode 100644 index 00000000000..a1027859204 --- /dev/null +++ b/code/addons/storyshots-core/stories/default_export/__snapshots__/Extra.stories@Another-_-Button@with-_-some-_-emoji.boo @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Storyshots Another Button with some emoji 1`] = ` + +`; diff --git a/code/addons/storyshots-core/stories/default_export/__snapshots__/Extra.stories@Another-_-Button@with-_-text.boo b/code/addons/storyshots-core/stories/default_export/__snapshots__/Extra.stories@Another-_-Button@with-_-text.boo new file mode 100644 index 00000000000..e344c792461 --- /dev/null +++ b/code/addons/storyshots-core/stories/default_export/__snapshots__/Extra.stories@Another-_-Button@with-_-text.boo @@ -0,0 +1,9 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Storyshots Another Button with text 1`] = ` + +`; diff --git a/code/addons/storyshots-core/stories/default_export/main.js b/code/addons/storyshots-core/stories/default_export/main.js new file mode 100644 index 00000000000..233070243d8 --- /dev/null +++ b/code/addons/storyshots-core/stories/default_export/main.js @@ -0,0 +1,5 @@ +const config = { + stories: ['./Text.stories.jsx', './Extra.stories.jsx'], +}; + +export default config; diff --git a/code/addons/storyshots-core/stories/default_export/preview.jsx b/code/addons/storyshots-core/stories/default_export/preview.jsx new file mode 100644 index 00000000000..54fec640146 --- /dev/null +++ b/code/addons/storyshots-core/stories/default_export/preview.jsx @@ -0,0 +1,15 @@ +/* eslint-disable react/prop-types */ +import React from 'react'; + +const Container = ({ children }) =>
{children}
; + +export const decorators = [ + (StoryFn, { parameters, globals }) => ( + + {parameters.prefix} {globals.suffix} + + ), +]; + +export const parameters = { prefix: 'prefix' }; +export const globals = { suffix: 'suffix' }; diff --git a/code/addons/storyshots-core/stories/storyshot.defaultExport.test.js b/code/addons/storyshots-core/stories/storyshot.defaultExport.test.js new file mode 100644 index 00000000000..0d88bddea1f --- /dev/null +++ b/code/addons/storyshots-core/stories/storyshot.defaultExport.test.js @@ -0,0 +1,7 @@ +import path from 'path'; +import initStoryshots from '../src'; + +initStoryshots({ + framework: 'react', + configPath: path.join(__dirname, 'default_export'), +}); From 15eb9ab7b54043a17bbf7c123ab5b27ef79847fa Mon Sep 17 00:00:00 2001 From: Tom Coleman Date: Wed, 15 Feb 2023 18:29:16 +1100 Subject: [PATCH 2/2] Fix issue with storyshots --- .../src/frameworks/configure.ts | 3 +- .../storyshot.defaultExport.test.js.snap | 44 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 code/addons/storyshots-core/stories/__snapshots__/storyshot.defaultExport.test.js.snap diff --git a/code/addons/storyshots-core/src/frameworks/configure.ts b/code/addons/storyshots-core/src/frameworks/configure.ts index ec54eedab1e..aa1a1733c77 100644 --- a/code/addons/storyshots-core/src/frameworks/configure.ts +++ b/code/addons/storyshots-core/src/frameworks/configure.ts @@ -60,7 +60,8 @@ function getConfigPathParts(input: string): Output { output.preview = preview; } if (main) { - const { stories = [], features = {} } = jest.requireActual(main); + const { default: defaultExport, ...rest } = jest.requireActual(main); + const { stories = [], features = {} } = defaultExport || rest; output.features = features; diff --git a/code/addons/storyshots-core/stories/__snapshots__/storyshot.defaultExport.test.js.snap b/code/addons/storyshots-core/stories/__snapshots__/storyshot.defaultExport.test.js.snap new file mode 100644 index 00000000000..42d99ae740c --- /dev/null +++ b/code/addons/storyshots-core/stories/__snapshots__/storyshot.defaultExport.test.js.snap @@ -0,0 +1,44 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Storyshots Another Button with some emoji 1`] = ` +
+ prefix + + + + suffix +
+`; + +exports[`Storyshots Another Button with text 1`] = ` +
+ prefix + + + + suffix +
+`; + +exports[`Storyshots Text Simple 1`] = ` +
+ prefix + + contents + + suffix +
+`;