From 2a8167fd5601b4b760457064349f1d59b35cd92d Mon Sep 17 00:00:00 2001 From: Dan Skinner Date: Tue, 25 Aug 2020 16:02:05 +0100 Subject: [PATCH] test(plugin-client-ip): convert tests --- jest.config.js | 1 + packages/core/client.d.ts | 4 +++- packages/core/event.d.ts | 1 + packages/plugin-client-ip/package.json | 7 +----- .../{client-ip.test.js => client-ip.test.ts} | 22 +++++++++---------- tsconfig.json | 2 +- 6 files changed, 17 insertions(+), 20 deletions(-) rename packages/plugin-client-ip/test/{client-ip.test.js => client-ip.test.ts} (79%) diff --git a/jest.config.js b/jest.config.js index 098a5204d6..f7879dd336 100644 --- a/jest.config.js +++ b/jest.config.js @@ -24,6 +24,7 @@ module.exports = { testsForPackage('plugin-browser-context'), testsForPackage('plugin-browser-device'), testsForPackage('plugin-browser-request'), + testsForPackage('plugin-client-ip'), testsForPackage('plugin-window-unhandled-rejection'), testsForPackage('plugin-window-onerror'), testsForPackage('plugin-strip-query-string'), diff --git a/packages/core/client.d.ts b/packages/core/client.d.ts index 872f6db865..5e873df4f2 100644 --- a/packages/core/client.d.ts +++ b/packages/core/client.d.ts @@ -1,4 +1,4 @@ -import { Client, OnErrorCallback, Config, Breadcrumb, Session, OnSessionCallback, OnBreadcrumbCallback, Plugin, Device, App } from './types' +import { Client, OnErrorCallback, Config, Breadcrumb, Session, OnSessionCallback, OnBreadcrumbCallback, Plugin, Device, App, User } from './types' import EventWithInternals from './event' interface LoggerConfig { @@ -46,6 +46,8 @@ export default class ClientWithInternals extends Clie _delivery: Delivery _setDelivery: (handler: (client: Client) => Delivery) => void + _user: User + _metadata: { [key: string]: any } startSession(): ClientWithInternals diff --git a/packages/core/event.d.ts b/packages/core/event.d.ts index 4327273e96..03682246c2 100644 --- a/packages/core/event.d.ts +++ b/packages/core/event.d.ts @@ -16,6 +16,7 @@ interface HandledState { export default class EventWithInternals extends Event { constructor (errorClass: string, errorMessage: string, stacktrace: any[], handledState?: HandledState, originalError?: Error) _metadata: { [key: string]: any } + _user: User _handledState: HandledState _session?: Session toJSON(): { diff --git a/packages/plugin-client-ip/package.json b/packages/plugin-client-ip/package.json index ed5d897806..5ae3e7a5e2 100644 --- a/packages/plugin-client-ip/package.json +++ b/packages/plugin-client-ip/package.json @@ -14,15 +14,10 @@ "files": [ "*.js" ], - "scripts": { - "test": "nyc --reporter=lcov -- jasmine '!(node_modules)/**/*.test.js'" - }, "author": "Bugsnag", "license": "MIT", "devDependencies": { - "@bugsnag/core": "^7.3.0", - "jasmine": "^3.1.0", - "nyc": "^12.0.2" + "@bugsnag/core": "^7.3.0" }, "peerDependencies": { "@bugsnag/core": "^7.0.0" diff --git a/packages/plugin-client-ip/test/client-ip.test.js b/packages/plugin-client-ip/test/client-ip.test.ts similarity index 79% rename from packages/plugin-client-ip/test/client-ip.test.js rename to packages/plugin-client-ip/test/client-ip.test.ts index e7eb4835a3..04a4f50b00 100644 --- a/packages/plugin-client-ip/test/client-ip.test.js +++ b/packages/plugin-client-ip/test/client-ip.test.ts @@ -1,15 +1,13 @@ -const { describe, it, expect } = global +import plugin from '../' -const plugin = require('../') - -const Client = require('@bugsnag/core/client') +import Client, { EventDeliveryPayload } from '@bugsnag/core/client' describe('plugin: ip', () => { it('does nothing when collectUserIp=true', () => { const client = new Client({ apiKey: 'API_KEY_YEAH' }, undefined, [plugin]) - const payloads = [] + const payloads: EventDeliveryPayload[] = [] - client._setDelivery(client => ({ sendEvent: (payload) => payloads.push(payload) })) + client._setDelivery(client => ({ sendEvent: (payload) => payloads.push(payload), sendSession: () => {} })) client.notify(new Error('noooo'), event => { event.request = { some: 'detail' } }) expect(payloads.length).toEqual(1) @@ -18,11 +16,11 @@ describe('plugin: ip', () => { it('doesn’t overwrite an existing user id', () => { const client = new Client({ apiKey: 'API_KEY_YEAH', collectUserIp: false }, undefined, [plugin]) - const payloads = [] + const payloads: EventDeliveryPayload[] = [] client._user = { id: 'foobar' } - client._setDelivery(client => ({ sendEvent: (payload) => payloads.push(payload) })) + client._setDelivery(client => ({ sendEvent: (payload) => payloads.push(payload), sendSession: () => {} })) client.notify(new Error('noooo')) expect(payloads.length).toEqual(1) @@ -32,11 +30,11 @@ describe('plugin: ip', () => { it('overwrites a user id if it is explicitly `undefined`', () => { const client = new Client({ apiKey: 'API_KEY_YEAH', collectUserIp: false }, undefined, [plugin]) - const payloads = [] + const payloads: EventDeliveryPayload[] = [] client._user = { id: undefined } - client._setDelivery(client => ({ sendEvent: (payload) => payloads.push(payload) })) + client._setDelivery(client => ({ sendEvent: (payload) => payloads.push(payload), sendSession: () => {} })) client.notify(new Error('noooo')) expect(payloads.length).toEqual(1) @@ -46,9 +44,9 @@ describe('plugin: ip', () => { it('redacts user IP if none is provided', () => { const client = new Client({ apiKey: 'API_KEY_YEAH', collectUserIp: false }, undefined, [plugin]) - const payloads = [] + const payloads: EventDeliveryPayload[] = [] - client._setDelivery(client => ({ sendEvent: (payload) => payloads.push(payload) })) + client._setDelivery(client => ({ sendEvent: (payload) => payloads.push(payload), sendSession: () => {} })) client.notify(new Error('noooo')) expect(payloads.length).toEqual(1) diff --git a/tsconfig.json b/tsconfig.json index 3f5b672292..161ed00db7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -74,7 +74,6 @@ "packages/plugin-react-native-hermes", "packages/plugin-react-native-event-sync", "packages/plugin-server-session", - "packages/plugin-react", "packages/plugin-vue", "packages/plugin-express", @@ -82,6 +81,7 @@ "packages/plugin-restify", "packages/node", "packages/react-native", + "packages/plugin-client-ip", "packages/plugin-window-unhandled-rejection", "packages/plugin-window-onerror", "packages/plugin-strip-query-string",