Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
EdamAme-x committed Dec 16, 2024
1 parent a39552b commit ab4c5f5
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 14 deletions.
25 changes: 25 additions & 0 deletions runtime-tests/workerd/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,28 @@ describe('workerd with WebSocket', () => {
expect(closeHandler).toHaveBeenCalled()
})
})

describe('worked with getColorEnabled()', () => {
let worker: UnstableDevWorker

beforeAll(async () => {
worker = await unstable_dev('./runtime-tests/workerd/index.ts', {
vars: {
NAME: 'Hono',
},
experimental: { disableExperimentalWarning: true },
})
})

afterAll(async () => {
await worker.stop()
})

it('Should return 200 response with the colorEnabled', async () => {
const res = await worker.fetch('/color')
expect(res.status).toBe(200)
expect(await res.json()).toEqual({
colorEnabled: false,
})
})
})
19 changes: 17 additions & 2 deletions runtime-tests/workerd/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import { upgradeWebSocket } from '../../src/adapter/cloudflare-workers'
import { env, getRuntimeKey } from '../../src/helper/adapter'
import { Hono } from '../../src/hono'
import { getColorEnabled } from '../../src/utils/color'

const app = new Hono()
interface Env {
NO_COLOR: boolean
NAME: string
}

const app = new Hono<{
Bindings: Env
}>()

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

app.get('/env', (c) => {
const { NAME } = env<{ NAME: string }>(c)
const { NAME } = env(c)
return c.text(NAME)
})

Expand All @@ -22,4 +30,11 @@ app.get(
})
)

app.get('/color', (c) => {
c.env.NO_COLOR = true
return c.json({
colorEnabled: getColorEnabled(c),
})
})

export default app
12 changes: 0 additions & 12 deletions src/utils/color.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,6 @@ describe('getColorEnabled() - With colors enabled', () => {
})
})

describe('getColorEnabled() - With colors disabled in Edge', () => {
const edgeContext = new Context(new Request('http://localhost/'), {
env: {
NO_COLOR: true,
},
})

it('should return false', async () => {
expect(getColorEnabled(edgeContext)).toBe(false)
})
})

describe('getColorEnabled() - With NO_COLOR environment variable set', () => {
const mockContext = new Context(new Request('http://localhost/'))

Expand Down

0 comments on commit ab4c5f5

Please sign in to comment.