Skip to content

Commit

Permalink
🎉 feat: merge pr
Browse files Browse the repository at this point in the history
  • Loading branch information
SaltyAom committed Feb 6, 2024
1 parent f45d609 commit 6fd8753
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 47 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# 0.8.16 - 6 Feb 2024
Feature:
- [#448](https://github.com/elysiajs/elysia/pull/448) BooleanString - @bogeychan

Bug fix:
- [#451](https://github.com/elysiajs/elysia/pull/464) handle spread operator use on possible null or undefined
- [#460](https://github.com/elysiajs/elysia/pull/460)
- [#457](https://github.com/elysiajs/elysia/pull/457) scoped plugin instances now respect the prefix property
- [#458](https://github.com/elysiajs/elysia/pull/458) adding a second scoped plugin does not unmount the route handler of a previously added scoped instance anymore.

# 0.8.15 - 30 Jan 2024
Bug fix:
- [#451](https://github.com/elysiajs/elysia/issues/451) macro does not run when it should (macro deduplication)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "elysia",
"description": "Ergonomic Framework for Human",
"version": "0.8.15",
"version": "0.8.16",
"author": {
"name": "saltyAom",
"url": "https://github.com/SaltyAom",
Expand Down
9 changes: 3 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1914,19 +1914,16 @@ export default class Elysia<

if (plugin.config.aot) plugin.compile()

if (isScoped && !plugin.config.prefix) {
if (isScoped && !plugin.config.prefix)
console.warn(
'When using scoped plugins it is recommended to use a prefix, else routing may not work correctly for the second scoped instance'
)
}

let instance

if (isScoped && plugin.config.prefix) {
if (isScoped && plugin.config.prefix)
instance = this.mount(plugin.config.prefix + '/', plugin.fetch)
} else {
instance = this.mount(plugin.fetch)
}
else instance = this.mount(plugin.fetch)

this.routes = this.routes.concat(instance.routes)

Expand Down
51 changes: 40 additions & 11 deletions test/core/scoped.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,50 @@ describe('Scoped', () => {
expect(count).toBe(1)
})

it('multible scoped events', async () => {
// TODO: Possibly Elysia 1.1, no promise tee-hee (finger-crossed)
// it('multiple scoped events', async () => {
// const first = new Elysia({ name: 'first', scoped: true }).get(
// '/first',
// () => 'first'
// )

const first = new Elysia({ name: "first", scoped: true }).get("/first", () => "first");
const second = new Elysia({name: "second", scoped: true }).get("/second", () => "second");
// const second = new Elysia({ name: 'second', scoped: true }).get(
// '/second',
// () => 'second'
// )

const app = new Elysia().use(first).use(second);
// const app = new Elysia().use(first).use(second)

const firstResponse = await app.handle(req("/first"));
const secondResponse = await app.handle(req("/second"));
// const firstResponse = await app.handle(req('/first'))
// const secondResponse = await app.handle(req('/second'))

const firstText = await firstResponse.text();
const secondText = await secondResponse.text();
// const firstText = await firstResponse.text()
// const secondText = await secondResponse.text()

expect(firstText).toBe("first")
expect(secondText).toBe("second")
})
// expect(firstText).toBe('first')
// expect(secondText).toBe('second')
// })

it('Multiple scopes registering all routes', async () => {
const app = new Elysia()

const plugin = new Elysia({
prefix: 'Plugin',
scoped: true
}).get('/testPrivate', () => 'OK')

const plugin2 = new Elysia({
prefix: 'PluginNext',
scoped: true
}).get('/testPrivate', () => 'OK')

app.use(plugin).use(plugin2)

const res = await app.handle(req('/Plugin/testPrivate'))

expect(res.status).toBe(200)

const res1 = await app.handle(req('/PluginNext/testPrivate'))
expect(res1.status).toBe(200)
})
})
29 changes: 0 additions & 29 deletions test/scoped/scoped.test.ts

This file was deleted.

0 comments on commit 6fd8753

Please sign in to comment.