-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathupload.js
61 lines (58 loc) · 1.68 KB
/
upload.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* eslint-env node, mocha */
const assert = require("assert");
const createServer = require("./_server");
const FormData = require("form-data");
const fs = require("fs");
const path = require("path");
describe("Upload", () => {
it("Should have updated req.files", (done) => {
// http://localhost:5000
createServer({
directory: path.join(__dirname, "tmp"),
filename: function(req, file, cb) {
cb(file.originalname);
}
}, () => {
// submit form and check req.files
var form = new FormData();
let file = fs.createReadStream(__dirname + "/files/medium_image.jpg");
form.append("upload_img", file);
form.submit("http://localhost:5000", (err, res) => {
let data = "";
res.on("data", (chunk) => {
data += chunk;
});
res.on("end", () => {
let req = JSON.parse(data);
assert.equal(req.files.upload_img.size, 130466);
done();
});
});
});
});
it("Should have updated req.files and created the necessary directories", (done) => {
// http://localhost:5000
createServer({
directory: path.join(__dirname, "tmp", Date.now().toString()),
filename: function(req, file, cb) {
cb(file.originalname);
}
}, () => {
// submit form and check req.files
var form = new FormData();
let file = fs.createReadStream(__dirname + "/files/medium_image.jpg");
form.append("upload_img", file);
form.submit("http://localhost:5000", (err, res) => {
let data = "";
res.on("data", (chunk) => {
data += chunk;
});
res.on("end", () => {
let req = JSON.parse(data);
assert.equal(req.files.upload_img.size, 130466);
done();
});
});
});
});
});