From 64ad25bde376d273c668716726300a5716b98135 Mon Sep 17 00:00:00 2001 From: Cody Kaup Date: Mon, 9 Dec 2024 11:36:41 -0600 Subject: [PATCH] WIP5 --- node-src/tasks/verify.test.ts | 85 ++++++++++++++++++++++++++++++++++- node-src/tasks/verify.ts | 6 +-- 2 files changed, 87 insertions(+), 4 deletions(-) diff --git a/node-src/tasks/verify.test.ts b/node-src/tasks/verify.test.ts index 120967c96..3cac9805e 100644 --- a/node-src/tasks/verify.test.ts +++ b/node-src/tasks/verify.test.ts @@ -1,4 +1,4 @@ -import { describe, expect, it, vi } from 'vitest'; +import { describe, expect, it, test, vi } from 'vitest'; import { exitCodes } from '../lib/setExitCode'; import { publishBuild, verifyBuild } from './verify'; @@ -229,6 +229,89 @@ describe('verifyBuild', () => { expect(ctx.exitCode).toBe(12); }); + describe('sets exitCode to 0 and skips snapshotting', () => { + const publishOnlyClient = { runQuery: vi.fn() }; + publishOnlyClient.runQuery.mockReturnValue({ + app: { + build: { + number: 1, + status: 'IN_PROGRESS', + storybookUrl: 'https://5d67dc0374b2e300209c41e7-pfkaemtlit.chromatic.com/', + features: { uiTests: false, uiReview: false }, + app: { account: { paymentRequired: true } }, + wasLimited: true, + startedAt: Date.now(), + }, + }, + }); + + const client = { runQuery: vi.fn() }; + client.runQuery.mockReturnValue({ + app: { + build: { + number: 1, + status: 'IN_PROGRESS', + storybookUrl: 'https://5d67dc0374b2e300209c41e7-pfkaemtlit.chromatic.com/', + features: { uiTests: true, uiReview: false }, + app: { account: { paymentRequired: false } }, + startedAt: Date.now(), + }, + }, + }); + + test('publish-only builds', async () => { + const ctx = { client: publishOnlyClient, ...defaultContext } as any; + await verifyBuild(ctx, {} as any); + expect(ctx.exitCode).toBe(0); + expect(ctx.skipSnapshots).toBe(true); + }); + + test('exitOnceUploaded from flags', async () => { + const ctx = { + client, + ...defaultContext, + flags: { exitOnceUploaded: true }, + git: { + matchesBranch: (glob: string | boolean) => + typeof glob === 'string' ? glob === 'true' : !!glob, + }, + } as any; + await verifyBuild(ctx, {} as any); + expect(ctx.exitCode).toBe(0); + expect(ctx.skipSnapshots).toBe(true); + }); + + test('exitOnceUploaded from configuration', async () => { + const ctx = { + client, + ...defaultContext, + configuration: { exitOnceUploaded: true }, + git: { + matchesBranch: (glob: string | boolean) => + typeof glob === 'string' ? glob === 'true' : !!glob, + }, + } as any; + await verifyBuild(ctx, {} as any); + expect(ctx.exitCode).toBe(0); + expect(ctx.skipSnapshots).toBe(true); + }); + + test('exitOnceUploaded from options', async () => { + const ctx = { + client, + ...defaultContext, + options: { exitOnceUploaded: true }, + git: { + matchesBranch: (glob: string | boolean) => + typeof glob === 'string' ? glob === 'true' : !!glob, + }, + } as any; + await verifyBuild(ctx, {} as any); + expect(ctx.exitCode).toBe(0); + expect(ctx.skipSnapshots).toBe(true); + }); + }); + it('sets exitCode to 0 and skips snapshotting for publish-only builds', async () => { const client = { runQuery: vi.fn() }; client.runQuery.mockReturnValue({ diff --git a/node-src/tasks/verify.ts b/node-src/tasks/verify.ts index 0d74511a1..2ec89cd4b 100644 --- a/node-src/tasks/verify.ts +++ b/node-src/tasks/verify.ts @@ -274,9 +274,9 @@ export const verifyBuild = async (ctx: Context, task: Task) => { list || ctx.isPublishOnly || matchesBranch?.( - ctx.options.exitOnceUploaded || - ctx.configuration.exitOnceUploaded || - ctx.options.exitOnceUploaded + ctx.flags?.exitOnceUploaded || + ctx.configuration?.exitOnceUploaded || + ctx.options?.exitOnceUploaded ) ) { ctx.log.info('Exit once uploaded triggered, skipping!!!');