Skip to content

Commit

Permalink
add test for route service provider
Browse files Browse the repository at this point in the history
  • Loading branch information
marcuspoehls committed Nov 16, 2023
1 parent 78feb4b commit f1f2f94
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/core/test/fixtures/routes/web.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

globalThis.valueSetByRouteServiceProvider = 'Supercharge'
56 changes: 56 additions & 0 deletions packages/core/test/route-service-provider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

import { test } from 'uvu'
import Path from 'node:path'
import { expect } from 'expect'
import { fileURLToPath } from 'node:url'
import { HttpKernel, Application, ErrorHandler, RouteServiceProvider as BaseRouteServiceProvider } from '../dist/index.js'

const __dirname = Path.dirname(fileURLToPath(import.meta.url))
const appRootPath = Path.resolve(__dirname, './fixtures')

class RouteServiceProvider extends BaseRouteServiceProvider {
/**
* Boot the service provider.
*/
async boot () {
this.loadRoutesFrom(
this.app().resolveGlobFromBasePath('routes/web.**')
)
}
}

let app = createApp()

function createApp () {
const app = Application
.createWithAppRoot(appRootPath)
.withErrorHandler(ErrorHandler)
.bind('view', () => {
// empty view mock
})

app.register(
new RouteServiceProvider(app)
)

app.config().set('app.key', 1234)
app.config().set('http', {
host: 'localhost',
port: 1234,
cookie: {}
})

return app
}

test.before.each(() => {
app = createApp()
})

test('boot route service provider', async () => {
const kernel = new HttpKernel(app)
await kernel.prepare()
expect(globalThis.valueSetByRouteServiceProvider).toEqual('Supercharge')
})

test.run()

0 comments on commit f1f2f94

Please sign in to comment.