From 93898342a824198788ea3ad8a4159ad49a90739f Mon Sep 17 00:00:00 2001 From: Tom Coleman Date: Wed, 6 Sep 2023 23:16:20 +1000 Subject: [PATCH] Change `onTaskX` options to be experimental --- node-src/lib/tasks.ts | 4 ++-- node-src/tasks/snapshot.test.ts | 10 +++++----- node-src/tasks/snapshot.ts | 2 +- node-src/tasks/upload.test.ts | 14 +++++++------- node-src/tasks/upload.ts | 2 +- node-src/types.ts | 6 +++--- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/node-src/lib/tasks.ts b/node-src/lib/tasks.ts index 5c90b3b35..62164a19e 100644 --- a/node-src/lib/tasks.ts +++ b/node-src/lib/tasks.ts @@ -22,7 +22,7 @@ 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) { @@ -30,7 +30,7 @@ export const createTask = ({ await step(ctx, task); } - ctx.options.onTaskComplete?.({ ...ctx }); + ctx.options.experimental_onTaskComplete?.({ ...ctx }); }, ...config, }); diff --git a/node-src/tasks/snapshot.test.ts b/node-src/tasks/snapshot.test.ts index d7cfb263a..fe3eb8d5c 100644 --- a/node-src/tasks/snapshot.test.ts +++ b/node-src/tasks/snapshot.test.ts @@ -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' } }, @@ -122,7 +122,7 @@ describe('takeSnapshots', () => { env, git: { matchesBranch }, log, - options: { onTaskProgress: jest.fn() }, + options: { experimental_onTaskProgress: jest.fn() }, build, } as any; @@ -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', diff --git a/node-src/tasks/snapshot.ts b/node-src/tasks/snapshot.ts index 01c5e2977..5d98cb72a 100644 --- a/node-src/tasks/snapshot.ts +++ b/node-src/tasks/snapshot.ts @@ -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' } ); diff --git a/node-src/tasks/upload.test.ts b/node-src/tasks/upload.test.ts index ec2407416..945a8957b 100644 --- a/node-src/tasks/upload.test.ts +++ b/node-src/tasks/upload.test.ts @@ -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: { @@ -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', diff --git a/node-src/tasks/upload.ts b/node-src/tasks/upload.ts index 99436b89b..979c3c567 100644 --- a/node-src/tasks/upload.ts +++ b/node-src/tasks/upload.ts @@ -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 diff --git a/node-src/types.ts b/node-src/types.ts index 9f3156442..9eddd48bf 100644 --- a/node-src/types.ts +++ b/node-src/types.ts @@ -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 =