Skip to content

Commit

Permalink
POC snapshots using jest's test.concurrent
Browse files Browse the repository at this point in the history
  • Loading branch information
jdelStrother committed Jan 30, 2021
1 parent 24898c8 commit 72f58da
Show file tree
Hide file tree
Showing 64 changed files with 2,665 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface StoryshotsTestMethod {

export interface StoryshotsOptions {
asyncJest?: boolean;
concurrentJest?: boolean;
config?: (options: any) => void;
integrityOptions?: IOptions | false;
configPath?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function ensureOptionsDefaults(options: StoryshotsOptions) {
const {
suite = 'Storyshots',
asyncJest,
concurrentJest,
storyNameRegex,
storyKindRegex,
renderer,
Expand All @@ -43,6 +44,7 @@ function ensureOptionsDefaults(options: StoryshotsOptions) {

return {
asyncJest,
concurrentJest,
suite,
storyNameRegex,
storyKindRegex,
Expand Down
2 changes: 2 additions & 0 deletions addons/storyshots/storyshots-core/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function testStorySnapshots(options: StoryshotsOptions = {}) {
const { storybook, framework, renderTree, renderShallowTree } = loadFramework(options);
const {
asyncJest,
concurrentJest,
suite,
storyNameRegex,
storyKindRegex,
Expand Down Expand Up @@ -86,6 +87,7 @@ function testStorySnapshots(options: StoryshotsOptions = {}) {
snapshotsTests({
data,
asyncJest,
concurrentJest,
suite,
framework,
testMethod,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
import { describe, it } from 'global';
import { addSerializer } from 'jest-specific-snapshot';

function snapshotTest({ item, asyncJest, framework, testMethod, testMethodParams }: any) {
function snapshotTest({
item,
asyncJest,
concurrentJest,
framework,
testMethod,
testMethodParams,
}: any) {
const { name } = item;
const context = { ...item, framework };

Expand All @@ -21,6 +28,21 @@ function snapshotTest({ item, asyncJest, framework, testMethod, testMethodParams
),
testMethod.timeout
);
} else if (concurrentJest === true) {
console.log('concurrent', name);
it.concurrent(
name,
() =>
new Promise((resolve, reject) => {
testMethod({
story: item,
context,
...testMethodParams,
});
resolve();
}),
testMethod.timeout
);
} else {
it(
name,
Expand Down
29 changes: 29 additions & 0 deletions examples/cra-kitchen-sink/src/__snapshots__/App.stories.storyshot
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[` 1`] = `
<div
className="App"
>
<div
className="App-header"
>
<img
alt="logo"
className="App-logo"
src="file-stub"
/>
<h2>
Welcome to React
</h2>
</div>
<p
className="App-intro"
>
To get started, edit
<code>
src/App.js
</code>
and save to reload.
</p>
</div>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[` 1`] = `
<div>
Lifecycle methods are logged to the console
</div>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[` 1`] = `
<button
onClick={[Function]}
style={
Object {
"backgroundColor": "#FFFFFF",
"border": "1px solid #eee",
"borderRadius": 3,
"cursor": "pointer",
"fontSize": 15,
"margin": 10,
"padding": "3px 10px",
}
}
type="button"
>
Hello Button
</button>
`;

exports[` 2`] = `
<button
onClick={[Function]}
style={
Object {
"backgroundColor": "#FFFFFF",
"border": "1px solid #eee",
"borderRadius": 3,
"cursor": "pointer",
"fontSize": 15,
"margin": 10,
"padding": "3px 10px",
}
}
type="button"
>
<span
aria-label="yolo"
role="img"
>
😀 😎 👍 💯
</span>
</button>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[` 1`] = `
<button
onClick={[Function]}
style={
Object {
"backgroundColor": "#FFFFFF",
"border": "1px solid #eee",
"borderRadius": 3,
"cursor": "pointer",
"fontSize": 15,
"margin": 10,
"padding": "3px 10px",
}
}
type="button"
>
Hello Button
</button>
`;

exports[` 2`] = `
<button
onClick={[Function]}
style={
Object {
"backgroundColor": "#FFFFFF",
"border": "1px solid #eee",
"borderRadius": 3,
"cursor": "pointer",
"fontSize": 15,
"margin": 10,
"padding": "3px 10px",
}
}
type="button"
>
<span
aria-label="yolo"
role="img"
>
😀 😎 👍 💯
</span>
</button>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[` 1`] = `
<button
onClick={[Function]}
style={
Object {
"backgroundColor": "#FFFFFF",
"border": "1px solid #eee",
"borderRadius": 3,
"cursor": "pointer",
"fontSize": 15,
"margin": 10,
"padding": "3px 10px",
}
}
type="button"
>
Hello Button
</button>
`;

exports[` 2`] = `
<button
onClick={[Function]}
style={
Object {
"backgroundColor": "#FFFFFF",
"border": "1px solid #eee",
"borderRadius": 3,
"cursor": "pointer",
"fontSize": 15,
"margin": 10,
"padding": "3px 10px",
}
}
type="button"
>
<span
aria-label="yolo"
role="img"
>
😀 😎 👍 💯
</span>
</button>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[` 1`] = `
<button
onClick={[Function]}
style={
Object {
"backgroundColor": "#FFFFFF",
"border": "1px solid #eee",
"borderRadius": 3,
"cursor": "pointer",
"fontSize": 15,
"margin": 10,
"padding": "3px 10px",
}
}
type="button"
>
Hello Button
</button>
`;

exports[` 2`] = `
<button
onClick={[Function]}
style={
Object {
"backgroundColor": "#FFFFFF",
"border": "1px solid #eee",
"borderRadius": 3,
"cursor": "pointer",
"fontSize": 15,
"margin": 10,
"padding": "3px 10px",
}
}
type="button"
>
<span
aria-label="yolo"
role="img"
>
😀 😎 👍 💯
</span>
</button>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Storyshots App full app 1`] = `
<button
onClick={[Function]}
style={
Object {
"backgroundColor": "#FFFFFF",
"border": "1px solid #eee",
"borderRadius": 3,
"cursor": "pointer",
"fontSize": 15,
"margin": 10,
"padding": "3px 10px",
}
}
type="button"
>
Hello Button
</button>
`;

exports[`Storyshots App full app 2`] = `
<button
onClick={[Function]}
style={
Object {
"backgroundColor": "#FFFFFF",
"border": "1px solid #eee",
"borderRadius": 3,
"cursor": "pointer",
"fontSize": 15,
"margin": 10,
"padding": "3px 10px",
}
}
type="button"
>
<span
aria-label="yolo"
role="img"
>
😀 😎 👍 💯
</span>
</button>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Storyshots App full app 1`] = `
<button
onClick={[Function]}
style={
Object {
"backgroundColor": "#FFFFFF",
"border": "1px solid #eee",
"borderRadius": 3,
"cursor": "pointer",
"fontSize": 15,
"margin": 10,
"padding": "3px 10px",
}
}
type="button"
>
Hello Button
</button>
`;

exports[`Storyshots App full app 2`] = `
<button
onClick={[Function]}
style={
Object {
"backgroundColor": "#FFFFFF",
"border": "1px solid #eee",
"borderRadius": 3,
"cursor": "pointer",
"fontSize": 15,
"margin": 10,
"padding": "3px 10px",
}
}
type="button"
>
<span
aria-label="yolo"
role="img"
>
😀 😎 👍 💯
</span>
</button>
`;
Loading

0 comments on commit 72f58da

Please sign in to comment.