我有一个Express应用程序,该应用程序在几个端点中实现了一些缓存/存储(调用可能需要几秒钟才能运行,因此我会根据端点的性质将结果保存各种时间)。但是,当我使用Supertest通过Mocha运行单元测试时,每次调用都花费较长的时间。我该如何实际测试应用程序的缓存部分是否正常运行?
我自己运行节点服务器时,可以看到每次返回的时间(例如,第一次返回3979.848µms,第二次返回3.180µms),并且 it 可以正常工作,但是测试 的方式不同。
我需要做什么来测试缓存/存储?可以使用这些工具吗?我需要利用其他模块吗?
我的代码如下:
var supertest = require('supertest');
var base_url = 'http://localhost:3000';
var server = supertest(base_url);
describe('big section', function() {
describe('test section', function() {
it('should do a thing', function(done) {
this.timeout(10000);
server
.get('/url1')
.expect('Content-Type', /json/)
.expect(200)
.end(function(err, res) {
if (err) return done(err);
//stuff
done();
});
});
});
describe('test section', function() {
it('should do a similar thing, but faster', function(done) {
this.timeout(10000); //I should be able to reduce this a lot
server
.get('/url1')
.expect('Content-Type', /json/)
.expect(200)
.end(function(err, res) {
if (err) return done(err);
//stuff
done();
});
});
});
});