mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 03:14:03 +03:00
6161f94910
refs: https://github.com/TryGhost/Toolbox/issues/595 We're rolling out new rules around the node assert library, the first of which is enforcing the use of assert/strict. This means we don't need to use the strict version of methods, as the standard version will work that way by default. This caught some gotchas in our existing usage of assert where the lack of strict mode had unexpected results: - Url matching needs to be done on `url.href` seeaa58b354a4
- Null and undefined are not the same thing, there were a few cases of this being confused - Particularly questionable changes in [PostExporter tests](c1a468744b
) tracked [here](https://github.com/TryGhost/Team/issues/3505). - A typo seeeaac9c293a
Moving forward, using assert strict should help us to catch unexpected behaviour, particularly around nulls and undefineds during implementation.
55 lines
2.2 KiB
JavaScript
55 lines
2.2 KiB
JavaScript
const assert = require('assert/strict');
|
|
const sinon = require('sinon');
|
|
const configUtils = require('../../utils/configUtils');
|
|
|
|
const Sentry = require('@sentry/node');
|
|
|
|
const fakeDSN = 'https://aaabbbccc000111222333444555667@sentry.io/1234567';
|
|
let sentry;
|
|
|
|
describe('UNIT: sentry', function () {
|
|
afterEach(async function () {
|
|
await configUtils.restore();
|
|
sinon.restore();
|
|
});
|
|
|
|
describe('No sentry config', function () {
|
|
beforeEach(function () {
|
|
delete require.cache[require.resolve('../../../core/shared/sentry')];
|
|
sentry = require('../../../core/shared/sentry');
|
|
});
|
|
|
|
it('returns expected function signature', function () {
|
|
assert.equal(sentry.requestHandler.name, 'expressNoop', 'Should return noop');
|
|
assert.equal(sentry.errorHandler.name, 'expressNoop', 'Should return noop');
|
|
assert.equal(sentry.captureException.name, 'noop', 'Should return noop');
|
|
});
|
|
});
|
|
|
|
describe('With sentry config', function () {
|
|
beforeEach(function () {
|
|
configUtils.set({sentry: {disabled: false, dsn: fakeDSN}});
|
|
delete require.cache[require.resolve('../../../core/shared/sentry')];
|
|
|
|
sinon.spy(Sentry, 'init');
|
|
|
|
sentry = require('../../../core/shared/sentry');
|
|
});
|
|
|
|
it('returns expected function signature', function () {
|
|
assert.equal(sentry.requestHandler.name, 'sentryRequestMiddleware', 'Should return sentry');
|
|
assert.equal(sentry.errorHandler.name, 'sentryErrorMiddleware', 'Should return sentry');
|
|
assert.equal(sentry.captureException.name, 'captureException', 'Should return sentry');
|
|
});
|
|
|
|
it('initialises sentry correctly', function () {
|
|
const initArgs = Sentry.init.getCall(0).args;
|
|
|
|
assert.equal(initArgs[0].dsn, fakeDSN, 'shoudl be our fake dsn');
|
|
assert.match(initArgs[0].release, /ghost@\d+\.\d+\.\d+/, 'should be a valid version');
|
|
assert.equal(initArgs[0].environment, 'testing', 'should be the testing env');
|
|
assert.ok(initArgs[0].hasOwnProperty('beforeSend'), 'should have a beforeSend function');
|
|
});
|
|
});
|
|
});
|