@@ -2,6 +2,7 @@ import nodejs from '../dist/index.js';
2
2
import { loadFixture } from './test-utils.js' ;
3
3
import { expect } from 'chai' ;
4
4
import * as cheerio from 'cheerio' ;
5
+ import express from 'express' ;
5
6
6
7
/**
7
8
* @typedef {import('../../../astro/test/test-utils').Fixture } Fixture
@@ -14,7 +15,7 @@ async function load() {
14
15
return mod ;
15
16
}
16
17
17
- describe ( 'behavior from middleware' , ( ) => {
18
+ describe ( 'behavior from middleware, standalone ' , ( ) => {
18
19
/** @type {import('./test-utils').Fixture } */
19
20
let fixture ;
20
21
let server ;
@@ -53,3 +54,42 @@ describe('behavior from middleware', () => {
53
54
} ) ;
54
55
} ) ;
55
56
} ) ;
57
+
58
+ describe ( 'behavior from middleware, middleware' , ( ) => {
59
+ /** @type {import('./test-utils').Fixture } */
60
+ let fixture ;
61
+ let server ;
62
+
63
+ before ( async ( ) => {
64
+ process . env . ASTRO_NODE_AUTOSTART = 'disabled' ;
65
+ process . env . PRERENDER = false ;
66
+ fixture = await loadFixture ( {
67
+ root : './fixtures/node-middleware/' ,
68
+ output : 'server' ,
69
+ adapter : nodejs ( { mode : 'middleware' } ) ,
70
+ } ) ;
71
+ await fixture . build ( ) ;
72
+ const { handler } = await load ( ) ;
73
+ const app = express ( ) ;
74
+ app . use ( handler ) ;
75
+ server = app . listen ( 8888 ) ;
76
+ } ) ;
77
+
78
+ after ( async ( ) => {
79
+ server . close ( ) ;
80
+ await fixture . clean ( ) ;
81
+ delete process . env . PRERENDER ;
82
+ } ) ;
83
+
84
+ it ( 'when mode is standalone' , async ( ) => {
85
+ const res = await fetch ( `http://localhost:8888/ssr` ) ;
86
+
87
+ expect ( res . status ) . to . equal ( 200 ) ;
88
+
89
+ const html = await res . text ( ) ;
90
+ const $ = cheerio . load ( html ) ;
91
+
92
+ const body = $ ( 'body' ) ;
93
+ expect ( body . text ( ) ) . to . contain ( "Here's a random number" ) ;
94
+ } ) ;
95
+ } ) ;
0 commit comments