Skip to content

Commit 1af3c0c

Browse files
committed
Add stories for snapshot task
1 parent 23e8409 commit 1af3c0c

File tree

5 files changed

+138
-32
lines changed

5 files changed

+138
-32
lines changed

node-src/tasks/snapshot.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -153,18 +153,18 @@ export const takeSnapshots = async (ctx: Context, task: Task) => {
153153
/**
154154
* Sets up the Listr task for snapshotting the Storybook.
155155
*
156-
* @param _ The context set when executing the CLI.
156+
* @param ctx The context set when executing the CLI.
157157
*
158158
* @returns A Listr task.
159159
*/
160-
export default function main(_: Context) {
160+
export default function main(ctx: Context) {
161161
return createTask({
162162
name: 'snapshot',
163-
title: initial.title,
163+
title: initial(ctx).title,
164164
skip: (ctx: Context) => {
165165
if (ctx.skip) return true;
166166
if (ctx.skipSnapshots) return skipped(ctx).output;
167-
if (ctx.options.dryRun) return dryRun().output;
167+
if (ctx.options.dryRun) return dryRun(ctx).output;
168168
return false;
169169
},
170170
steps: [transitionTo(pending), takeSnapshots],

node-src/ui/tasks/snapshot.stories.ts

+21-15
Original file line numberDiff line numberDiff line change
@@ -28,51 +28,57 @@ const build = {
2828
specCount: 8,
2929
features: { uiTests: true },
3030
};
31-
const options = {};
31+
const ctx = { options: {} } as any;
3232

3333
const now = 0;
3434
const startedAt = -123_456;
3535

36-
export const Initial = () => initial;
36+
export const Initial = () => initial(ctx);
3737

38-
export const DryRun = () => dryRun();
38+
export const DryRun = () => dryRun(ctx);
3939

4040
export const Pending = () =>
41-
pending({ build, options } as any, {
41+
pending({ ...ctx, build } as any, {
4242
cursor: 6,
4343
label: 'ComponentName › StoryName',
4444
});
4545

4646
export const PendingOnlyChanged = () =>
47-
pending({ build: { ...build, actualTestCount: 8 }, options, onlyStoryFiles: [] } as any, {
47+
pending({ ...ctx, build: { ...build, actualTestCount: 8 }, onlyStoryFiles: [] } as any, {
4848
cursor: 6,
4949
});
5050

5151
export const PendingOnlyStoryNames = () =>
5252
pending(
53-
{ build: { ...build, actualTestCount: 8 }, options: { onlyStoryNames: ['Pages/**'] } } as any,
53+
{
54+
...ctx,
55+
build: { ...build, actualTestCount: 8 },
56+
options: { ...ctx.options, onlyStoryNames: ['Pages/**'] },
57+
} as any,
5458
{ cursor: 6 }
5559
);
5660

57-
export const BuildPassed = () => buildPassed({ build, now, startedAt } as any);
61+
export const BuildPassed = () => buildPassed({ ...ctx, build, now, startedAt } as any);
5862

59-
export const BuildComplete = () => buildComplete({ build, now, startedAt, exitCode: 1 } as any);
63+
export const BuildComplete = () =>
64+
buildComplete({ ...ctx, build, now, startedAt, exitCode: 1 } as any);
6065

6166
export const BuildAutoAccepted = () =>
62-
buildComplete({ build: { ...build, autoAcceptChanges: true }, now, startedAt } as any);
67+
buildComplete({ ...ctx, build: { ...build, autoAcceptChanges: true }, now, startedAt } as any);
6368

6469
export const BuildBroken = () =>
65-
buildBroken({ build, now, startedAt, exitCode: exitCodes.BUILD_HAS_ERRORS } as any);
70+
buildBroken({ ...ctx, build, now, startedAt, exitCode: exitCodes.BUILD_HAS_ERRORS } as any);
6671

6772
export const BuildFailed = () =>
68-
buildFailed({ build, now, startedAt, exitCode: exitCodes.BUILD_FAILED } as any);
73+
buildFailed({ ...ctx, build, now, startedAt, exitCode: exitCodes.BUILD_FAILED } as any);
6974

7075
export const BuildCanceled = () =>
71-
buildCanceled({ build, now, startedAt, exitCode: exitCodes.BUILD_WAS_CANCELED } as any);
76+
buildCanceled({ ...ctx, build, now, startedAt, exitCode: exitCodes.BUILD_WAS_CANCELED } as any);
7277

73-
export const SkippedPublishOnly = () => skipped({ isPublishOnly: true } as any);
78+
export const SkippedPublishOnly = () => skipped({ ...ctx, isPublishOnly: true } as any);
7479

75-
export const SkippedList = () => skipped({ options: { list: true } } as any);
80+
export const SkippedList = () =>
81+
skipped({ ...ctx, options: { ...ctx.options, list: true } } as any);
7682

7783
export const SkippedExitOnceUploaded = () =>
78-
skipped({ options: { exitOnceUploaded: true } } as any);
84+
skipped({ ...ctx, options: { ...ctx.optionns, exitOnceUploaded: true } } as any);

node-src/ui/tasks/snapshot.ts

+28-12
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
import pluralize from 'pluralize';
22

3+
import { isE2EBuild } from '../../lib/e2eUtils';
34
import { getDuration } from '../../lib/tasks';
45
import { progressBar } from '../../lib/utils';
56
import { Context } from '../../types';
67

7-
export const initial = {
8+
const testType = (ctx: Context) => (isE2EBuild(ctx.options) ? 'test suite' : 'stories');
9+
10+
export const initial = (ctx: Context) => ({
811
status: 'initial',
9-
title: 'Test your stories',
10-
};
12+
title: `Test your ${testType(ctx)}`,
13+
});
1114

12-
export const dryRun = () => ({
15+
export const dryRun = (ctx: Context) => ({
1316
status: 'skipped',
14-
title: 'Test your stories',
17+
title: `Test your ${testType(ctx)}`,
1518
output: 'Skipped due to --dry-run',
1619
});
1720

@@ -33,6 +36,7 @@ export const stats = ({
3336
errors: pluralize('component error', build.errorCount, true),
3437
changes: pluralize('change', build.changeCount, true),
3538
stories: pluralize('story', build.specCount, true),
39+
e2eTests: pluralize('test', build.specCount, true),
3640
components: pluralize('component', build.componentCount, true),
3741
skips: pluralize('test', build.testCount - build.actualTestCount, true),
3842
snapshots: pluralize('snapshot', build.actualCaptureCount, true),
@@ -70,31 +74,43 @@ export const pending = (ctx: Context, { cursor = 0, label = '' } = {}) => {
7074
};
7175

7276
export const buildPassed = (ctx: Context) => {
73-
const { snapshots, components, stories } = stats(ctx);
77+
const { snapshots, components, stories, e2eTests } = stats(ctx);
78+
const output = isE2EBuild(ctx.options)
79+
? `Tested ${e2eTests}; captured ${snapshots} in ${getDuration(ctx)}`
80+
: `Tested ${stories} across ${components}; captured ${snapshots} in ${getDuration(ctx)}`;
81+
7482
return {
7583
status: 'success',
7684
title: `Build ${ctx.build.number} passed!`,
77-
output: `Tested ${stories} across ${components}; captured ${snapshots} in ${getDuration(ctx)}`,
85+
output,
7886
};
7987
};
8088

8189
export const buildComplete = (ctx: Context) => {
82-
const { snapshots, components, stories } = stats(ctx);
90+
const { snapshots, components, stories, e2eTests } = stats(ctx);
91+
const output = isE2EBuild(ctx.options)
92+
? `Tested ${e2eTests}; captured ${snapshots} in ${getDuration(ctx)}`
93+
: `Tested ${stories} across ${components}; captured ${snapshots} in ${getDuration(ctx)}`;
94+
8395
return {
8496
status: 'success',
8597
title: ctx.build.autoAcceptChanges
8698
? `Build ${ctx.build.number} auto-accepted`
8799
: `Build ${ctx.build.number} completed`,
88-
output: `Tested ${stories} across ${components}; captured ${snapshots} in ${getDuration(ctx)}`,
100+
output,
89101
};
90102
};
91103

92104
export const buildBroken = (ctx: Context) => {
93-
const { snapshots, components, stories, errors } = stats(ctx);
105+
const { snapshots, components, stories, e2eTests, errors } = stats(ctx);
106+
const output = isE2EBuild(ctx.options)
107+
? `Tested ${e2eTests}; captured ${snapshots} and found ${errors}`
108+
: `Tested ${stories} across ${components}; captured ${snapshots} and found ${errors}`;
109+
94110
return {
95111
status: 'error',
96112
title: `Build ${ctx.build.number} failed after ${getDuration(ctx)}`,
97-
output: `Tested ${stories} across ${components}; captured ${snapshots} and found ${errors}`,
113+
output,
98114
};
99115
};
100116

@@ -117,7 +133,7 @@ export const buildCanceled = (ctx: Context) => {
117133
export const skipped = (ctx: Context) => {
118134
return {
119135
status: 'skipped',
120-
title: 'Test your stories',
136+
title: `Test your ${testType(ctx)}`,
121137
output: ctx.isPublishOnly
122138
? `No UI tests or UI review enabled`
123139
: `Skipped due to ${ctx.options.list ? '--list' : '--exit-once-uploaded'}`,
+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import { exitCodes } from '../../lib/setExitCode';
2+
import task from '../components/task';
3+
import {
4+
buildBroken,
5+
buildCanceled,
6+
buildComplete,
7+
buildFailed,
8+
buildPassed,
9+
dryRun,
10+
initial,
11+
pending,
12+
skipped,
13+
} from './snapshot';
14+
15+
export default {
16+
title: 'CLI/Tasks/Snapshot/E2E',
17+
decorators: [(storyFunction) => task(storyFunction())],
18+
};
19+
20+
const build = {
21+
number: 42,
22+
errorCount: 1,
23+
changeCount: 2,
24+
testCount: 10,
25+
actualTestCount: 10,
26+
actualCaptureCount: 20,
27+
componentCount: 5,
28+
specCount: 8,
29+
features: { uiTests: true },
30+
};
31+
const ctx = { options: { playwright: true } } as any;
32+
33+
const now = 0;
34+
const startedAt = -123_456;
35+
36+
export const Initial = () => initial(ctx);
37+
38+
export const DryRun = () => dryRun(ctx);
39+
40+
export const Pending = () =>
41+
pending({ ...ctx, build } as any, {
42+
cursor: 6,
43+
label: 'ComponentName › StoryName',
44+
});
45+
46+
export const PendingOnlyChanged = () =>
47+
pending({ ...ctx, build: { ...build, actualTestCount: 8 }, onlyStoryFiles: [] } as any, {
48+
cursor: 6,
49+
});
50+
51+
export const PendingOnlyStoryNames = () =>
52+
pending(
53+
{
54+
...ctx,
55+
build: { ...build, actualTestCount: 8 },
56+
options: { ...ctx.options, onlyStoryNames: ['Pages/**'] },
57+
} as any,
58+
{ cursor: 6 }
59+
);
60+
61+
export const BuildPassed = () => buildPassed({ ...ctx, build, now, startedAt } as any);
62+
63+
export const BuildComplete = () =>
64+
buildComplete({ ...ctx, build, now, startedAt, exitCode: 1 } as any);
65+
66+
export const BuildAutoAccepted = () =>
67+
buildComplete({ ...ctx, build: { ...build, autoAcceptChanges: true }, now, startedAt } as any);
68+
69+
export const BuildBroken = () =>
70+
buildBroken({ ...ctx, build, now, startedAt, exitCode: exitCodes.BUILD_HAS_ERRORS } as any);
71+
72+
export const BuildFailed = () =>
73+
buildFailed({ ...ctx, build, now, startedAt, exitCode: exitCodes.BUILD_FAILED } as any);
74+
75+
export const BuildCanceled = () =>
76+
buildCanceled({ ...ctx, build, now, startedAt, exitCode: exitCodes.BUILD_WAS_CANCELED } as any);
77+
78+
export const SkippedPublishOnly = () => skipped({ ...ctx, isPublishOnly: true } as any);
79+
80+
export const SkippedList = () =>
81+
skipped({ ...ctx, options: { ...ctx.options, list: true } } as any);
82+
83+
export const SkippedExitOnceUploaded = () =>
84+
skipped({ ...ctx, options: { ...ctx.options, exitOnceUploaded: true } } as any);

node-src/ui/workflows/uploadBuildE2E.stories.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as auth from '../tasks/auth.stories';
77
import * as build from '../tasks/buildE2E.stories';
88
import * as gitInfo from '../tasks/gitInfo.stories';
99
import * as initialize from '../tasks/initialize.stories';
10-
import * as snapshot from '../tasks/snapshot.stories';
10+
import * as snapshot from '../tasks/snapshotE2E.stories';
1111
import * as storybookInfo from '../tasks/storybookInfoE2E.stories';
1212
import * as upload from '../tasks/uploadE2E.stories';
1313
import * as verify from '../tasks/verifyE2E.stories';

0 commit comments

Comments
 (0)