Skip to content

Commit 136f23f

Browse files
refactor(site): Suport template version variables on template creation (#6434)
1 parent 84dd59e commit 136f23f

16 files changed

+1173
-428
lines changed

site/jest.setup.ts

+17
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,30 @@ import { server } from "./src/testHelpers/server"
55
import "jest-location-mock"
66
import { TextEncoder, TextDecoder } from "util"
77
import { Blob } from "buffer"
8+
import { fetch, Request, Response, Headers } from "@remix-run/web-fetch"
89

910
global.TextEncoder = TextEncoder
1011
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Polyfill for jsdom
1112
global.TextDecoder = TextDecoder as any
1213
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Polyfill for jsdom
1314
global.Blob = Blob as any
1415

16+
// From REMIX https://github.com/remix-run/react-router/blob/main/packages/react-router-dom/__tests__/setup.ts
17+
if (!global.fetch) {
18+
// Built-in lib.dom.d.ts expects `fetch(Request | string, ...)` but the web
19+
// fetch API allows a URL so @remix-run/web-fetch defines
20+
// `fetch(string | URL | Request, ...)`
21+
// @ts-expect-error -- Polyfill for jsdom
22+
global.fetch = fetch
23+
// Same as above, lib.dom.d.ts doesn't allow a URL to the Request constructor
24+
// @ts-expect-error -- Polyfill for jsdom
25+
global.Request = Request
26+
// web-std/fetch Response does not currently implement Response.error()
27+
// @ts-expect-error -- Polyfill for jsdom
28+
global.Response = Response
29+
global.Headers = Headers
30+
}
31+
1532
// Polyfill the getRandomValues that is used on utils/random.ts
1633
Object.defineProperty(global.self, "crypto", {
1734
value: {

site/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"@material-ui/icons": "4.5.1",
3737
"@material-ui/lab": "4.0.0-alpha.42",
3838
"@monaco-editor/react": "4.4.6",
39+
"@remix-run/web-fetch": "4.3.2",
3940
"@tanstack/react-query": "4.22.4",
4041
"@testing-library/react-hooks": "8.0.1",
4142
"@types/color-convert": "2.0.0",

site/src/components/RequireAuth/RequireAuth.test.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { screen } from "@testing-library/react"
22
import { rest } from "msw"
3-
import { Route } from "react-router-dom"
43
import { renderWithAuth } from "testHelpers/renderHelpers"
54
import { server } from "testHelpers/server"
65

@@ -20,7 +19,12 @@ describe("RequireAuth", () => {
2019
)
2120

2221
renderWithAuth(<h1>Test</h1>, {
23-
routes: <Route path="setup" element={<h1>Setup</h1>} />,
22+
nonAuthenticatedRoutes: [
23+
{
24+
path: "setup",
25+
element: <h1>Setup</h1>,
26+
},
27+
],
2428
})
2529

2630
await screen.findByText("Setup")

0 commit comments

Comments
 (0)