@@ -19,89 +19,7 @@ describe('Context', () => {
1919 expect ( c . now ) . toBeNumber ( ) ;
2020 expect ( c . url ) . toBeInstanceOf ( URL ) ;
2121 expect ( c . url . pathname ) . toBe ( '/home' ) ;
22- } ) ;
23- it ( 'should handle files' , async ( ) => {
24- const request = new Request ( 'http://localhost/home.html' ) ;
25- const app = new HttpRouter ( ) ;
26- const c = new Context ( request , server , app ) ;
27- const resp = await c . file (
28- `${ import . meta. dir } /../../testFixtures/home.html`
29- ) ;
30- expect ( resp ) . toBeInstanceOf ( Response ) ;
31- expect ( resp . headers . get ( 'Accept-Ranges' ) ) . toBe ( 'bytes' ) ;
32- const file = await resp . blob ( ) ;
33- const text = await file . text ( ) ;
34- expect ( text ) . toBe ( '<h1>Welcome home</h1>\n' ) ;
35- } ) ;
36- it ( 'should handle files with disposition="attachment' , async ( ) => {
37- const request = new Request ( 'http://localhost/home.html' ) ;
38- const app = new HttpRouter ( ) ;
39- const c = new Context ( request , server , app ) ;
40- const resp = await c . file (
41- `${ import . meta. dir } /../../testFixtures/home.html` ,
42- { disposition : 'attachment' }
43- ) ;
44- expect ( resp ) . toBeInstanceOf ( Response ) ;
45- expect ( resp . headers . get ( 'Content-Disposition' ) ) . toBe (
46- 'attachment; filename="home.html"'
47- ) ;
48- const file = await resp . blob ( ) ;
49- const text = await file . text ( ) ;
50- expect ( text ) . toBe ( '<h1>Welcome home</h1>\n' ) ;
51- } ) ;
52- it ( 'should handle files with range "bytes=0-3"' , async ( ) => {
53- const request = new Request ( 'http://localhost/home.html' , {
54- headers : { Range : 'bytes=0-3' } ,
55- } ) ;
56- const app = new HttpRouter ( ) ;
57- const c = new Context ( request , server , app ) ;
58- const resp = await c . file (
59- `${ import . meta. dir } /../../testFixtures/home.html`
60- ) ;
61- expect ( resp ) . toBeInstanceOf ( Response ) ;
62- const file = await resp . blob ( ) ;
63- const text = await file . text ( ) ;
64- expect ( resp . status ) . toBe ( 206 ) ;
65- expect ( text ) . toBe ( '<h1>' ) ;
66- } ) ;
67- it ( 'should handle files with range "bytes=0-"' , async ( ) => {
68- const request = new Request ( 'http://localhost/home.html' , {
69- headers : { Range : 'bytes=0-' } ,
70- } ) ;
71- const app = new HttpRouter ( ) ;
72- const c = new Context ( request , server , app ) ;
73- const resp = await c . file (
74- `${ import . meta. dir } /../../testFixtures/home.html`
75- ) ;
76- expect ( resp ) . toBeInstanceOf ( Response ) ;
77- const file = await resp . blob ( ) ;
78- const text = await file . text ( ) ;
79- expect ( text ) . toBe ( '<h1>Welcome home</h1>\n' ) ;
80- } ) ;
81- it ( 'should handle files with range "bytes=0-999"' , async ( ) => {
82- const request = new Request ( 'http://localhost/home.html' , {
83- headers : { Range : 'bytes=0-999' } ,
84- } ) ;
85- const app = new HttpRouter ( ) ;
86- const c = new Context ( request , server , app ) ;
87- const resp = await c . file (
88- `${ import . meta. dir } /../../testFixtures/home.html`
89- ) ;
90- expect ( resp ) . toBeInstanceOf ( Response ) ;
91- expect ( resp . status ) . toBe ( 200 ) ;
92- } ) ;
93- it ( 'should handle files with range "bytes=-3"' , async ( ) => {
94- const request = new Request ( 'http://localhost/home.html' , {
95- headers : { Range : 'bytes=-3' } ,
96- } ) ;
97- const app = new HttpRouter ( ) ;
98- const c = new Context ( request , server , app ) ;
99- const resp = await c . file (
100- `${ import . meta. dir } /../../testFixtures/home.html`
101- ) ;
102- expect ( resp ) . toBeInstanceOf ( Response ) ;
103- expect ( resp . status ) . toBe ( 206 ) ;
104- expect ( await resp . text ( ) ) . toBe ( '<h1>' ) ;
22+ expect ( c . locals ) . toBeTypeOf ( 'object' ) ;
10523 } ) ;
10624 describe ( 'server' , ( ) => {
10725 let c : Context ;
@@ -157,15 +75,5 @@ describe('Context', () => {
15775 expect ( resp . headers . get ( 'Content-type' ) ) . toStartWith ( 'application/json' ) ;
15876 expect ( resp . headers . get ( 'X-Hello' ) ) . toBe ( 'World' ) ;
15977 } ) ;
160- // it('should include redirect(url)', () => {
161- // const resp = redirect('/home');
162- // expect(resp.headers.get('Location')).toBe('/home');
163- // expect(resp.status).toBe(302);
164- // });
165- // it('should include redirect(url, status)', () => {
166- // const resp = redirect('/home', 301);
167- // expect(resp.headers.get('Location')).toBe('/home');
168- // expect(resp.status).toBe(301);
169- // });
17078 } ) ;
17179} ) ;
0 commit comments