-
Notifications
You must be signed in to change notification settings - Fork 251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
V7: Move context and breadcrumbs to private properties #681
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var __1 = __importDefault(require("../..")); | ||
require("jasmine"); | ||
// the client's constructor isn't public in TS so this drops down to JS to create one for the tests | ||
function createClient(opts) { | ||
var c = new __1.default.Client(opts, undefined, { name: 'Type Tests', version: 'nope', url: 'https://github.com/bugsnag/bugsnag-js' }); | ||
c._setDelivery(function () { return ({ | ||
sendSession: function (p, cb) { cb(); }, | ||
sendEvent: function (p, cb) { cb(); } | ||
}); }); | ||
c._sessionDelegate = { startSession: function () { return c; }, pauseSession: function () { }, resumeSession: function () { } }; | ||
return c; | ||
} | ||
describe('Type definitions', function () { | ||
it('has all the classes matching the types available at runtime', function () { | ||
expect(__1.default.Client).toBeDefined(); | ||
expect(__1.default.Breadcrumb).toBeDefined(); | ||
expect(__1.default.Event).toBeDefined(); | ||
expect(__1.default.Session).toBeDefined(); | ||
var client = createClient({ apiKey: 'API_KEY' }); | ||
expect(client.Breadcrumb).toBeDefined(); | ||
expect(client.Event).toBeDefined(); | ||
expect(client.Session).toBeDefined(); | ||
}); | ||
it('works for reporting errors', function (done) { | ||
var client = createClient({ apiKey: 'API_KEY' }); | ||
client.notify(new Error('uh oh'), function (event) { | ||
expect(event.apiKey).toBe(undefined); | ||
expect(event.context).toBe(undefined); | ||
expect(event.errors[0].errorMessage).toBe('uh oh'); | ||
expect(event.errors[0].stacktrace.length > 0).toBe(true); | ||
event.addMetadata('abc', { def: 'ghi' }); | ||
event.addMetadata('jkl', 'mno', 'pqr'); | ||
event.clearMetadata('jkl'); | ||
var val = event.getMetadata('jkl'); | ||
expect(val).toBe(undefined); | ||
}, function (err, event) { | ||
expect(err).toBe(undefined); | ||
expect(event).toBeTruthy(); | ||
done(); | ||
}); | ||
}); | ||
it('works for reporting sessions', function () { | ||
var client = createClient({ apiKey: 'API_KEY' }); | ||
var sessionClient = client.startSession(); | ||
sessionClient.notify(new Error('oh')); | ||
client.pauseSession(); | ||
client.resumeSession(); | ||
}); | ||
it('works for leaving breadcrumbs', function () { | ||
var client = createClient({ apiKey: 'API_KEY' }); | ||
client.leaveBreadcrumb('testing 123'); | ||
expect(client._breadcrumbs.length).toBe(1); | ||
expect(client._breadcrumbs[0].message).toBe('testing 123'); | ||
}); | ||
it('works adding and removing onError callbacks', function () { | ||
var client = createClient({ apiKey: 'API_KEY' }); | ||
client.addOnError(function () { }); | ||
client.removeOnError(function () { }); | ||
}); | ||
it('works adding and removing onSession callbacks', function () { | ||
var client = createClient({ apiKey: 'API_KEY' }); | ||
client.addOnSession(function () { }); | ||
client.removeOnSession(function () { }); | ||
}); | ||
it('works adding and removing onBreadcrumb callbacks', function () { | ||
var client = createClient({ apiKey: 'API_KEY' }); | ||
client.addOnBreadcrumb(function () { }); | ||
client.removeOnBreadcrumb(function () { }); | ||
}); | ||
it('works manipulating metadata on client', function () { | ||
var client = createClient({ apiKey: 'API_KEY' }); | ||
client.addMetadata('abc', { def: 'ghi' }); | ||
client.addMetadata('jkl', 'mno', 'pqr'); | ||
client.clearMetadata('jkl'); | ||
var val = client.getMetadata('jkl'); | ||
expect(val).toBe(undefined); | ||
expect(client.getMetadata('abc', 'def')).toBe('ghi'); | ||
}); | ||
it('works setting context', function () { | ||
var client = createClient({ apiKey: 'API_KEY' }); | ||
client.setContext('foo'); | ||
expect(client.getContext()).toBe('foo'); | ||
}); | ||
it('works setting/clearing user', function () { | ||
var client = createClient({ apiKey: 'API_KEY' }); | ||
client.setUser('123', 'ben.gourley@bugsnag.com', 'Ben'); | ||
expect(client.getUser()).toEqual({ id: '123', name: 'Ben', email: 'ben.gourley@bugsnag.com' }); | ||
client.setUser(undefined, undefined, undefined); | ||
expect(client.getUser()).toEqual({ id: undefined, name: undefined, email: undefined }); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do these need adding to the public interface typedefs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah – I was in the middle of a big types refactor when I realised this change was needed, so they are in #682 to save a conflict!