|
| 1 | +const fs = require('fs'); |
1 | 2 | const test = require('ava');
|
2 | 3 | const Blob = require('.');
|
| 4 | +const blobFrom = require('./from'); |
3 | 5 | const getStream = require('get-stream');
|
4 | 6 | const {Response} = require('node-fetch');
|
5 | 7 | const {TextDecoder} = require('util');
|
@@ -142,3 +144,19 @@ test('Blob works with node-fetch Response.text()', async t => {
|
142 | 144 | const text = await response.text();
|
143 | 145 | t.is(text, data);
|
144 | 146 | });
|
| 147 | + |
| 148 | +test('blob part backed up by filesystem', async t => { |
| 149 | + const blob = blobFrom('./LICENSE'); |
| 150 | + t.is(await blob.slice(0, 3).text(), 'MIT'); |
| 151 | + t.is(await blob.slice(4, 11).text(), 'License'); |
| 152 | +}); |
| 153 | + |
| 154 | +test('Reading after modified should fail', async t => { |
| 155 | + const blob = blobFrom('./LICENSE'); |
| 156 | + await new Promise(resolve => setTimeout(resolve, 100)); |
| 157 | + const now = new Date(); |
| 158 | + // Change modified time |
| 159 | + fs.utimesSync('./LICENSE', now, now); |
| 160 | + const error = await blob.text().catch(error => error); |
| 161 | + t.is(error.name, 'NotReadableError'); |
| 162 | +}); |
0 commit comments