From dde7c1a0e209950388be46d80c97b8f1204df515 Mon Sep 17 00:00:00 2001 From: Baptiste Morelle Date: Mon, 30 Oct 2023 17:15:11 +0100 Subject: [PATCH 01/14] test: unskip previously skipped tests (#1159) --- cypress/e2e/slices/00-create.cy.js | 19 +++++++------------ .../scenario_custom_screenshots.cy.js | 18 ++++++++++-------- cypress/pages/slices/sliceBuilder.js | 10 ---------- cypress/pages/slices/sliceCard.js | 13 +++++++++++-- cypress/pages/slices/slicesList.js | 2 +- .../slices/sliceCards/SharedSliceCard.tsx | 8 ++++++-- .../slice-machine/test/pages/slices.test.tsx | 4 ++-- 7 files changed, 37 insertions(+), 37 deletions(-) diff --git a/cypress/e2e/slices/00-create.cy.js b/cypress/e2e/slices/00-create.cy.js index db119e44ac..441c359a2f 100644 --- a/cypress/e2e/slices/00-create.cy.js +++ b/cypress/e2e/slices/00-create.cy.js @@ -16,29 +16,24 @@ describe("Create Slices", () => { cy.clearProject(); }); - it.skip("A user can create and rename a slice", () => { + it("A user can create and rename a slice", () => { cy.createSlice(lib, sliceId, sliceName); sliceBuilder.addNewWidgetField("Title", "Key Text"); sliceBuilder.addNewWidgetField("Description", "Rich Text"); - cy.contains("Save").click(); - - // remove widget - cy.get('[data-cy="slice-menu-button"]').first().click(); - cy.contains("Delete field").click(); - cy.get('[data-cy="builder-save-button"]').should("not.be.disabled"); - // add a variation - cy.contains("button", "Add a new variation").click(); - cy.getInputByLabel("Variation name*").type("foo"); cy.getInputByLabel("Variation ID*").clear(); cy.getInputByLabel("Variation ID*").type("bar"); - cy.get("#variation-add").submit(); + // remove widget + cy.get('[data-cy="slice-menu-button"]').first().click(); + cy.contains("Delete field").click(); + cy.get('[data-cy="builder-save-button"]').should("not.be.disabled"); + cy.contains("button", "Simulate").should("have.attr", "disabled"); cy.contains("button", "Simulate").realHover(); cy.get("#simulator-button-tooltip").should("be.visible"); @@ -144,7 +139,7 @@ describe("Create Slices", () => { }); // See: #791 - it.skip("A user cannot rename a slice with a name starting with a number", () => { + it("A user cannot rename a slice with a name starting with a number", () => { const sliceName = "SliceName"; cy.createSlice(lib, sliceId, sliceName); diff --git a/cypress/e2e/user-flows/scenario_custom_screenshots.cy.js b/cypress/e2e/user-flows/scenario_custom_screenshots.cy.js index a683cc6869..185d24d5c8 100644 --- a/cypress/e2e/user-flows/scenario_custom_screenshots.cy.js +++ b/cypress/e2e/user-flows/scenario_custom_screenshots.cy.js @@ -26,10 +26,11 @@ describe("I am an existing SM user and I want to upload screenshots on variation sliceBuilder.goTo(slice.library, slice.name); }); - it.skip("Upload and replace custom screenshots", () => { + it("Upload and replace custom screenshots", () => { // Upload custom screenshot on default variation - sliceBuilder.imagePreview.should("not.exist"); - sliceBuilder.openScreenshotModal(); + let sliceCard = new SliceCard(slice.name); + sliceCard.imagePreview.should("not.exist"); + sliceCard.openScreenshotModal(); screenshotModal .verifyImageIsEmpty() @@ -38,22 +39,23 @@ describe("I am an existing SM user and I want to upload screenshots on variation .dragAndDropImage(defaultScreenshot) .verifyImageIs(defaultScreenshot) .close(); - sliceBuilder.imagePreview.isSameImageAs(defaultScreenshot); + sliceCard.imagePreview.isSameImageAs(defaultScreenshot); // Upload screenshot on variation from the Changes Page const missingScreenshotVariation = "Missing screenshot"; sliceBuilder.addVariation(missingScreenshotVariation); - sliceBuilder.imagePreview.should("not.exist"); + sliceCard = new SliceCard(slice.name, missingScreenshotVariation); + sliceCard.imagePreview.should("not.exist"); sliceBuilder.save(); menu.navigateTo("Slices"); - const sliceCard = new SliceCard(slice.name); + sliceCard = new SliceCard(slice.name); sliceCard.imagePreview.isSameImageAs(defaultScreenshot); menu.navigateTo("Changes"); changesPage.screenshotsButton.should("be.visible"); - sliceCard.content.should("include.text", "1/2 screenshots missing"); + sliceCard.content.should("include.text", "Missing screenshot"); sliceCard.imagePreview.isSameImageAs(defaultScreenshot); sliceCard.openScreenshotModal(); @@ -64,7 +66,7 @@ describe("I am an existing SM user and I want to upload screenshots on variation .dragAndDropImage(variationScreenshot) .verifyImageIs(variationScreenshot) .close(); - sliceCard.content.should("not.include.text", "screenshots missing"); + sliceCard.content.should("not.include.text", "Missing screenshot"); sliceCard.imagePreview.isSameImageAs(defaultScreenshot); changesPage.pushChanges().isUpToDate(); diff --git a/cypress/pages/slices/sliceBuilder.js b/cypress/pages/slices/sliceBuilder.js index 9780748f9e..76e97551e1 100644 --- a/cypress/pages/slices/sliceBuilder.js +++ b/cypress/pages/slices/sliceBuilder.js @@ -1,16 +1,6 @@ import { BaseBuilder } from "../BaseBuilder"; class SliceBuilder extends BaseBuilder { - get imagePreview() { - return cy.get("[alt='Preview image']"); - } - - get imagePreviewSrc() { - this.imagePreview.then(($img) => { - return $img.attr("src"); - }); - } - get renameButton() { return cy.get('[data-cy="edit-slice-name"]'); } diff --git a/cypress/pages/slices/sliceCard.js b/cypress/pages/slices/sliceCard.js index 04723918de..3bcb0380cc 100644 --- a/cypress/pages/slices/sliceCard.js +++ b/cypress/pages/slices/sliceCard.js @@ -15,8 +15,17 @@ export class SliceCard { } openScreenshotModal() { - cy.get(this.root).find('[aria-haspopup="menu"]').click(); - cy.contains("Update screenshot").click(); + cy.get(this.root) + .realHover() + .then(($root) => { + if ($root.find(':contains("Update screenshot")').length > 0) { + cy.wrap($root).contains("Update screenshot").click(); + } else { + cy.wrap($root).find('[aria-haspopup="menu"]').click(); + cy.contains("Update screenshot").click(); + } + }); + cy.root().children().realHover(); // Stop hovering the card. return this; } } diff --git a/cypress/pages/slices/slicesList.js b/cypress/pages/slices/slicesList.js index 428df066ad..2fca2c623a 100644 --- a/cypress/pages/slices/slicesList.js +++ b/cypress/pages/slices/slicesList.js @@ -10,7 +10,7 @@ class SlicesList { } getSliceCard(sliceName) { - return cy.get(`[aria-label="${sliceName} slice card"]`); + return cy.get(`[aria-label^="${sliceName}"][aria-label$="slice card"]`); } get optionDopDownMenu() { diff --git a/packages/slice-machine/src/features/slices/sliceCards/SharedSliceCard.tsx b/packages/slice-machine/src/features/slices/sliceCards/SharedSliceCard.tsx index 32136c332f..3c57ff9f5f 100644 --- a/packages/slice-machine/src/features/slices/sliceCards/SharedSliceCard.tsx +++ b/packages/slice-machine/src/features/slices/sliceCards/SharedSliceCard.tsx @@ -116,6 +116,7 @@ export const SharedSliceCard: FC = (props) => { > {src !== undefined ? ( @@ -156,9 +157,12 @@ export const SharedSliceCard: FC = (props) => { ) : action.type === "menu" ? ( - + - + {action.onRename ? ( { mockRouter.setCurrentUrl("/slices"); }); - test.skip("When user creates a slice it should send a tracking event", async (ctx) => { + test("When user creates a slice it should send a tracking event", async (ctx) => { const adapter = createTestPlugin({ setup: ({ hook }) => { hook("slice:create", () => void 0); @@ -206,7 +206,7 @@ describe("slices", () => { ); }); - test.skip("if creation fails it sohuld not send the tracking event", async (ctx) => { + test("if creation fails it sohuld not send the tracking event", async (ctx) => { const adapter = createTestPlugin({ setup: ({ hook }) => { hook("slice:create", () => { From 02ca1bb02a863ee787e7a151bb89425bd8f7fd2a Mon Sep 17 00:00:00 2001 From: bapmrl Date: Mon, 30 Oct 2023 16:17:24 +0000 Subject: [PATCH 02/14] Publish - cimsirp@1.19.2-dev-next-release.0 - next-upgrade@1.19.2-dev-next-release.0 - sveltekit@1.19.2-dev-next-release.0 - @slicemachine/adapter-next@0.3.24-dev-next-release.0 - @slicemachine/adapter-nuxt@0.3.24-dev-next-release.0 - @slicemachine/adapter-nuxt2@0.3.24-dev-next-release.0 - @slicemachine/adapter-sveltekit@0.3.24-dev-next-release.0 - @slicemachine/init@2.9.2-dev-next-release.0 - @slicemachine/manager@0.15.3-dev-next-release.0 - @slicemachine/plugin-kit@0.4.24-dev-next-release.0 - slice-machine-ui@1.19.2-dev-next-release.0 - start-slicemachine@0.12.4-dev-next-release.0 --- e2e-projects/next-upgrade/package.json | 2 +- e2e-projects/next/package.json | 2 +- e2e-projects/sveltekit/package.json | 2 +- packages/adapter-next/package.json | 2 +- packages/adapter-nuxt/package.json | 2 +- packages/adapter-nuxt2/package.json | 2 +- packages/adapter-sveltekit/package.json | 2 +- packages/init/package.json | 2 +- packages/manager/package.json | 2 +- packages/plugin-kit/package.json | 2 +- packages/slice-machine/package.json | 2 +- packages/start-slicemachine/package.json | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/e2e-projects/next-upgrade/package.json b/e2e-projects/next-upgrade/package.json index 7fb7e24b65..0750d26346 100644 --- a/e2e-projects/next-upgrade/package.json +++ b/e2e-projects/next-upgrade/package.json @@ -1,6 +1,6 @@ { "name": "next-upgrade", - "version": "1.19.1", + "version": "1.19.2-dev-next-release.0", "private": true, "scripts": { "dev": "next dev", diff --git a/e2e-projects/next/package.json b/e2e-projects/next/package.json index a805fe956a..7449e9ae15 100644 --- a/e2e-projects/next/package.json +++ b/e2e-projects/next/package.json @@ -1,6 +1,6 @@ { "name": "cimsirp", - "version": "1.19.1", + "version": "1.19.2-dev-next-release.0", "private": true, "scripts": { "dev": "next dev", diff --git a/e2e-projects/sveltekit/package.json b/e2e-projects/sveltekit/package.json index 7fefb30c4c..60d5559c5f 100644 --- a/e2e-projects/sveltekit/package.json +++ b/e2e-projects/sveltekit/package.json @@ -1,6 +1,6 @@ { "name": "sveltekit", - "version": "1.19.1", + "version": "1.19.2-dev-next-release.0", "private": true, "scripts": { "dev": "vite dev", diff --git a/packages/adapter-next/package.json b/packages/adapter-next/package.json index 44f372d070..d922536a47 100644 --- a/packages/adapter-next/package.json +++ b/packages/adapter-next/package.json @@ -1,6 +1,6 @@ { "name": "@slicemachine/adapter-next", - "version": "0.3.23", + "version": "0.3.24-dev-next-release.0", "description": "Slice Machine adapter for Next.js.", "keywords": [ "typescript", diff --git a/packages/adapter-nuxt/package.json b/packages/adapter-nuxt/package.json index 4ef5d138ce..30c8b1de18 100644 --- a/packages/adapter-nuxt/package.json +++ b/packages/adapter-nuxt/package.json @@ -1,6 +1,6 @@ { "name": "@slicemachine/adapter-nuxt", - "version": "0.3.23", + "version": "0.3.24-dev-next-release.0", "description": "Slice Machine adapter for Nuxt 3.", "keywords": [ "typescript", diff --git a/packages/adapter-nuxt2/package.json b/packages/adapter-nuxt2/package.json index 8e025156df..dbf60596f2 100644 --- a/packages/adapter-nuxt2/package.json +++ b/packages/adapter-nuxt2/package.json @@ -1,6 +1,6 @@ { "name": "@slicemachine/adapter-nuxt2", - "version": "0.3.23", + "version": "0.3.24-dev-next-release.0", "description": "Slice Machine adapter for Nuxt 2.", "keywords": [ "typescript", diff --git a/packages/adapter-sveltekit/package.json b/packages/adapter-sveltekit/package.json index 84f2339233..7e0d80a1f2 100644 --- a/packages/adapter-sveltekit/package.json +++ b/packages/adapter-sveltekit/package.json @@ -1,6 +1,6 @@ { "name": "@slicemachine/adapter-sveltekit", - "version": "0.3.23", + "version": "0.3.24-dev-next-release.0", "description": "Slice Machine adapter for SvelteKit.", "keywords": [ "typescript", diff --git a/packages/init/package.json b/packages/init/package.json index 73c43f2dad..4462ad5c59 100644 --- a/packages/init/package.json +++ b/packages/init/package.json @@ -1,6 +1,6 @@ { "name": "@slicemachine/init", - "version": "2.9.1", + "version": "2.9.2-dev-next-release.0", "description": "Init Prismic Slice Machine in your project", "keywords": [ "typescript", diff --git a/packages/manager/package.json b/packages/manager/package.json index eafd7358a7..84f1b742e4 100644 --- a/packages/manager/package.json +++ b/packages/manager/package.json @@ -1,6 +1,6 @@ { "name": "@slicemachine/manager", - "version": "0.15.2", + "version": "0.15.3-dev-next-release.0", "description": "Manage all aspects of a Slice Machine project.", "repository": { "type": "git", diff --git a/packages/plugin-kit/package.json b/packages/plugin-kit/package.json index 95eea035aa..2fb98f595d 100644 --- a/packages/plugin-kit/package.json +++ b/packages/plugin-kit/package.json @@ -1,6 +1,6 @@ { "name": "@slicemachine/plugin-kit", - "version": "0.4.23", + "version": "0.4.24-dev-next-release.0", "description": "A set of helpers to develop and run Slice Machine plugins", "keywords": [ "typescript", diff --git a/packages/slice-machine/package.json b/packages/slice-machine/package.json index ed7c583d6f..621f91c7d3 100644 --- a/packages/slice-machine/package.json +++ b/packages/slice-machine/package.json @@ -1,6 +1,6 @@ { "name": "slice-machine-ui", - "version": "1.19.1", + "version": "1.19.2-dev-next-release.0", "license": "MIT", "description": "A visual builder for your Slice Models with all the tools you need to generate data models and mock CMS content locally.", "repository": { diff --git a/packages/start-slicemachine/package.json b/packages/start-slicemachine/package.json index 3396e76f0d..c9fba14023 100644 --- a/packages/start-slicemachine/package.json +++ b/packages/start-slicemachine/package.json @@ -1,6 +1,6 @@ { "name": "start-slicemachine", - "version": "0.12.3", + "version": "0.12.4-dev-next-release.0", "description": "Start Slice Machine from within a project.", "repository": { "type": "git", From 70ad2cd3336cf4b1f4d536639d362ff87156364f Mon Sep 17 00:00:00 2001 From: Baptiste Morelle Date: Mon, 30 Oct 2023 17:34:34 +0100 Subject: [PATCH 03/14] fix(slice-machine-ui): WindowTabsList overflowing the CustomTypesBuilderPage (#1202) --- .../customTypes/customTypesBuilder/CustomTypesBuilderPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/slice-machine/src/features/customTypes/customTypesBuilder/CustomTypesBuilderPage.tsx b/packages/slice-machine/src/features/customTypes/customTypesBuilder/CustomTypesBuilderPage.tsx index 9853ad7205..d1437811ef 100644 --- a/packages/slice-machine/src/features/customTypes/customTypesBuilder/CustomTypesBuilderPage.tsx +++ b/packages/slice-machine/src/features/customTypes/customTypesBuilder/CustomTypesBuilderPage.tsx @@ -139,7 +139,7 @@ const CustomTypesBuilderPageWithProvider: React.FC< - + From cd266a020a4504ea90a7d21faa96a1e1604d1800 Mon Sep 17 00:00:00 2001 From: bapmrl Date: Mon, 30 Oct 2023 16:36:55 +0000 Subject: [PATCH 04/14] Publish - cimsirp@1.19.2-dev-next-release.1 - next-upgrade@1.19.2-dev-next-release.1 - sveltekit@1.19.2-dev-next-release.1 - @slicemachine/adapter-next@0.3.24-dev-next-release.1 - @slicemachine/adapter-nuxt@0.3.24-dev-next-release.1 - @slicemachine/adapter-nuxt2@0.3.24-dev-next-release.1 - @slicemachine/adapter-sveltekit@0.3.24-dev-next-release.1 - @slicemachine/init@2.9.2-dev-next-release.1 - @slicemachine/manager@0.15.3-dev-next-release.1 - @slicemachine/plugin-kit@0.4.24-dev-next-release.1 - slice-machine-ui@1.19.2-dev-next-release.1 - start-slicemachine@0.12.4-dev-next-release.1 --- e2e-projects/next-upgrade/package.json | 2 +- e2e-projects/next/package.json | 2 +- e2e-projects/sveltekit/package.json | 2 +- packages/adapter-next/package.json | 2 +- packages/adapter-nuxt/package.json | 2 +- packages/adapter-nuxt2/package.json | 2 +- packages/adapter-sveltekit/package.json | 2 +- packages/init/package.json | 2 +- packages/manager/package.json | 2 +- packages/plugin-kit/package.json | 2 +- packages/slice-machine/package.json | 2 +- packages/start-slicemachine/package.json | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/e2e-projects/next-upgrade/package.json b/e2e-projects/next-upgrade/package.json index 0750d26346..e23c213f92 100644 --- a/e2e-projects/next-upgrade/package.json +++ b/e2e-projects/next-upgrade/package.json @@ -1,6 +1,6 @@ { "name": "next-upgrade", - "version": "1.19.2-dev-next-release.0", + "version": "1.19.2-dev-next-release.1", "private": true, "scripts": { "dev": "next dev", diff --git a/e2e-projects/next/package.json b/e2e-projects/next/package.json index 7449e9ae15..6a5cb974b5 100644 --- a/e2e-projects/next/package.json +++ b/e2e-projects/next/package.json @@ -1,6 +1,6 @@ { "name": "cimsirp", - "version": "1.19.2-dev-next-release.0", + "version": "1.19.2-dev-next-release.1", "private": true, "scripts": { "dev": "next dev", diff --git a/e2e-projects/sveltekit/package.json b/e2e-projects/sveltekit/package.json index 60d5559c5f..5923f6a4b9 100644 --- a/e2e-projects/sveltekit/package.json +++ b/e2e-projects/sveltekit/package.json @@ -1,6 +1,6 @@ { "name": "sveltekit", - "version": "1.19.2-dev-next-release.0", + "version": "1.19.2-dev-next-release.1", "private": true, "scripts": { "dev": "vite dev", diff --git a/packages/adapter-next/package.json b/packages/adapter-next/package.json index d922536a47..de255bf02f 100644 --- a/packages/adapter-next/package.json +++ b/packages/adapter-next/package.json @@ -1,6 +1,6 @@ { "name": "@slicemachine/adapter-next", - "version": "0.3.24-dev-next-release.0", + "version": "0.3.24-dev-next-release.1", "description": "Slice Machine adapter for Next.js.", "keywords": [ "typescript", diff --git a/packages/adapter-nuxt/package.json b/packages/adapter-nuxt/package.json index 30c8b1de18..48ad113cfe 100644 --- a/packages/adapter-nuxt/package.json +++ b/packages/adapter-nuxt/package.json @@ -1,6 +1,6 @@ { "name": "@slicemachine/adapter-nuxt", - "version": "0.3.24-dev-next-release.0", + "version": "0.3.24-dev-next-release.1", "description": "Slice Machine adapter for Nuxt 3.", "keywords": [ "typescript", diff --git a/packages/adapter-nuxt2/package.json b/packages/adapter-nuxt2/package.json index dbf60596f2..b2e98df741 100644 --- a/packages/adapter-nuxt2/package.json +++ b/packages/adapter-nuxt2/package.json @@ -1,6 +1,6 @@ { "name": "@slicemachine/adapter-nuxt2", - "version": "0.3.24-dev-next-release.0", + "version": "0.3.24-dev-next-release.1", "description": "Slice Machine adapter for Nuxt 2.", "keywords": [ "typescript", diff --git a/packages/adapter-sveltekit/package.json b/packages/adapter-sveltekit/package.json index 7e0d80a1f2..06b97fc413 100644 --- a/packages/adapter-sveltekit/package.json +++ b/packages/adapter-sveltekit/package.json @@ -1,6 +1,6 @@ { "name": "@slicemachine/adapter-sveltekit", - "version": "0.3.24-dev-next-release.0", + "version": "0.3.24-dev-next-release.1", "description": "Slice Machine adapter for SvelteKit.", "keywords": [ "typescript", diff --git a/packages/init/package.json b/packages/init/package.json index 4462ad5c59..16deb9dfff 100644 --- a/packages/init/package.json +++ b/packages/init/package.json @@ -1,6 +1,6 @@ { "name": "@slicemachine/init", - "version": "2.9.2-dev-next-release.0", + "version": "2.9.2-dev-next-release.1", "description": "Init Prismic Slice Machine in your project", "keywords": [ "typescript", diff --git a/packages/manager/package.json b/packages/manager/package.json index 84f1b742e4..880603c21e 100644 --- a/packages/manager/package.json +++ b/packages/manager/package.json @@ -1,6 +1,6 @@ { "name": "@slicemachine/manager", - "version": "0.15.3-dev-next-release.0", + "version": "0.15.3-dev-next-release.1", "description": "Manage all aspects of a Slice Machine project.", "repository": { "type": "git", diff --git a/packages/plugin-kit/package.json b/packages/plugin-kit/package.json index 2fb98f595d..7c424a2847 100644 --- a/packages/plugin-kit/package.json +++ b/packages/plugin-kit/package.json @@ -1,6 +1,6 @@ { "name": "@slicemachine/plugin-kit", - "version": "0.4.24-dev-next-release.0", + "version": "0.4.24-dev-next-release.1", "description": "A set of helpers to develop and run Slice Machine plugins", "keywords": [ "typescript", diff --git a/packages/slice-machine/package.json b/packages/slice-machine/package.json index 621f91c7d3..7e4ba20f71 100644 --- a/packages/slice-machine/package.json +++ b/packages/slice-machine/package.json @@ -1,6 +1,6 @@ { "name": "slice-machine-ui", - "version": "1.19.2-dev-next-release.0", + "version": "1.19.2-dev-next-release.1", "license": "MIT", "description": "A visual builder for your Slice Models with all the tools you need to generate data models and mock CMS content locally.", "repository": { diff --git a/packages/start-slicemachine/package.json b/packages/start-slicemachine/package.json index c9fba14023..7f7e097c7a 100644 --- a/packages/start-slicemachine/package.json +++ b/packages/start-slicemachine/package.json @@ -1,6 +1,6 @@ { "name": "start-slicemachine", - "version": "0.12.4-dev-next-release.0", + "version": "0.12.4-dev-next-release.1", "description": "Start Slice Machine from within a project.", "repository": { "type": "git", From cf75798cba9ce6b5040a9a378ab11a8a5227af45 Mon Sep 17 00:00:00 2001 From: Xavier Rutayisire Date: Tue, 31 Oct 2023 14:18:08 +0100 Subject: [PATCH 05/14] feat(logs): Add more logs for Sentry (#1205) --- packages/init/src/lib/setupSentry.ts | 4 ++-- packages/init/src/lib/updateSentryContext.ts | 5 +++++ .../manager/src/auth/PrismicAuthManager.ts | 10 ++++++++-- .../lib/fetchGitHubReleaseBodyForRelease.ts | 5 ++++- .../manager/src/lib/installDependencies.ts | 6 ++++++ .../customTypes/CustomTypesManager.ts | 3 +++ .../PrismicRepositoryManager.ts | 9 ++++++--- .../src/managers/project/ProjectManager.ts | 4 +++- .../screenshots/ScreenshotsManager.ts | 19 +++++++++++++++++-- ...Manager-refreshAuthenticationToken.test.ts | 5 ++++- ...er-user-refreshAuthenticationToken.test.ts | 5 ++++- .../src/lib/sentryErrorHandlers.ts | 4 +++- .../start-slicemachine/src/lib/setupSentry.ts | 3 +++ 13 files changed, 68 insertions(+), 14 deletions(-) diff --git a/packages/init/src/lib/setupSentry.ts b/packages/init/src/lib/setupSentry.ts index c35f7a5df9..578429f224 100644 --- a/packages/init/src/lib/setupSentry.ts +++ b/packages/init/src/lib/setupSentry.ts @@ -19,8 +19,8 @@ export function setupSentry(): void { environment: isStableVersion ? import.meta.env.MODE || "production" : "alpha", - // Increase the default truncation length of 250 to 2500 (x10) + // Increase the default truncation length of 250 to 12500 (x50) // to have enough details in Sentry - maxValueLength: 2_500, + maxValueLength: 12_500, }); } diff --git a/packages/init/src/lib/updateSentryContext.ts b/packages/init/src/lib/updateSentryContext.ts index 1b7a4d028b..55fb8981dc 100644 --- a/packages/init/src/lib/updateSentryContext.ts +++ b/packages/init/src/lib/updateSentryContext.ts @@ -39,4 +39,9 @@ export async function updateSentryContext({ if (framework) { Sentry.setTag("framework", framework); } + + Sentry.setContext("Process", { + "Command used": process.argv.join(" "), + cwd: process.cwd(), + }); } diff --git a/packages/manager/src/auth/PrismicAuthManager.ts b/packages/manager/src/auth/PrismicAuthManager.ts index c06620bffe..cdc6bd55ae 100644 --- a/packages/manager/src/auth/PrismicAuthManager.ts +++ b/packages/manager/src/auth/PrismicAuthManager.ts @@ -295,7 +295,9 @@ export class PrismicAuthManager { await this._writePersistedAuthState(authState); } else { - throw new InternalError("Failed to refresh authentication token."); + throw new InternalError("Failed to refresh authentication token.", { + cause: text, + }); } } else { throw new UnauthenticatedError(); @@ -320,9 +322,9 @@ export class PrismicAuthManager { "User-Agent": SLICE_MACHINE_USER_AGENT, }, }); - const json = await res.json(); if (res.ok) { + const json = await res.json(); const { value: profile, error } = decode(PrismicUserProfile, json); if (error) { @@ -333,8 +335,12 @@ export class PrismicAuthManager { return profile; } else { + const text = await res.text(); throw new InternalError( "Failed to retrieve profile from the Prismic user service.", + { + cause: text, + }, ); } } diff --git a/packages/manager/src/lib/fetchGitHubReleaseBodyForRelease.ts b/packages/manager/src/lib/fetchGitHubReleaseBodyForRelease.ts index 14383c20bc..2a36675f5e 100644 --- a/packages/manager/src/lib/fetchGitHubReleaseBodyForRelease.ts +++ b/packages/manager/src/lib/fetchGitHubReleaseBodyForRelease.ts @@ -45,7 +45,10 @@ const fetchAllGitHubReleases = async ( return value; } else { - throw new Error(`Invalid GitHub Release response.`); + const text = await res.text(); + throw new Error(`Invalid GitHub Release response.`, { + cause: text, + }); } }; diff --git a/packages/manager/src/lib/installDependencies.ts b/packages/manager/src/lib/installDependencies.ts index 507126cd81..b239b9f326 100644 --- a/packages/manager/src/lib/installDependencies.ts +++ b/packages/manager/src/lib/installDependencies.ts @@ -45,6 +45,12 @@ export const installDependencies = async ( if (!command) { throw new Error( "Failed to begin dependency installation (could not parse command)", + { + cause: { + packageManager: args.packageManager, + dependencies: args.dependencies, + }, + }, ); } diff --git a/packages/manager/src/managers/customTypes/CustomTypesManager.ts b/packages/manager/src/managers/customTypes/CustomTypesManager.ts index 489415a85a..bf3eaf0f03 100644 --- a/packages/manager/src/managers/customTypes/CustomTypesManager.ts +++ b/packages/manager/src/managers/customTypes/CustomTypesManager.ts @@ -252,6 +252,9 @@ export class CustomTypesManager extends BaseManager { } else if (error instanceof prismicCustomTypesClient.ForbiddenError) { throw new UnauthorizedError( "You do not have access to push types to this Prismic repository.", + { + cause: error, + }, ); } else { throw error; diff --git a/packages/manager/src/managers/prismicRepository/PrismicRepositoryManager.ts b/packages/manager/src/managers/prismicRepository/PrismicRepositoryManager.ts index d876482828..0dfcda52be 100644 --- a/packages/manager/src/managers/prismicRepository/PrismicRepositoryManager.ts +++ b/packages/manager/src/managers/prismicRepository/PrismicRepositoryManager.ts @@ -65,9 +65,9 @@ export class PrismicRepositoryManager extends BaseManager { async readAll(): Promise { const url = new URL("./repositories", API_ENDPOINTS.PrismicUser); const res = await this._fetch({ url }); - const json = await res.json(); if (res.ok) { + const json = await res.json(); const { value: repositories, error } = decode( t.array(PrismicRepository), json, @@ -81,7 +81,8 @@ export class PrismicRepositoryManager extends BaseManager { return repositories; } else { - throw new Error(`Failed to read repositories`, { cause: json }); + const text = await res.text(); + throw new Error(`Failed to read repositories`, { cause: text }); } } @@ -413,7 +414,9 @@ export class PrismicRepositoryManager extends BaseManager { const text = await response.text(); throw new Error(text); default: - throw new Error(`Unexpected status code ${response.status}`); + throw new Error(`Unexpected status code ${response.status}`, { + cause: await response.text(), + }); } } catch (err) { console.error("An error happened while pushing your changes"); diff --git a/packages/manager/src/managers/project/ProjectManager.ts b/packages/manager/src/managers/project/ProjectManager.ts index 8409ed9e16..0168b9bb75 100644 --- a/packages/manager/src/managers/project/ProjectManager.ts +++ b/packages/manager/src/managers/project/ProjectManager.ts @@ -173,7 +173,9 @@ export class ProjectManager extends BaseManager { if (error) { // TODO: Write a more friendly and useful message. - throw new Error(`Invalid config. ${error.errors.join(", ")}`); + throw new Error(`Invalid config. ${error.errors.join(", ")}`, { + cause: { rawConfig }, + }); } // Allow cached config reading using `SliceMachineManager.prototype.getProjectConfig()`. diff --git a/packages/manager/src/managers/screenshots/ScreenshotsManager.ts b/packages/manager/src/managers/screenshots/ScreenshotsManager.ts index 25f222eaa1..fb1f2bdcdd 100644 --- a/packages/manager/src/managers/screenshots/ScreenshotsManager.ts +++ b/packages/manager/src/managers/screenshots/ScreenshotsManager.ts @@ -140,6 +140,9 @@ export class ScreenshotsManager extends BaseManager { // Response is not JSON throw new Error( `Invalid AWS ACL response from ${awsACLURL}: ${awsACLText}`, + { + cause: error, + }, ); } @@ -162,12 +165,16 @@ export class ScreenshotsManager extends BaseManager { ); if (error) { - throw new Error(`Invalid AWS ACL response from ${awsACLURL}`); + throw new Error(`Invalid AWS ACL response from ${awsACLURL}`, { + cause: error, + }); } const errorMessage = awsACL.error || awsACL.message || awsACL.Message; if (errorMessage) { - throw new Error(`Failed to create an AWS ACL: ${errorMessage}`); + throw new Error(`Failed to create an AWS ACL: ${errorMessage}`, { + cause: error, + }); } this._s3ACL = { @@ -302,8 +309,12 @@ export class ScreenshotsManager extends BaseManager { url: url.toString(), }; } else { + const text = await res.text(); throw new Error( `Unable to upload screenshot with status code: ${res.status}`, + { + cause: text, + }, ); } } @@ -319,8 +330,12 @@ export class ScreenshotsManager extends BaseManager { url: new URL("delete-folder", API_ENDPOINTS.AwsAclProvider), }); if (!res.ok) { + const text = await res.text(); throw new Error( `Unable to delete screenshot folder with status code: ${res.status}`, + { + cause: text, + }, ); } } diff --git a/packages/manager/test/PrismicAuthManager-refreshAuthenticationToken.test.ts b/packages/manager/test/PrismicAuthManager-refreshAuthenticationToken.test.ts index 56607ea5ea..37158150d2 100644 --- a/packages/manager/test/PrismicAuthManager-refreshAuthenticationToken.test.ts +++ b/packages/manager/test/PrismicAuthManager-refreshAuthenticationToken.test.ts @@ -5,6 +5,7 @@ import { mockPrismicAuthAPI } from "./__testutils__/mockPrismicAuthAPI"; import { mockPrismicUserAPI } from "./__testutils__/mockPrismicUserAPI"; import { createPrismicAuthManager } from "../src"; +import { InternalError } from "../src/errors"; it("refreshes the auth token in the auth state file", async (ctx) => { const prismicAuthManager = createPrismicAuthManager(); @@ -39,7 +40,9 @@ it("throws if the authentication API cannot refresh the token", async (ctx) => { await expect(async () => { await prismicAuthManager.refreshAuthenticationToken(); - }).rejects.toThrow(/failed to refresh/i); + }).rejects.toThrow( + new InternalError("Failed to refresh authentication token."), + ); }); it("throws if the user is not logged in", async () => { diff --git a/packages/manager/test/SliceMachineManager-user-refreshAuthenticationToken.test.ts b/packages/manager/test/SliceMachineManager-user-refreshAuthenticationToken.test.ts index a7d53f57da..fe6f3c768a 100644 --- a/packages/manager/test/SliceMachineManager-user-refreshAuthenticationToken.test.ts +++ b/packages/manager/test/SliceMachineManager-user-refreshAuthenticationToken.test.ts @@ -7,6 +7,7 @@ import { mockPrismicAuthAPI } from "./__testutils__/mockPrismicAuthAPI"; import { mockPrismicUserAPI } from "./__testutils__/mockPrismicUserAPI"; import { createSliceMachineManager } from "../src"; +import { InternalError } from "../src/errors"; it("refreshes the auth token in the auth state file", async (ctx) => { const adapter = createTestPlugin(); @@ -51,7 +52,9 @@ it("throws if the authentication API cannot refresh the token", async (ctx) => { await expect(async () => { await manager.user.refreshAuthenticationToken(); - }).rejects.toThrow(/failed to refresh/i); + }).rejects.toThrow( + new InternalError("Failed to refresh authentication token."), + ); }); it("throws if the user is not logged in", async () => { diff --git a/packages/start-slicemachine/src/lib/sentryErrorHandlers.ts b/packages/start-slicemachine/src/lib/sentryErrorHandlers.ts index 778665076a..de3aa9fde0 100644 --- a/packages/start-slicemachine/src/lib/sentryErrorHandlers.ts +++ b/packages/start-slicemachine/src/lib/sentryErrorHandlers.ts @@ -9,7 +9,9 @@ export const node = (name: string, error: unknown): void => { if (checkIsSentryEnabled()) { Sentry.withScope(function (scope) { scope.setTransactionName(name); - Sentry.captureException(error); + Sentry.captureException(error, { + ...(error instanceof Error ? { extra: { cause: error.cause } } : {}), + }); }); } }; diff --git a/packages/start-slicemachine/src/lib/setupSentry.ts b/packages/start-slicemachine/src/lib/setupSentry.ts index dec6851aba..70cc80f4a7 100644 --- a/packages/start-slicemachine/src/lib/setupSentry.ts +++ b/packages/start-slicemachine/src/lib/setupSentry.ts @@ -34,6 +34,9 @@ export const setupSentry = async ( environment: isStableVersion ? import.meta.env.MODE || "production" : "alpha", + // Increase the default truncation length of 250 to 12500 (x50) + // to have enough details in Sentry + maxValueLength: 12_500, }); if (userProfile) { Sentry.setUser({ id: userProfile.shortId }); From 332d488ecf32ef67995b101972e196465f8b6dab Mon Sep 17 00:00:00 2001 From: xrutayisire Date: Tue, 31 Oct 2023 13:20:50 +0000 Subject: [PATCH 06/14] Publish - cimsirp@1.19.2-dev-next-release.2 - next-upgrade@1.19.2-dev-next-release.2 - sveltekit@1.19.2-dev-next-release.2 - @slicemachine/adapter-next@0.3.24-dev-next-release.2 - @slicemachine/adapter-nuxt@0.3.24-dev-next-release.2 - @slicemachine/adapter-nuxt2@0.3.24-dev-next-release.2 - @slicemachine/adapter-sveltekit@0.3.24-dev-next-release.2 - @slicemachine/init@2.9.2-dev-next-release.2 - @slicemachine/manager@0.15.3-dev-next-release.2 - @slicemachine/plugin-kit@0.4.24-dev-next-release.2 - slice-machine-ui@1.19.2-dev-next-release.2 - start-slicemachine@0.12.4-dev-next-release.2 --- e2e-projects/next-upgrade/package.json | 2 +- e2e-projects/next/package.json | 2 +- e2e-projects/sveltekit/package.json | 2 +- packages/adapter-next/package.json | 2 +- packages/adapter-nuxt/package.json | 2 +- packages/adapter-nuxt2/package.json | 2 +- packages/adapter-sveltekit/package.json | 2 +- packages/init/package.json | 2 +- packages/manager/package.json | 2 +- packages/plugin-kit/package.json | 2 +- packages/slice-machine/package.json | 2 +- packages/start-slicemachine/package.json | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/e2e-projects/next-upgrade/package.json b/e2e-projects/next-upgrade/package.json index e23c213f92..c4e7c5e929 100644 --- a/e2e-projects/next-upgrade/package.json +++ b/e2e-projects/next-upgrade/package.json @@ -1,6 +1,6 @@ { "name": "next-upgrade", - "version": "1.19.2-dev-next-release.1", + "version": "1.19.2-dev-next-release.2", "private": true, "scripts": { "dev": "next dev", diff --git a/e2e-projects/next/package.json b/e2e-projects/next/package.json index 6a5cb974b5..4f6298fa15 100644 --- a/e2e-projects/next/package.json +++ b/e2e-projects/next/package.json @@ -1,6 +1,6 @@ { "name": "cimsirp", - "version": "1.19.2-dev-next-release.1", + "version": "1.19.2-dev-next-release.2", "private": true, "scripts": { "dev": "next dev", diff --git a/e2e-projects/sveltekit/package.json b/e2e-projects/sveltekit/package.json index 5923f6a4b9..bc369f7d6d 100644 --- a/e2e-projects/sveltekit/package.json +++ b/e2e-projects/sveltekit/package.json @@ -1,6 +1,6 @@ { "name": "sveltekit", - "version": "1.19.2-dev-next-release.1", + "version": "1.19.2-dev-next-release.2", "private": true, "scripts": { "dev": "vite dev", diff --git a/packages/adapter-next/package.json b/packages/adapter-next/package.json index de255bf02f..a545db9d94 100644 --- a/packages/adapter-next/package.json +++ b/packages/adapter-next/package.json @@ -1,6 +1,6 @@ { "name": "@slicemachine/adapter-next", - "version": "0.3.24-dev-next-release.1", + "version": "0.3.24-dev-next-release.2", "description": "Slice Machine adapter for Next.js.", "keywords": [ "typescript", diff --git a/packages/adapter-nuxt/package.json b/packages/adapter-nuxt/package.json index 48ad113cfe..30dd3b7695 100644 --- a/packages/adapter-nuxt/package.json +++ b/packages/adapter-nuxt/package.json @@ -1,6 +1,6 @@ { "name": "@slicemachine/adapter-nuxt", - "version": "0.3.24-dev-next-release.1", + "version": "0.3.24-dev-next-release.2", "description": "Slice Machine adapter for Nuxt 3.", "keywords": [ "typescript", diff --git a/packages/adapter-nuxt2/package.json b/packages/adapter-nuxt2/package.json index b2e98df741..23a2347ce9 100644 --- a/packages/adapter-nuxt2/package.json +++ b/packages/adapter-nuxt2/package.json @@ -1,6 +1,6 @@ { "name": "@slicemachine/adapter-nuxt2", - "version": "0.3.24-dev-next-release.1", + "version": "0.3.24-dev-next-release.2", "description": "Slice Machine adapter for Nuxt 2.", "keywords": [ "typescript", diff --git a/packages/adapter-sveltekit/package.json b/packages/adapter-sveltekit/package.json index 06b97fc413..eec52dbae2 100644 --- a/packages/adapter-sveltekit/package.json +++ b/packages/adapter-sveltekit/package.json @@ -1,6 +1,6 @@ { "name": "@slicemachine/adapter-sveltekit", - "version": "0.3.24-dev-next-release.1", + "version": "0.3.24-dev-next-release.2", "description": "Slice Machine adapter for SvelteKit.", "keywords": [ "typescript", diff --git a/packages/init/package.json b/packages/init/package.json index 16deb9dfff..0c094f1f8f 100644 --- a/packages/init/package.json +++ b/packages/init/package.json @@ -1,6 +1,6 @@ { "name": "@slicemachine/init", - "version": "2.9.2-dev-next-release.1", + "version": "2.9.2-dev-next-release.2", "description": "Init Prismic Slice Machine in your project", "keywords": [ "typescript", diff --git a/packages/manager/package.json b/packages/manager/package.json index 880603c21e..94496a9895 100644 --- a/packages/manager/package.json +++ b/packages/manager/package.json @@ -1,6 +1,6 @@ { "name": "@slicemachine/manager", - "version": "0.15.3-dev-next-release.1", + "version": "0.15.3-dev-next-release.2", "description": "Manage all aspects of a Slice Machine project.", "repository": { "type": "git", diff --git a/packages/plugin-kit/package.json b/packages/plugin-kit/package.json index 7c424a2847..f61376248c 100644 --- a/packages/plugin-kit/package.json +++ b/packages/plugin-kit/package.json @@ -1,6 +1,6 @@ { "name": "@slicemachine/plugin-kit", - "version": "0.4.24-dev-next-release.1", + "version": "0.4.24-dev-next-release.2", "description": "A set of helpers to develop and run Slice Machine plugins", "keywords": [ "typescript", diff --git a/packages/slice-machine/package.json b/packages/slice-machine/package.json index 7e4ba20f71..116b2cd3a1 100644 --- a/packages/slice-machine/package.json +++ b/packages/slice-machine/package.json @@ -1,6 +1,6 @@ { "name": "slice-machine-ui", - "version": "1.19.2-dev-next-release.1", + "version": "1.19.2-dev-next-release.2", "license": "MIT", "description": "A visual builder for your Slice Models with all the tools you need to generate data models and mock CMS content locally.", "repository": { diff --git a/packages/start-slicemachine/package.json b/packages/start-slicemachine/package.json index 7f7e097c7a..13ab5a5bf7 100644 --- a/packages/start-slicemachine/package.json +++ b/packages/start-slicemachine/package.json @@ -1,6 +1,6 @@ { "name": "start-slicemachine", - "version": "0.12.4-dev-next-release.1", + "version": "0.12.4-dev-next-release.2", "description": "Start Slice Machine from within a project.", "repository": { "type": "git", From 7282b39a58107443d64962f77fb115bb6953440f Mon Sep 17 00:00:00 2001 From: Xavier Rutayisire Date: Tue, 31 Oct 2023 14:27:13 +0100 Subject: [PATCH 07/14] refactor(screenshots): Remove Puppeteer related code (#1188) --- ...ild-slices.cy.js => 02-build-slices.cy.js} | 0 .../e2e/slices/02-simulator-screenshots.cy.js | 70 ---- cypress/pages/simulator/simulatorPage.js | 83 ----- .../createSliceMachineManagerMiddleware.ts | 1 - .../screenshots/ScreenshotsManager.ts | 163 --------- .../manager/src/managers/telemetry/types.ts | 4 +- ...ts-captureSliceSimulatorScreenshot.test.ts | 334 ------------------ ...ger-screenshots-initBrowserContext.test.ts | 32 -- ...itBrowserContext.without-puppeteer.test.ts | 23 -- .../test/__testutils__/createPuppeteerMock.ts | 114 ------ .../mockSliceSimulatorEndpoint.ts | 61 ---- .../components/ScreenshotToaster/index.tsx | 53 --- .../components/IframeRenderer/index.tsx | 3 - .../Simulator/components/Toolbar/index.tsx | 42 --- .../components/Simulator/index.tsx | 2 - .../lib/models/common/Screenshots.ts | 11 +- .../[sliceName]/[variation]/screenshot.tsx | 61 ---- packages/slice-machine/src/apiClient.ts | 41 +-- .../src/modules/loading/types.ts | 1 - .../src/modules/screenshots/actions.ts | 29 +- .../src/modules/screenshots/sagas.ts | 64 +--- .../src/modules/selectedSlice/actions.ts | 6 +- .../src/modules/selectedSlice/reducer.ts | 6 +- .../slice-machine/src/modules/slices/index.ts | 7 +- .../src/modules/toaster/index.tsx | 28 +- .../src/modules/useSliceMachineActions.ts | 27 +- .../screenshots/__fixtures__/mocks.json | 41 --- .../screenshots/__fixtures__/model.json | 35 -- .../getSelectedSliceDummyData.ts | 29 -- .../src/modules/screenshots/sagas.test.ts | 82 ----- .../src/StartSliceMachineProcess.ts | 13 - .../src/lib/createSliceMachineExpressApp.ts | 9 - 32 files changed, 20 insertions(+), 1455 deletions(-) rename cypress/e2e/slices/{03-build-slices.cy.js => 02-build-slices.cy.js} (100%) delete mode 100644 cypress/e2e/slices/02-simulator-screenshots.cy.js delete mode 100644 packages/manager/test/SliceMachineManager-screenshots-captureSliceSimulatorScreenshot.test.ts delete mode 100644 packages/manager/test/SliceMachineManager-screenshots-initBrowserContext.test.ts delete mode 100644 packages/manager/test/SliceMachineManager-screenshots-initBrowserContext.without-puppeteer.test.ts delete mode 100644 packages/manager/test/__testutils__/createPuppeteerMock.ts delete mode 100644 packages/manager/test/__testutils__/mockSliceSimulatorEndpoint.ts delete mode 100644 packages/slice-machine/components/ScreenshotToaster/index.tsx delete mode 100644 packages/slice-machine/pages/slices/[lib]/[sliceName]/[variation]/screenshot.tsx delete mode 100644 packages/slice-machine/test/src/modules/screenshots/__fixtures__/mocks.json delete mode 100644 packages/slice-machine/test/src/modules/screenshots/__fixtures__/model.json delete mode 100644 packages/slice-machine/test/src/modules/screenshots/__testutils__/getSelectedSliceDummyData.ts delete mode 100644 packages/slice-machine/test/src/modules/screenshots/sagas.test.ts diff --git a/cypress/e2e/slices/03-build-slices.cy.js b/cypress/e2e/slices/02-build-slices.cy.js similarity index 100% rename from cypress/e2e/slices/03-build-slices.cy.js rename to cypress/e2e/slices/02-build-slices.cy.js diff --git a/cypress/e2e/slices/02-simulator-screenshots.cy.js b/cypress/e2e/slices/02-simulator-screenshots.cy.js deleted file mode 100644 index 84a706d1fc..0000000000 --- a/cypress/e2e/slices/02-simulator-screenshots.cy.js +++ /dev/null @@ -1,70 +0,0 @@ -import { simulatorPage } from "../../pages/simulator/simulatorPage"; -import { screenshotModal } from "../../pages/simulator/screenshotModal"; -import { sliceBuilder } from "../../pages/slices/sliceBuilder"; - -describe.skip("I am an existing SM user and I want to take a screenshot from the slice simulator", () => { - const random = Date.now(); - - const slice = { - id: `test_screenshots${random}`, - name: `TestScreenshots${random}`, - library: ".--slices", - newVariationName: "foo", - }; - - before("Cleanup local data and create a new slice", () => { - cy.clearProject(); - cy.setSliceMachineUserContext({}); - cy.createSlice(slice.library, slice.id, slice.name); - - sliceBuilder.addVariation(slice.newVariationName); - sliceBuilder.save(); - }); - - beforeEach("Start from the Slice page", () => { - cy.setSliceMachineUserContext({}); - - sliceBuilder.goTo(slice.library, slice.name); - }); - - it("Open the simulator on the default variant", () => { - simulatorPage.setup(); - - sliceBuilder.openSimulator(); - - simulatorPage - .resizeScreenWithDropdown("Desktop", "Tablet") - .validateSimulatorSize(1080, 810) - .resizeScreenWithDropdown("Tablet", "Desktop") - .validateSimulatorSize(1280, 800) - .takeAScreenshotAndOpenModal(); - screenshotModal.imagePreview.isCorrectDimensions(1280, 800); - screenshotModal.close(); - simulatorPage - .resizeScreenWithInput(500, 500) - .validateSimulatorSize(500, 500) - .takeAScreenshotAndOpenModal(); - screenshotModal.imagePreview.isCorrectDimensions(500, 500); - const mainVariationScreenshotSrc = screenshotModal.imageSrc; - screenshotModal.close(); - - // Take a screenshot of the second variation - simulatorPage - .changeVariations(slice.newVariationName) - .resizeScreenWithDropdown("Custom", "Desktop") - .validateSimulatorSize(1280, 800) - .takeAScreenshotAndOpenModal(); - screenshotModal.imagePreview.isCorrectDimensions(1280, 800); - const secondVariationScreenshotSrc = screenshotModal.imageSrc; - screenshotModal.close(); - - // Check screenshots in the slice page preview - sliceBuilder.goTo(slice.library, slice.name); - sliceBuilder.imagePreview.isCorrectDimensions(500, 500); - expect(sliceBuilder.imagePreviewSrc).to.equal(mainVariationScreenshotSrc); - sliceBuilder - .changeToVariation("Default", slice.newVariationName) - .imagePreview.isCorrectDimensions(1280, 800); - expect(sliceBuilder.imagePreviewSrc).to.equal(secondVariationScreenshotSrc); - }); -}); diff --git a/cypress/pages/simulator/simulatorPage.js b/cypress/pages/simulator/simulatorPage.js index 8bcc2c3559..d30c3f1ced 100644 --- a/cypress/pages/simulator/simulatorPage.js +++ b/cypress/pages/simulator/simulatorPage.js @@ -5,30 +5,6 @@ class SimulatorPage { return cy.contains("Save mock content"); } - get takeScreenshotButton() { - return cy.contains("Take a screenshot"); - } - - get screenshotToast() { - return cy.contains("Tap to view screenshot"); - } - - get simulatorIframe() { - return cy.get("#__iframe-renderer"); - } - - get widthInput() { - return cy.get('input[name="W-screensize-input"]'); - } - - get heightInput() { - return cy.get('input[name="H-screensize-input"]'); - } - - getScreenSizeDropdown(currentValue) { - return cy.get("button").contains(currentValue); - } - /** * Setup the slice simulator in the example project, and stub the window open * event to open in the same page. @@ -45,65 +21,6 @@ class SimulatorPage { return this; } - /** - * Use the screen size dropdown menu to change the simulator screen size. - * - * @param {string} startValue The expected start value of the dropdown button. - * @param {string} newValue The new value to set the screen size to. - */ - resizeScreenWithDropdown(startValue, newValue) { - this.getScreenSizeDropdown(startValue).click(); - cy.contains(newValue).click(); - - return this; - } - - /** - * Use the screen size input fields to change the simulator screen size. - * - * @param {number} newWidth The new value to the the width to. - * @param {number} newHeight The new value to the the height to. - */ - resizeScreenWithInput(newWidth, newHeight) { - this.widthInput.clear().type(`{rightArrow}${newWidth}`); - this.heightInput.clear().type(`{rightArrow}${newHeight}`); - - return this; - } - - /** - * Check that the dimensions of the simulator are equal to the provided ones. - * - * @param {number} expectedWidth The value which the width should equal. - * @param {number} expectedHeight The value which the height should equal. - */ - validateSimulatorSize(expectedWidth, expectedHeight) { - this.simulatorIframe - .should("have.css", "maxWidth") - .and("eq", `${expectedWidth}px`); - this.simulatorIframe - .should("have.css", "minWidth") - .and("eq", `${expectedWidth}px`); - this.simulatorIframe - .should("have.css", "maxHeight") - .and("eq", `${expectedHeight}px`); - this.simulatorIframe - .should("have.css", "minHeight") - .and("eq", `${expectedHeight}px`); - - return this; - } - - takeAScreenshotAndOpenModal() { - this.takeScreenshotButton.click(); - - cy.contains("Screenshot taken", { timeout: 30000 }).should("be.visible"); - - this.screenshotToast.click(); - - return this; - } - /** * Change the slice variations using the variations dropdown in the simulator. * diff --git a/packages/manager/src/managers/createSliceMachineManagerMiddleware.ts b/packages/manager/src/managers/createSliceMachineManagerMiddleware.ts index 5c3dfa287c..19fc798488 100644 --- a/packages/manager/src/managers/createSliceMachineManagerMiddleware.ts +++ b/packages/manager/src/managers/createSliceMachineManagerMiddleware.ts @@ -40,7 +40,6 @@ const omitProcedures = defineOmits()([ "sliceTemplateLibrary._sliceMachineManager", "getSliceMachinePluginRunner", "getPrismicAuthManager", - "screenshots.browserContext", ]); export type SliceMachineManagerMiddleware = RPCMiddleware< diff --git a/packages/manager/src/managers/screenshots/ScreenshotsManager.ts b/packages/manager/src/managers/screenshots/ScreenshotsManager.ts index fb1f2bdcdd..b2f0d2d7d3 100644 --- a/packages/manager/src/managers/screenshots/ScreenshotsManager.ts +++ b/packages/manager/src/managers/screenshots/ScreenshotsManager.ts @@ -3,7 +3,6 @@ import { fileTypeFromBuffer } from "file-type"; import pLimit from "p-limit"; import fetch, { FormData, Blob, Response } from "../../lib/fetch"; -import { checkIsURLAccessible } from "../../lib/checkIsURLAccessible"; import { createContentDigest } from "../../lib/createContentDigest"; import { decode } from "../../lib/decode"; @@ -13,21 +12,6 @@ import { API_ENDPOINTS } from "../../constants/API_ENDPOINTS"; import { BaseManager } from "../BaseManager"; -const SLICE_SIMULATOR_WAIT_FOR_SELECTOR = "#__iframe-ready"; -const SLICE_SIMULATOR_WAIT_FOR_SELECTOR_TIMEOUT = 10_000; // ms -const SLICE_SIMULATOR_SCREENSHOT_SELECTOR = "#__iframe-renderer"; - -// TODO(DT-1534): Use Puppeteer types if we want reactive Puppeteer screenshots -// eslint-disable-next-line @typescript-eslint/no-explicit-any -type Viewport = any; -// eslint-disable-next-line @typescript-eslint/no-explicit-any -type BrowserContext = any; - -const DEFAULT_SCREENSHOT_VIEWPORT: Viewport = { - width: 1200, - height: 800, -}; - function assertS3ACLInitialized( s3ACL: S3ACL | undefined, ): asserts s3ACL is NonNullable { @@ -38,48 +22,8 @@ function assertS3ACLInitialized( } } -function assertBrowserContextInitialized( - browserContext: BrowserContext | undefined, -): asserts browserContext is NonNullable { - if (browserContext == undefined) { - throw new Error( - "A browser context has not been initialized. Run `SliceMachineManager.screenshots.prototype.initBrowserContext()` before re-calling this method.", - ); - } -} - const uploadScreenshotLimit = pLimit(10); -/** - * Encodes a part of a Slice Simulator URL to ensure it can be added to a URL - * safely. - * - * The encoding logic must match Slice Machine UI's URL encoding practices. - * Today, that requires the following: - * - * - Replace "/" with "--" (e.g. a Slice Library ID of "./slices" should turn into - * ".--slices") - * - * @param urlPart - A part of the URL. - * - * @returns `urlPart` encoded for use in a URL. - */ -const encodeSliceSimulatorURLPart = (urlPart: string): string => { - return urlPart.replace(/\//g, "--"); -}; - -type ScreenshotsManagerCaptureSliceSimulatorScreenshotArgs = { - sliceMachineUIOrigin: string; - libraryID: string; - sliceID: string; - variationID: string; - viewport?: Viewport; -}; - -type ScreenshotsManagerCaptureSliceSimulatorScreenshotReturnType = { - data: Buffer; -}; - type ScreenshotsManagerUploadScreenshotArgs = { data: Buffer; keyPrefix?: string; @@ -94,35 +38,8 @@ type ScreenshotsManagerDeleteScreenshotFolderArgs = { }; export class ScreenshotsManager extends BaseManager { - private _browserContext: BrowserContext | undefined; private _s3ACL: S3ACL | undefined; - async initBrowserContext(): Promise { - // TODO(DT-1534): Uncomment to enable Puppeteer screenshots or delete if we decide to remove Puppeteer - // - // if (this._browserContext) { - // return; - // } - // - // let puppeteer: typeof import("puppeteer"); - // try { - // // Lazy-load Puppeteer only once it is needed. - // puppeteer = await import("puppeteer"); - // } catch { - // throw new InternalError( - // "Screenshots require Puppeteer but Puppeteer was not found. Check that the `puppeteer` package is installed before trying again.", - // ); - // } - // try { - // const browser = await puppeteer.launch({ headless: "new" }); - // this._browserContext = await browser.createIncognitoBrowserContext(); - // } catch (error) { - // throw new InternalError( - // "Error launching browser. If you're using an Apple Silicon Mac, check if Rosetta is installed.", - // ); - // } - } - async initS3ACL(): Promise { // TODO: we need to find a way to create a new AWS ACL only when necessary (e.g., when it has expired). // if (this._s3ACL) { @@ -184,86 +101,6 @@ export class ScreenshotsManager extends BaseManager { }; } - // TODO: Abstract to a generic `captureScreenshot()` method that is - // used within a Slice-specific method in SliceManager. - async captureSliceSimulatorScreenshot( - args: ScreenshotsManagerCaptureSliceSimulatorScreenshotArgs, - ): Promise { - assertBrowserContextInitialized(this._browserContext); - - const sliceMachineConfig = await this.project.getSliceMachineConfig(); - - if (!sliceMachineConfig.localSliceSimulatorURL) { - // TODO: Provide a more helpful error message. - throw new Error( - "A local Slice Simulator URL must be configured in your Slice Machine configuration file.", - ); - } - - const { model } = await this.slices.readSlice({ - libraryID: args.libraryID, - sliceID: args.sliceID, - }); - if (!model) { - throw new Error( - `Did not find a Slice in library "${args.libraryID}" with ID "${args.sliceID}".`, - ); - } - - const viewport = args.viewport || DEFAULT_SCREENSHOT_VIEWPORT; - - // TODO: Change `model.name` to `args.sliceID`? - // Making that change would require changing the screenshot - // page path in Slice Machine UI. - const url = new URL( - `./${encodeSliceSimulatorURLPart(args.libraryID)}/${model.name}/${ - args.variationID - }/screenshot`, - args.sliceMachineUIOrigin, - ); - url.searchParams.set("screenWidth", viewport.width.toString()); - url.searchParams.set("screenHeight", viewport.height.toString()); - - const isURLAccessible = await checkIsURLAccessible(url.toString()); - - if (!isURLAccessible) { - throw new Error( - `Slice Simulator screenshot URL is not accessible: ${url}`, - ); - } - - const page = await this._browserContext.newPage(); - page.setViewport(viewport); - - await page.goto(url.toString(), { waitUntil: ["load", "networkidle0"] }); - await page.waitForSelector(SLICE_SIMULATOR_WAIT_FOR_SELECTOR, { - timeout: SLICE_SIMULATOR_WAIT_FOR_SELECTOR_TIMEOUT, - }); - - const element = await page.$(SLICE_SIMULATOR_SCREENSHOT_SELECTOR); - if (!element) { - const baseURL = new URL(url.pathname, url.origin); - - throw new Error( - `Slice Simulator did not find ${SLICE_SIMULATOR_WAIT_FOR_SELECTOR} on the page. Verify the URL is correct: ${baseURL}`, - ); - } - - const data = (await element.screenshot({ - encoding: "binary", - clip: { - width: viewport.width, - height: viewport.height, - x: 0, - y: 0, - }, - })) as Buffer; - - return { - data, - }; - } - async uploadScreenshot( args: ScreenshotsManagerUploadScreenshotArgs, ): Promise { diff --git a/packages/manager/src/managers/telemetry/types.ts b/packages/manager/src/managers/telemetry/types.ts index 193321ed4d..4a89077903 100644 --- a/packages/manager/src/managers/telemetry/types.ts +++ b/packages/manager/src/managers/telemetry/types.ts @@ -206,8 +206,8 @@ type LegacySliceConvertedSegmentEvent = SegmentEvent< type ScreenshotTakenSegmentEvent = SegmentEvent< typeof SegmentEventType.screenshotTaken, { - type: "custom" | "automatic"; - method: "fromSimulator" | "upload" | "dragAndDrop"; + type: "custom"; + method: "upload" | "dragAndDrop"; } >; diff --git a/packages/manager/test/SliceMachineManager-screenshots-captureSliceSimulatorScreenshot.test.ts b/packages/manager/test/SliceMachineManager-screenshots-captureSliceSimulatorScreenshot.test.ts deleted file mode 100644 index 5816b77b69..0000000000 --- a/packages/manager/test/SliceMachineManager-screenshots-captureSliceSimulatorScreenshot.test.ts +++ /dev/null @@ -1,334 +0,0 @@ -import { expect, it, vi } from "vitest"; - -import { createPuppeteerMock } from "./__testutils__/createPuppeteerMock"; -import { createTestPlugin } from "./__testutils__/createTestPlugin"; -import { createTestProject } from "./__testutils__/createTestProject"; -import { mockSliceSimulatorEndpoint } from "./__testutils__/mockSliceSimulatorEndpoint"; - -import { createSliceMachineManager } from "../src"; - -const puppeteerMock = createPuppeteerMock(); - -vi.mock("puppeteer", () => { - return puppeteerMock; -}); - -it.skip("captures a Slice Simulator screenshot for a given Slice variation", async (ctx) => { - const model = ctx.mockPrismic.model.sharedSlice(); - const adapter = createTestPlugin({ - setup: ({ hook }) => { - hook("slice:read", () => { - return { model }; - }); - }, - }); - const cwd = await createTestProject({ - adapter, - localSliceSimulatorURL: "https://localhost:3000/slice-simulator", - }); - const manager = createSliceMachineManager({ - nativePlugins: { [adapter.meta.name]: adapter }, - cwd, - }); - - await manager.plugins.initPlugins(); - await manager.screenshots.initBrowserContext(); - - const sliceMachineUIOrigin = "http://localhost:1234"; - const { sliceSimulatorEndpoint } = mockSliceSimulatorEndpoint(ctx, { - sliceMachineUIOrigin, - libraryID: "foo", - sliceName: model.name, - variationID: "baz", - viewport: { - width: 1200, - height: 800, - }, - }); - - const screenshotData = Buffer.from("screenshot-data"); - puppeteerMock.__element__screenshot.mockReturnValueOnce(screenshotData); - - const res = await manager.screenshots.captureSliceSimulatorScreenshot({ - sliceMachineUIOrigin, - libraryID: "foo", - sliceID: model.id, - variationID: "baz", - }); - - expect(res).toStrictEqual({ - data: screenshotData, - }); - expect(puppeteerMock.__page__setViewport).toHaveBeenCalledWith({ - width: 1200, - height: 800, - }); - expect(puppeteerMock.__page__goto).toHaveBeenCalledWith( - sliceSimulatorEndpoint, - { waitUntil: ["load", "networkidle0"] }, - ); - expect(puppeteerMock.__page__waitForSelector).toHaveBeenCalledWith( - "#__iframe-ready", - { timeout: 10_000 }, - ); - expect(puppeteerMock.__page__$).toHaveBeenCalledWith("#__iframe-renderer"); - expect(puppeteerMock.__element__screenshot).toHaveBeenCalledWith({ - encoding: "binary", - clip: { - width: 1200, - height: 800, - x: 0, - y: 0, - }, - }); -}); - -it.skip("can be configured to capture a specific viewport", async (ctx) => { - const model = ctx.mockPrismic.model.sharedSlice(); - const adapter = createTestPlugin({ - setup: ({ hook }) => { - hook("slice:read", () => { - return { model }; - }); - }, - }); - const cwd = await createTestProject({ - adapter, - localSliceSimulatorURL: "https://localhost:3000/slice-simulator", - }); - const manager = createSliceMachineManager({ - nativePlugins: { [adapter.meta.name]: adapter }, - cwd, - }); - - await manager.plugins.initPlugins(); - await manager.screenshots.initBrowserContext(); - - const sliceMachineUIOrigin = "http://localhost:1234"; - const viewport = { width: 200, height: 100 }; - mockSliceSimulatorEndpoint(ctx, { - sliceMachineUIOrigin, - libraryID: "foo", - sliceName: model.name, - variationID: "baz", - viewport, - }); - - const screenshotData = Buffer.from("screenshot-data"); - puppeteerMock.__element__screenshot.mockReturnValueOnce(screenshotData); - - const res = await manager.screenshots.captureSliceSimulatorScreenshot({ - sliceMachineUIOrigin, - libraryID: "foo", - sliceID: model.id, - variationID: "baz", - viewport, - }); - - expect(res).toStrictEqual({ - data: screenshotData, - }); - expect(puppeteerMock.__page__setViewport).toHaveBeenCalledWith({ - width: viewport.width, - height: viewport.height, - }); - expect(puppeteerMock.__element__screenshot).toHaveBeenCalledWith({ - encoding: "binary", - clip: { - width: viewport.width, - height: viewport.height, - x: 0, - y: 0, - }, - }); -}); - -it.skip("throws if the root selector cannot be found", async (ctx) => { - const model = ctx.mockPrismic.model.sharedSlice(); - const adapter = createTestPlugin({ - setup: ({ hook }) => { - hook("slice:read", () => { - return { model }; - }); - }, - }); - const cwd = await createTestProject({ - adapter, - localSliceSimulatorURL: "https://localhost:3000/slice-simulator", - }); - const manager = createSliceMachineManager({ - nativePlugins: { [adapter.meta.name]: adapter }, - cwd, - }); - - await manager.plugins.initPlugins(); - await manager.screenshots.initBrowserContext(); - - const sliceMachineUIOrigin = "http://localhost:1234"; - mockSliceSimulatorEndpoint(ctx, { - sliceMachineUIOrigin, - libraryID: "foo", - sliceName: model.name, - variationID: "baz", - viewport: { - width: 1200, - height: 800, - }, - }); - - puppeteerMock.__page__$.mockReturnValueOnce(null); - - await expect(async () => { - await manager.screenshots.captureSliceSimulatorScreenshot({ - sliceMachineUIOrigin, - libraryID: "foo", - sliceID: model.id, - variationID: "baz", - }); - }).rejects.toThrow(/did not find #__iframe-ready/i); -}); - -it.skip("throws if the Slice model cannot be found", async () => { - const adapter = createTestPlugin({ - setup: ({ hook }) => { - hook("slice:read", () => { - throw new Error("not found"); - }); - }, - }); - const cwd = await createTestProject({ - adapter, - localSliceSimulatorURL: "https://localhost:3000/slice-simulator", - }); - const manager = createSliceMachineManager({ - nativePlugins: { [adapter.meta.name]: adapter }, - cwd, - }); - - await manager.plugins.initPlugins(); - await manager.screenshots.initBrowserContext(); - - await expect(async () => { - await manager.screenshots.captureSliceSimulatorScreenshot({ - sliceMachineUIOrigin: "http://localhost:1234", - libraryID: "foo", - sliceID: "bar", - variationID: "baz", - }); - }).rejects.toThrow(/did not find a slice/i); -}); - -it.skip("throws if a Slice Simulator screenshot URL is not accessible", async (ctx) => { - const model = ctx.mockPrismic.model.sharedSlice(); - const adapter = createTestPlugin({ - setup: ({ hook }) => { - hook("slice:read", () => { - return { model }; - }); - }, - }); - const cwd = await createTestProject({ - adapter, - localSliceSimulatorURL: "https://localhost:3000/slice-simulator", - }); - const manager = createSliceMachineManager({ - nativePlugins: { [adapter.meta.name]: adapter }, - cwd, - }); - - await manager.plugins.initPlugins(); - await manager.screenshots.initBrowserContext(); - - const sliceMachineUIOrigin = "http://localhost:1234"; - mockSliceSimulatorEndpoint(ctx, { - sliceMachineUIOrigin, - libraryID: "foo", - sliceName: model.name, - variationID: "baz", - viewport: { - width: 1200, - height: 800, - }, - exists: false, - }); - - await expect(async () => { - await manager.screenshots.captureSliceSimulatorScreenshot({ - sliceMachineUIOrigin, - libraryID: "foo", - sliceID: "bar", - variationID: "baz", - }); - }).rejects.toThrow(/slice simulator screenshot url is not accessible/i); -}); - -it.skip("throws if a Slice Simulator URL is not configured", async (ctx) => { - const model = ctx.mockPrismic.model.sharedSlice(); - const adapter = createTestPlugin({ - setup: ({ hook }) => { - hook("slice:read", () => { - return { model }; - }); - }, - }); - const cwd = await createTestProject({ adapter }); - const manager = createSliceMachineManager({ - nativePlugins: { [adapter.meta.name]: adapter }, - cwd, - }); - - await manager.plugins.initPlugins(); - await manager.screenshots.initBrowserContext(); - - await expect(async () => { - await manager.screenshots.captureSliceSimulatorScreenshot({ - sliceMachineUIOrigin: "http://localhost:1234", - libraryID: "foo", - sliceID: model.id, - variationID: "baz", - }); - }).rejects.toThrow(/slice simulator url must be configured/i); -}); - -it.skip("throws if a browser context has not been initialized", async () => { - const adapter = createTestPlugin(); - const cwd = await createTestProject({ adapter }); - const manager = createSliceMachineManager({ - nativePlugins: { [adapter.meta.name]: adapter }, - cwd, - }); - - await manager.plugins.initPlugins(); - - await expect(async () => { - await manager.screenshots.captureSliceSimulatorScreenshot({ - sliceMachineUIOrigin: "http://localhost:1234", - libraryID: "foo", - sliceID: "bar", - variationID: "baz", - }); - }).rejects.toThrow(/browser context has not been initialized/i); -}); - -it.skip("throws if plugins have not been initialized", async () => { - const adapter = createTestPlugin(); - const cwd = await createTestProject({ - adapter, - localSliceSimulatorURL: "https://localhost:3000/slice-simulator", - }); - const manager = createSliceMachineManager({ - nativePlugins: { [adapter.meta.name]: adapter }, - cwd, - }); - - await manager.screenshots.initBrowserContext(); - - await expect(async () => { - await manager.screenshots.captureSliceSimulatorScreenshot({ - sliceMachineUIOrigin: "http://localhost:1234", - libraryID: "foo", - sliceID: "bar", - variationID: "baz", - }); - }).rejects.toThrow(/plugins have not been initialized/i); -}); diff --git a/packages/manager/test/SliceMachineManager-screenshots-initBrowserContext.test.ts b/packages/manager/test/SliceMachineManager-screenshots-initBrowserContext.test.ts deleted file mode 100644 index 59286d0042..0000000000 --- a/packages/manager/test/SliceMachineManager-screenshots-initBrowserContext.test.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { expect, it, vi } from "vitest"; - -import { createPuppeteerMock } from "./__testutils__/createPuppeteerMock"; -import { createTestPlugin } from "./__testutils__/createTestPlugin"; -import { createTestProject } from "./__testutils__/createTestProject"; - -import { createSliceMachineManager } from "../src"; - -vi.mock("puppeteer", () => { - return createPuppeteerMock(); -}); - -it.skip("creates a reusable browser context", async () => { - const adapter = createTestPlugin(); - const cwd = await createTestProject({ adapter }); - const manager = createSliceMachineManager({ - nativePlugins: { [adapter.meta.name]: adapter }, - cwd, - }); - - // @ts-expect-error - Accessing an internal private property - expect(manager.screenshots._browserContext).toBe(undefined); - - await manager.screenshots.initBrowserContext(); - - // @ts-expect-error - Accessing an internal private property - expect(manager.screenshots._browserContext).toStrictEqual( - expect.objectContaining({ - newPage: expect.any(Function), - }), - ); -}); diff --git a/packages/manager/test/SliceMachineManager-screenshots-initBrowserContext.without-puppeteer.test.ts b/packages/manager/test/SliceMachineManager-screenshots-initBrowserContext.without-puppeteer.test.ts deleted file mode 100644 index bc34d84635..0000000000 --- a/packages/manager/test/SliceMachineManager-screenshots-initBrowserContext.without-puppeteer.test.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { expect, it, vi } from "vitest"; - -import { createTestPlugin } from "./__testutils__/createTestPlugin"; -import { createTestProject } from "./__testutils__/createTestProject"; - -import { createSliceMachineManager } from "../src"; - -vi.mock("puppeteer", () => { - throw new Error("forced failure"); -}); - -it.skip("throws if Puppeteer is not importable (e.g. not installed)", async () => { - const adapter = createTestPlugin(); - const cwd = await createTestProject({ adapter }); - const manager = createSliceMachineManager({ - nativePlugins: { [adapter.meta.name]: adapter }, - cwd, - }); - - await expect(async () => { - await manager.screenshots.initBrowserContext(); - }).rejects.toThrow(/puppeteer was not found/i); -}); diff --git a/packages/manager/test/__testutils__/createPuppeteerMock.ts b/packages/manager/test/__testutils__/createPuppeteerMock.ts deleted file mode 100644 index dfaa337af1..0000000000 --- a/packages/manager/test/__testutils__/createPuppeteerMock.ts +++ /dev/null @@ -1,114 +0,0 @@ -import { vi } from "vitest"; - -export const createPuppeteerMock = (): { - launch: () => void; - __page__$: { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - mockReturnValueOnce: (args: any) => void; - }; - __browser__createIncognitoBrowserContext: () => void; - __browserContext__newPage: () => void; - __page__goto: () => void; - __element__screenshot: { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - mockReturnValueOnce: (args: any) => void; - }; - __page__setViewport: () => void; - __page__waitForSelector: () => { - mockReturnValueOnce: () => void; - }; -} => { - return { - launch: vi.fn(), - __page__$: { - mockReturnValueOnce: vi.fn(), - }, - __browser__createIncognitoBrowserContext: vi.fn(), - __browserContext__newPage: vi.fn(), - __page__goto: vi.fn(), - __element__screenshot: { - mockReturnValueOnce: vi.fn(), - }, - __page__setViewport: vi.fn(), - __page__waitForSelector: () => ({ - mockReturnValueOnce: vi.fn(), - }), - }; -}; - -// TODO(DT-1534): Uncomment to enable Puppeteer screenshots or delete if we decide to remove Puppeteer -// import type * as puppeteer from "puppeteer"; - -// type CreatePuppeteerMockReturnType = typeof import("puppeteer") & { -// launch: Mock>; -// __browserContext__newPage: Mock< -// Parameters -// >; -// __browser__createIncognitoBrowserContext: Mock< -// Parameters -// >; -// __element__screenshot: Mock< -// Parameters -// >; -// __page__$: Mock>; -// __page__goto: Mock>; -// __page__setViewport: Mock>; -// __page__waitForSelector: Mock>; -// }; - -// export const createPuppeteerMock = (): CreatePuppeteerMockReturnType => { -// const __element__screenshot = -// vi.fn>(); - -// const __page__$ = vi.fn>(() => { -// return { -// screenshot: __element__screenshot, -// }; -// }); - -// const __page__setViewport = vi.fn>( -// () => void 0, -// ); -// const __page__goto = vi.fn>(() => void 0); -// const __page__waitForSelector = vi.fn< -// Parameters -// >(() => void 0); - -// const __browserContext__newPage = vi.fn< -// Parameters -// >(() => { -// return { -// setViewport: __page__setViewport, -// goto: __page__goto, -// waitForSelector: __page__waitForSelector, -// $: __page__$, -// }; -// }); - -// const __browser__createIncognitoBrowserContext = vi.fn< -// Parameters -// >(() => { -// return { -// newPage: __browserContext__newPage, -// }; -// }); - -// const __launch = vi.fn(() => { -// return { -// createIncognitoBrowserContext: __browser__createIncognitoBrowserContext, -// }; -// }); - -// return { -// launch: __launch, -// __page__$, -// __browser__createIncognitoBrowserContext, -// __browserContext__newPage, -// __page__goto, -// __element__screenshot, -// __page__setViewport, -// __page__waitForSelector, -// } as unknown as CreatePuppeteerMockReturnType; -// // If you have time to fix the types so `as unknown as ...` is not -// // required, please fix this! - Angelo 2023-02-22 -// }; diff --git a/packages/manager/test/__testutils__/mockSliceSimulatorEndpoint.ts b/packages/manager/test/__testutils__/mockSliceSimulatorEndpoint.ts deleted file mode 100644 index 2b5a738367..0000000000 --- a/packages/manager/test/__testutils__/mockSliceSimulatorEndpoint.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { TestContext } from "vitest"; -import { rest } from "msw"; - -type MockSliceSimulatorEndpointConfig = { - exists?: boolean; - sliceMachineUIOrigin: string; - libraryID: string; - sliceName: string; - variationID: string; - viewport: { - width: number; - height: number; - }; -}; - -type MockSliceSimulatorEndpointReturnType = { - sliceSimulatorEndpoint: string; -}; - -export const mockSliceSimulatorEndpoint = ( - ctx: TestContext, - config: MockSliceSimulatorEndpointConfig, -): MockSliceSimulatorEndpointReturnType => { - const screenshotEndpoint = new URL( - `./${config.libraryID}/${config.sliceName}/${config.variationID}/screenshot`, - config.sliceMachineUIOrigin, - ); - - ctx.msw.use( - rest.get(screenshotEndpoint.toString(), (req, res, ctx) => { - if (config.exists ?? true) { - if ( - req.url.searchParams.get("screenWidth") === - config.viewport.width.toString() && - req.url.searchParams.get("screenHeight") === - config.viewport.height.toString() - ) { - return res(ctx.status(200)); - } else { - return res(ctx.status(500)); - } - } else { - return res(ctx.status(404)); - } - }), - ); - - const screnshotEndpointWithURLParams = new URL(screenshotEndpoint.toString()); - screnshotEndpointWithURLParams.searchParams.set( - "screenWidth", - config.viewport.width.toString(), - ); - screnshotEndpointWithURLParams.searchParams.set( - "screenHeight", - config.viewport.height.toString(), - ); - - return { - sliceSimulatorEndpoint: screnshotEndpointWithURLParams.toString(), - }; -}; diff --git a/packages/slice-machine/components/ScreenshotToaster/index.tsx b/packages/slice-machine/components/ScreenshotToaster/index.tsx deleted file mode 100644 index 92c0afa368..0000000000 --- a/packages/slice-machine/components/ScreenshotToaster/index.tsx +++ /dev/null @@ -1,53 +0,0 @@ -import useSliceMachineActions from "@src/modules/useSliceMachineActions"; -import { FC } from "react"; -import { Container, Flex, Image, Text } from "theme-ui"; - -type ScreenshotToasterProps = { - url: string; -}; - -const ScreenshotToaster: FC = ({ url }) => { - const { openScreenshotPreviewModal } = useSliceMachineActions(); - - return ( - - - - - - - Screenshot taken - - - Tap to view screenshot - - - - ); -}; - -export default ScreenshotToaster; diff --git a/packages/slice-machine/components/Simulator/components/IframeRenderer/index.tsx b/packages/slice-machine/components/Simulator/components/IframeRenderer/index.tsx index a9e6354c40..0dea42cb92 100644 --- a/packages/slice-machine/components/Simulator/components/IframeRenderer/index.tsx +++ b/packages/slice-machine/components/Simulator/components/IframeRenderer/index.tsx @@ -125,7 +125,6 @@ const IframeRenderer: React.FunctionComponent = ({ {/* eslint-disable-next-line @typescript-eslint/strict-boolean-expressions */} {simulatorUrl ? (