From 4ab67ebf0babd1e6ca0e263b9d06521c5d8e0b19 Mon Sep 17 00:00:00 2001 From: Gert Hengeveld Date: Tue, 16 Jan 2024 11:24:28 +0100 Subject: [PATCH 1/2] Add missing skip option to configuration schema --- node-src/lib/getConfiguration.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/node-src/lib/getConfiguration.ts b/node-src/lib/getConfiguration.ts index 08de59115..eff09345c 100644 --- a/node-src/lib/getConfiguration.ts +++ b/node-src/lib/getConfiguration.ts @@ -26,6 +26,7 @@ const configurationSchema = z buildScriptName: z.string(), outputDir: z.string(), + skip: z.union([z.string(), z.boolean()]), storybookBuildDir: z.string(), storybookBaseDir: z.string(), From 09cdc3809f3ec397641d1f217f7535a22bb85605 Mon Sep 17 00:00:00 2001 From: Gert Hengeveld Date: Tue, 16 Jan 2024 11:41:41 +0100 Subject: [PATCH 2/2] Add tests for configuration options --- node-src/lib/getConfiguration.test.ts | 92 ++++++++++++++++++++++++++- 1 file changed, 90 insertions(+), 2 deletions(-) diff --git a/node-src/lib/getConfiguration.test.ts b/node-src/lib/getConfiguration.test.ts index 9ed6f8f14..ef6a577ae 100644 --- a/node-src/lib/getConfiguration.test.ts +++ b/node-src/lib/getConfiguration.test.ts @@ -11,9 +11,97 @@ beforeEach(() => { }); it('reads configuration successfully', async () => { - mockedReadFile.mockReturnValue(JSON.stringify({ projectToken: 'json-file-token' })); + mockedReadFile.mockReturnValue( + JSON.stringify({ + projectId: 'project-id', + projectToken: 'project-token', + + onlyChanged: 'only-changed', + onlyStoryFiles: ['only-story-files'], + onlyStoryNames: ['only-story-names'], + untraced: ['untraced'], + externals: ['externals'], + debug: true, + diagnosticFile: 'diagnostic-file', + fileHashing: true, + junitReport: 'junit-report', + zip: true, + autoAcceptChanges: 'auto-accept-changes', + exitZeroOnChanges: 'exit-zero-on-changes', + exitOnceUploaded: 'exit-once-uploaded', + ignoreLastBuildOnBranch: 'ignore-last-build-on-branch', + + buildScriptName: 'build-script-name', + outputDir: 'output-dir', + skip: 'skip', + + storybookBuildDir: 'storybook-build-dir', + storybookBaseDir: 'storybook-base-dir', + storybookConfigDir: 'storybook-config-dir', + storybookLogFile: 'storybook-log-file', + logFile: 'log-file', + uploadMetadata: true, + }) + ); + + expect(await getConfiguration()).toEqual({ + projectId: 'project-id', + projectToken: 'project-token', + + onlyChanged: 'only-changed', + onlyStoryFiles: ['only-story-files'], + onlyStoryNames: ['only-story-names'], + untraced: ['untraced'], + externals: ['externals'], + debug: true, + diagnosticFile: 'diagnostic-file', + fileHashing: true, + junitReport: 'junit-report', + zip: true, + autoAcceptChanges: 'auto-accept-changes', + exitZeroOnChanges: 'exit-zero-on-changes', + exitOnceUploaded: 'exit-once-uploaded', + ignoreLastBuildOnBranch: 'ignore-last-build-on-branch', + + buildScriptName: 'build-script-name', + outputDir: 'output-dir', + skip: 'skip', + + storybookBuildDir: 'storybook-build-dir', + storybookBaseDir: 'storybook-base-dir', + storybookConfigDir: 'storybook-config-dir', + storybookLogFile: 'storybook-log-file', + logFile: 'log-file', + uploadMetadata: true, + }); +}); - expect(await getConfiguration()).toEqual({ projectToken: 'json-file-token' }); +it('handles other side of union options', async () => { + mockedReadFile.mockReturnValue( + JSON.stringify({ + onlyChanged: true, + diagnosticFile: true, + junitReport: true, + autoAcceptChanges: true, + exitZeroOnChanges: true, + exitOnceUploaded: true, + skip: true, + storybookLogFile: true, + logFile: true, + }) + ); + + expect(await getConfiguration()).toEqual({ + onlyChanged: true, + diagnosticFile: true, + junitReport: true, + autoAcceptChanges: true, + exitZeroOnChanges: true, + exitOnceUploaded: true, + skip: true, + storybookLogFile: true, + logFile: true, + }); }); it('reads from chromatic.config.json by default', async () => {