Skip to content

Commit

Permalink
ignore all screenshots
Browse files Browse the repository at this point in the history
  • Loading branch information
alextaing committed Oct 17, 2023
1 parent dabec5d commit a072c4d
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 43 deletions.
3 changes: 1 addition & 2 deletions e2e-tests/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { PlaywrightTestConfig, expect } from "@playwright/test";
import fs from "node:fs";
import os from "node:os";

expect.extend({
async toHaveContents(filepath: string, expectedContents: string) {
Expand Down Expand Up @@ -52,7 +51,7 @@ const config: PlaywrightTestConfig = {
video: "on",
},
workers: 1,
ignoreSnapshots: os.platform() !== "darwin",
ignoreSnapshots: true,
};

export default config;
2 changes: 1 addition & 1 deletion packages/studio-ui/src/AppWithLazyLoading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import LoadingOverlay from "./components/LoadingOverlay";
import { Suspense, lazy, useEffect, useState } from "react";
import useStudioStore from "./store/useStudioStore";
import ProgressBar from "./components/ProgressBar";
import { loadComponents, loadStyling } from "./utils/preloadStudio";
import { loadComponents, loadStyling } from "./utils/loadUserAssets";
import classNames from "classnames";

const AppPromise = import("./App");
Expand Down
41 changes: 27 additions & 14 deletions packages/studio-ui/src/components/IFramePortal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,33 +67,46 @@ function useInjectUserStyles(iframeDocument: Document | undefined) {
});
});
pageCss?.forEach((cssFilepath) => {
injectStyleIntoIframe(iframeDocument, cssFilepath);
injectStyleIntoIframe(iframeDocument, cssFilepath);
});

return () => {
clearStylingFromIframe(iframeDocument);
};
}, [componentTree, getComponentMetadata, iframeDocument, pageCss, activePage, UUIDToFileMetadata]);
}, [
componentTree,
getComponentMetadata,
iframeDocument,
pageCss,
activePage,
UUIDToFileMetadata,
]);
}

function clearStylingFromIframe(iframeDocument: Document) {
const styleElements = Array.from(
iframeDocument.head.getElementsByTagName("style")
);
for (const el of styleElements) {
el.remove();
}
const styleElements = [...iframeDocument.head.getElementsByTagName("style")];
styleElements.forEach((element) => {
element.remove();
});
}

function injectStyleIntoIframe(iframeDocument: Document | undefined, filepath: string) {
const originalStyletag = document.querySelector(`[studio-style-filepath='${filepath}']`)
if (originalStyletag && iframeDocument) {
const iframeStyletag = originalStyletag.cloneNode(true)
iframeDocument.head.appendChild(iframeStyletag)
function injectStyleIntoIframe(
iframeDocument: Document,
filepath: string
) {
const originalStyletag = document.querySelector(
`[studio-style-filepath='${filepath}']`
);
if (originalStyletag) {
const iframeStyletag = originalStyletag.cloneNode(true);
iframeDocument.head.appendChild(iframeStyletag);
}
}

const useViewportOption = (viewport: Viewport, previewRef: RefObject<HTMLDivElement>) => {
const useViewportOption = (
viewport: Viewport,
previewRef: RefObject<HTMLDivElement>
) => {
const [css, setCss] = useState(
(viewport.styles?.width ?? 0) * (previewRef.current?.clientHeight ?? 0) >
(viewport.styles?.height ?? 0) * (previewRef.current?.clientWidth ?? 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,41 +28,35 @@ export function loadComponents(): Promise<void>[] {
}

/**
* Load all user styling as disabled style tags in Studio's iframe.
* Load all user styling as disabled style tags in Studio's head.
*/
export function loadStyling() {
const studioStore = useStudioStore.getState()
const UUIDToFileMetadata = studioStore.fileMetadatas.UUIDToFileMetadata
const pages = studioStore.pages.pages
const studioStore = useStudioStore.getState();
const UUIDToFileMetadata = studioStore.fileMetadatas.UUIDToFileMetadata;
const pages = studioStore.pages.pages;

Object.values(UUIDToFileMetadata).forEach(
(fileMetadata) => {
if (fileMetadata.kind === FileMetadataKind.Component) {
importAndInjectIntoStudio(fileMetadata.cssImports);
}
Object.values(UUIDToFileMetadata).forEach((fileMetadata) => {
if (fileMetadata.kind === FileMetadataKind.Component) {
importAndInjectIntoStudio(fileMetadata.cssImports);
}
);
});

Object.values(pages).forEach(
(page) => {
importAndInjectIntoStudio(page.cssImports);
}
);
Object.values(pages).forEach((page) => {
importAndInjectIntoStudio(page.cssImports);
});
}

function importAndInjectIntoStudio(cssImports: string[]) {
cssImports.forEach(async (filepath) => {
await dynamicImportFromBrowser(
filepath
).then((styling) => {
if (document.querySelector(`[studio-style-filepath='${filepath}']`)){
return
await dynamicImportFromBrowser(filepath).then((styling) => {
if (document.querySelector(`[studio-style-filepath='${filepath}']`)) {
return;
}
const styleEl = document.createElement("style")
const styleEl = document.createElement("style");
styleEl.innerText = styling.default;
styleEl.setAttribute("studio-style-filepath", filepath)
document.head.appendChild(styleEl)
styleEl.setAttribute("studio-style-filepath", filepath);
document.head.appendChild(styleEl);
styleEl.disabled = true;
});
})
});
}
2 changes: 1 addition & 1 deletion packages/studio-ui/tests/components/PreviewPanel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
PropValueKind,
PropValueType,
} from "@yext/studio-plugin";
import loadComponents from "../../src/utils/loadComponents";
import { loadComponents } from "../../src/utils/loadUserAssets";

const mockSetState = jest.fn();

Expand Down
2 changes: 1 addition & 1 deletion packages/studio-ui/tests/utils/loadComponents.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FileMetadataKind } from "@yext/studio-plugin";
import loadComponents from "../../src/utils/loadComponents";
import { loadComponents } from "../../src/utils/loadUserAssets";
import mockStore, { MockStudioStore } from "../__utils__/mockStore";
import path from "path";
import { waitFor } from "@testing-library/react";
Expand Down

0 comments on commit a072c4d

Please sign in to comment.