0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-04-07 23:41:43 -05:00

fix(NodeApp): end with "Internal server error" on mid-stream error (#9908)

* fix(NodeApp): end with "Internal server error" on mid-stream error

* add changeset

* add test

* Apply suggestions from code review

---------

Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
This commit is contained in:
Arsh 2024-02-01 07:02:40 +00:00 committed by GitHub
parent 3f967e5605
commit a403027516
2 changed files with 28 additions and 2 deletions

View file

@ -1,4 +1,4 @@
import * as assert from 'node:assert/strict';
import assert from 'node:assert/strict';
import { describe, it, before, after } from 'node:test';
import nodejs from '../dist/index.js';
import { loadFixture } from './test-utils.js';
@ -22,11 +22,26 @@ describe('Errors', () => {
after(async () => {
await devPreview.stop();
});
it('when mode is standalone', async () => {
it('rejected promise in template', async () => {
const res = await fixture.fetch('/in-stream');
const html = await res.text();
const $ = cheerio.load(html);
assert.equal($('p').text().trim(), 'Internal server error');
});
it('generator that throws called in template', async () => {
/** @type {Response} */
const res = await fixture.fetch('/generator');
const reader = res.body.getReader();
const decoder = new TextDecoder();
const expect = async ({ done, value }) => {
const result = await reader.read();
assert.equal(result.done, done);
if (!done) assert.equal(decoder.decode(result.value), value);
}
await expect({ done: false, value: "<!DOCTYPE html><h1>Astro</h1> 1Internal server error" });
await expect({ done: true });
});
});

View file

@ -0,0 +1,11 @@
---
function * generator () {
yield 1
throw Error('ohnoes')
}
---
<h1>Astro</h1>
{generator()}
<footer>
Footer
</footer>