summaryrefslogtreecommitdiff
path: root/packages/integrations/node/test/errors.test.js
diff options
context:
space:
mode:
authorGravatar Alexander Niebuhr <alexander@nbhr.io> 2024-08-30 19:43:43 +0200
committerGravatar GitHub <noreply@github.com> 2024-08-30 19:43:43 +0200
commit11ebf3bd152042dd36ce2af464a07b02e65dd1d2 (patch)
tree65f3f69ad33ad013632cecfdfedf89000e4b9a27 /packages/integrations/node/test/errors.test.js
parent8e5257addaeff809ed6f0c47ac0ed4ded755320e (diff)
downloadastro-11ebf3bd152042dd36ce2af464a07b02e65dd1d2.tar.gz
astro-11ebf3bd152042dd36ce2af464a07b02e65dd1d2.tar.zst
astro-11ebf3bd152042dd36ce2af464a07b02e65dd1d2.zip
chore: move node and vercel to adapters repo (#11866)
Diffstat (limited to 'packages/integrations/node/test/errors.test.js')
-rw-r--r--packages/integrations/node/test/errors.test.js91
1 files changed, 0 insertions, 91 deletions
diff --git a/packages/integrations/node/test/errors.test.js b/packages/integrations/node/test/errors.test.js
deleted file mode 100644
index 802fa6e25..000000000
--- a/packages/integrations/node/test/errors.test.js
+++ /dev/null
@@ -1,91 +0,0 @@
-import assert from 'node:assert/strict';
-import { after, before, describe, it } from 'node:test';
-import { fileURLToPath } from 'node:url';
-import { Worker } from 'node:worker_threads';
-import * as cheerio from 'cheerio';
-import nodejs from '../dist/index.js';
-import { loadFixture } from './test-utils.js';
-
-describe('Errors', () => {
- /** @type {import('./test-utils.js').Fixture} */
- let fixture;
-
- before(async () => {
- fixture = await loadFixture({
- root: './fixtures/errors/',
- output: 'server',
- adapter: nodejs({ mode: 'standalone' }),
- });
- await fixture.build();
- });
- let devPreview;
-
- before(async () => {
- // The two tests that need the server to run are skipped
- // devPreview = await fixture.preview();
- });
- after(async () => {
- await devPreview?.stop();
- });
-
- it('stays alive after offshoot promise rejections', async () => {
- // this test needs to happen in a worker because node test runner adds a listener for unhandled rejections in the main thread
- const url = new URL('./fixtures/errors/dist/server/entry.mjs', import.meta.url);
- const worker = new Worker(fileURLToPath(url), {
- type: 'module',
- env: { ASTRO_NODE_LOGGING: 'enabled' },
- });
-
- await new Promise((resolve, reject) => {
- worker.stdout.on('data', (data) => {
- setTimeout(() => reject('Server took too long to start'), 1000);
- if (data.toString().includes('Server listening on http://localhost:4321')) resolve();
- });
- });
-
- await fetch('http://localhost:4321/offshoot-promise-rejection');
-
- // if there was a crash, it becomes an error here
- await worker.terminate();
- });
-
- it(
- 'rejected promise in template',
- { skip: true, todo: 'Review the response from the in-stream' },
- 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',
- { skip: true, todo: 'Review the response from the generator' },
- async () => {
- const result = ['<!DOCTYPE html><h1>Astro</h1> 1', 'Internal server error'];
-
- /** @type {Response} */
- const res = await fixture.fetch('/generator');
- const reader = res.body.getReader();
- const decoder = new TextDecoder();
- const chunk1 = await reader.read();
- const chunk2 = await reader.read();
- const chunk3 = await reader.read();
- assert.equal(chunk1.done, false);
- console.log(chunk1);
- console.log(chunk2);
- console.log(chunk3);
- if (chunk2.done) {
- assert.equal(decoder.decode(chunk1.value), result.join(''));
- } else if (chunk3.done) {
- assert.equal(decoder.decode(chunk1.value), result[0]);
- assert.equal(decoder.decode(chunk2.value), result[1]);
- } else {
- throw new Error('The response should take at most 2 chunks.');
- }
- },
- );
-});