mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
[ci] format
This commit is contained in:
parent
83f9105cd5
commit
7138aa4678
2 changed files with 17 additions and 15 deletions
|
@ -14,7 +14,7 @@ export function createAppHandler(app: NodeApp): RequestHandler {
|
|||
*/
|
||||
const als = new AsyncLocalStorage<string>();
|
||||
const logger = app.getAdapterLogger();
|
||||
process.on('unhandledRejection', reason => {
|
||||
process.on('unhandledRejection', (reason) => {
|
||||
const requestUrl = als.getStore();
|
||||
logger.error(`Unhandled rejection while rendering ${requestUrl}`);
|
||||
console.error(reason);
|
||||
|
@ -32,11 +32,13 @@ export function createAppHandler(app: NodeApp): RequestHandler {
|
|||
|
||||
const routeData = app.match(request);
|
||||
if (routeData) {
|
||||
const response = await als.run(request.url, () => app.render(request, {
|
||||
addCookieHeader: true,
|
||||
locals,
|
||||
routeData,
|
||||
}));
|
||||
const response = await als.run(request.url, () =>
|
||||
app.render(request, {
|
||||
addCookieHeader: true,
|
||||
locals,
|
||||
routeData,
|
||||
})
|
||||
);
|
||||
await NodeApp.writeResponse(response, res);
|
||||
} else if (next) {
|
||||
return next();
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import { spawn } from 'node:child_process';
|
||||
import { Worker } from 'node:worker_threads';
|
||||
import assert from 'node:assert/strict';
|
||||
import { spawn } from 'node:child_process';
|
||||
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';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
describe('Errors', () => {
|
||||
/** @type {import('./test-utils.js').Fixture} */
|
||||
|
@ -33,17 +33,17 @@ describe('Errors', () => {
|
|||
// this test needs to happen in a worker because node test runner adds a listener for unhandled rejections in the main thread
|
||||
const worker = new Worker('./test/fixtures/errors/dist/server/entry.mjs', {
|
||||
type: 'module',
|
||||
env: { ASTRO_NODE_LOGGING: 'enabled' }
|
||||
env: { ASTRO_NODE_LOGGING: 'enabled' },
|
||||
});
|
||||
|
||||
|
||||
await new Promise((resolve, reject) => {
|
||||
worker.stdout.on('data', data => {
|
||||
setTimeout(() => reject("Server took too long to start"), 1000);
|
||||
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");
|
||||
|
||||
await fetch('http://localhost:4321/offshoot-promise-rejection');
|
||||
|
||||
// if there was a crash, it becomes an error here
|
||||
await worker.terminate();
|
||||
|
|
Loading…
Reference in a new issue