1
0

fullstack.spec.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // @ts-check
  2. const { test, expect } = require("@playwright/test");
  3. test("hydration", async ({ page }) => {
  4. await page.goto("http://localhost:3333");
  5. // Expect the page to contain the pending text.
  6. const main = page.locator("#main");
  7. await expect(main).toContainText("Server said: ...");
  8. // Expect the page to contain the counter text.
  9. await expect(main).toContainText("hello axum! 12345");
  10. // Expect the title to contain the counter text.
  11. await expect(page).toHaveTitle("hello axum! 12345");
  12. // Click the increment button.
  13. let button = page.locator("button.increment-button");
  14. await button.click();
  15. // Click the server button.
  16. let serverButton = page.locator("button.server-button");
  17. await serverButton.click();
  18. // Expect the page to contain the updated counter text.
  19. await expect(main).toContainText("hello axum! 12346");
  20. // Expect the title to contain the updated counter text.
  21. await expect(page).toHaveTitle("hello axum! 12346");
  22. // Expect the page to contain the updated counter text.
  23. await expect(main).toContainText("Server said: Hello from the server!");
  24. // Make sure the error that was thrown on the server is shown in the error boundary on the client
  25. const errors = page.locator("#errors");
  26. await expect(errors).toContainText("Hmm, something went wrong.");
  27. // Expect the onmounted event to be called exactly once.
  28. const mountedDiv = page.locator("div.onmounted-div");
  29. await expect(mountedDiv).toHaveText("onmounted was called 1 times");
  30. });
  31. test("document elements", async ({ page }) => {
  32. await page.goto("http://localhost:3333");
  33. // wait until the meta element is mounted
  34. const meta = page.locator("meta#meta-head[name='testing']");
  35. await meta.waitFor({ state: "attached" });
  36. await expect(meta).toHaveAttribute("data", "dioxus-meta-element");
  37. const link = page.locator("link#link-head[rel='stylesheet']");
  38. await link.waitFor({ state: "attached" });
  39. await expect(link).toHaveAttribute(
  40. "href",
  41. "https://fonts.googleapis.com/css?family=Roboto+Mono"
  42. );
  43. const stylesheet = page.locator("link#stylesheet-head[rel='stylesheet']");
  44. await stylesheet.waitFor({ state: "attached" });
  45. await expect(stylesheet).toHaveAttribute(
  46. "href",
  47. "https://fonts.googleapis.com/css?family=Roboto:300,300italic,700,700italic"
  48. );
  49. const script = page.locator("script#script-head");
  50. await script.waitFor({ state: "attached" });
  51. await expect(script).toHaveAttribute("async", "true");
  52. const style = page.locator("style#style-head");
  53. await style.waitFor({ state: "attached" });
  54. const main = page.locator("#main");
  55. await expect(main).toHaveCSS("font-family", "Roboto");
  56. });
  57. test("assets cache correctly", async ({ page }) => {
  58. // Wait for the hashed image to be loaded
  59. const hashedImageFuture = page.waitForResponse((resp) => {
  60. console.log("Response URL:", resp.url());
  61. return resp.url().includes("/assets/image-") && resp.status() === 200;
  62. });
  63. // Navigate to the page that includes the image.
  64. await page.goto("http://localhost:3333");
  65. const hashedImageResponse = await hashedImageFuture;
  66. // Make sure the hashed image cache control header is set to immutable
  67. const cacheControl = hashedImageResponse.headers()["cache-control"];
  68. console.log("Cache-Control header:", cacheControl);
  69. expect(cacheControl).toContain("immutable");
  70. // TODO: raw assets support was removed and needs to be restored
  71. // https://github.com/DioxusLabs/dioxus/issues/4115
  72. // // Wait for the asset image to be loaded
  73. // const assetImageResponse = await page.waitForResponse(
  74. // (resp) => resp.url().includes("/assets/image.png") && resp.status() === 200
  75. // );
  76. // // Make sure the asset image cache control header does not contain immutable
  77. // const assetCacheControl = assetImageResponse.headers()["cache-control"];
  78. // console.log("Cache-Control header:", assetCacheControl);
  79. // expect(assetCacheControl).not.toContain("immutable");
  80. // // Wait for the nested asset image to be loaded
  81. // const nestedAssetImageResponse = await page.waitForResponse(
  82. // (resp) =>
  83. // resp.url().includes("/assets/nested/image.png") && resp.status() === 200
  84. // );
  85. // // Make sure the nested asset image cache control header does not contain immutable
  86. // const nestedAssetCacheControl =
  87. // nestedAssetImageResponse.headers()["cache-control"];
  88. // console.log("Cache-Control header:", nestedAssetCacheControl);
  89. // expect(nestedAssetCacheControl).not.toContain("immutable");
  90. });
  91. test("websockets", async ({ page }) => {
  92. await page.goto("http://localhost:3333");
  93. // wait until the websocket div is mounted
  94. const wsDiv = page.locator("div#websocket-div");
  95. await expect(wsDiv).toHaveText("Received: HELLO WORLD");
  96. });