test(runtimes): build plugins as named objects on Deno and Bun
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
3 files changed
+19
-10
No files matched your search
+5
-2
@@ -31,8 +31,11 @@ class UserController {
|
|||||||
@Module({ mountpoint: '/api', providers: [Database], steps: [Authenticate], controllers: [UserController] })
|
@Module({ mountpoint: '/api', providers: [Database], steps: [Authenticate], controllers: [UserController] })
|
||||||
class ApiModule {}
|
class ApiModule {}
|
||||||
|
|
||||||
const logger: Plugin = (api) => {
|
const logger: Plugin = {
|
||||||
api.bus.on('request:step:enter', (p) => console.log(`-> ${p.name}`));
|
name: 'step-logger',
|
||||||
|
mount(api) {
|
||||||
|
api.bus.on('request:step:enter', (p) => console.log(`-> ${p.name}`));
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const app = createApp({ modules: [ApiModule], plugins: [logger] });
|
export const app = createApp({ modules: [ApiModule], plugins: [logger] });
|
||||||
|
|||||||
@@ -57,10 +57,13 @@ test('serveBun close() runs registered teardown', async () => {
|
|||||||
const app = createApp({
|
const app = createApp({
|
||||||
modules: [M],
|
modules: [M],
|
||||||
hooks: [{ onShutdown: () => void closed.push('hook') }],
|
hooks: [{ onShutdown: () => void closed.push('hook') }],
|
||||||
plugins: [(api) => api.onShutdown(async () => {
|
plugins: [{
|
||||||
await Bun.sleep(10);
|
name: 'teardown-probe',
|
||||||
closed.push('plugin');
|
mount: (api) => api.onShutdown(async () => {
|
||||||
})],
|
await Bun.sleep(10);
|
||||||
|
closed.push('plugin');
|
||||||
|
}),
|
||||||
|
}],
|
||||||
});
|
});
|
||||||
const server = serveBun(app, { port: 0 });
|
const server = serveBun(app, { port: 0 });
|
||||||
|
|
||||||
|
|||||||
@@ -72,10 +72,13 @@ Deno.test('serveDeno close() runs registered teardown', async () => {
|
|||||||
const app = createApp({
|
const app = createApp({
|
||||||
modules: [M],
|
modules: [M],
|
||||||
hooks: [{ onShutdown: () => void closed.push('hook') }],
|
hooks: [{ onShutdown: () => void closed.push('hook') }],
|
||||||
plugins: [(api) => api.onShutdown(async () => {
|
plugins: [{
|
||||||
await new Promise((r) => setTimeout(r, 10));
|
name: 'teardown-probe',
|
||||||
closed.push('plugin');
|
mount: (api) => api.onShutdown(async () => {
|
||||||
})],
|
await new Promise((r) => setTimeout(r, 10));
|
||||||
|
closed.push('plugin');
|
||||||
|
}),
|
||||||
|
}],
|
||||||
});
|
});
|
||||||
const server = serveDeno(app, { port: 0 });
|
const server = serveDeno(app, { port: 0 });
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user