Skip to content

Commit b90ec26

Browse files
committed
Update tests to fetch
1 parent debb812 commit b90ec26

File tree

4 files changed

+55
-27
lines changed

4 files changed

+55
-27
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
language: node_js
22
node_js:
3-
- 12
43
- 14
54
before_install:
6-
- "curl -L http://git.io/ejPSng | /bin/sh"
5+
- "curl -L http://git.io/ejPSng | /bin/sh"

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# Changelog
22

3+
## v1.1.1 - 2022-5-07
4+
* Updated tests to use `fetch`
35
## v1.1.0 - 2020-9-05
46

57
### Changes
68
* Updated `path-to-regexp` npm dependency to v6.1
79
* Modernized code
810
* New management under Meteor Community Packages
911
* Bumped minimum required Meteor version to 1.9 as it is the oldest Meteor version running on Node v12 (currently the oldest Node major version that is still supported).
10-
* Incorporate PRs 34, 39, 42, 52 from the original Picker repository.
12+
* Incorporate PRs 34, 39, 42, 52 from the original Picker repository.

package.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ Package.onUse(function(api) {
2323
Package.onTest(function(api) {
2424
configurePackage(api);
2525
api.use('communitypackages:picker', 'server');
26-
api.use(['tinytest', 'http', 'random'], 'server');
26+
api.use(['tinytest', 'fetch', 'random'], 'server');
2727
api.mainModule('test/instance.js', 'server');
2828
});

test/instance.js

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,33 @@
1-
import { Picker } from 'meteor/storyteller:picker';
2-
// TODO replace HTTP with fetch
3-
import { HTTP } from 'meteor/http';
4-
import { Random } from 'meteor/random';
5-
import { Meteor } from 'meteor/meteor';
1+
import { Picker } from 'meteor/communitypackages:picker'
2+
import { fetch } from 'meteor/fetch'
3+
import { Meteor } from 'meteor/meteor'
4+
import { Random } from 'meteor/random'
65

76
function getPath(path) {
87
return Meteor.absoluteUrl(path);
98
}
109

10+
async function getAsync (url, options) {
11+
try {
12+
const response = await fetch(url, options)
13+
return await response.text()
14+
} catch (e) {
15+
throw new Meteor.Error(500, e.message)
16+
}
17+
}
18+
19+
const get = Meteor.wrapAsync(getAsync)
20+
1121
Tinytest.add('normal route', function(test) {
1222
const id = Random.id();
1323
Picker.route(`/${id}`, function(params, req, res) {
1424
res.end("done");
1525
});
1626

17-
const res = HTTP.get(getPath(id));
18-
test.equal(res.content, 'done');
27+
get(getPath(id), { method: 'GET' }, (error, success) => {
28+
test.equal(success, 'done');
29+
});
30+
1931
});
2032

2133
Tinytest.add('with params', function(test) {
@@ -25,8 +37,9 @@ Tinytest.add('with params', function(test) {
2537
res.end(params.id);
2638
});
2739

28-
const res = HTTP.get(getPath(`post/${id}`));
29-
test.equal(res.content, id);
40+
get(getPath(`post/${id}`), { method: 'GET' }, (error, res) => {
41+
test.equal(res, id);
42+
});
3043
});
3144

3245
Tinytest.add('filter only POST', function(test) {
@@ -39,11 +52,15 @@ Tinytest.add('filter only POST', function(test) {
3952
res.end("done");
4053
});
4154

42-
const res1 = HTTP.get(getPath(`/${id}`));
43-
test.isFalse(res1.content === "done");
55+
get(getPath(`/${id}`), { method: 'GET' }, (error, res) => {
56+
test.isFalse(res === "done");
57+
});
58+
59+
60+
get(getPath(`/${id}`), { method: 'POST' }, (error, res) => {
61+
test.isTrue(res === "done");
62+
});
4463

45-
const res2 = HTTP.post(getPath(`/${id}`));
46-
test.isTrue(res2.content === "done");
4764
});
4865

4966
Tinytest.add('query strings', function(test) {
@@ -52,8 +69,10 @@ Tinytest.add('query strings', function(test) {
5269
res.end("" + params.query.aa);
5370
});
5471

55-
const res = HTTP.get(getPath(`/${id}?aa=10&bb=10`));
56-
test.equal(res.content, "10");
72+
get(getPath(`/${id}?aa=10&bb=10`), { method: 'GET' }, (error, res) => {
73+
test.equal(res, "10");
74+
});
75+
5776
});
5877

5978
Tinytest.add('middlewares', function(test) {
@@ -70,8 +89,10 @@ Tinytest.add('middlewares', function(test) {
7089
res.end(req.middlewarePass);
7190
});
7291

73-
const res = HTTP.get(getPath(`/${id}?aa=10`));
74-
test.equal(res.content, "ok");
92+
get(getPath(`/${id}?aa=10`), { method: 'GET' }, (error, res) => {
93+
test.equal(res, "ok");
94+
});
95+
7596
});
7697

7798
Tinytest.add('middlewares - with filtered routes', function(test) {
@@ -93,8 +114,10 @@ Tinytest.add('middlewares - with filtered routes', function(test) {
93114
res.end(req.middlewarePass);
94115
});
95116

96-
const res = HTTP.get(getPath(path));
97-
test.equal(res.content, "ok");
117+
get(getPath(path), { method: 'GET' }, (error, res) => {
118+
test.equal(res, "ok");
119+
});
120+
98121
});
99122

100123

@@ -125,9 +148,13 @@ Tinytest.add('middlewares - with several filtered routes', function(test) {
125148
res.end(req.result+'');
126149
});
127150

128-
const res1 = HTTP.get(getPath(path1));
129-
test.equal(res1.content, "11");
151+
get(getPath(path1), { method: 'GET' }, (error, res) => {
152+
test.equal(res, "11");
153+
});
154+
155+
156+
get(getPath(path2), { method: 'GET' }, (error, res) => {
157+
test.equal(res, "12");
158+
});
130159

131-
const res2 = HTTP.get(getPath(path2));
132-
test.equal(res2.content, "12");
133160
});

0 commit comments

Comments
 (0)