Skip to content

Commit bac761c

Browse files
committed
add simple unit tests
1 parent 36bdd79 commit bac761c

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

test/unit/tw_external.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const external = require('../../src/extension-support/tw-external');
2+
const {test} = require('tap');
3+
4+
test('importModule', t => {
5+
external.importModule('data:text/javascript;,export%20default%201').then(mod => {
6+
t.equal(mod.default, 1);
7+
t.end();
8+
});
9+
});
10+
11+
test('fetch', t => {
12+
external.fetch('data:text/plain;,test').then(res => {
13+
res.text().then(text => {
14+
t.equal(text, 'test');
15+
t.end();
16+
});
17+
});
18+
});
19+
20+
// Node.js does not support FileReader (yet?) so not really possible to properly test dataURL
21+
22+
test('blob', t => {
23+
external.blob('data:text/plain;,test').then(blob => {
24+
blob.text().then(blobText => {
25+
t.equal(blobText, 'test');
26+
t.end();
27+
});
28+
});
29+
});
30+
31+
test('evalAndReturn', t => {
32+
external.evalAndReturn('data:text/plain;,var%20x=20', 'x').then(result => {
33+
t.equal(result, 20);
34+
t.end();
35+
});
36+
});

0 commit comments

Comments
 (0)