From 36dcdd47e769cc17c39c8bdea9555d5f36844fed Mon Sep 17 00:00:00 2001 From: Steven Kitterman Date: Fri, 17 Nov 2023 12:52:32 -0800 Subject: [PATCH 1/2] Blows away the chromatic-archives directory at the start of the test run to avoid old archives from polluting new tests --- src/cypress-api/index.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/cypress-api/index.ts b/src/cypress-api/index.ts index ae650da8..ab94cdde 100644 --- a/src/cypress-api/index.ts +++ b/src/cypress-api/index.ts @@ -1,3 +1,4 @@ +import fs from 'fs'; import type { elementNode } from 'rrweb-snapshot'; import { writeTestResult } from '../write-archive'; import type { ChromaticStorybookParameters } from '../types'; @@ -55,3 +56,15 @@ export const archiveCypress = async (params: ArchiveParams): Promise => { return null; }; + +/** + * To be run in the before:run Cypress command + * before:run only runs if Cypress is in non-interactive mode, e.g. "npx cypress run" (https://docs.cypress.io/api/plugins/before-run-api#Syntax) + */ +export const ensureCleanDirectory = () => { + const archivesPath = './chromatic-archives'; + // remove archives directory so we have a fresh start with each run + if (fs.existsSync(archivesPath)) { + fs.rmSync(archivesPath, { recursive: true }); + } +}; From fe259ab7272d8ab14ebf7938bee690b53c359dd8 Mon Sep 17 00:00:00 2001 From: Steven Kitterman Date: Fri, 17 Nov 2023 14:58:53 -0800 Subject: [PATCH 2/2] Put archives in the Cypress-written downloads directory --- src/cypress-api/index.ts | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/src/cypress-api/index.ts b/src/cypress-api/index.ts index ab94cdde..d0dbcebf 100644 --- a/src/cypress-api/index.ts +++ b/src/cypress-api/index.ts @@ -1,4 +1,3 @@ -import fs from 'fs'; import type { elementNode } from 'rrweb-snapshot'; import { writeTestResult } from '../write-archive'; import type { ChromaticStorybookParameters } from '../types'; @@ -39,9 +38,9 @@ const doArchive = async ({ await writeTestResult( { title: testTitle, - // doesn't matter what value we put here, as long as it's a subdirectory of where we want this to actually go + // this will store it at ./cypress/downloads (the last directory doesn't matter) // TODO: change so we don't have to do this trickery - outputDir: './some', + outputDir: './cypress/downloads/some', pageUrl, }, allSnapshots, @@ -56,15 +55,3 @@ export const archiveCypress = async (params: ArchiveParams): Promise => { return null; }; - -/** - * To be run in the before:run Cypress command - * before:run only runs if Cypress is in non-interactive mode, e.g. "npx cypress run" (https://docs.cypress.io/api/plugins/before-run-api#Syntax) - */ -export const ensureCleanDirectory = () => { - const archivesPath = './chromatic-archives'; - // remove archives directory so we have a fresh start with each run - if (fs.existsSync(archivesPath)) { - fs.rmSync(archivesPath, { recursive: true }); - } -};