Skip to content

Commit

Permalink
feat(gatsby): test redirects (#31011)
Browse files Browse the repository at this point in the history
* feat(gatsby): test redirects

* Fix test

* refine message

* another error tweak

* actually fix test
  • Loading branch information
KyleAMathews committed Apr 23, 2021
1 parent 8250c9c commit 7838b18
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
8 changes: 8 additions & 0 deletions integration-tests/functions/src/api/redirect-me.ts
@@ -0,0 +1,8 @@
import { GatsbyAPIFunctionResponse, GatsbyAPIFunctionRequest } from "gatsby"

export default function topLevel(
req: GatsbyAPIFunctionRequest,
res: GatsbyAPIFunctionResponse
) {
res.redirect(`/`)
}
8 changes: 8 additions & 0 deletions integration-tests/functions/test-helpers.js
Expand Up @@ -212,6 +212,14 @@ export function runTests(env, host) {
})
})

describe(`functions can redirect`, () => {
test(`normal`, async () => {
const result = await fetch(`${host}/api/redirect-me`)

expect(result.url).toEqual(host + `/`)
})
})

// TODO figure out why this gets into endless loops
// describe.only(`hot reloading`, () => {
// const fixturesDir = path.join(__dirname, `fixtures`)
Expand Down
Expand Up @@ -364,7 +364,11 @@ export async function onCreateDevServer({
await Promise.resolve(fnToExecute(req, res))
} catch (e) {
reporter.error(e)
res.sendStatus(500)
res
.status(500)
.send(
`Error when executing function "${functionObj.originalFilePath}": "${e.message}"`
)
}

const end = Date.now()
Expand Down

0 comments on commit 7838b18

Please sign in to comment.