MIRROR: javascript for ๐Ÿœ's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

add live fetching to spec

+36 -14
+36 -14
examples/spec/fetch.js
··· 23 23 const jsonResponse = await fetch('data:application/json,%7B%22ok%22%3Atrue%7D'); 24 24 test('fetch data url json content-type', jsonResponse.headers.get('content-type'), 'application/json'); 25 25 test('fetch data url json body', (await jsonResponse.json()).ok, true); 26 - test('fetch response headers immutable', (() => { 27 - try { 28 - jsonResponse.headers.append('x-test', '1'); 29 - return false; 30 - } catch (_err) { 31 - return true; 32 - } 33 - })(), true); 26 + 27 + test( 28 + 'fetch response headers immutable', 29 + (() => { 30 + try { 31 + jsonResponse.headers.append('x-test', '1'); 32 + return false; 33 + } catch (_err) { 34 + return true; 35 + } 36 + })(), 37 + true 38 + ); 34 39 35 40 const requestInput = new Request('data:text/plain,request-body'); 36 41 const requestResponse = await fetch(requestInput); 37 42 test('fetch accepts Request input', await requestResponse.text(), 'request-body'); 38 43 44 + const encoder = new TextEncoder(); 45 + const streamBody = new ReadableStream({ 46 + start(controller) { 47 + controller.enqueue(encoder.encode('{"runtime":"ant",')); 48 + controller.enqueue(encoder.encode('"stream":true}')); 49 + controller.close(); 50 + } 51 + }); 52 + const streamedUploadResponse = await fetch('https://httpbingo.org/post', { 53 + method: 'POST', 54 + body: streamBody, 55 + duplex: 'half', 56 + headers: { 57 + 'Content-Type': 'application/json' 58 + } 59 + }); 60 + const streamedUploadJson = await streamedUploadResponse.json(); 61 + test('fetch streamed body status', streamedUploadResponse.status, 200); 62 + test('fetch streamed body json runtime', streamedUploadJson.json.runtime, 'ant'); 63 + test('fetch streamed body json stream', streamedUploadJson.json.stream, true); 64 + 39 65 const abortedController = new AbortController(); 40 66 abortedController.abort(new Error('aborted')); 41 - await testRejects('fetch with aborted signal', () => 42 - fetch('data:,ignored', { signal: abortedController.signal }) 43 - ); 67 + await testRejects('fetch with aborted signal', () => fetch('data:,ignored', { signal: abortedController.signal })); 44 68 45 - await testRejects('fetch unsupported scheme', () => 46 - fetch('file:///tmp/ant-fetch-unsupported') 47 - ); 69 + await testRejects('fetch unsupported scheme', () => fetch('file:///tmp/ant-fetch-unsupported')); 48 70 49 71 summary();