Skip to content

Commit ab4c5f5

Browse files
committed
wip
1 parent a39552b commit ab4c5f5

File tree

3 files changed

+42
-14
lines changed

3 files changed

+42
-14
lines changed

runtime-tests/workerd/index.test.ts

+25
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,28 @@ describe('workerd with WebSocket', () => {
6767
expect(closeHandler).toHaveBeenCalled()
6868
})
6969
})
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+
})

runtime-tests/workerd/index.ts

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
import { upgradeWebSocket } from '../../src/adapter/cloudflare-workers'
22
import { env, getRuntimeKey } from '../../src/helper/adapter'
33
import { Hono } from '../../src/hono'
4+
import { getColorEnabled } from '../../src/utils/color'
45

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+
}>()
614

715
app.get('/', (c) => c.text(`Hello from ${getRuntimeKey()}`))
816

917
app.get('/env', (c) => {
10-
const { NAME } = env<{ NAME: string }>(c)
18+
const { NAME } = env(c)
1119
return c.text(NAME)
1220
})
1321

@@ -22,4 +30,11 @@ app.get(
2230
})
2331
)
2432

33+
app.get('/color', (c) => {
34+
c.env.NO_COLOR = true
35+
return c.json({
36+
colorEnabled: getColorEnabled(c),
37+
})
38+
})
39+
2540
export default app

src/utils/color.test.ts

-12
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,6 @@ describe('getColorEnabled() - With colors enabled', () => {
77
})
88
})
99

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-
2210
describe('getColorEnabled() - With NO_COLOR environment variable set', () => {
2311
const mockContext = new Context(new Request('http://localhost/'))
2412

0 commit comments

Comments
 (0)