diff --git a/playwright-tests/tests/redirectmap.spec.js b/playwright-tests/tests/redirectmap.spec.js index 25cd9ed..a7d3495 100644 --- a/playwright-tests/tests/redirectmap.spec.js +++ b/playwright-tests/tests/redirectmap.spec.js @@ -46,150 +46,154 @@ describe("session-storage", () => { ); }); }); +}); - describe("hot-reload", () => { - test.beforeEach(async ({ page }) => { - await page.goto("/"); - }); - - test("should trigger api request to */socket.io/* if hot reload is enabled", async ({ - page, - }) => { - let websocketCount = 0; - - await page.route("**/socket.io/*", (route) => { - websocketCount++; - route.continue(); - }); +describe("hot-reload", () => { + test.beforeEach(async ({ page }) => { + await page.goto("/"); + }); - await page.evaluate(() => { - document.body.innerHTML = ``; - }); + test("should trigger api request to */socket.io/* if hot reload is enabled", async ({ + page, + }) => { + let websocketCount = 0; - await waitForSelectorToBeVisible(page, "near-social-viewer"); + await page.route("**/socket.io/*", (route) => { + websocketCount++; + route.continue(); + }); - expect(websocketCount).toBeGreaterThan(0); + await page.evaluate(() => { + document.body.innerHTML = ``; }); - test("should not trigger api request to */socket.io/* if hot reload is not enabled", async ({ - page, - }) => { - let websocketCount = 0; + await waitForSelectorToBeVisible(page, "near-social-viewer"); - await page.route("**/socket.io/*", (route) => { - websocketCount++; - route.continue(); - }); + expect(websocketCount).toBeGreaterThan(0); + }); - await page.evaluate(() => { - document.body.innerHTML = ``; - }); + test("should not trigger api request to */socket.io/* if hot reload is not enabled", async ({ + page, + }) => { + let websocketCount = 0; - await waitForSelectorToBeVisible(page, "near-social-viewer"); + await page.route("**/socket.io/*", (route) => { + websocketCount++; + route.continue(); + }); - expect(websocketCount).toEqual(0); + await page.evaluate(() => { + document.body.innerHTML = ``; }); - describe("with running socket server", () => { - let io, httpServer; - const PORT = 3001; - let HOST = "localhost"; + await waitForSelectorToBeVisible(page, "near-social-viewer"); - test.beforeAll(async () => { - httpServer = http.createServer(); + expect(websocketCount).toEqual(0); + }); - io = new Server(httpServer, { - cors: { - origin: `http://${HOST}:3000`, - methods: ["GET", "POST"], - }, - }); + describe("with running socket server", () => { + let io, httpServer; + const PORT = 3001; + let HOST = "localhost"; - io.on("connection", () => { - io.emit("fileChange", { + test.beforeAll(async () => { + httpServer = http.createServer(); + + io = new Server(httpServer, { + cors: { + origin: `http://${HOST}:3000`, + methods: ["GET", "POST"], + }, + }); + + io.on("connection", () => { + io.emit("fileChange", { + components: { "anybody.near/widget/test": { code: "return

hello world

;", }, - }); + }, }); + }); - // wait for socket start - await new Promise((resolve) => { - httpServer.listen(PORT, HOST, () => { - resolve(); - }); + // wait for socket start + await new Promise((resolve) => { + httpServer.listen(PORT, HOST, () => { + resolve(); }); }); + }); - test("should show local redirect map and react to changes", async ({ - page, - }) => { - // Verify the viewer is visible - await waitForSelectorToBeVisible(page, "near-social-viewer"); + test("should show local redirect map and react to changes", async ({ + page, + }) => { + // Verify the viewer is visible + await waitForSelectorToBeVisible(page, "near-social-viewer"); - await page.evaluate(() => { - const viewer = document.querySelector("near-social-viewer"); - viewer.setAttribute("src", "anybody.near/widget/test"); // this code does not exist - }); + await page.evaluate(() => { + const viewer = document.querySelector("near-social-viewer"); + viewer.setAttribute("src", "anybody.near/widget/test"); // this code does not exist + }); - await page.waitForSelector( - 'div.alert.alert-danger:has-text("is not found")' - ); + await page.waitForSelector( + 'div.alert.alert-danger:has-text("is not found")' + ); - // Verify error - const errMsg = await page.locator( - 'div.alert.alert-danger:has-text("is not found")' - ); + // Verify error + const errMsg = await page.locator( + 'div.alert.alert-danger:has-text("is not found")' + ); - expect(await errMsg.isVisible()).toBe(true); + expect(await errMsg.isVisible()).toBe(true); - let websocketCount = 0; + let websocketCount = 0; - await page.route("**/socket.io/*", (route) => { - websocketCount++; - route.continue(); - }); + await page.route("**/socket.io/*", (route) => { + websocketCount++; + route.continue(); + }); - const config = { - dev: { hotreload: { enabled: true, wss: `ws://${HOST}:${PORT}` } }, - }; + const config = { + dev: { hotreload: { enabled: true, wss: `ws://${HOST}:${PORT}` } }, + }; - // Enable hot reload - await page.evaluate( - ({ config }) => { - const viewer = document.querySelector("near-social-viewer"); - viewer.setAttribute("config", JSON.stringify(config)); - }, - { config } - ); + // Enable hot reload + await page.evaluate( + ({ config }) => { + const viewer = document.querySelector("near-social-viewer"); + viewer.setAttribute("config", JSON.stringify(config)); + }, + { config } + ); - await page.waitForSelector("near-social-viewer"); + await page.waitForSelector("near-social-viewer"); - // Get the value of the config attribute - const actualConfig = await page.evaluate(() => { - const viewer = document.querySelector("near-social-viewer"); - return viewer.getAttribute("config"); - }); + // Get the value of the config attribute + const actualConfig = await page.evaluate(() => { + const viewer = document.querySelector("near-social-viewer"); + return viewer.getAttribute("config"); + }); - // Assert it is set and equals custom value - expect(actualConfig).toBe(JSON.stringify(config)); + // Assert it is set and equals custom value + expect(actualConfig).toBe(JSON.stringify(config)); - // Assert web socket was hit - expect(websocketCount).toBeGreaterThan(0); + // Assert web socket was hit + expect(websocketCount).toBeGreaterThan(0); - await expect(await page.getByText("hello world")).toBeVisible(); + await expect(await page.getByText("hello world")).toBeVisible(); - io.emit("fileChange", { + io.emit("fileChange", { + components: { "anybody.near/widget/test": { code: "return

goodbye world

;" }, - }); - - await expect(await page.getByText("goodbye world")).toBeVisible(); + }, }); - test.afterAll(() => { - io.close(); - httpServer.close(); - }); + await expect(await page.getByText("goodbye world")).toBeVisible(); + }); + + test.afterAll(() => { + io.close(); + httpServer.close(); }); }); }); diff --git a/src/utils/bos-workspace.js b/src/utils/bos-workspace.js index 735ac0c..3f997f4 100644 --- a/src/utils/bos-workspace.js +++ b/src/utils/bos-workspace.js @@ -38,7 +38,7 @@ export function useRedirectMap() { socket.on("fileChange", (d) => { console.log("File change detected via WebSocket", d); - setDevJson(d); + setDevJson(d.components); }); socket.on("connect_error", (error) => {