-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow components to return a Response (#2944)
* Allow components to return a Response * Changeset
- Loading branch information
Showing
6 changed files
with
80 additions
and
15 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 | ||
--- | ||
|
||
Allow components to 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { expect } from 'chai'; | ||
import { load as cheerioLoad } from 'cheerio'; | ||
import { loadFixture } from './test-utils.js'; | ||
|
||
// Asset bundling | ||
describe('Returning responses', () => { | ||
let fixture; | ||
/** @type {import('./test-utils').DevServer} */ | ||
let devServer; | ||
|
||
before(async () => { | ||
fixture = await loadFixture({ | ||
projectRoot: './fixtures/astro-response/', | ||
}); | ||
|
||
devServer = await fixture.startDevServer(); | ||
}); | ||
|
||
after(async () => { | ||
await devServer.stop(); | ||
}); | ||
|
||
it('Works from a page', async () => { | ||
let response = await fixture.fetch('/not-found'); | ||
expect(response.status).to.equal(404); | ||
}); | ||
|
||
it('Works from a component', async () => { | ||
let response = await fixture.fetch('/not-found-component'); | ||
expect(response.status).to.equal(404); | ||
}); | ||
}); |
6 changes: 6 additions & 0 deletions
6
packages/astro/test/fixtures/astro-response/src/components/not-found.astro
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,6 @@ | ||
--- | ||
return new Response(null, { | ||
status: 404, | ||
statusText: `Not found` | ||
}); | ||
--- |
4 changes: 4 additions & 0 deletions
4
packages/astro/test/fixtures/astro-response/src/pages/not-found-component.astro
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,4 @@ | ||
--- | ||
import NotFound from '../components/not-found.astro'; | ||
--- | ||
<NotFound /> |
6 changes: 6 additions & 0 deletions
6
packages/astro/test/fixtures/astro-response/src/pages/not-found.astro
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,6 @@ | ||
--- | ||
return new Response(null, { | ||
status: 404, | ||
statusText: `Not found` | ||
}); | ||
--- |