Skip to content

Commit

Permalink
Change onTaskX options to be experimental
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeasday committed Sep 6, 2023
1 parent d19e6aa commit 9389834
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions node-src/lib/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ export const createTask = ({
ctx.title = title;
ctx.startedAt = Number.isInteger(ctx.now) ? ctx.now : new Date().getTime();

ctx.options.onTaskStart?.({ ...ctx });
ctx.options.experimental_onTaskStart?.({ ...ctx });

// eslint-disable-next-line no-restricted-syntax
for (const step of steps) {
// eslint-disable-next-line no-await-in-loop
await step(ctx, task);
}

ctx.options.onTaskComplete?.({ ...ctx });
ctx.options.experimental_onTaskComplete?.({ ...ctx });
},
...config,
});
Expand Down
10 changes: 5 additions & 5 deletions node-src/tasks/snapshot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe('takeSnapshots', () => {
expect(ctx.exitCode).toBe(3);
});

it('calls onTaskProgress with progress', async () => {
it('calls experimental_onTaskProgress with progress', async () => {
const client = { runQuery: jest.fn(), setAuthorization: jest.fn() };
const build = {
app: { repository: { provider: 'github' } },
Expand All @@ -122,7 +122,7 @@ describe('takeSnapshots', () => {
env,
git: { matchesBranch },
log,
options: { onTaskProgress: jest.fn() },
options: { experimental_onTaskProgress: jest.fn() },
build,
} as any;

Expand All @@ -138,13 +138,13 @@ describe('takeSnapshots', () => {

await takeSnapshots(ctx, {} as any);

expect(ctx.options.onTaskProgress).toHaveBeenCalledTimes(2);
expect(ctx.options.onTaskProgress).toHaveBeenCalledWith(expect.any(Object), {
expect(ctx.options.experimental_onTaskProgress).toHaveBeenCalledTimes(2);
expect(ctx.options.experimental_onTaskProgress).toHaveBeenCalledWith(expect.any(Object), {
progress: 1,
total: 5,
unit: 'snapshots',
});
expect(ctx.options.onTaskProgress).toHaveBeenCalledWith(expect.any(Object), {
expect(ctx.options.experimental_onTaskProgress).toHaveBeenCalledWith(expect.any(Object), {
progress: 3,
total: 5,
unit: 'snapshots',
Expand Down
2 changes: 1 addition & 1 deletion node-src/tasks/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const takeSnapshots = async (ctx: Context, task: Task) => {
const updateProgress = throttle(
({ cursor, label }) => {
task.output = pending(ctx, { cursor, label }).output;
ctx.options.onTaskProgress?.(
ctx.options.experimental_onTaskProgress?.(
{ ...ctx },
{ progress: cursor, total: actualTestCount, unit: 'snapshots' }
);
Expand Down
14 changes: 7 additions & 7 deletions node-src/tasks/upload.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ describe('uploadStorybook', () => {
expect(ctx.isolatorUrl).toBe('https://asdqwe.chromatic.com/iframe.html');
});

it('calls onTaskProgress with progress', async () => {
it('calls experimental_onTaskProgress with progress', async () => {
const client = { runQuery: jest.fn() };
client.runQuery.mockReturnValue({
getUploadUrls: {
Expand Down Expand Up @@ -294,29 +294,29 @@ describe('uploadStorybook', () => {
log,
http,
sourceDir: '/static/',
options: { onTaskProgress: jest.fn() },
options: { experimental_onTaskProgress: jest.fn() },
fileInfo,
announcedBuild: { id: '1' },
} as any;
await uploadStorybook(ctx, {} as any);

expect(ctx.options.onTaskProgress).toHaveBeenCalledTimes(4);
expect(ctx.options.onTaskProgress).toHaveBeenCalledWith(expect.any(Object), {
expect(ctx.options.experimental_onTaskProgress).toHaveBeenCalledTimes(4);
expect(ctx.options.experimental_onTaskProgress).toHaveBeenCalledWith(expect.any(Object), {
progress: 21,
total: 84,
unit: 'bytes',
});
expect(ctx.options.onTaskProgress).toHaveBeenCalledWith(expect.any(Object), {
expect(ctx.options.experimental_onTaskProgress).toHaveBeenCalledWith(expect.any(Object), {
progress: 42,
total: 84,
unit: 'bytes',
});
expect(ctx.options.onTaskProgress).toHaveBeenCalledWith(expect.any(Object), {
expect(ctx.options.experimental_onTaskProgress).toHaveBeenCalledWith(expect.any(Object), {
progress: 63,
total: 84,
unit: 'bytes',
});
expect(ctx.options.onTaskProgress).toHaveBeenCalledWith(expect.any(Object), {
expect(ctx.options.experimental_onTaskProgress).toHaveBeenCalledWith(expect.any(Object), {
progress: 84,
total: 84,
unit: 'bytes',
Expand Down
2 changes: 1 addition & 1 deletion node-src/tasks/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ export const uploadStorybook = async (ctx: Context, task: Task) => {
const percentage = Math.round((progress / total) * 100);
task.output = uploading({ percentage }).output;

ctx.options.onTaskProgress?.({ ...ctx }, { progress, total, unit: 'bytes' });
ctx.options.experimental_onTaskProgress?.({ ...ctx }, { progress, total, unit: 'bytes' });
},
// Avoid spamming the logs with progress updates in non-interactive mode
ctx.options.interactive ? 100 : ctx.env.CHROMATIC_OUTPUT_INTERVAL
Expand Down
6 changes: 3 additions & 3 deletions node-src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,16 @@ export interface Options {
patchBaseRef: string;

/** A callback that is called at the start of each task */
onTaskStart?: (ctx: Context) => void;
experimental_onTaskStart?: (ctx: Context) => void;

/** A callback that is called during tasks that have incremental progress */
onTaskProgress?: (
experimental_onTaskProgress?: (
ctx: Context,
status: { progress: number; total: number; unit: string }
) => void;

/** A callback that is called at the completion of each task */
onTaskComplete?: (ctx: Context) => void;
experimental_onTaskComplete?: (ctx: Context) => void;
}

export type TaskName =
Expand Down

0 comments on commit 9389834

Please sign in to comment.