fixed testing cache
This commit is contained in:
@ -99,7 +99,7 @@
|
||||
{
|
||||
"_id": {"$oid":"400000000000000000000007"},
|
||||
"number": "34",
|
||||
"type": "liquid",
|
||||
"type": "other",
|
||||
"color": "black",
|
||||
"batch": "",
|
||||
"condition": {},
|
||||
|
@ -29,7 +29,10 @@ export default class TestHelper {
|
||||
}
|
||||
|
||||
static beforeEach (server, done) {
|
||||
delete require.cache[require.resolve('../index')]; // prevent loading from cache
|
||||
// delete cached server code except models as these are needed in the testing files as well
|
||||
Object.keys(require.cache).filter(e => /API\\dist\\(?!(models|db|test))/.test(e)).forEach(key => {
|
||||
delete require.cache[key]; // prevent loading from cache
|
||||
});
|
||||
server = require('../index');
|
||||
db.drop(err => { // reset database
|
||||
if (err) return done(err);
|
||||
@ -38,10 +41,13 @@ export default class TestHelper {
|
||||
return server
|
||||
}
|
||||
|
||||
static request (server, done, options) { // options in form: {method, url, contentType, auth: {key/basic: 'name' or 'key'/{name, pass}}, httpStatus, req, res, default (set to false if you want to dismiss default .end handling)}
|
||||
// options in form: {method, url, contentType, auth: {key/basic: 'name' or 'key'/{name, pass}}, httpStatus, req, res,
|
||||
// default (set to false if you want to dismiss default .end handling)}
|
||||
static request (server, done, options) {
|
||||
let st = supertest(server);
|
||||
if (options.hasOwnProperty('auth') && options.auth.hasOwnProperty('key')) { // resolve API key
|
||||
options.url += '?key=' + (this.auth.hasOwnProperty(options.auth.key)? this.auth[options.auth.key].key : options.auth.key);
|
||||
options.url += '?key=' +
|
||||
(this.auth.hasOwnProperty(options.auth.key)? this.auth[options.auth.key].key : options.auth.key);
|
||||
}
|
||||
switch (options.method) { // http method
|
||||
case 'get':
|
||||
@ -91,10 +97,12 @@ export default class TestHelper {
|
||||
done();
|
||||
});
|
||||
}
|
||||
else if (options.hasOwnProperty('log')) { // check changelog, takes log: {collection, skip, data/(dataAdd, dataIgn)}
|
||||
// check changelog, takes log: {collection, skip, data/(dataAdd, dataIgn)}
|
||||
else if (options.hasOwnProperty('log')) {
|
||||
return st.end(err => {
|
||||
if (err) return done (err);
|
||||
ChangelogModel.findOne({}).sort({_id: -1}).skip(options.log.skip? options.log.skip : 0).lean().exec((err, data) => { // latest entry
|
||||
ChangelogModel.findOne({}).sort({_id: -1}).skip(options.log.skip? options.log.skip : 0)
|
||||
.lean().exec((err, data) => { // latest entry
|
||||
if (err) return done(err);
|
||||
should(data).have.only.keys('_id', 'action', 'collectionName', 'conditions', 'data', 'user_id', '__v');
|
||||
should(data).have.property('action', options.method.toUpperCase() + ' ' + options.url);
|
||||
|
Reference in New Issue
Block a user