-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
78feb4b
commit f1f2f94
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
globalThis.valueSetByRouteServiceProvider = 'Supercharge' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |