-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
qol(endpoints): helpful error message when a response is not provided (…
…#10455) * qol(endpoints): helpful error message when a response is not provded * add changeset * add test
- Loading branch information
Showing
4 changed files
with
84 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,5 @@ | ||
--- | ||
"astro": patch | ||
--- | ||
|
||
Adds a helpful error message that will be shown when an endpoint does not return a `Response`. |
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
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
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,49 @@ | ||
import * as assert from 'node:assert/strict'; | ||
import { after, before, describe, it } from 'node:test'; | ||
import { fileURLToPath } from 'node:url'; | ||
import { createContainer } from '../../../dist/core/dev/container.js'; | ||
import testAdapter from '../../test-adapter.js'; | ||
import { | ||
createBasicSettings, | ||
createFs, | ||
createRequestAndResponse, | ||
defaultLogger, | ||
} from '../test-utils.js'; | ||
|
||
const root = new URL('../../fixtures/api-routes/', import.meta.url); | ||
const fileSystem = { | ||
'/src/pages/incorrect.ts': `export const GET = _ => {}`, | ||
}; | ||
|
||
describe('endpoints', () => { | ||
let container; | ||
let settings; | ||
|
||
before(async () => { | ||
const fs = createFs(fileSystem, root); | ||
settings = await createBasicSettings({ | ||
root: fileURLToPath(root), | ||
output: 'server', | ||
adapter: testAdapter(), | ||
}); | ||
container = await createContainer({ | ||
fs, | ||
settings, | ||
logger: defaultLogger, | ||
}); | ||
}); | ||
|
||
after(async () => { | ||
await container.close(); | ||
}); | ||
|
||
it('should respond with 500 for incorrect implementation', async () => { | ||
const { req, res, done } = createRequestAndResponse({ | ||
method: 'GET', | ||
url: '/incorrect', | ||
}); | ||
container.handle(req, res); | ||
await done; | ||
assert.equal(res.statusCode, 500); | ||
}); | ||
}); |