|
| 1 | +import { describe, expect, it } from 'bun:test' |
| 2 | +import { Elysia } from '../../src' |
| 3 | +import { req } from '../utils' |
| 4 | + |
| 5 | +describe('context', () => { |
| 6 | + describe('return route', () => { |
| 7 | + it('on aot=true', async () => { |
| 8 | + const app = new Elysia().get('/hi/:id', ({ route }) => route) |
| 9 | + const res = await app.handle(req('/hi/123')).then((x) => x.text()) |
| 10 | + expect(res).toBe('/hi/:id') |
| 11 | + }) |
| 12 | + |
| 13 | + it('on aot=false', async () => { |
| 14 | + const app = new Elysia({ aot: false }).get( |
| 15 | + '/hi/:id', |
| 16 | + ({ route }) => route |
| 17 | + ) |
| 18 | + const res = await app.handle(req('/hi/123')).then((x) => x.text()) |
| 19 | + expect(res).toBe('/hi/:id') |
| 20 | + }) |
| 21 | + }) |
| 22 | + |
| 23 | + describe('early return on macros with route data', () => { |
| 24 | + it('on aot=true', async () => { |
| 25 | + const app = new Elysia() |
| 26 | + .macro({ |
| 27 | + test: { |
| 28 | + beforeHandle({ route }) { |
| 29 | + return route |
| 30 | + } |
| 31 | + } |
| 32 | + }) |
| 33 | + .get('/hi/:id', () => 'should not returned', { |
| 34 | + test: true |
| 35 | + }) |
| 36 | + const res = await app.handle(req('/hi/123')).then((x) => x.text()) |
| 37 | + expect(res).toBe('/hi/:id') |
| 38 | + }) |
| 39 | + |
| 40 | + it('on aot=false', async () => { |
| 41 | + const app = new Elysia({ aot: false }) |
| 42 | + .macro({ |
| 43 | + test: { |
| 44 | + beforeHandle({ route }) { |
| 45 | + return route |
| 46 | + } |
| 47 | + } |
| 48 | + }) |
| 49 | + .get('/hi/:id', () => 'should not returned', { |
| 50 | + test: true |
| 51 | + }) |
| 52 | + const res = await app.handle(req('/hi/123')).then((x) => x.text()) |
| 53 | + expect(res).toBe('/hi/:id') |
| 54 | + }) |
| 55 | + }) |
| 56 | +}) |
0 commit comments