@util.js/node-http 0.41.0 → 0.41.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +1 -1
- package/lib/Urls.js +1 -1
- package/package.json +4 -4
- package/test/UrlsTest.js +24 -20
package/index.js
CHANGED
package/lib/Urls.js
CHANGED
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "Chris Topher <c@creemama.com>",
|
|
3
3
|
"dependencies": {
|
|
4
|
-
"@util.js/node-files": "0.41.
|
|
5
|
-
"@util.js/promises": "0.41.
|
|
4
|
+
"@util.js/node-files": "0.41.2",
|
|
5
|
+
"@util.js/promises": "0.41.2"
|
|
6
6
|
},
|
|
7
7
|
"description": "JavaScript utility methods for URLs",
|
|
8
8
|
"keywords": [
|
|
@@ -27,6 +27,6 @@
|
|
|
27
27
|
"type": "git",
|
|
28
28
|
"url": "https://github.com/creemama/utiljs/tree/master/packages/utiljs-node-http"
|
|
29
29
|
},
|
|
30
|
-
"version": "0.41.
|
|
31
|
-
"gitHead": "
|
|
30
|
+
"version": "0.41.2",
|
|
31
|
+
"gitHead": "174b81ec0ead0221b9bb6617bc254b025bd20a5a"
|
|
32
32
|
}
|
package/test/UrlsTest.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const expect = require("chai").expect
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
const expect = require("chai").expect;
|
|
4
|
+
const files = require("@util.js/node-files");
|
|
5
|
+
const targetDir = files.join(__dirname, "..", "target");
|
|
6
|
+
const urls = require("..");
|
|
7
7
|
let fileNum = 0;
|
|
8
8
|
|
|
9
9
|
describe("Urls", () => {
|
|
@@ -33,11 +33,11 @@ describe("Urls", () => {
|
|
|
33
33
|
|
|
34
34
|
describe("#download(url, destination)", () => {
|
|
35
35
|
it("handles HTTP requests", () =>
|
|
36
|
-
|
|
36
|
+
downloadUrlDestination("http://www.google.com"));
|
|
37
37
|
it("handles HTTPS requests", () =>
|
|
38
|
-
|
|
38
|
+
downloadUrlDestination("https://www.google.com"));
|
|
39
39
|
it("should throw an error if the protocol is not HTTP or HTTPS", () =>
|
|
40
|
-
|
|
40
|
+
downloadUrlDestination("ftp://www.google.com").then(
|
|
41
41
|
(value) => {
|
|
42
42
|
throw new Error("Unexpected success");
|
|
43
43
|
},
|
|
@@ -46,7 +46,7 @@ describe("Urls", () => {
|
|
|
46
46
|
}
|
|
47
47
|
));
|
|
48
48
|
it("should throw an error if there is no protocol", () =>
|
|
49
|
-
|
|
49
|
+
downloadUrlDestination("www.google.com").then(
|
|
50
50
|
(value) => {
|
|
51
51
|
throw new Error("Unexpected success");
|
|
52
52
|
},
|
|
@@ -55,24 +55,26 @@ describe("Urls", () => {
|
|
|
55
55
|
}
|
|
56
56
|
));
|
|
57
57
|
it("handles HTTP errors", () =>
|
|
58
|
-
|
|
58
|
+
downloadUrlDestination("http://doesnotexist:8080", {
|
|
59
59
|
timeout: 50,
|
|
60
60
|
}).then(
|
|
61
61
|
(value) => {
|
|
62
62
|
throw new Error("Unexpected success");
|
|
63
63
|
},
|
|
64
64
|
(error) => {
|
|
65
|
+
if (!error) throw new Error("Unexpected");
|
|
65
66
|
/* expected */
|
|
66
67
|
}
|
|
67
68
|
));
|
|
68
69
|
it("handles HTTPS errors", () =>
|
|
69
|
-
|
|
70
|
+
downloadUrlDestination("https://doesnotexist:8443", {
|
|
70
71
|
timeout: 50,
|
|
71
72
|
}).then(
|
|
72
73
|
(value) => {
|
|
73
74
|
throw new Error("Unexpected success");
|
|
74
75
|
},
|
|
75
76
|
(error) => {
|
|
77
|
+
if (!error) throw new Error("Unexpected");
|
|
76
78
|
/* expected */
|
|
77
79
|
}
|
|
78
80
|
));
|
|
@@ -80,11 +82,11 @@ describe("Urls", () => {
|
|
|
80
82
|
|
|
81
83
|
describe("#download(url, destination, callback)", () => {
|
|
82
84
|
it("handles HTTP requests", (callback) =>
|
|
83
|
-
|
|
85
|
+
downloadUrlDestinationCallback("http://www.google.com", callback));
|
|
84
86
|
it("handles HTTPS requests", (callback) =>
|
|
85
|
-
|
|
87
|
+
downloadUrlDestinationCallback("https://www.google.com", callback));
|
|
86
88
|
it("handles HTTP errors", (callback) =>
|
|
87
|
-
|
|
89
|
+
downloadUrlDestinationCallback(
|
|
88
90
|
"http://doesnotexist:8080",
|
|
89
91
|
{ timeout: 50 },
|
|
90
92
|
(error) => {
|
|
@@ -93,7 +95,7 @@ describe("Urls", () => {
|
|
|
93
95
|
}
|
|
94
96
|
));
|
|
95
97
|
it("handles HTTPS errors", (callback) =>
|
|
96
|
-
|
|
98
|
+
downloadUrlDestinationCallback(
|
|
97
99
|
"https://doesnotexist:8443",
|
|
98
100
|
{ timeout: 50 },
|
|
99
101
|
(error) => {
|
|
@@ -122,6 +124,7 @@ describe("Urls", () => {
|
|
|
122
124
|
throw new Error("Unexpected success");
|
|
123
125
|
},
|
|
124
126
|
(error) => {
|
|
127
|
+
if (!error) throw new Error("Unexpected");
|
|
125
128
|
/* expected */
|
|
126
129
|
}
|
|
127
130
|
));
|
|
@@ -131,6 +134,7 @@ describe("Urls", () => {
|
|
|
131
134
|
throw new Error("Unexpected success");
|
|
132
135
|
},
|
|
133
136
|
(error) => {
|
|
137
|
+
if (!error) throw new Error("Unexpected");
|
|
134
138
|
/* expected */
|
|
135
139
|
}
|
|
136
140
|
));
|
|
@@ -160,13 +164,13 @@ describe("Urls", () => {
|
|
|
160
164
|
});
|
|
161
165
|
});
|
|
162
166
|
|
|
163
|
-
async function
|
|
167
|
+
async function downloadUrlDestination(url, options) {
|
|
164
168
|
await files.mkdirp(targetDir);
|
|
165
169
|
const destination =
|
|
166
170
|
targetDir +
|
|
167
171
|
"/" +
|
|
168
172
|
files.sanitizeFilename(
|
|
169
|
-
fileNum++ + ".
|
|
173
|
+
fileNum++ + ".downloadUrlDestination." + url + ".html",
|
|
170
174
|
{ replacement: "_" }
|
|
171
175
|
);
|
|
172
176
|
|
|
@@ -186,11 +190,11 @@ async function download_url_destination(url, options) {
|
|
|
186
190
|
.then(verifyFile);
|
|
187
191
|
}
|
|
188
192
|
|
|
189
|
-
function
|
|
190
|
-
|
|
193
|
+
function downloadUrlDestinationCallback() {
|
|
194
|
+
asyncDownloadUrlDestinationCallback(...arguments);
|
|
191
195
|
}
|
|
192
196
|
|
|
193
|
-
async function
|
|
197
|
+
async function asyncDownloadUrlDestinationCallback(
|
|
194
198
|
url,
|
|
195
199
|
callbackOrOptions,
|
|
196
200
|
callback
|
|
@@ -201,7 +205,7 @@ async function async_download_url_destination_callback(
|
|
|
201
205
|
targetDir +
|
|
202
206
|
"/" +
|
|
203
207
|
files.sanitizeFilename(
|
|
204
|
-
fileNum++ + ".
|
|
208
|
+
fileNum++ + ".asyncDownloadUrlDestinationCallback." + url + ".html",
|
|
205
209
|
{ replacement: "_" }
|
|
206
210
|
);
|
|
207
211
|
const options = callbackOrOptions
|