Skip to content

Commit

Permalink
[pocketbase#3025] manually trigger the OnBeforeServe hook for tests.A…
Browse files Browse the repository at this point in the history
…piScenario
  • Loading branch information
ganigeorgiev committed Jul 31, 2023
1 parent 6d2677a commit f652dc7
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()
Expand All @@ -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)
}
Expand Down

0 comments on commit f652dc7

Please sign in to comment.