File tree 3 files changed +42
-14
lines changed
3 files changed +42
-14
lines changed Original file line number Diff line number Diff line change @@ -67,3 +67,28 @@ describe('workerd with WebSocket', () => {
67
67
expect ( closeHandler ) . toHaveBeenCalled ( )
68
68
} )
69
69
} )
70
+
71
+ describe ( 'worked with getColorEnabled()' , ( ) => {
72
+ let worker : UnstableDevWorker
73
+
74
+ beforeAll ( async ( ) => {
75
+ worker = await unstable_dev ( './runtime-tests/workerd/index.ts' , {
76
+ vars : {
77
+ NAME : 'Hono' ,
78
+ } ,
79
+ experimental : { disableExperimentalWarning : true } ,
80
+ } )
81
+ } )
82
+
83
+ afterAll ( async ( ) => {
84
+ await worker . stop ( )
85
+ } )
86
+
87
+ it ( 'Should return 200 response with the colorEnabled' , async ( ) => {
88
+ const res = await worker . fetch ( '/color' )
89
+ expect ( res . status ) . toBe ( 200 )
90
+ expect ( await res . json ( ) ) . toEqual ( {
91
+ colorEnabled : false ,
92
+ } )
93
+ } )
94
+ } )
Original file line number Diff line number Diff line change 1
1
import { upgradeWebSocket } from '../../src/adapter/cloudflare-workers'
2
2
import { env , getRuntimeKey } from '../../src/helper/adapter'
3
3
import { Hono } from '../../src/hono'
4
+ import { getColorEnabled } from '../../src/utils/color'
4
5
5
- const app = new Hono ( )
6
+ interface Env {
7
+ NO_COLOR : boolean
8
+ NAME : string
9
+ }
10
+
11
+ const app = new Hono < {
12
+ Bindings : Env
13
+ } > ( )
6
14
7
15
app . get ( '/' , ( c ) => c . text ( `Hello from ${ getRuntimeKey ( ) } ` ) )
8
16
9
17
app . get ( '/env' , ( c ) => {
10
- const { NAME } = env < { NAME : string } > ( c )
18
+ const { NAME } = env ( c )
11
19
return c . text ( NAME )
12
20
} )
13
21
@@ -22,4 +30,11 @@ app.get(
22
30
} )
23
31
)
24
32
33
+ app . get ( '/color' , ( c ) => {
34
+ c . env . NO_COLOR = true
35
+ return c . json ( {
36
+ colorEnabled : getColorEnabled ( c ) ,
37
+ } )
38
+ } )
39
+
25
40
export default app
Original file line number Diff line number Diff line change @@ -7,18 +7,6 @@ describe('getColorEnabled() - With colors enabled', () => {
7
7
} )
8
8
} )
9
9
10
- describe ( 'getColorEnabled() - With colors disabled in Edge' , ( ) => {
11
- const edgeContext = new Context ( new Request ( 'http://localhost/' ) , {
12
- env : {
13
- NO_COLOR : true ,
14
- } ,
15
- } )
16
-
17
- it ( 'should return false' , async ( ) => {
18
- expect ( getColorEnabled ( edgeContext ) ) . toBe ( false )
19
- } )
20
- } )
21
-
22
10
describe ( 'getColorEnabled() - With NO_COLOR environment variable set' , ( ) => {
23
11
const mockContext = new Context ( new Request ( 'http://localhost/' ) )
24
12
You can’t perform that action at this time.
0 commit comments