@marimo-team/islands 0.25.1-dev40 → 0.25.1-dev42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marimo-team/islands",
3
- "version": "0.25.1-dev40",
3
+ "version": "0.25.1-dev42",
4
4
  "main": "dist/main.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
@@ -39,6 +39,6 @@
39
39
 
40
40
  ul,
41
41
  ol {
42
- padding-left: 10px;
42
+ padding-left: 24px;
43
43
  }
44
44
  }
@@ -0,0 +1,154 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ import { fireEvent, render, screen, waitFor } from "@testing-library/react";
4
+ import type React from "react";
5
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
6
+ import { Dialog } from "@/components/ui/dialog";
7
+ import { TooltipProvider } from "@/components/ui/tooltip";
8
+ import { ShareStaticNotebookModal } from "../share-modal";
9
+ import { stageForPublish } from "../stage-for-publish";
10
+
11
+ const exportAsHTML = vi.fn();
12
+
13
+ vi.mock("@/core/network/requests", () => ({
14
+ useRequestClient: () => ({ exportAsHTML }),
15
+ }));
16
+ vi.mock("@/core/export/layout", () => ({
17
+ getExportLayout: vi.fn().mockResolvedValue(undefined),
18
+ }));
19
+ vi.mock("@/core/static/virtual-file-tracker", () => ({
20
+ VirtualFileTracker: { INSTANCE: { filenames: () => [] } },
21
+ }));
22
+ vi.mock("../stage-for-publish", () => ({
23
+ stageForPublish: vi.fn(),
24
+ }));
25
+
26
+ const stageForPublishMock = vi.mocked(stageForPublish);
27
+ const CLAIM_URL = "https://claim.example/abc";
28
+
29
+ function wrapper({ children }: { children: React.ReactNode }) {
30
+ return (
31
+ <TooltipProvider>
32
+ <Dialog open={true}>{children}</Dialog>
33
+ </TooltipProvider>
34
+ );
35
+ }
36
+
37
+ describe("ShareStaticNotebookModal", () => {
38
+ const onClose = vi.fn();
39
+ const windowOpen = vi.fn<typeof window.open>();
40
+
41
+ beforeEach(() => {
42
+ vi.clearAllMocks();
43
+ vi.stubGlobal("open", windowOpen);
44
+ exportAsHTML.mockResolvedValue({
45
+ contents: "<html></html>",
46
+ filename: "nb.html",
47
+ });
48
+ });
49
+
50
+ afterEach(() => {
51
+ vi.unstubAllGlobals();
52
+ });
53
+
54
+ function renderModal() {
55
+ return render(<ShareStaticNotebookModal onClose={onClose} />, {
56
+ wrapper,
57
+ });
58
+ }
59
+
60
+ it("exports with CDN assets, opens the claim page, and keeps the link in the dialog", async () => {
61
+ stageForPublishMock.mockResolvedValue(CLAIM_URL);
62
+ renderModal();
63
+
64
+ fireEvent.click(screen.getByTestId("share-static-notebook-button"));
65
+
66
+ const link = await screen.findByTestId("open-claim-page-link");
67
+ expect(link).toHaveAttribute("href", CLAIM_URL);
68
+ expect(link).toHaveAttribute("rel", "noopener noreferrer");
69
+ expect(link).toHaveAttribute("target", "_blank");
70
+
71
+ expect(windowOpen).toHaveBeenCalledWith(
72
+ CLAIM_URL,
73
+ "_blank",
74
+ "noopener,noreferrer",
75
+ );
76
+ expect(exportAsHTML).toHaveBeenCalledWith(
77
+ expect.objectContaining({
78
+ includeCode: true,
79
+ download: false,
80
+ assetUrl: expect.stringContaining("cdn.jsdelivr.net"),
81
+ }),
82
+ );
83
+ expect(stageForPublishMock).toHaveBeenCalledWith(
84
+ "nb.html",
85
+ "<html></html>",
86
+ );
87
+ // The dialog stays open so the link survives a blocked popup.
88
+ expect(onClose).not.toHaveBeenCalled();
89
+ expect(
90
+ screen.queryByTestId("share-static-notebook-button"),
91
+ ).not.toBeInTheDocument();
92
+ });
93
+
94
+ it("closes from the staged view via Done", async () => {
95
+ stageForPublishMock.mockResolvedValue(CLAIM_URL);
96
+ renderModal();
97
+
98
+ fireEvent.click(screen.getByTestId("share-static-notebook-button"));
99
+ fireEvent.click(
100
+ await screen.findByTestId("done-share-static-notebook-button"),
101
+ );
102
+
103
+ expect(onClose).toHaveBeenCalledTimes(1);
104
+ });
105
+
106
+ it("shows the failure in the dialog and allows retrying", async () => {
107
+ stageForPublishMock
108
+ .mockRejectedValueOnce(new Error("Too many uploads, try again later"))
109
+ .mockResolvedValueOnce(CLAIM_URL);
110
+ renderModal();
111
+
112
+ fireEvent.click(screen.getByTestId("share-static-notebook-button"));
113
+
114
+ const error = await screen.findByTestId("share-static-notebook-error");
115
+ expect(error).toHaveTextContent(
116
+ "Publish failed: Too many uploads, try again later",
117
+ );
118
+ expect(windowOpen).not.toHaveBeenCalled();
119
+ expect(onClose).not.toHaveBeenCalled();
120
+
121
+ const retry = screen.getByTestId("share-static-notebook-button");
122
+ expect(retry).toHaveTextContent("Try again");
123
+ expect(retry).toBeEnabled();
124
+ fireEvent.click(retry);
125
+
126
+ expect(await screen.findByTestId("open-claim-page-link")).toHaveAttribute(
127
+ "href",
128
+ CLAIM_URL,
129
+ );
130
+ });
131
+
132
+ it("disables both buttons while staging", async () => {
133
+ let resolveStage: (url: string) => void = () => undefined;
134
+ stageForPublishMock.mockImplementation(
135
+ () =>
136
+ new Promise<string>((resolve) => {
137
+ resolveStage = resolve;
138
+ }),
139
+ );
140
+ renderModal();
141
+
142
+ fireEvent.click(screen.getByTestId("share-static-notebook-button"));
143
+
144
+ await waitFor(() => {
145
+ expect(screen.getByTestId("share-static-notebook-button")).toBeDisabled();
146
+ });
147
+ expect(
148
+ screen.getByTestId("cancel-share-static-notebook-button"),
149
+ ).toBeDisabled();
150
+
151
+ resolveStage(CLAIM_URL);
152
+ await screen.findByTestId("open-claim-page-link");
153
+ });
154
+ });
@@ -0,0 +1,111 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
4
+ import { MAX_PUBLISH_BYTES, stageForPublish } from "../stage-for-publish";
5
+
6
+ // Opaque to the client; the shapes here are deliberately not molab's.
7
+ const PENDING = {
8
+ pendingId: "id-1",
9
+ presignedUrl: "https://upload.example/put?token=abc",
10
+ claimUrl: "https://claim.example/abc",
11
+ expiresAt: "2026-01-01T00:00:00Z",
12
+ };
13
+
14
+ function jsonResponse(body: unknown, status = 200): Response {
15
+ return new Response(JSON.stringify(body), {
16
+ status,
17
+ headers: { "Content-Type": "application/json" },
18
+ });
19
+ }
20
+
21
+ describe("stageForPublish", () => {
22
+ const fetchMock = vi.fn<typeof fetch>();
23
+
24
+ beforeEach(() => {
25
+ vi.stubGlobal("fetch", fetchMock);
26
+ });
27
+
28
+ afterEach(() => {
29
+ fetchMock.mockReset();
30
+ vi.unstubAllGlobals();
31
+ });
32
+
33
+ it("reserves a pending upload, PUTs the export, and returns the claim URL", async () => {
34
+ fetchMock
35
+ .mockResolvedValueOnce(jsonResponse(PENDING))
36
+ .mockResolvedValueOnce(new Response(null, { status: 200 }));
37
+
38
+ const claimUrl = await stageForPublish("nb.html", "<html>hi</html>");
39
+
40
+ expect(claimUrl).toBe(PENDING.claimUrl);
41
+ expect(fetchMock).toHaveBeenCalledTimes(2);
42
+
43
+ const [stageUrl, stageInit] = fetchMock.mock.calls[0];
44
+ expect(String(stageUrl)).toMatch(/\/api\/artifacts\/pending$/);
45
+ expect(stageInit?.method).toBe("POST");
46
+ expect(JSON.parse(String(stageInit?.body))).toEqual({
47
+ fileName: "nb.html",
48
+ fileSize: new Blob(["<html>hi</html>"]).size,
49
+ });
50
+
51
+ const [putUrl, putInit] = fetchMock.mock.calls[1];
52
+ expect(putUrl).toBe(PENDING.presignedUrl);
53
+ expect(putInit?.method).toBe("PUT");
54
+ expect(putInit?.body).toBeInstanceOf(Blob);
55
+ });
56
+
57
+ it("surfaces the server's error message when staging is rejected", async () => {
58
+ fetchMock.mockResolvedValueOnce(
59
+ jsonResponse({ error: "Only .html or .htm files are supported" }, 400),
60
+ );
61
+
62
+ await expect(stageForPublish("nb.txt", "x")).rejects.toThrow(
63
+ "Only .html or .htm files are supported",
64
+ );
65
+ expect(fetchMock).toHaveBeenCalledTimes(1);
66
+ });
67
+
68
+ it("explains a 429 when the body carries no message", async () => {
69
+ fetchMock.mockResolvedValueOnce(new Response("", { status: 429 }));
70
+
71
+ await expect(stageForPublish("nb.html", "x")).rejects.toThrow(
72
+ "Too many uploads, try again later",
73
+ );
74
+ });
75
+
76
+ it("falls back to a generic message for other bodiless failures", async () => {
77
+ fetchMock.mockResolvedValueOnce(new Response("", { status: 500 }));
78
+
79
+ await expect(stageForPublish("nb.html", "x")).rejects.toThrow(
80
+ "Failed to prepare the upload",
81
+ );
82
+ });
83
+
84
+ it("fails when the presigned PUT is rejected", async () => {
85
+ fetchMock
86
+ .mockResolvedValueOnce(jsonResponse(PENDING))
87
+ .mockResolvedValueOnce(new Response(null, { status: 403 }));
88
+
89
+ await expect(stageForPublish("nb.html", "x")).rejects.toThrow(
90
+ "Failed to upload the notebook export",
91
+ );
92
+ });
93
+
94
+ it("rejects exports over the size limit before touching the network", async () => {
95
+ // Stub Blob so the test doesn't allocate 100 MB.
96
+ const RealBlob = globalThis.Blob;
97
+ vi.stubGlobal(
98
+ "Blob",
99
+ class extends RealBlob {
100
+ override get size() {
101
+ return MAX_PUBLISH_BYTES + 1;
102
+ }
103
+ },
104
+ );
105
+
106
+ await expect(stageForPublish("nb.html", "x")).rejects.toThrow(
107
+ "File is too large. Maximum size is 100 MB.",
108
+ );
109
+ expect(fetchMock).not.toHaveBeenCalled();
110
+ });
111
+ });
@@ -1,7 +1,8 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
2
 
3
- import { CopyIcon } from "lucide-react";
4
- import React, { useMemo, useState } from "react";
3
+ import { ExternalLinkIcon } from "lucide-react";
4
+ import type React from "react";
5
+ import { useState } from "react";
5
6
  import { Button } from "@/components/ui/button";
6
7
  import {
7
8
  DialogContent,
@@ -10,176 +11,144 @@ import {
10
11
  DialogHeader,
11
12
  DialogTitle,
12
13
  } from "@/components/ui/dialog";
13
- import { toast } from "@/components/ui/use-toast";
14
14
  import { Constants } from "@/core/constants";
15
15
  import { getExportLayout } from "@/core/export/layout";
16
16
  import { useRequestClient } from "@/core/network/requests";
17
17
  import { VirtualFileTracker } from "@/core/static/virtual-file-tracker";
18
- import { copyToClipboard } from "@/utils/copy";
19
- import { Events } from "@/utils/events";
20
- import { Input } from "../ui/input";
21
- import { Tooltip } from "../ui/tooltip";
18
+ import { Spinner } from "../icons/spinner";
19
+ import { stageForPublish } from "./stage-for-publish";
20
+
21
+ type PublishState =
22
+ | { kind: "idle" }
23
+ | { kind: "publishing" }
24
+ | { kind: "staged"; claimUrl: string }
25
+ | { kind: "failed"; message: string };
22
26
 
23
- const BASE_URL = "https://static.marimo.app";
24
27
  export const ShareStaticNotebookModal: React.FC<{
25
28
  onClose: () => void;
26
29
  }> = ({ onClose }) => {
27
- const [slug, setSlug] = useState("");
30
+ const [state, setState] = useState<PublishState>({ kind: "idle" });
28
31
  const { exportAsHTML } = useRequestClient();
29
32
 
30
- // Keep one random suffix for the lifetime of the modal.
31
- // oxlint-disable-next-line react/purity
32
- const randomHash = useMemo(() => Math.random().toString(36).slice(2, 6), []);
33
-
34
- // Globally unique path
35
- const path = `${slug}-${randomHash}`;
36
- const url = `${BASE_URL}/static/${path}`;
37
-
38
- return (
39
- <DialogContent className="w-fit">
40
- <form
41
- onSubmit={async (e) => {
42
- e.preventDefault();
43
-
44
- onClose();
45
- const { contents: html } = await exportAsHTML({
46
- download: false,
47
- includeCode: true,
48
- files: VirtualFileTracker.INSTANCE.filenames(),
49
- layout: await getExportLayout(),
50
- });
33
+ const handlePublish = async () => {
34
+ setState({ kind: "publishing" });
35
+ try {
36
+ const { contents: html, filename } = await exportAsHTML({
37
+ download: false,
38
+ includeCode: true,
39
+ files: VirtualFileTracker.INSTANCE.filenames(),
40
+ layout: await getExportLayout(),
41
+ // Published notebooks are served from a remote origin, so assets must
42
+ // come from the CDN — never the local server (which is the dev-mode
43
+ // default). The server substitutes {version}.
44
+ assetUrl:
45
+ "https://cdn.jsdelivr.net/npm/@marimo-team/frontend@{version}/dist",
46
+ });
51
47
 
52
- const prevToast = toast({
53
- title: "Uploading static notebook...",
54
- description: "Please wait.",
55
- });
48
+ const claimUrl = await stageForPublish(filename, html);
56
49
 
57
- await fetch(`${BASE_URL}/api/static`, {
58
- method: "POST",
59
- headers: {
60
- "Content-Type": "application/json",
61
- },
62
- body: JSON.stringify({
63
- html: html,
64
- path: path,
65
- }),
66
- }).catch(() => {
67
- prevToast.dismiss();
68
- toast({
69
- title: "Error uploading static page",
70
- description: (
71
- <div>
72
- Please try again later. If the problem persists, please file a
73
- bug report on{" "}
74
- <a
75
- href={Constants.issuesPage}
76
- target="_blank"
77
- rel="noreferrer"
78
- className="underline"
79
- >
80
- GitHub
81
- </a>
82
- .
83
- </div>
84
- ),
85
- });
86
- });
50
+ // Best effort: after the async work above, browsers may treat this as a
51
+ // popup and block it. The dialog keeps the link either way.
52
+ window.open(claimUrl, "_blank", "noopener,noreferrer");
53
+ setState({ kind: "staged", claimUrl });
54
+ } catch (error) {
55
+ setState({
56
+ kind: "failed",
57
+ message:
58
+ error instanceof Error ? error.message : "Something went wrong",
59
+ });
60
+ }
61
+ };
87
62
 
88
- prevToast.dismiss();
89
- toast({
90
- title: "Static page uploaded!",
91
- description: (
92
- <div>
93
- The URL has been copied to your clipboard.
94
- <br />
95
- You can share it with anyone.
96
- </div>
97
- ),
98
- });
99
- }}
100
- >
63
+ if (state.kind === "staged") {
64
+ return (
65
+ <DialogContent className="sm:max-w-[480px]">
101
66
  <DialogHeader>
102
- <DialogTitle>Share static notebook</DialogTitle>
67
+ <DialogTitle>Finish publishing</DialogTitle>
103
68
  <DialogDescription>
104
- You can publish a static, non-interactive version of this notebook
105
- to the public web. We will create a link for you that lives on{" "}
106
- <a href={BASE_URL} target="_blank" rel="noreferrer">
107
- {BASE_URL}
108
- </a>
109
- .
69
+ If the confirmation page didn't open in a new tab, open it below.
110
70
  </DialogDescription>
111
71
  </DialogHeader>
112
- <div className="flex flex-col gap-6 py-4">
113
- <Input
114
- data-testid="slug-input"
115
- id="slug"
116
- autoFocus={true}
117
- value={slug}
118
- placeholder="Notebook slug"
119
- onChange={(e) => {
120
- const newSlug = e.target.value
121
- .toLowerCase()
122
- .replaceAll(/\s/g, "-")
123
- .replaceAll(/[^\da-z-]/g, "");
124
- setSlug(newSlug);
125
- }}
126
- required={true}
127
- autoComplete="off"
128
- />
129
-
130
- <div className="font-semibold text-sm text-muted-foreground gap-2 flex flex-col">
131
- Anyone will be able to access your notebook at this URL:
132
- <div className="flex items-center gap-2">
133
- <CopyButton text={url} />
134
- <span className="text-primary">{url}</span>
135
- </div>
136
- </div>
137
- </div>
138
72
  <DialogFooter>
139
73
  <Button
140
- data-testid="cancel-share-static-notebook-button"
74
+ data-testid="done-share-static-notebook-button"
141
75
  variant="secondary"
142
76
  onClick={onClose}
143
77
  >
144
- Cancel
78
+ Done
145
79
  </Button>
146
- <Button
147
- data-testid="share-static-notebook-button"
148
- aria-label="Save"
149
- variant="default"
150
- type="submit"
151
- onClick={async () => {
152
- await copyToClipboard(url);
153
- }}
154
- >
155
- Create
80
+ <Button asChild={true} variant="default">
81
+ <a
82
+ data-testid="open-claim-page-link"
83
+ href={state.claimUrl}
84
+ target="_blank"
85
+ rel="noopener noreferrer"
86
+ >
87
+ <ExternalLinkIcon size={14} strokeWidth={1.5} className="mr-2" />
88
+ Open confirmation page
89
+ </a>
156
90
  </Button>
157
91
  </DialogFooter>
158
- </form>
159
- </DialogContent>
160
- );
161
- };
162
-
163
- const CopyButton = (props: { text: string }) => {
164
- const [copied, setCopied] = React.useState(false);
92
+ </DialogContent>
93
+ );
94
+ }
165
95
 
166
- const copy = Events.stopPropagation(async (e) => {
167
- e.preventDefault();
168
- await copyToClipboard(props.text);
169
- setCopied(true);
170
- setTimeout(() => setCopied(false), 2000);
171
- });
96
+ const isPublishing = state.kind === "publishing";
172
97
 
173
98
  return (
174
- <Tooltip content="Copied!" open={copied}>
175
- <Button
176
- data-testid="copy-static-notebook-url-button"
177
- onClick={copy}
178
- size="xs"
179
- variant="secondary"
180
- >
181
- <CopyIcon size={14} strokeWidth={1.5} />
182
- </Button>
183
- </Tooltip>
99
+ <DialogContent className="sm:max-w-[480px]">
100
+ <DialogHeader>
101
+ <DialogTitle>Publish HTML to web</DialogTitle>
102
+ <DialogDescription>
103
+ Publish a static snapshot of this notebook to{" "}
104
+ <a
105
+ href={Constants.molab}
106
+ target="_blank"
107
+ rel="noopener noreferrer"
108
+ className="underline"
109
+ >
110
+ molab
111
+ </a>
112
+ . Snapshots can be viewed by anyone on the internet.
113
+ </DialogDescription>
114
+ </DialogHeader>
115
+ {state.kind === "failed" && (
116
+ <p
117
+ role="alert"
118
+ className="text-sm text-destructive"
119
+ data-testid="share-static-notebook-error"
120
+ >
121
+ Publish failed: {state.message}
122
+ </p>
123
+ )}
124
+ <DialogFooter>
125
+ <Button
126
+ data-testid="cancel-share-static-notebook-button"
127
+ variant="secondary"
128
+ onClick={onClose}
129
+ disabled={isPublishing}
130
+ >
131
+ Cancel
132
+ </Button>
133
+ <Button
134
+ data-testid="share-static-notebook-button"
135
+ variant="default"
136
+ disabled={isPublishing}
137
+ onClick={handlePublish}
138
+ >
139
+ {isPublishing ? (
140
+ <>
141
+ <Spinner className="mr-2" size="small" />
142
+ Snapshotting notebook ...
143
+ </>
144
+ ) : (
145
+ <>
146
+ <ExternalLinkIcon size={14} strokeWidth={1.5} className="mr-2" />
147
+ {state.kind === "failed" ? "Try again" : "Publish"}
148
+ </>
149
+ )}
150
+ </Button>
151
+ </DialogFooter>
152
+ </DialogContent>
184
153
  );
185
154
  };
@@ -0,0 +1,56 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ import { Constants } from "@/core/constants";
4
+
5
+ interface PendingUploadResponse {
6
+ pendingId: string;
7
+ presignedUrl: string;
8
+ claimUrl: string;
9
+ expiresAt: string;
10
+ }
11
+
12
+ // Keep in sync with molab.
13
+ export const MAX_PUBLISH_BYTES = 100 * 1024 * 1024;
14
+
15
+ /**
16
+ * Stage an HTML export for publishing on molab: reserve a pending upload,
17
+ * PUT the bytes to the presigned URL, and return the claim URL where the
18
+ * user finishes publishing after signing in.
19
+ */
20
+ export async function stageForPublish(
21
+ fileName: string,
22
+ html: string,
23
+ ): Promise<string> {
24
+ const blob = new Blob([html], { type: "text/html" });
25
+ if (blob.size > MAX_PUBLISH_BYTES) {
26
+ throw new Error("File is too large. Maximum size is 100 MB.");
27
+ }
28
+
29
+ const staged = await fetch(`${Constants.molab}/api/artifacts/pending`, {
30
+ method: "POST",
31
+ headers: { "Content-Type": "application/json" },
32
+ body: JSON.stringify({ fileName, fileSize: blob.size }),
33
+ });
34
+ if (!staged.ok) {
35
+ const body = (await staged.json().catch(() => null)) as {
36
+ error?: string;
37
+ } | null;
38
+ throw new Error(
39
+ body?.error ??
40
+ (staged.status === 429
41
+ ? "Too many uploads, try again later"
42
+ : "Failed to prepare the upload"),
43
+ );
44
+ }
45
+ const { presignedUrl, claimUrl } =
46
+ (await staged.json()) as PendingUploadResponse;
47
+
48
+ // The presigned PUT is capped to the declared size; the browser sends the
49
+ // matching Content-Length automatically from the blob.
50
+ const put = await fetch(presignedUrl, { method: "PUT", body: blob });
51
+ if (!put.ok) {
52
+ throw new Error("Failed to upload the notebook export");
53
+ }
54
+
55
+ return claimUrl;
56
+ }
@@ -0,0 +1,45 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ import { afterEach, describe, expect, it } from "vitest";
4
+ import { withDevAssetUrl } from "../export-asset-url";
5
+ import type { ExportAsHTMLRequest } from "../types";
6
+
7
+ const REQUEST: ExportAsHTMLRequest = {
8
+ download: false,
9
+ includeCode: true,
10
+ files: [],
11
+ };
12
+
13
+ describe("withDevAssetUrl", () => {
14
+ const originalEnv = process.env.NODE_ENV;
15
+
16
+ afterEach(() => {
17
+ process.env.NODE_ENV = originalEnv;
18
+ });
19
+
20
+ it.each(["development", "test"])(
21
+ "defaults assetUrl to the dev server in %s",
22
+ (env) => {
23
+ process.env.NODE_ENV = env;
24
+ expect(withDevAssetUrl(REQUEST).assetUrl).toBe(window.location.origin);
25
+ },
26
+ );
27
+
28
+ it("leaves a caller-provided assetUrl alone in dev", () => {
29
+ process.env.NODE_ENV = "development";
30
+ const cdn = "https://cdn.example.com/dist";
31
+ expect(withDevAssetUrl({ ...REQUEST, assetUrl: cdn }).assetUrl).toBe(cdn);
32
+ });
33
+
34
+ it("does nothing in production", () => {
35
+ process.env.NODE_ENV = "production";
36
+ expect(withDevAssetUrl(REQUEST)).toBe(REQUEST);
37
+ });
38
+
39
+ it("does not mutate the caller's request", () => {
40
+ process.env.NODE_ENV = "development";
41
+ const request = { ...REQUEST };
42
+ withDevAssetUrl(request);
43
+ expect(request.assetUrl).toBeUndefined();
44
+ });
45
+ });