Skip to content

Commit 1ae638c

Browse files
author
Marius
committed
Add tests for type definitions
1 parent 3774a74 commit 1ae638c

File tree

4 files changed

+1194
-4
lines changed

4 files changed

+1194
-4
lines changed

lib/index.test-d.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// This is a test file for ensuring that the type definitions in index.d.ts are
2+
// working correctly. For more details see:
3+
// https://github.com/SamVerschueren/tsd
4+
5+
import * as tus from '../';
6+
import {expectType} from 'tsd';
7+
8+
expectType<boolean>(tus.isSupported);
9+
expectType<boolean>(tus.canStoreURLs);
10+
11+
const file = new File(["foo"], "foo.txt", {
12+
type: "text/plain",
13+
});
14+
15+
const upload = new tus.Upload(file, {
16+
endpoint: "",
17+
fingerprint: (file: File) => Promise.resolve(file.name),
18+
metadata: {
19+
filename: "foo.txt"
20+
},
21+
onProgress: (bytesSent: number, bytesTotal: number) => {
22+
const percentage = (bytesSent / bytesTotal * 100).toFixed(2);
23+
console.log(bytesSent, bytesTotal, percentage + "%");
24+
},
25+
onChunkComplete: (chunkSize: number, bytesAccepted: number) => {},
26+
onSuccess: () => {
27+
console.log("Download from %s complete", upload.url);
28+
},
29+
onError: (error: Error) => {
30+
console.log("Failed because: " + error);
31+
},
32+
headers: {TestHeader: 'TestValue'},
33+
chunkSize: 100,
34+
uploadUrl: "",
35+
uploadSize: 50,
36+
overridePatchMethod: true,
37+
retryDelays: [10, 20, 50],
38+
removeFingerprintOnSuccess: true,
39+
parallelUploads: 42,
40+
onAfterResponse: function (req: tus.HttpRequest, res: tus.HttpResponse) {
41+
var url = req.getURL();
42+
var value = res.getHeader("X-My-Header");
43+
console.log(`Request for ${url} responded with ${value}`);
44+
}
45+
});
46+
47+
upload.start();
48+
49+
upload.findPreviousUploads().then((uploads: tus.PreviousUpload[]) => {
50+
upload.resumeFromPreviousUpload(uploads[0]);
51+
})
52+
53+
upload.abort();
54+
upload.abort(true).then(() => {});
55+
56+
const upload2 = new tus.Upload(file, {
57+
endpoint: ""
58+
});
59+
60+
const reader = {
61+
read: () => Promise.resolve({ done: true, value: '' }),
62+
};
63+
const upload3 = new tus.Upload(reader, {
64+
endpoint: '',
65+
uploadLengthDeferred: true,
66+
});
67+
68+
tus.Upload.terminate('https://myurl.com', {
69+
endpoint: ""
70+
});

0 commit comments

Comments
 (0)