Skip to content

Commit 5ba554e

Browse files
committed
Lowered targeted node version to those who support ESM
closes #98
1 parent 4747497 commit 5ba554e

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fetch-blob",
3-
"version": "3.0.0",
3+
"version": "3.0.1",
44
"description": "Blob & File implementation in Node.js, originally from node-fetch.",
55
"main": "index.js",
66
"type": "module",
@@ -26,7 +26,7 @@
2626
"node-fetch"
2727
],
2828
"engines": {
29-
"node": ">=14.0.0"
29+
"node": "^12.20 || >= 14.13"
3030
},
3131
"author": "Jimmy Wärting <jimmy@warting.se> (https://jimmy.warting.se)",
3232
"license": "MIT",
@@ -39,6 +39,7 @@
3939
"unicorn/prefer-node-protocol": "off",
4040
"unicorn/numeric-separators-style": "off",
4141
"unicorn/prefer-spread": "off",
42+
"unicorn/prefer-number-properties": "off",
4243
"import/extensions": [
4344
"error",
4445
"always",

test.js

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,19 @@ test('Reading after modified should fail', async t => {
162162
await new Promise(resolve => {
163163
setTimeout(resolve, 100);
164164
});
165-
const now = new Date();
166-
// Change modified time
167-
fs.utimesSync('./LICENSE', now, now);
165+
fs.closeSync(fs.openSync('./LICENSE', 'a'));
168166
const error = await t.throwsAsync(blob.text());
169167
t.is(error.constructor.name, 'DOMException');
170168
t.is(error instanceof Error, true);
171169
t.is(error.name, 'NotReadableError');
170+
171+
const file = fileFromSync('./LICENSE');
172+
// Above test updates the last modified date to now
173+
t.is(typeof file.lastModified, 'number');
174+
// The lastModifiedDate is deprecated and removed from spec
175+
t.false('lastModifiedDate' in file);
176+
const mod = file.lastModified - Date.now();
177+
t.true(mod <= 0 && mod >= -100); // Close to tolerance: 0.100ms
172178
});
173179

174180
test('Reading file after modified should fail', async t => {
@@ -297,13 +303,29 @@ test('fileFrom(path, type) sets the type', async t => {
297303
t.is(file.type, 'text/plain');
298304
});
299305

300-
test('fileFrom(path, type) read/sets the lastModified ', async t => {
301-
const file = await fileFrom('./LICENSE', 'text/plain');
302-
// Earlier test updates the last modified date to now
303-
t.is(typeof file.lastModified, 'number');
304-
// The lastModifiedDate is deprecated and removed from spec
305-
t.false('lastModifiedDate' in file);
306-
t.is(file.lastModified > Date.now() - 60000, true);
306+
test('new File(,,{lastModified: 100})', t => {
307+
const mod = new File([], '', {lastModified: 100}).lastModified;
308+
t.is(mod, 100);
309+
});
310+
311+
test('new File(,,{lastModified: "200"})', t => {
312+
const mod = new File([], '', {lastModified: '200'}).lastModified;
313+
t.is(mod, 200);
314+
});
315+
316+
test('new File(,,{lastModified: true})', t => {
317+
const mod = new File([], '', {lastModified: true}).lastModified;
318+
t.is(mod, 1);
319+
});
320+
321+
test('new File(,,{lastModified: new Date()})', t => {
322+
const mod = new File([], '', {lastModified: new Date()}).lastModified - Date.now();
323+
t.true(mod <= 0 && mod >= -20); // Close to tolerance: 0.020ms
324+
});
325+
326+
test('new File(,,{}) sets current time', t => {
327+
const mod = new File([], '').lastModified - Date.now();
328+
t.true(mod <= 0 && mod >= -20); // Close to tolerance: 0.020ms
307329
});
308330

309331
test('blobFrom(path, type) sets the type', async t => {

0 commit comments

Comments
 (0)