2024-02-01 07:02:40 +00:00
|
|
|
import assert from 'node:assert/strict';
|
2024-01-25 16:17:31 +00:00
|
|
|
import { describe, it, before, after } from 'node:test';
|
2023-05-01 10:08:18 -04:00
|
|
|
import nodejs from '../dist/index.js';
|
|
|
|
import { loadFixture } from './test-utils.js';
|
|
|
|
import * as cheerio from 'cheerio';
|
|
|
|
|
|
|
|
describe('Errors', () => {
|
|
|
|
let fixture;
|
|
|
|
before(async () => {
|
|
|
|
fixture = await loadFixture({
|
|
|
|
root: './fixtures/errors/',
|
|
|
|
output: 'server',
|
|
|
|
adapter: nodejs({ mode: 'standalone' }),
|
|
|
|
});
|
|
|
|
await fixture.build();
|
|
|
|
});
|
2024-01-25 16:17:31 +00:00
|
|
|
let devPreview;
|
2023-05-01 10:08:18 -04:00
|
|
|
|
2024-01-25 16:17:31 +00:00
|
|
|
before(async () => {
|
|
|
|
devPreview = await fixture.preview();
|
|
|
|
});
|
|
|
|
after(async () => {
|
|
|
|
await devPreview.stop();
|
|
|
|
});
|
2024-02-01 07:02:40 +00:00
|
|
|
|
|
|
|
it('rejected promise in template', async () => {
|
2024-01-25 16:17:31 +00:00
|
|
|
const res = await fixture.fetch('/in-stream');
|
|
|
|
const html = await res.text();
|
|
|
|
const $ = cheerio.load(html);
|
2023-05-01 10:08:18 -04:00
|
|
|
|
2024-01-25 16:17:31 +00:00
|
|
|
assert.equal($('p').text().trim(), 'Internal server error');
|
2023-05-01 10:08:18 -04:00
|
|
|
});
|
2024-02-01 07:03:42 +00:00
|
|
|
|
2024-02-01 07:02:40 +00:00
|
|
|
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);
|
2024-02-01 07:03:42 +00:00
|
|
|
};
|
|
|
|
await expect({ done: false, value: '<!DOCTYPE html><h1>Astro</h1> 1Internal server error' });
|
2024-02-01 07:02:40 +00:00
|
|
|
await expect({ done: true });
|
|
|
|
});
|
2023-05-01 10:08:18 -04:00
|
|
|
});
|