|
1 |
| - |
2 |
| -import test from 'ava'; |
3 |
| -import Blob from './blob'; |
4 |
| -import util from 'util'; |
5 |
| -import stream from 'stream'; |
6 |
| -import getStream from 'get-stream'; |
7 |
| -import { Response } from 'node-fetch'; |
8 |
| - |
9 |
| -const TextDecoder = util.TextDecoder; |
10 |
| -const Readable = stream.Readable; |
| 1 | +const test = require('ava'); |
| 2 | +const Blob = require('./blob'); |
| 3 | +const getStream = require('get-stream'); |
| 4 | +const {Response} = require('node-fetch'); |
11 | 5 |
|
12 | 6 | test('Blob ctor', t => {
|
13 |
| - let data = 'a=1'; |
14 |
| - let blob = new Blob([data]); |
| 7 | + const data = 'a=1'; |
| 8 | + const blob = new Blob([data]); // eslint-disable-line no-unused-vars |
15 | 9 | t.pass();
|
16 | 10 | });
|
17 | 11 |
|
18 | 12 | test('Blob size', t => {
|
19 |
| - let data = 'a=1'; |
20 |
| - let blob = new Blob([data]); |
| 13 | + const data = 'a=1'; |
| 14 | + const blob = new Blob([data]); |
21 | 15 | t.is(blob.size, data.length);
|
22 | 16 | });
|
23 | 17 |
|
24 | 18 | test('Blob type', t => {
|
25 |
| - let data = 'a=1'; |
26 |
| - let type = 'text/plain'; |
27 |
| - let blob = new Blob([data], { type }); |
| 19 | + const data = 'a=1'; |
| 20 | + const type = 'text/plain'; |
| 21 | + const blob = new Blob([data], {type}); |
28 | 22 | t.is(blob.type, type);
|
29 | 23 | });
|
30 | 24 |
|
31 | 25 | test('Blob text()', async t => {
|
32 |
| - let data = 'a=1'; |
33 |
| - let type = 'text/plain'; |
34 |
| - let blob = new Blob([data], { type }); |
| 26 | + const data = 'a=1'; |
| 27 | + const type = 'text/plain'; |
| 28 | + const blob = new Blob([data], {type}); |
35 | 29 | t.is(await blob.text(), data);
|
36 | 30 | });
|
37 | 31 |
|
38 | 32 | test('Blob arrayBuffer()', async t => {
|
39 |
| - let data = 'a=1'; |
40 |
| - let type = 'text/plain'; |
41 |
| - let blob = new Blob([data], { type }); |
| 33 | + const data = 'a=1'; |
| 34 | + const type = 'text/plain'; |
| 35 | + const blob = new Blob([data], {type}); |
42 | 36 |
|
43 |
| - let decoder = new TextDecoder('utf-8'); |
44 |
| - let buffer = await blob.arrayBuffer(); |
| 37 | + const decoder = new TextDecoder('utf-8'); |
| 38 | + const buffer = await blob.arrayBuffer(); |
45 | 39 | t.is(decoder.decode(buffer), data);
|
46 | 40 | });
|
47 | 41 |
|
48 | 42 | test('Blob stream()', async t => {
|
49 |
| - let data = 'a=1'; |
50 |
| - let type = 'text/plain'; |
51 |
| - let blob = new Blob([data], { type }); |
52 |
| - let result = await getStream(blob.stream()); |
| 43 | + const data = 'a=1'; |
| 44 | + const type = 'text/plain'; |
| 45 | + const blob = new Blob([data], {type}); |
| 46 | + const result = await getStream(blob.stream()); |
53 | 47 | t.is(result, data);
|
54 | 48 | });
|
55 | 49 |
|
56 | 50 | test('Blob toString()', t => {
|
57 |
| - let data = 'a=1'; |
58 |
| - let type = 'text/plain'; |
59 |
| - let blob = new Blob([data], { type }); |
| 51 | + const data = 'a=1'; |
| 52 | + const type = 'text/plain'; |
| 53 | + const blob = new Blob([data], {type}); |
60 | 54 | t.is(blob.toString(), '[object Blob]');
|
61 | 55 | });
|
62 | 56 |
|
63 | 57 | test('Blob slice()', async t => {
|
64 |
| - let data = 'a=1'; |
65 |
| - let type = 'text/plain'; |
66 |
| - let blob = new Blob([data], { type }); |
67 |
| - let blob2 = blob.slice(0, 1); |
| 58 | + const data = 'a=1'; |
| 59 | + const type = 'text/plain'; |
| 60 | + const blob = new Blob([data], {type}); |
| 61 | + const blob2 = blob.slice(0, 1); |
68 | 62 | t.is(await blob2.text(), data.slice(0, 1));
|
69 | 63 | });
|
70 | 64 |
|
71 | 65 | test('Blob works with node-fetch Response.blob()', async t => {
|
72 |
| - let data = 'a=1'; |
73 |
| - let type = 'text/plain'; |
74 |
| - let blob = new Blob([data], { type }); |
75 |
| - let res = new Response(blob); |
76 |
| - let blob2 = await res.blob(); |
| 66 | + const data = 'a=1'; |
| 67 | + const type = 'text/plain'; |
| 68 | + const blob = new Blob([data], {type}); |
| 69 | + const res = new Response(blob); |
| 70 | + const blob2 = await res.blob(); |
77 | 71 | t.is(await blob2.text(), data);
|
78 | 72 | });
|
79 | 73 |
|
80 | 74 | test('Blob works with node-fetch Response.text()', async t => {
|
81 |
| - let data = 'a=1'; |
82 |
| - let type = 'text/plain'; |
83 |
| - let blob = new Blob([data], { type }); |
84 |
| - let res = new Response(blob); |
85 |
| - let text = await res.text(); |
| 75 | + const data = 'a=1'; |
| 76 | + const type = 'text/plain'; |
| 77 | + const blob = new Blob([data], {type}); |
| 78 | + const res = new Response(blob); |
| 79 | + const text = await res.text(); |
86 | 80 | t.is(text, data);
|
87 | 81 | });
|
0 commit comments