@@ -4,121 +4,119 @@ import { afterAll, assert, beforeAll, describe, it } from "vitest";
44import { runWranglerDev } from "../../shared/src/run-wrangler-long-lived" ;
55
66describe ( "local explorer" , ( ) => {
7- describe ( "with X_LOCAL_EXPLORER=true" , ( ) => {
8- let ip : string ;
9- let port : number ;
10- let stop : ( ( ) => Promise < unknown > ) | undefined ;
11-
12- beforeAll ( async ( ) => {
13- ( { ip, port, stop } = await runWranglerDev (
14- resolve ( __dirname , ".." ) ,
15- [ "--port=0" , "--inspector-port=0" ] ,
16- { X_LOCAL_EXPLORER : "true" }
17- ) ) ;
18- } ) ;
7+ let ip : string ;
8+ let port : number ;
9+ let stop : ( ( ) => Promise < unknown > ) | undefined ;
10+
11+ beforeAll ( async ( ) => {
12+ ( { ip, port, stop } = await runWranglerDev ( resolve ( __dirname , ".." ) , [
13+ "--port=0" ,
14+ "--inspector-port=0" ,
15+ ] ) ) ;
16+ } ) ;
1917
20- afterAll ( async ( ) => {
21- await stop ?.( ) ;
22- } ) ;
18+ afterAll ( async ( ) => {
19+ await stop ?.( ) ;
20+ } ) ;
2321
24- it ( `returns local explorer API response for ${ LOCAL_EXPLORER_API_PATH } ` , async ( {
25- expect,
26- } ) => {
27- const response = await fetch (
28- `http://${ ip } :${ port } ${ LOCAL_EXPLORER_API_PATH } /storage/kv/namespaces`
29- ) ;
30- expect ( response . headers . get ( "Content-Type" ) ) . toBe ( "application/json" ) ;
31- const json = await response . json ( ) ;
32- expect ( json ) . toMatchObject ( {
33- errors : [ ] ,
34- messages : [ ] ,
35- result : [
36- {
37- id : "KV" ,
38- title : "KV" ,
39- } ,
40- {
41- id : "some-kv-id" ,
42- title : "KV_WITH_ID" ,
43- } ,
44- ] ,
45- result_info : {
46- count : 2 ,
22+ it ( `returns local explorer API response for ${ LOCAL_EXPLORER_API_PATH } ` , async ( {
23+ expect,
24+ } ) => {
25+ const response = await fetch (
26+ `http://${ ip } :${ port } ${ LOCAL_EXPLORER_API_PATH } /storage/kv/namespaces`
27+ ) ;
28+ expect ( response . headers . get ( "Content-Type" ) ) . toBe ( "application/json" ) ;
29+ const json = await response . json ( ) ;
30+ expect ( json ) . toMatchObject ( {
31+ errors : [ ] ,
32+ messages : [ ] ,
33+ result : [
34+ {
35+ id : "KV" ,
36+ title : "KV" ,
4737 } ,
48- success : true ,
49- } ) ;
50- } ) ;
51-
52- it ( "returns worker response for normal requests" , async ( { expect } ) => {
53- const response = await fetch ( `http://${ ip } :${ port } /` ) ;
54- const text = await response . text ( ) ;
55- expect ( text ) . toBe ( "Hello World!" ) ;
56- } ) ;
57-
58- it ( `serves UI index.html at ${ LOCAL_EXPLORER_BASE_PATH } ` , async ( {
59- expect,
60- } ) => {
61- const response = await fetch (
62- `http://${ ip } :${ port } ${ LOCAL_EXPLORER_BASE_PATH } `
63- ) ;
64- expect ( response . status ) . toBe ( 200 ) ;
65- expect ( response . headers . get ( "Content-Type" ) ) . toBe (
66- "text/html; charset=utf-8"
67- ) ;
68- const text = await response . text ( ) ;
69- expect ( text ) . toContain ( "<!doctype html>" ) ;
70- expect ( text ) . toContain ( "Cloudflare Local Explorer" ) ;
38+ {
39+ id : "some-kv-id" ,
40+ title : "KV_WITH_ID" ,
41+ } ,
42+ ] ,
43+ result_info : {
44+ count : 2 ,
45+ } ,
46+ success : true ,
7147 } ) ;
48+ } ) ;
7249
73- it ( `serves UI assets at ${ LOCAL_EXPLORER_BASE_PATH } /assets/*` , async ( {
74- expect,
75- } ) => {
76- // First get index.html to find the actual asset paths
77- const indexResponse = await fetch (
78- `http://${ ip } :${ port } ${ LOCAL_EXPLORER_BASE_PATH } `
79- ) ;
80- const html = await indexResponse . text ( ) ;
50+ it ( "returns worker response for normal requests" , async ( { expect } ) => {
51+ const response = await fetch ( `http://${ ip } :${ port } /` ) ;
52+ const text = await response . text ( ) ;
53+ expect ( text ) . toBe ( "Hello World!" ) ;
54+ } ) ;
8155
82- // Extract JS asset path from the HTML
83- // The HTML looks like: <script type="module" crossorigin src="/cdn-cgi/explorer/assets/index-xxx.js">
84- const jsMatch = html . match ( / a s s e t s \/ i n d e x - [ ^ " ] + \. j s / ) ;
85- assert ( jsMatch , "Expected JS asset path in HTML" ) ;
86- const jsPath = jsMatch [ 0 ] ;
56+ it ( `serves UI index.html at ${ LOCAL_EXPLORER_BASE_PATH } ` , async ( {
57+ expect,
58+ } ) => {
59+ const response = await fetch (
60+ `http://${ ip } :${ port } ${ LOCAL_EXPLORER_BASE_PATH } `
61+ ) ;
62+ expect ( response . status ) . toBe ( 200 ) ;
63+ expect ( response . headers . get ( "Content-Type" ) ) . toBe (
64+ "text/html; charset=utf-8"
65+ ) ;
66+ const text = await response . text ( ) ;
67+ expect ( text ) . toContain ( "<!doctype html>" ) ;
68+ expect ( text ) . toContain ( "Cloudflare Local Explorer" ) ;
69+ } ) ;
8770
88- // Fetch the JS asset
89- const jsResponse = await fetch (
90- `http://${ ip } :${ port } ${ LOCAL_EXPLORER_BASE_PATH } /${ jsPath } `
91- ) ;
92- expect ( jsResponse . status ) . toBe ( 200 ) ;
93- expect ( jsResponse . headers . get ( "Content-Type" ) ) . toMatch (
94- / ^ a p p l i c a t i o n \/ j a v a s c r i p t /
95- ) ;
96- } ) ;
71+ it ( `serves UI assets at ${ LOCAL_EXPLORER_BASE_PATH } /assets/*` , async ( {
72+ expect,
73+ } ) => {
74+ // First get index.html to find the actual asset paths
75+ const indexResponse = await fetch (
76+ `http://${ ip } :${ port } ${ LOCAL_EXPLORER_BASE_PATH } `
77+ ) ;
78+ const html = await indexResponse . text ( ) ;
79+
80+ // Extract JS asset path from the HTML
81+ // The HTML looks like: <script type="module" crossorigin src="/cdn-cgi/explorer/assets/index-xxx.js">
82+ const jsMatch = html . match ( / a s s e t s \/ i n d e x - [ ^ " ] + \. j s / ) ;
83+ assert ( jsMatch , "Expected JS asset path in HTML" ) ;
84+ const jsPath = jsMatch [ 0 ] ;
85+
86+ // Fetch the JS asset
87+ const jsResponse = await fetch (
88+ `http://${ ip } :${ port } ${ LOCAL_EXPLORER_BASE_PATH } /${ jsPath } `
89+ ) ;
90+ expect ( jsResponse . status ) . toBe ( 200 ) ;
91+ expect ( jsResponse . headers . get ( "Content-Type" ) ) . toMatch (
92+ / ^ a p p l i c a t i o n \/ j a v a s c r i p t /
93+ ) ;
94+ } ) ;
9795
98- it ( "serves UI with SPA fallback for unknown routes" , async ( { expect } ) => {
99- // Request a route that doesn't exist as a file but should be handled by the SPA
100- const response = await fetch (
101- `http://${ ip } :${ port } ${ LOCAL_EXPLORER_BASE_PATH } /kv/some-namespace`
102- ) ;
103- expect ( response . status ) . toBe ( 200 ) ;
104- expect ( response . headers . get ( "Content-Type" ) ) . toBe (
105- "text/html; charset=utf-8"
106- ) ;
107- const text = await response . text ( ) ;
108- expect ( text ) . toContain ( "<!doctype html>" ) ;
109- } ) ;
96+ it ( "serves UI with SPA fallback for unknown routes" , async ( { expect } ) => {
97+ // Request a route that doesn't exist as a file but should be handled by the SPA
98+ const response = await fetch (
99+ `http://${ ip } :${ port } ${ LOCAL_EXPLORER_BASE_PATH } /kv/some-namespace`
100+ ) ;
101+ expect ( response . status ) . toBe ( 200 ) ;
102+ expect ( response . headers . get ( "Content-Type" ) ) . toBe (
103+ "text/html; charset=utf-8"
104+ ) ;
105+ const text = await response . text ( ) ;
106+ expect ( text ) . toContain ( "<!doctype html>" ) ;
110107 } ) ;
111108
112- describe ( "without X_LOCAL_EXPLORER (default) " , ( ) => {
109+ describe ( "with X_LOCAL_EXPLORER=false " , ( ) => {
113110 let ip : string ;
114111 let port : number ;
115112 let stop : ( ( ) => Promise < unknown > ) | undefined ;
116113
117114 beforeAll ( async ( ) => {
118- ( { ip, port, stop } = await runWranglerDev ( resolve ( __dirname , ".." ) , [
119- "--port=0" ,
120- "--inspector-port=0" ,
121- ] ) ) ;
115+ ( { ip, port, stop } = await runWranglerDev (
116+ resolve ( __dirname , ".." ) ,
117+ [ "--port=0" , "--inspector-port=0" ] ,
118+ { X_LOCAL_EXPLORER : "false" }
119+ ) ) ;
122120 } ) ;
123121
124122 afterAll ( async ( ) => {
0 commit comments