From d584e25a806b89140883bb262b7698fbc3492218 Mon Sep 17 00:00:00 2001 From: Julien Ripouteau Date: Thu, 4 Apr 2024 19:35:15 +0200 Subject: [PATCH] fix: `renderInertia` returns Route type Close #16 --- providers/inertia_provider.ts | 4 ++-- tests/provider.spec.ts | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/providers/inertia_provider.ts b/providers/inertia_provider.ts index f341770..49faa6d 100644 --- a/providers/inertia_provider.ts +++ b/providers/inertia_provider.ts @@ -10,8 +10,8 @@ /// import { configProvider } from '@adonisjs/core' -import { BriskRoute } from '@adonisjs/core/http' import { RuntimeException } from '@poppinss/utils' +import { BriskRoute, Route } from '@adonisjs/core/http' import type { ApplicationService } from '@adonisjs/core/types' import InertiaMiddleware from '../src/inertia_middleware.js' @@ -27,7 +27,7 @@ declare module '@adonisjs/core/http' { component: string, props?: Record, viewProps?: Record - ): void + ): Route } } diff --git a/tests/provider.spec.ts b/tests/provider.spec.ts index 5ac8be6..9daf6bc 100644 --- a/tests/provider.spec.ts +++ b/tests/provider.spec.ts @@ -4,6 +4,7 @@ import { IgnitorFactory } from '@adonisjs/core/factories' import { defineConfig } from '../index.js' import { defineConfig as viteDefineConfig } from '@adonisjs/vite' import InertiaMiddleware from '../src/inertia_middleware.js' +import { Route } from '@adonisjs/core/http' const BASE_URL = new URL('./tmp/', import.meta.url) const IMPORTER = (filePath: string) => { @@ -39,4 +40,33 @@ test.group('Inertia Provider', () => { assert.instanceOf(await app.container.make(InertiaMiddleware), InertiaMiddleware) }) + + test('register brisk route macro', async ({ assert, cleanup, expectTypeOf }) => { + const ignitor = new IgnitorFactory() + .merge({ + rcFileContents: { + providers: [ + () => import('../providers/inertia_provider.js'), + () => import('@adonisjs/vite/vite_provider'), + ], + }, + }) + .withCoreConfig() + .withCoreProviders() + .merge({ + config: { inertia: defineConfig({ rootView: 'root' }), vite: viteDefineConfig({}) }, + }) + .create(BASE_URL, { importer: IMPORTER }) + + const app = ignitor.createApp('web') + await app.init() + await app.boot() + + cleanup(() => app.terminate()) + + const router = await app.container.make('router') + + assert.property(router.on('foo'), 'renderInertia') + expectTypeOf(router.on('foo').renderInertia('/foo')).toEqualTypeOf() + }) })