2018-04-25 23:11:24 +02:00
|
|
|
'use strict';
|
2019-07-10 22:48:43 +01:00
|
|
|
const _interface = require('../../lib/interface');
|
2018-10-15 22:29:53 -04:00
|
|
|
const chai = require('chai');
|
2018-04-25 23:11:24 +02:00
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
describe('interface', function () {
|
|
|
|
it('catch and rethrow with an async stack trace', function (done) {
|
2018-10-15 22:29:53 -04:00
|
|
|
const error = new Error('Some SQL error');
|
2018-04-25 23:11:24 +02:00
|
|
|
function SomeClass() {
|
|
|
|
this.client = {
|
|
|
|
config: {
|
2018-07-09 08:10:34 -04:00
|
|
|
asyncStackTraces: true,
|
2018-04-25 23:11:24 +02:00
|
|
|
},
|
2020-04-19 00:40:23 +02:00
|
|
|
runner: function () {
|
2018-04-25 23:11:24 +02:00
|
|
|
return {
|
2020-04-19 00:40:23 +02:00
|
|
|
run: function () {
|
2018-04-25 23:11:24 +02:00
|
|
|
return {
|
2020-04-19 00:40:23 +02:00
|
|
|
catch: function (rethrow) {
|
2018-07-09 08:10:34 -04:00
|
|
|
rethrow.call(fakeInstance, error); // by calling here we're simulating that the promise was rejected
|
|
|
|
chai
|
|
|
|
.expect(error.stack)
|
|
|
|
.to.equal('Error: Some SQL error\nline1\nline2\nline3');
|
|
|
|
done();
|
2018-04-25 23:11:24 +02:00
|
|
|
},
|
2020-04-19 00:40:23 +02:00
|
|
|
then: function () {},
|
2018-07-09 08:10:34 -04:00
|
|
|
};
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
};
|
2018-04-25 23:11:24 +02:00
|
|
|
}
|
|
|
|
|
2018-07-09 08:10:34 -04:00
|
|
|
_interface(SomeClass);
|
2018-10-15 22:29:53 -04:00
|
|
|
const fakeInstance = new SomeClass();
|
2020-03-19 18:19:57 -04:00
|
|
|
chai.expect(fakeInstance[Symbol.toStringTag]).to.eq('object');
|
2018-07-09 08:10:34 -04:00
|
|
|
fakeInstance._asyncStack = ['line1', 'line2', 'line3'];
|
|
|
|
fakeInstance.then();
|
|
|
|
});
|
|
|
|
});
|