我正在编写文件上传API,并且在模拟multer时遇到了一些麻烦。我正在尝试使用supertest测试端点。
it('load image', async () => {
await app
.post(`${apiImage}`)
.set('Authorization', 'abc123')
.attach('avatar', `${__dirname}/test.jpg`);
.expect(200);
});
Run Code Online (Sandbox Code Playgroud)
上传效果正常。但是每次我运行测试时,都会创建新文件。因此,如何模拟multer并且不会每次都创建新文件?
我正在尝试设置 socket.io,这是我的 server.js 的一部分
const app = require('express')();
const http = require('http').Server(app);
const io = require('socket.io')(http, { path: '/websocket', origins:'*:*' });
io.on('connection', (socket) => {
socket.send('Hi');
socket.on('message', (message) => {
console.log(message);
socket.emit('hello', `New: ${message}`);
});
console.log('a user connected');
});
http.listen(3030, function(){
console.log('listening on *:3030');
});
Run Code Online (Sandbox Code Playgroud)
和我的简单客户:
var socket = io('https://*******.com', {
secure: true,
path: '/websocket'
});
const input = document.getElementById('text');
const button = document.getElementById('button');
const msg = document.getElementById('msg');
button.onclick = () => {
socket.emit('message', input.value);
socket.on('hello', (text) => {
const …
Run Code Online (Sandbox Code Playgroud)