小编apr*_*iak的帖子

如何用超级测试嘲笑穆尔特?

我正在编写文件上传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并且不会每次都创建新文件?

node.js supertest multer

5
推荐指数
1
解决办法
389
查看次数

Socket.io 发送两条消息

我正在尝试设置 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)

websocket socket.io

2
推荐指数
1
解决办法
4291
查看次数

标签 统计

multer ×1

node.js ×1

socket.io ×1

supertest ×1

websocket ×1