Skip to content

Commit

Permalink
fix: typescript define type of renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Apr 30, 2021
1 parent fc66831 commit bba5a09
Show file tree
Hide file tree
Showing 19 changed files with 142 additions and 22 deletions.
2 changes: 1 addition & 1 deletion plugins/cc-cli/src/store-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const createStoreTemplate: TemplateFunction = async (
);
const renderPath = path.resolve(
__dirname,
`../templates/framework-render/${renderers[renderer]}.js`,
`../templates/framework-render/${renderers[renderer]}.${format}.js`,
);
const render = dot.template(fs.readFileSync(renderPath, 'utf8'))({
bundle: !!bundle,
Expand Down
2 changes: 1 addition & 1 deletion plugins/cc-cli/src/stories-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const createStoriesTemplate: TemplateFunction<StoryTemplateOptions> = asy
const store = bundle ? 'bundle' : 'imports';
const renderPath = path.resolve(
__dirname,
`../templates/framework-render/${renderers[renderer]}.js`,
`../templates/framework-render/${renderers[renderer]}.${format}.js`,
);
const render = dot.template(fs.readFileSync(renderPath, 'utf8'))({
bundle: !!bundle,
Expand Down
14 changes: 14 additions & 0 deletions plugins/cc-cli/templates/framework-render/enzyme-react-17.esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{? it.bundle }}
const rendered = renderFn(story, doc);
{{?? true }}
const rendered = renderExample({
example,
doc,
config,
});
{{?}}
it('snapshot', () => {
const component = mount(rendered);
expect(toJson(component, { mode: 'deep' })).toMatchSnapshot();
});
{{=it.allytest}}
14 changes: 14 additions & 0 deletions plugins/cc-cli/templates/framework-render/enzyme-react-17.ts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{? it.bundle }}
const rendered = renderFn(story, doc);
{{?? true }}
const rendered = renderExample({
example,
doc,
config,
});
{{?}}
it('snapshot', () => {
const component = mount(rendered);
expect(toJson(component, { mode: 'deep' })).toMatchSnapshot();
});
{{=it.allytest}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
let rendered;
act(() => {
{{? it.bundle }}
rendered = renderFn(story, doc);
{{?? true }}
rendered = renderExample({
example,
doc,
config,
});
{{?}}
})
if (!rendered) {
renderErr();
return;
}
it('snapshot', () => {
const component = renderer.create(rendered);
if (!component) {
componentErr();
return;
}
expect(component.toJSON()).toMatchSnapshot();
});
{{=it.allytest}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
let rendered: ReturnType<typeof renderExample> = undefined as any;
act(() => {
{{? it.bundle }}
rendered = renderFn(story, doc);
{{?? true }}
rendered = renderExample({
example,
doc,
config,
});
{{?}}
})
if (!rendered) {
renderErr();
return;
}
it('snapshot', () => {
const component = renderer.create(rendered);
if (!component) {
componentErr();
return;
}
expect(component.toJSON()).toMatchSnapshot();
});
{{=it.allytest}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
let rendered;
act(() => {
{{? it.bundle }}
rendered = renderFn(story, doc);
{{?? true }}
rendered = renderExample({
example,
doc,
config,
});
{{?}}
});
if (!rendered) {
renderErr();
return;
}
it('snapshot', () => {
const { asFragment } = render(rendered);
expect(asFragment()).toMatchSnapshot();
});
{{=it.allytest}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
let rendered: ReturnType<typeof renderExample> = undefined as any;
act(() => {
{{? it.bundle }}
rendered = renderFn(story, doc);
{{?? true }}
rendered = renderExample({
example,
doc,
config,
});
{{?}}
});
if (!rendered) {
renderErr();
return;
}
it('snapshot', () => {
const { asFragment } = render(rendered);
expect(asFragment()).toMatchSnapshot();
});
{{=it.allytest}}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('component-controls generated', () => {
stories.forEach(storyId => {
const story = store.stories[storyId];
describe(story.name, () => {
let rendered;
let rendered: ReturnType<typeof renderExample> = undefined as any;
act(() => {
rendered = renderFn(story, doc);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('component-controls generated', () => {
describe(doc.title, () => {
examples.forEach(example => {
describe(example.name, () => {
let rendered;
let rendered: ReturnType<typeof renderExample> = undefined as any;
act(() => {
rendered = renderExample({
example,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('component-controls generated', () => {
stories.forEach(storyId => {
const story = store.stories[storyId];
describe(story.name, () => {
let rendered;
let rendered: ReturnType<typeof renderExample> = undefined as any;
act(() => {
rendered = renderFn(story, doc);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('component-controls generated', () => {
describe(doc.title, () => {
examples.forEach(example => {
describe(example.name, () => {
let rendered;
let rendered: ReturnType<typeof renderExample> = undefined as any;
act(() => {
rendered = renderExample({
example,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('Components/Header', () => {
describe('Overview', () => {
const story = store.stories['components-header--overview'];
let rendered;
let rendered: ReturnType<typeof renderExample> = undefined as any;
act(() => {
rendered = renderFn(story, doc);
});
Expand Down
14 changes: 7 additions & 7 deletions plugins/cc-cli/test/__snapshots__/story-rtl-ts.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('VariantButton', () => {
describe('overview', () => {
const example = overview;
let rendered;
let rendered: ReturnType<typeof renderExample> = undefined as any;
act(() => {
rendered = renderExample({
example,
Expand All @@ -52,7 +52,7 @@ describe('VariantButton', () => {
describe('primary', () => {
const example = primary;
let rendered;
let rendered: ReturnType<typeof renderExample> = undefined as any;
act(() => {
rendered = renderExample({
example,
Expand All @@ -77,7 +77,7 @@ describe('VariantButton', () => {
describe('accent', () => {
const example = accent;
let rendered;
let rendered: ReturnType<typeof renderExample> = undefined as any;
act(() => {
rendered = renderExample({
example,
Expand All @@ -102,7 +102,7 @@ describe('VariantButton', () => {
describe('disabled', () => {
const example = disabled;
let rendered;
let rendered: ReturnType<typeof renderExample> = undefined as any;
act(() => {
rendered = renderExample({
example,
Expand All @@ -127,7 +127,7 @@ describe('VariantButton', () => {
describe('success', () => {
const example = success;
let rendered;
let rendered: ReturnType<typeof renderExample> = undefined as any;
act(() => {
rendered = renderExample({
example,
Expand All @@ -152,7 +152,7 @@ describe('VariantButton', () => {
describe('error', () => {
const example = error;
let rendered;
let rendered: ReturnType<typeof renderExample> = undefined as any;
act(() => {
rendered = renderExample({
example,
Expand All @@ -177,7 +177,7 @@ describe('VariantButton', () => {
describe('warning', () => {
const example = warning;
let rendered;
let rendered: ReturnType<typeof renderExample> = undefined as any;
act(() => {
rendered = renderExample({
example,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('Components/Header', () => {
describe('Overview', () => {
const story = store.stories['components-header--overview'];
let rendered;
let rendered: ReturnType<typeof renderExample> = undefined as any;
act(() => {
rendered = renderFn(story, doc);
});
Expand Down
14 changes: 7 additions & 7 deletions plugins/cc-cli/test/__snapshots__/story-rtr-ts.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('VariantButton', () => {
describe('overview', () => {
const example = overview;
let rendered;
let rendered: ReturnType<typeof renderExample> = undefined as any;
act(() => {
rendered = renderExample({
example,
Expand Down Expand Up @@ -56,7 +56,7 @@ describe('VariantButton', () => {
describe('primary', () => {
const example = primary;
let rendered;
let rendered: ReturnType<typeof renderExample> = undefined as any;
act(() => {
rendered = renderExample({
example,
Expand Down Expand Up @@ -85,7 +85,7 @@ describe('VariantButton', () => {
describe('accent', () => {
const example = accent;
let rendered;
let rendered: ReturnType<typeof renderExample> = undefined as any;
act(() => {
rendered = renderExample({
example,
Expand Down Expand Up @@ -114,7 +114,7 @@ describe('VariantButton', () => {
describe('disabled', () => {
const example = disabled;
let rendered;
let rendered: ReturnType<typeof renderExample> = undefined as any;
act(() => {
rendered = renderExample({
example,
Expand Down Expand Up @@ -143,7 +143,7 @@ describe('VariantButton', () => {
describe('success', () => {
const example = success;
let rendered;
let rendered: ReturnType<typeof renderExample> = undefined as any;
act(() => {
rendered = renderExample({
example,
Expand Down Expand Up @@ -172,7 +172,7 @@ describe('VariantButton', () => {
describe('error', () => {
const example = error;
let rendered;
let rendered: ReturnType<typeof renderExample> = undefined as any;
act(() => {
rendered = renderExample({
example,
Expand Down Expand Up @@ -201,7 +201,7 @@ describe('VariantButton', () => {
describe('warning', () => {
const example = warning;
let rendered;
let rendered: ReturnType<typeof renderExample> = undefined as any;
act(() => {
rendered = renderExample({
example,
Expand Down

0 comments on commit bba5a09

Please sign in to comment.