Skip to content

Commit ea9f3cd

Browse files
committed
Improved top-level webapi tests
1 parent 5360544 commit ea9f3cd

17 files changed

+119
-128
lines changed
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
'use strict';
22

33

4-
atob("foo");
4+
var binary = atob("foo");
55

6-
btoa("gibberish");
6+
var ascii = btoa("gibberish");
77

8-
/* Not a pure module */
8+
exports.binary = binary;
9+
exports.ascii = ascii;
10+
/* binary Not a pure module */
Lines changed: 25 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,23 @@
11
'use strict';
22

33

4-
function test_arrayBuffer(blob) {
5-
return blob.arrayBuffer().then(function (buffer) {
6-
return Promise.resolve((console.log(buffer.byteLength), undefined));
7-
});
8-
}
9-
10-
function test_size(blob) {
11-
console.log(blob.size);
12-
13-
}
14-
15-
function test_slice(blob) {
16-
var blob$1 = blob.slice(0, undefined, undefined);
17-
console.log(blob$1.size);
18-
19-
}
20-
21-
function test_stream(blob) {
22-
return blob.stream();
23-
}
24-
25-
function test_text(blob) {
26-
return blob.text().then(function (string) {
27-
return Promise.resolve((console.log(string), undefined));
28-
});
29-
}
30-
31-
function test_type(blob) {
32-
console.log(blob.type);
33-
34-
}
4+
var test_blob = new Blob([]);
5+
6+
var test_arrayBuffer = test_blob.arrayBuffer().then(function (buffer) {
7+
return buffer.byteLength;
8+
});
9+
10+
var test_size = test_blob.size;
11+
12+
var test_slice = test_blob.slice(0, undefined, undefined);
13+
14+
var test_stream = test_blob.stream();
15+
16+
var test_text = test_blob.text().then(function (string) {
17+
return Promise.resolve((console.log(string), undefined));
18+
});
19+
20+
var test_type = test_blob.type;
3521

3622
var test_blobPropertyBag = {
3723
type: "text/plain",
@@ -46,11 +32,9 @@ var test_blobPropertyBagNone = {};
4632

4733
var test_blobPart_blob = new Blob([]);
4834

49-
function test_blobPart_arrayBuffer(blob) {
50-
return blob.arrayBuffer().then(function (buffer) {
51-
return Promise.resolve(buffer);
52-
});
53-
}
35+
var test_blobPart_arrayBuffer = test_blob.arrayBuffer().then(function (buffer) {
36+
return Promise.resolve(buffer);
37+
});
5438

5539
var test_blobPart_int8Array = new Int8Array(10);
5640

@@ -68,18 +52,15 @@ var test_blobPart_float32 = new Float32Array(10);
6852

6953
var test_blobPart_float64Array = new Float64Array(10);
7054

71-
function test_blobPart_dataView(blob) {
72-
return blob.arrayBuffer().then(function (buffer) {
73-
return Promise.resolve(new DataView(buffer));
74-
});
75-
}
76-
77-
var test_blob = new Blob([]);
55+
var test_blobPart_dataView = test_blob.arrayBuffer().then(function (buffer) {
56+
return Promise.resolve(new DataView(buffer));
57+
});
7858

7959
var test_blobWithOptions = new Blob(["hello"], {});
8060

8161
var test_blobPart_string = "hello";
8262

63+
exports.test_blob = test_blob;
8364
exports.test_arrayBuffer = test_arrayBuffer;
8465
exports.test_size = test_size;
8566
exports.test_slice = test_slice;
@@ -101,6 +82,5 @@ exports.test_blobPart_uint32Array = test_blobPart_uint32Array;
10182
exports.test_blobPart_float32 = test_blobPart_float32;
10283
exports.test_blobPart_float64Array = test_blobPart_float64Array;
10384
exports.test_blobPart_dataView = test_blobPart_dataView;
104-
exports.test_blob = test_blob;
10585
exports.test_blobWithOptions = test_blobWithOptions;
106-
/* test_blobPart_blob Not a pure module */
86+
/* test_blob Not a pure module */
Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
'use strict';
22

33

4-
function test_lastModified(file) {
5-
console.log(file.lastModified);
6-
7-
}
4+
var test_file = new File(["hello"], "hello.txt");
85

9-
function test_name(file) {
10-
console.log(file.name);
11-
12-
}
6+
var test_lastModified = test_file.lastModified;
7+
8+
var test_name = test_file.name;
139

1410
var test_filePropertyBag = {
1511
endings: "transparent",
@@ -19,16 +15,14 @@ var test_filePropertyBag = {
1915

2016
var test_filePropertyBagNone = {};
2117

22-
var test_make = new File(["hello"], "hello.txt");
23-
2418
var test_makeWithOptions = new File(["hello"], "hello.txt", {
2519
type: "text/plain"
2620
});
2721

22+
exports.test_file = test_file;
2823
exports.test_lastModified = test_lastModified;
2924
exports.test_name = test_name;
3025
exports.test_filePropertyBag = test_filePropertyBag;
3126
exports.test_filePropertyBagNone = test_filePropertyBagNone;
32-
exports.test_make = test_make;
3327
exports.test_makeWithOptions = test_makeWithOptions;
34-
/* test_make Not a pure module */
28+
/* test_file Not a pure module */

lib/js/tests/Webapi/Webapi__Performace__test.js

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
4+
var n = window.performance.now();
5+
6+
exports.n = n;
7+
/* n Not a pure module */

lib/js/tests/Webapi/Webapi__ResizeObserver__test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ var Caml_array = require("rescript/lib/js/caml_array.js");
55
var el = document.createElement("strong");
66

77
function handler(entries) {
8-
Caml_array.get(entries, 0);
8+
var entry = Caml_array.get(entries, 0);
9+
var cr = entry.contentRect;
10+
var t = entry.target;
11+
console.log(cr, t);
912

1013
}
1114

lib/js/tests/Webapi/Webapi__Url__test.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ params.forEach(function (prim0, prim1) {
88

99
});
1010

11-
function test_entries(params) {
12-
return Array.from(params.entries());
13-
}
14-
15-
console.log(Array.from(params.entries()));
11+
var test_entries = Array.from(params.entries());
1612

1713
exports.params = params;
1814
exports.test_entries = test_entries;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
open Webapi.Base64
22

3-
let _ = atob("foo")
4-
let _ = btoa("gibberish")
3+
let binary: string = atob("foo")
4+
let ascii: string = btoa("gibberish")
Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,61 @@
11
open Webapi.Blob
22

3-
let test_arrayBuffer = blob =>
4-
blob
3+
let test_blob: t = make([])
4+
5+
let test_arrayBuffer: Js.Promise.t<int> =
6+
test_blob
57
->arrayBuffer
6-
->Promise.then(buffer =>
7-
buffer->Js.Typed_array.ArrayBuffer.byteLength->Js.log->Promise.resolve
8-
)
8+
->Promise.thenResolve(buffer => buffer->Js.Typed_array.ArrayBuffer.byteLength)
99

10-
let test_size = blob => blob->size->Js.log
10+
let test_size: float = test_blob->size
1111

12-
let test_slice = blob => test_size(blob->slice(~start=0, ()))
12+
let test_slice: t = test_blob->slice(~start=0, ())
1313

14-
let test_stream = blob => blob->stream
14+
let test_stream: Webapi.ReadableStream.t = test_blob->stream
1515

16-
let test_text = blob => blob->text->Promise.then(string => string->Js.log->Promise.resolve)
16+
let test_text: Js.Promise.t<unit> =
17+
test_blob->text->Promise.then(string => string->Js.log->Promise.resolve)
1718

18-
let test_type = blob => blob->type_->Js.log
19+
let test_type: string = test_blob->type_
1920

20-
let test_blobPropertyBag: blobPropertyBag = makeBlobPropertyBag(~_type="text/plain", ~endings=#transparent, ())
21+
let test_blobPropertyBag: blobPropertyBag = makeBlobPropertyBag(
22+
~_type="text/plain",
23+
~endings=#transparent,
24+
(),
25+
)
2126
let test_blobPropertyBagTypeOnly: blobPropertyBag = makeBlobPropertyBag(~_type="text/plain", ())
2227
let test_blobPropertyBagNone: blobPropertyBag = makeBlobPropertyBag()
2328

2429
let test_blobPart_string: blobPart = stringToBlobPart("hello")
2530
let test_blobPart_blob: blobPart = blobToBlobPart(make([]))
26-
let test_blobPart_arrayBuffer: t => Promise.t<blobPart> = blob =>
27-
blob
28-
->arrayBuffer
29-
->Promise.then(buffer =>
30-
buffer->arrayBufferToBlobPart->Promise.resolve
31-
)
31+
let test_blobPart_arrayBuffer: Promise.t<blobPart> =
32+
test_blob->arrayBuffer->Promise.then(buffer => buffer->arrayBufferToBlobPart->Promise.resolve)
33+
3234
let test_blobPart_int8Array: blobPart = int8ArrayToBlobPart(Js.Typed_array.Int8Array.fromLength(10))
33-
let test_blobPart_uint8Array: blobPart = uint8ArrayToBlobPart(Js.Typed_array.Uint8Array.fromLength(10))
34-
let test_blobPart_uint8ClampedArray: blobPart = uint8ClampedArrayToBlobPart(Js.Typed_array.Uint8ClampedArray.fromLength(10))
35-
let test_blobPart_int16Array: blobPart = int16ArrayToBlobPart(Js.Typed_array.Int16Array.fromLength(10))
36-
let test_blobPart_int32Array: blobPart = int32ArrayToBlobPart(Js.Typed_array.Int32Array.fromLength(10))
37-
let test_blobPart_uint32Array: blobPart = uint32ArrayToBlobPart(Js.Typed_array.Uint32Array.fromLength(10))
35+
let test_blobPart_uint8Array: blobPart = uint8ArrayToBlobPart(
36+
Js.Typed_array.Uint8Array.fromLength(10),
37+
)
38+
let test_blobPart_uint8ClampedArray: blobPart = uint8ClampedArrayToBlobPart(
39+
Js.Typed_array.Uint8ClampedArray.fromLength(10),
40+
)
41+
let test_blobPart_int16Array: blobPart = int16ArrayToBlobPart(
42+
Js.Typed_array.Int16Array.fromLength(10),
43+
)
44+
let test_blobPart_int32Array: blobPart = int32ArrayToBlobPart(
45+
Js.Typed_array.Int32Array.fromLength(10),
46+
)
47+
let test_blobPart_uint32Array: blobPart = uint32ArrayToBlobPart(
48+
Js.Typed_array.Uint32Array.fromLength(10),
49+
)
3850
let test_blobPart_float32: blobPart = float32ToBlobPart(Js.Typed_array.Float32Array.fromLength(10))
39-
let test_blobPart_float64Array: blobPart = float64ArrayToBlobPart(Js.Typed_array.Float64Array.fromLength(10))
40-
let test_blobPart_dataView: t => Promise.t<blobPart> = (blob) => blob
51+
let test_blobPart_float64Array: blobPart = float64ArrayToBlobPart(
52+
Js.Typed_array.Float64Array.fromLength(10),
53+
)
54+
let test_blobPart_dataView: Promise.t<blobPart> =
55+
test_blob
4156
->arrayBuffer
4257
->Promise.then(buffer =>
4358
dataViewToBlobPart(Js.Typed_array.DataView.make(buffer))->Promise.resolve
4459
)
4560

46-
let test_blob: t = make([])
4761
let test_blobWithOptions: t = makeWithOptions([stringToBlobPart("hello")], makeBlobPropertyBag())
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
open Webapi.File
22

3-
let test_lastModified = file => file->lastModified->Js.log
4-
let test_name = file => file->name->Js.log
3+
let test_file: t = make([Webapi.Blob.stringToBlobPart("hello")], "hello.txt")
4+
let test_lastModified: float = test_file->lastModified
5+
let test_name: string = test_file->name
56
let test_filePropertyBag: filePropertyBag = makeFilePropertyBag(~endings=#transparent, ~_type="text/plain", ~lastModified=123.0, ())
67
let test_filePropertyBagNone: filePropertyBag = makeFilePropertyBag()
7-
let test_make: t = make([Webapi.Blob.stringToBlobPart("hello")], "hello.txt")
88
let test_makeWithOptions: t = makeWithOptions([Webapi.Blob.stringToBlobPart("hello")], "hello.txt", makeFilePropertyBag(~_type="text/plain", ()))

0 commit comments

Comments
 (0)