Skip to content

Commit

Permalink
fix: renderInertia returns Route type
Browse files Browse the repository at this point in the history
Close #16
  • Loading branch information
Julien-R44 committed Apr 4, 2024
1 parent d463e5d commit d584e25
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions providers/inertia_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
/// <reference types="@adonisjs/vite/vite_provider" />

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'
Expand All @@ -27,7 +27,7 @@ declare module '@adonisjs/core/http' {
component: string,
props?: Record<string, any>,
viewProps?: Record<string, any>
): void
): Route
}
}

Expand Down
30 changes: 30 additions & 0 deletions tests/provider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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<Route>()
})
})

0 comments on commit d584e25

Please sign in to comment.