mirror of
https://github.com/pocketbase/pocketbase.git
synced 2025-02-13 16:31:59 +02:00
[#3025] manually trigger the OnBeforeServe hook for tests.ApiScenario
This commit is contained in:
parent
6d2677a5e3
commit
f652dc71bb
@ -13,6 +13,7 @@ import (
|
||||
|
||||
"github.com/labstack/echo/v5"
|
||||
"github.com/pocketbase/pocketbase/apis"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
)
|
||||
|
||||
// ApiScenario defines a single api request test case/scenario.
|
||||
@ -55,6 +56,8 @@ func (scenario *ApiScenario) test(t *testing.T) {
|
||||
var testApp *TestApp
|
||||
var testAppErr error
|
||||
if scenario.TestAppFactory != nil {
|
||||
// @todo consider passing the testing instance to the factory and maybe remove the error from the declaration
|
||||
// (see https://github.com/pocketbase/pocketbase/discussions/3025)
|
||||
testApp, testAppErr = scenario.TestAppFactory()
|
||||
} else {
|
||||
testApp, testAppErr = NewTestApp()
|
||||
@ -69,6 +72,12 @@ func (scenario *ApiScenario) test(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// manually trigger the serve event to ensure that custom app routes and middlewares are registered
|
||||
testApp.OnBeforeServe().Trigger(&core.ServeEvent{
|
||||
App: testApp,
|
||||
Router: e,
|
||||
})
|
||||
|
||||
if scenario.BeforeTestFunc != nil {
|
||||
scenario.BeforeTestFunc(t, testApp, e)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user