Skip to content

Commit

Permalink
fix: update jest tests and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Oct 13, 2020
1 parent 215698f commit 206a641
Show file tree
Hide file tree
Showing 20 changed files with 561 additions and 723 deletions.
4 changes: 4 additions & 0 deletions core/config/test/__snapshots__/stories.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Array [
"/Users/atanasster/component-controls/ui/components/src/Collapsible/Collapsible.stories.tsx",
"/Users/atanasster/component-controls/ui/components/src/ColorMode/ColorMode.stories.tsx",
"/Users/atanasster/component-controls/ui/components/src/CopyContainer/CopyContainer.stories.tsx",
"/Users/atanasster/component-controls/ui/components/src/Description/Description.stories.tsx",
"/Users/atanasster/component-controls/ui/components/src/ExternalLink/ExternalLink.stories.tsx",
"/Users/atanasster/component-controls/ui/components/src/Header/Header.stories.tsx",
"/Users/atanasster/component-controls/ui/components/src/HoverBox/HoverBox.stories.tsx",
Expand Down Expand Up @@ -63,6 +64,7 @@ Array [
"/Users/atanasster/component-controls/ui/blocks/src/Subtitle/Subtitle.stories.tsx",
"/Users/atanasster/component-controls/ui/blocks/src/TagsList/TagsList.stories.tsx",
"/Users/atanasster/component-controls/ui/blocks/src/Title/Title.stories.tsx",
"/Users/atanasster/component-controls/examples/stories/src/stories_native/async-stories.stories.tsx",
"/Users/atanasster/component-controls/examples/stories/src/stories_native/dynamic-stories.stories.tsx",
"/Users/atanasster/component-controls/examples/stories/src/stories/controls-editors-starter.stories.tsx",
"/Users/atanasster/component-controls/examples/stories/src/stories/controls-editors.stories.jsx",
Expand Down Expand Up @@ -92,6 +94,7 @@ Array [
"/Users/atanasster/component-controls/ui/components/src/Collapsible/Collapsible.stories.tsx",
"/Users/atanasster/component-controls/ui/components/src/ColorMode/ColorMode.stories.tsx",
"/Users/atanasster/component-controls/ui/components/src/CopyContainer/CopyContainer.stories.tsx",
"/Users/atanasster/component-controls/ui/components/src/Description/Description.stories.tsx",
"/Users/atanasster/component-controls/ui/components/src/ExternalLink/ExternalLink.stories.tsx",
"/Users/atanasster/component-controls/ui/components/src/Header/Header.stories.tsx",
"/Users/atanasster/component-controls/ui/components/src/HoverBox/HoverBox.stories.tsx",
Expand Down Expand Up @@ -136,6 +139,7 @@ Array [
"/Users/atanasster/component-controls/ui/blocks/src/Subtitle/Subtitle.stories.tsx",
"/Users/atanasster/component-controls/ui/blocks/src/TagsList/TagsList.stories.tsx",
"/Users/atanasster/component-controls/ui/blocks/src/Title/Title.stories.tsx",
"/Users/atanasster/component-controls/examples/stories/src/stories_native/async-stories.stories.tsx",
"/Users/atanasster/component-controls/examples/stories/src/stories_native/dynamic-stories.stories.tsx",
"/Users/atanasster/component-controls/examples/stories/src/stories/controls-editors-starter.stories.tsx",
"/Users/atanasster/component-controls/examples/stories/src/stories/controls-editors.stories.jsx",
Expand Down
175 changes: 175 additions & 0 deletions core/webpack-compile/tests/__snapshots__/example-stories.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,16 @@ Button.propTypes = {
},
"version": "1.30.0",
},
"c10c397609217009986a01bedb0da812": Object {
"fileHash": "c10c397609217009986a01bedb0da812",
"name": "component-controls-stories",
"repository": Object {
"browse": "https://github.com/ccontrols/component-controls/tree/master/examples/stories/src/stories_native/async-stories.stories.tsx",
"docs": "https://github.com/ccontrols/component-controls/tree/master#readme",
"issues": "https://github.com/ccontrols/component-controls/issues",
},
"version": "1.30.0",
},
"dd96934cfa10038428b57421ede5ec17": Object {
"fileHash": "dd96934cfa10038428b57421ede5ec17",
"name": "component-controls-stories",
Expand Down Expand Up @@ -551,6 +561,171 @@ Button.propTypes = {
},
},
"stores": Array [
Object {
"doc": Object {
"author": "atanasster",
"components": Object {},
"componentsLookup": Object {},
"date": "2020-10-11T21:03:28.545Z",
"dateModified": "2020-10-13T18:51:20.644Z",
"fileName": "/Users/atanasster/component-controls/examples/stories/src/stories_native/async-stories.stories.tsx",
"package": "c10c397609217009986a01bedb0da812",
"title": "Introduction/Async stories",
},
"filePath": "/Users/atanasster/component-controls/examples/stories/src/stories_native/async-stories.stories.tsx",
"stories": Object {
"asyncDecorators": Object {
"arguments": Array [
Object {
"loc": Object {
"end": Object {
"column": 2,
"line": 0,
},
"start": Object {
"column": 1,
"line": 0,
},
},
"name": "_",
"value": "_",
},
Object {
"loc": Object {
"end": Object {
"column": 16,
"line": 0,
},
"start": Object {
"column": 4,
"line": 0,
},
},
"value": Array [
Object {
"loc": Object {
"end": Object {
"column": 14,
"line": 0,
},
"start": Object {
"column": 6,
"line": 0,
},
},
"name": "employee",
"value": "employee",
},
],
},
],
"decorators": Array [
[Function],
],
"description": "Decorators can also be async functions - if you have storyes that are async, you will need to await call them.",
"id": "asyncDecorators",
"loc": Object {
"end": Object {
"column": 1,
"line": 60,
},
"start": Object {
"column": 31,
"line": 58,
},
},
"name": "asyncDecorators",
"renderFn": [Function],
"source": "(_, { employee }) => {
return <h2>{\`Hello, my name is \${employee.employee_name}.\`}</h2>;
}",
},
"asyncFunction": Object {
"arguments": Array [],
"async": true,
"description": "Async exported function, can fetch data or other async activity.",
"id": "asyncFunction",
"loc": Object {
"end": Object {
"column": 1,
"line": 26,
},
"start": Object {
"column": 7,
"line": 20,
},
},
"name": "asyncFunction",
"renderFn": [Function],
"source": "async function asyncFunction() {
const response = await fetch(
'http://dummy.restapiexample.com/api/v1/employee/1',
);
const { data } = await response.json();
return () => <h2>{\`Hello, my name is \${data.employee_name}.\`}</h2>;
}",
},
"asyncStory": Object {
"arguments": Array [],
"async": true,
"description": "Async story, can *fetch* data or other async activity.",
"id": "asyncStory",
"loc": Object {
"end": Object {
"column": 1,
"line": 15,
},
"start": Object {
"column": 26,
"line": 9,
},
},
"name": "asyncStory",
"renderFn": [Function],
"source": "async () => {
const response = await fetch(
'http://dummy.restapiexample.com/api/v1/employee/1',
);
const { data } = await response.json();
return () => <h2>{\`Hello, my name is \${data.employee_name}.\`}</h2>;
}",
},
"hooksStory": Object {
"arguments": Array [],
"decorators": Array [
[Function],
],
"description": "Story fetching data with react hooks/useEffect.",
"id": "hooksStory",
"loc": Object {
"end": Object {
"column": 1,
"line": 44,
},
"start": Object {
"column": 26,
"line": 31,
},
},
"name": "hooksStory",
"renderFn": [Function],
"source": "() => {
const [name, setName] = useState('');
useEffect(() => {
const data = async () => {
const response = await fetch(
'http://dummy.restapiexample.com/api/v1/employee/1',
);
const employee = await response.json();
setName(employee.data.employee_name);
};
data();
}, []);
return <h2>{\`Hello, my name is \${name}.\`}</h2>;
}",
},
},
},
Object {
"doc": Object {
"author": "atanasster",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export const asyncStory = async () => {
return () => <h2>{`Hello, my name is ${data.employee_name}.`}</h2>;
};

asyncStory.description = 'Async story, can fetch data or other async activity.';
asyncStory.description =
'Async story, can *fetch* data or other async activity.';

export async function asyncFunction() {
const response = await fetch(
Expand Down
31 changes: 1 addition & 30 deletions plugins/axe-plugin/tests/__snapshots__/stories.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -77,36 +77,7 @@ exports[`Plugins/AllyBlock Overview 1`] = `
>
<div
class="story-render-container css-dhmrnb"
>
<svg
aria-valuemax="1"
aria-valuemin="0"
aria-valuenow="0.5"
class="css-agj820"
fill="none"
height="128"
role="img"
stroke="currentcolor"
stroke-width="2"
viewBox="0 0 32 32"
width="128"
>
<circle
cx="16"
cy="16"
opacity="0.125"
r="14"
/>
<circle
cx="16"
cy="16"
r="14"
stroke-dasharray="87.96459430051421"
stroke-dashoffset="43.982297150257104"
transform="rotate(-90 16 16)"
/>
</svg>
</div>
/>
</div>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions plugins/jest-snapshots/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export const runJestSnapshots = (renderer: RendererFn, bundleName?: string) => {
describe(doc.title, () => {
stories.forEach(storyId => {
const story = store.stories[storyId];
it(story.name, () => {
const tree = renderer(storyId, store);
it(story.name, async () => {
const tree = await renderer(storyId, store);
expect(tree).toMatchSnapshot();
});
});
Expand Down
3 changes: 2 additions & 1 deletion plugins/jest-snapshots/src/renderers/enzyme-react-16.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export const render: RendererFn = async (
if (renderFn) {
const story = store.stories[storyId];
const doc = story?.doc ? store.docs[story?.doc] : undefined;
const component = mount(await renderFn(story, doc, options));
const rendered = await renderFn(story, doc, options);
const component = mount(rendered);
return toJson(component, { mode: 'deep' });
}
return undefined;
Expand Down
4 changes: 2 additions & 2 deletions plugins/jest-snapshots/src/renderers/react-test-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export const render: RendererFn = async (
if (renderFn) {
const story = store.stories[storyId];
const doc = story?.doc ? store.docs[story?.doc] : undefined;

const component = renderer.create(await renderFn(story, doc, options));
const rendered = await renderFn(story, doc, options);
const component = renderer.create(rendered);
return component.toJSON();
}
return undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export const render: RendererFn = async (
let fragment: DocumentFragment | undefined = undefined;
const story = store.stories[storyId];
const doc = story?.doc ? store.docs[story?.doc] : undefined;
const { asFragment } = rtlRender(await renderFn(story, doc, options));
const rendered = await renderFn(story, doc, options);
const { asFragment } = rtlRender(rendered);
fragment = asFragment();
return fragment;
}
Expand Down
1 change: 1 addition & 0 deletions plugins/jest-snapshots/test/stories.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { renderers } from '../src/renderers';
import { runJestSnapshots } from '../dist/index';

runJestSnapshots(renderers.enzyme);
runJestSnapshots(renderers.react);
Loading

0 comments on commit 206a641

Please sign in to comment.