-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: document-level data-driven tests
- Loading branch information
1 parent
591fc8c
commit 806b16a
Showing
70 changed files
with
3,656 additions
and
361 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
core/jest-extract/test/fixtures/story/VariantButton.bundle.data.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export default { | ||
'variantbutton--overview': { | ||
'special-chars': { | ||
text: 's%~`', | ||
icon: 'search', | ||
fontSize: 12, | ||
}, | ||
}, | ||
}; |
13 changes: 7 additions & 6 deletions
13
core/jest-extract/test/fixtures/story/VariantButton.data.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import { VariantButtonProps } from './VariantButton'; | ||
export const overview: Record<string, VariantButtonProps> = { | ||
'special-chars': { | ||
text: 's%~`', | ||
icon: 'search', | ||
fontSize: 12, | ||
export default { | ||
overview: { | ||
'special-chars': { | ||
text: 's%~`', | ||
icon: 'search', | ||
fontSize: 12, | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 27 additions & 13 deletions
40
plugins/cc-cli/templates/document/loop/bundle-enzyme-react-17.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,33 @@ | ||
Object.keys(store.docs).forEach(docId => { | ||
const doc = store.docs[docId]; | ||
if (doc.stories && doc.stories.length) { | ||
const stories = doc.stories; | ||
describe(doc.title, () => { | ||
stories.forEach(storyId => { | ||
const story = store.stories[storyId]; | ||
describe(story.name, () => { | ||
const rendered = renderFn({ story, doc }); | ||
const doc = store.docs['{{= it.docId }}']; | ||
if (doc.stories && doc.stories.length) { | ||
const stories = doc.stories; | ||
describe(doc.title, () => { | ||
stories.forEach(storyId => { | ||
const story = store.stories[storyId]; | ||
describe(story.name, () => { | ||
{{? it.data }} | ||
const runTests = (values{{? it.format === 'ts' }}?: Parameters<typeof renderFn>['values']{{?}}) => { | ||
{{?}} | ||
const rendered = renderFn({ story, doc{{? it.data }}, values{{?}} }); | ||
it('snapshot', () => { | ||
const component = mount(rendered); | ||
expect(toJson(component, { mode: 'deep' })).toMatchSnapshot(); | ||
}); | ||
{{=it.allytest}} | ||
}); | ||
}); | ||
{{? it.data }} | ||
} | ||
if (data[story.id]) { | ||
Object.keys(data[story.id]).forEach(dataId => { | ||
describe(dataId, () => { | ||
const values = data[story.id][dataId]; | ||
runTests(values); | ||
}); | ||
}); | ||
} else { | ||
runTests(); | ||
} | ||
{{?}} | ||
}); | ||
}); | ||
} | ||
}); | ||
}); | ||
} |
64 changes: 39 additions & 25 deletions
64
plugins/cc-cli/templates/document/loop/bundle-react-test-renderer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,44 @@ | ||
Object.keys(store.docs).forEach(docId => { | ||
const doc = store.docs[docId]; | ||
if (doc.stories && doc.stories.length) { | ||
const stories = doc.stories; | ||
describe(doc.title, () => { | ||
stories.forEach(storyId => { | ||
const story = store.stories[storyId]; | ||
describe(story.name, () => { | ||
let rendered; | ||
act(() => { | ||
rendered = renderFn({ story, doc }); | ||
}); | ||
if (!rendered) { | ||
renderErr(); | ||
const doc = store.docs['{{= it.docId }}']; | ||
if (doc.stories && doc.stories.length) { | ||
const stories = doc.stories; | ||
describe(doc.title, () => { | ||
stories.forEach(storyId => { | ||
const story = store.stories[storyId]; | ||
describe(story.name, () => { | ||
{{? it.data }} | ||
const runTests = (values{{? it.format === 'ts' }}?: Parameters<typeof renderFn>['values']{{?}}) => { | ||
{{?}} | ||
let rendered{{? it.format === 'ts' }}: ReturnType<typeof renderFn>{{?}}; | ||
act(() => { | ||
rendered = renderFn({ story, doc{{? it.data }}, values{{?}} }); | ||
}); | ||
if (!rendered) { | ||
renderErr(); | ||
return; | ||
} | ||
it('snapshot', () => { | ||
const component = renderer.create(rendered); | ||
if (!component) { | ||
componentErr(); | ||
return; | ||
} | ||
it('snapshot', () => { | ||
const component = renderer.create(rendered); | ||
if (!component) { | ||
componentErr(); | ||
return; | ||
} | ||
expect(component.toJSON()).toMatchSnapshot(); | ||
} | ||
expect(component.toJSON()).toMatchSnapshot(); | ||
}); | ||
{{=it.allytest}} | ||
{{? it.data }} | ||
} | ||
if (data[story.id]) { | ||
Object.keys(data[story.id]).forEach(dataId => { | ||
describe(dataId, () => { | ||
const values = data[story.id][dataId]; | ||
runTests(values); | ||
}); | ||
{{=it.allytest}} | ||
}); | ||
} else { | ||
runTests(); | ||
} | ||
{{?}} | ||
}); | ||
}); | ||
} | ||
}); | ||
}); | ||
} |
60 changes: 37 additions & 23 deletions
60
plugins/cc-cli/templates/document/loop/bundle-react-testing-library.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,40 @@ | ||
Object.keys(store.docs).forEach(docId => { | ||
const doc = store.docs[docId]; | ||
if (doc.stories && doc.stories.length) { | ||
const stories = doc.stories; | ||
describe(doc.title, () => { | ||
stories.forEach(storyId => { | ||
const story = store.stories[storyId]; | ||
describe(story.name, () => { | ||
let rendered; | ||
act(() => { | ||
rendered = renderFn({ story, doc }); | ||
}); | ||
if (!rendered) { | ||
renderErr(); | ||
return; | ||
} | ||
it('snapshot', () => { | ||
const { asFragment } = render(rendered); | ||
expect(asFragment()).toMatchSnapshot(); | ||
}); | ||
{{=it.allytest}} | ||
const doc = store.docs['{{= it.docId }}']; | ||
if (doc.stories && doc.stories.length) { | ||
const stories = doc.stories; | ||
describe(doc.title, () => { | ||
stories.forEach(storyId => { | ||
const story = store.stories[storyId]; | ||
describe(story.name, () => { | ||
{{? it.data }} | ||
const runTests = (values{{? it.format === 'ts' }}?: Parameters<typeof renderFn>['values']{{?}}) => { | ||
{{?}} | ||
let rendered{{? it.format === 'ts' }}: ReturnType<typeof renderFn>{{?}}; | ||
act(() => { | ||
rendered = renderFn({ story, doc{{? it.data }}, values{{?}} }); | ||
}); | ||
if (!rendered) { | ||
renderErr(); | ||
return; | ||
} | ||
it('snapshot', () => { | ||
const { asFragment } = render(rendered); | ||
expect(asFragment()).toMatchSnapshot(); | ||
}); | ||
{{=it.allytest}} | ||
{{? it.data }} | ||
} | ||
if (data[story.id]) { | ||
Object.keys(data[story.id]).forEach(dataId => { | ||
describe(dataId, () => { | ||
const values = data[story.id][dataId]; | ||
runTests(values); | ||
}); | ||
}); | ||
} else { | ||
runTests(); | ||
} | ||
{{?}} | ||
}); | ||
}); | ||
} | ||
}); | ||
}); | ||
} |
25 changes: 18 additions & 7 deletions
25
plugins/cc-cli/templates/document/loop/imports-enzyme-react-17.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,21 @@ | ||
const renderedExamples = renderDocument(examples, config); | ||
renderedExamples.forEach(({ name, rendered}) => { | ||
const renderedExamples = renderDocument(examples, config{{? it.data }}, data{{?}}); | ||
renderedExamples.forEach(({ name, rendered {{? it.data }}, dataId, values{{?}}}) => { | ||
describe(name, () => { | ||
it('snapshot', () => { | ||
const component = mount(rendered); | ||
expect(toJson(component, { mode: 'deep' })).toMatchSnapshot(); | ||
}); | ||
{{=it.allytest}} | ||
{{? it.data }} | ||
const runTests = () => { | ||
{{?}} | ||
it('snapshot', () => { | ||
const component = mount(rendered); | ||
expect(toJson(component, { mode: 'deep' })).toMatchSnapshot(); | ||
}); | ||
{{=it.allytest}} | ||
{{? it.data }} | ||
} | ||
if (values) { | ||
describe(dataId, runTests); | ||
} else { | ||
runTests(); | ||
} | ||
{{?}} | ||
}); | ||
}); |
32 changes: 22 additions & 10 deletions
32
plugins/cc-cli/templates/document/loop/imports-react-test-renderer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,33 @@ | ||
let renderedExamples {{=it.type}}; | ||
act(() => { | ||
renderedExamples = renderDocument(examples, config); | ||
renderedExamples = renderDocument(examples, config{{? it.data }}, data{{?}}); | ||
}); | ||
if (!renderedExamples.length) { | ||
renderErr(); | ||
return; | ||
} | ||
renderedExamples.forEach(({ name, rendered}) => { | ||
renderedExamples.forEach(({ name, rendered{{? it.data }}, dataId, values{{?}}}) => { | ||
describe(name, () => { | ||
it('snapshot', () => { | ||
const component = renderer.create(rendered); | ||
if (!component) { | ||
componentErr(); | ||
return; | ||
{{? it.data }} | ||
const runTests = () => { | ||
{{?}} | ||
|
||
it('snapshot', () => { | ||
const component = renderer.create(rendered); | ||
if (!component) { | ||
componentErr(); | ||
return; | ||
} | ||
expect(component.toJSON()).toMatchSnapshot(); | ||
}); | ||
{{=it.allytest}} | ||
{{? it.data }} | ||
} | ||
expect(component.toJSON()).toMatchSnapshot(); | ||
}); | ||
{{=it.allytest}} | ||
if (values) { | ||
describe(dataId, runTests); | ||
} else { | ||
runTests(); | ||
} | ||
{{?}} | ||
}); | ||
}); |
26 changes: 19 additions & 7 deletions
26
plugins/cc-cli/templates/document/loop/imports-react-testing-library.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,29 @@ | ||
let renderedExamples {{=it.type}}; | ||
act(() => { | ||
renderedExamples = renderDocument(examples, config); | ||
renderedExamples = renderDocument(examples, config{{? it.data }}, data{{?}}); | ||
}); | ||
if (!renderedExamples) { | ||
renderErr(); | ||
return; | ||
} | ||
renderedExamples.forEach(({ name, rendered}) => { | ||
renderedExamples.forEach(({ name, rendered{{? it.data }}, dataId, values{{?}}}) => { | ||
describe(name, () => { | ||
it('snapshot', () => { | ||
const { asFragment } = render(rendered); | ||
expect(asFragment()).toMatchSnapshot(); | ||
}); | ||
{{=it.allytest}} | ||
{{? it.data }} | ||
const runTests = () => { | ||
{{?}} | ||
|
||
it('snapshot', () => { | ||
const { asFragment } = render(rendered); | ||
expect(asFragment()).toMatchSnapshot(); | ||
}); | ||
{{=it.allytest}} | ||
{{? it.data }} | ||
} | ||
if (values) { | ||
describe(dataId, runTests); | ||
} else { | ||
runTests(); | ||
} | ||
{{?}} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import * as path from 'path'; | ||
import { run, AxeResults } from 'axe-core'; | ||
import { reactRunDOM } from '@component-controls/test-renderers'; | ||
import '@component-controls/jest-axe-matcher'; | ||
import { loadConfigurations } from '@component-controls/config'; | ||
import { renderDocument } from '@component-controls/test-renderers'; | ||
import { mount, configure } from 'enzyme'; | ||
import toJson from 'enzyme-to-json'; | ||
import Adapter from '@wojtekmaj/enzyme-adapter-react-17'; | ||
|
||
configure({ adapter: new Adapter() }); | ||
|
||
import * as examples from './fixtures/VariantButton.docs'; | ||
import data from '../../../core/jest-extract/test/fixtures/story/VariantButton.data'; | ||
|
||
describe('VariantButton', () => { | ||
const configPath = path.resolve(__dirname, '.config'); | ||
const config = loadConfigurations(configPath); | ||
const renderedExamples = renderDocument(examples, config, data); | ||
renderedExamples.forEach(({ name, rendered, dataId, values }) => { | ||
describe(name, () => { | ||
const runTests = () => { | ||
it('snapshot', () => { | ||
const component = mount(rendered); | ||
expect(toJson(component, { mode: 'deep' })).toMatchSnapshot(); | ||
}); | ||
it('accessibility', async () => { | ||
const axeResults = await reactRunDOM<AxeResults>(rendered, run); | ||
expect(axeResults).toHaveNoAxeViolations(); | ||
}); | ||
}; | ||
if (values) { | ||
describe(dataId, runTests); | ||
} else { | ||
runTests(); | ||
} | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.