Skip to content

Commit

Permalink
Merge pull request #1189 from bugsnag/jest-consolidation-1
Browse files Browse the repository at this point in the history
test: tidy test output and fix open handles
  • Loading branch information
djskinner committed Dec 16, 2020
2 parents 2f48364 + 5adb986 commit f4b67be
Show file tree
Hide file tree
Showing 13 changed files with 112 additions and 88 deletions.
157 changes: 72 additions & 85 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,99 +1,86 @@
const testsForPackage = (packageName) => `<rootDir>/packages/${packageName}/**/*.test.[jt]s?(x)`

const package = (displayName, packageNames, config = {}) => ({
roots: ['<rootDir>/packages'],
displayName,
testMatch: packageNames.map(testsForPackage),
...config
})

module.exports = {
projects: [
{
displayName: 'core',
testMatch: [
testsForPackage('core')
]
},
{
displayName: 'shared plugins',
testMatch: [
testsForPackage('plugin-app-duration')
]
},
{
displayName: 'browser',
testMatch: [
testsForPackage('browser'),
testsForPackage('delivery-x-domain-request'),
testsForPackage('delivery-xml-http-request'),
testsForPackage('plugin-react'),
testsForPackage('plugin-vue'),
testsForPackage('plugin-browser-context'),
testsForPackage('plugin-browser-device'),
testsForPackage('plugin-browser-request'),
testsForPackage('plugin-client-ip'),
testsForPackage('plugin-navigation-breadcrumbs'),
testsForPackage('plugin-network-breadcrumbs'),
testsForPackage('plugin-window-unhandled-rejection'),
testsForPackage('plugin-window-onerror'),
testsForPackage('plugin-strip-query-string'),
testsForPackage('plugin-interaction-breadcrumbs'),
testsForPackage('plugin-simple-throttle'),
testsForPackage('plugin-console-breadcrumbs'),
testsForPackage('plugin-browser-session')
]
},
{
displayName: 'react native',
package('core', ['core']),
package('shared plugins', ['plugin-app-duration']),
package('browser', [
'browser',
'delivery-x-domain-request',
'delivery-xml-http-request',
'plugin-react',
'plugin-vue',
'plugin-browser-context',
'plugin-browser-device',
'plugin-browser-request',
'plugin-client-ip',
'plugin-navigation-breadcrumbs',
'plugin-network-breadcrumbs',
'plugin-window-unhandled-rejection',
'plugin-window-onerror',
'plugin-strip-query-string',
'plugin-interaction-breadcrumbs',
'plugin-simple-throttle',
'plugin-console-breadcrumbs',
'plugin-browser-session'
]),
package('react native', [
'react-native',
'delivery-react-native',
'plugin-react-native-app-state-breadcrumbs',
'plugin-react-native-connectivity-breadcrumbs',
'plugin-react-native-orientation-breadcrumbs',
'plugin-react-native-unhandled-rejection',
'plugin-react-native-hermes',
'plugin-react-native-client-sync',
'plugin-react-native-event-sync',
'plugin-react-native-global-error-handler',
'plugin-react-native-session',
'plugin-react-navigation',
'plugin-react-native-navigation'
], {
preset: 'react-native',
testMatch: [
testsForPackage('react-native'),
testsForPackage('delivery-react-native'),
testsForPackage('plugin-react-native-app-state-breadcrumbs'),
testsForPackage('plugin-react-native-connectivity-breadcrumbs'),
testsForPackage('plugin-react-native-orientation-breadcrumbs'),
testsForPackage('plugin-react-native-unhandled-rejection'),
testsForPackage('plugin-react-native-hermes'),
testsForPackage('plugin-react-native-client-sync'),
testsForPackage('plugin-react-native-event-sync'),
testsForPackage('plugin-react-native-global-error-handler'),
testsForPackage('plugin-react-native-session'),
testsForPackage('plugin-react-navigation'),
testsForPackage('plugin-react-native-navigation')
],
setupFiles: [
'<rootDir>/packages/react-native/src/test/setup.js'
]
},
{
displayName: 'expo',
testMatch: [
testsForPackage('delivery-expo'),
testsForPackage('expo'),
testsForPackage('expo-cli'),
testsForPackage('plugin-expo-app'),
testsForPackage('plugin-expo-device')
]
},
{
displayName: 'node plugins',
testEnvironment: 'node',
testMatch: [
testsForPackage('delivery-node'),
testsForPackage('plugin-express'),
testsForPackage('plugin-koa'),
testsForPackage('plugin-restify'),
testsForPackage('plugin-contextualize'),
testsForPackage('plugin-server-*'),
testsForPackage('plugin-strip-project-root'),
testsForPackage('plugin-intercept'),
testsForPackage('plugin-node-unhandled-rejection'),
testsForPackage('plugin-node-in-project'),
testsForPackage('plugin-node-device'),
testsForPackage('plugin-node-surrounding-code'),
testsForPackage('plugin-node-uncaught-exception')
]
},
{
displayName: 'node integration tests',
}),
package('expo', [
'delivery-expo',
'expo',
'expo-cli',
'plugin-expo-app',
'plugin-expo-device'
]),
package('node plugins', [
'delivery-node',
'plugin-express',
'plugin-koa',
'plugin-restify',
'plugin-contextualize',
'plugin-server-*',
'plugin-strip-project-root',
'plugin-intercept',
'plugin-node-unhandled-rejection',
'plugin-node-in-project',
'plugin-node-device',
'plugin-node-surrounding-code',
'plugin-node-uncaught-exception'
], {
testEnvironment: 'node'
}),
package('node integration tests', [
], {
testEnvironment: 'node',
testMatch: [
'<rootDir>/packages/node/test/integration/**/*.test.[jt]s'
]
}
})
]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"cdn-upload": "lerna run cdn-upload --stream",
"build": "lerna run build --scope '@bugsnag/node' --scope '@bugsnag/browser' --scope '@bugsnag/expo' && lerna run build --ignore '@bugsnag/node' --ignore '@bugsnag/browser' --ignore '@bugsnag/expo'",
"test:lint": "eslint --ext .ts,.js --report-unused-disable-directives --max-warnings=0 .",
"test:unit": "jest && lerna run test --ignore '@bugsnag/browser' --ignore '@bugsnag/node'",
"test:unit": "jest",
"test:types": "tsc -p tsconfig.json && lerna run test:types",
"test:test-container-registry-login": "aws ecr get-login-password --profile=opensource | docker login --username AWS --password-stdin 855461928731.dkr.ecr.us-west-1.amazonaws.com",
"test:build-browser-container": "docker-compose up --build minimal-packager && docker-compose build --pull browser-maze-runner",
Expand Down
5 changes: 5 additions & 0 deletions packages/browser/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ function mockFetch () {
}

describe('browser notifier', () => {
beforeAll(() => {
jest.spyOn(console, 'debug').mockImplementation(() => {})
jest.spyOn(console, 'warn').mockImplementation(() => {})
})

beforeEach(() => {
jest.resetModules()
mockFetch()
Expand Down
4 changes: 4 additions & 0 deletions packages/delivery-expo/test/delivery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ describe('delivery: expo', () => {
expect(err).toBeTruthy()
expect((err as any).code).toBe('ECONNRESET')
expect(enqueueSpy).toHaveBeenCalled()

server.close()
done()
})
})
Expand Down Expand Up @@ -268,6 +270,8 @@ describe('delivery: expo', () => {
expect(didLog).toBe(true)
expect(err).toBeTruthy()
expect(enqueueSpy).toHaveBeenCalled()

server.close()
done()
})
})
Expand Down
4 changes: 4 additions & 0 deletions packages/delivery-node/test/delivery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ describe('delivery:node', () => {
expect(didLog).toBe(true)
expect(err).toBeTruthy()
expect(err.code).toBe('ECONNRESET')

server.close()
done()
})
})
Expand All @@ -149,6 +151,8 @@ describe('delivery:node', () => {
delivery({ _config: config, _logger: { error: log } } as unknown as Client).sendEvent(payload, (err) => {
expect(didLog).toBe(true)
expect(err).toBeTruthy()

server.close()
done()
})
})
Expand Down
4 changes: 4 additions & 0 deletions packages/expo/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ describe('expo notifier', () => {
let Bugsnag: typeof BugsnagExpoStatic
let _delivery

beforeAll(() => {
jest.spyOn(console, 'debug').mockImplementation(() => {})
})

beforeEach(() => {
(delivery as jest.MockedFunction<typeof delivery>).mockImplementation(() => {
_delivery = {
Expand Down
3 changes: 3 additions & 0 deletions packages/node/test/integration/handled-unhandled.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ jest.mock('https', () => {
// we can only start bugsnag once per file, because it installs global handlers
// and doesn't have a way to uninstall itself
beforeAll(() => {
jest.spyOn(console, 'debug').mockImplementation(() => {})
jest.spyOn(console, 'error').mockImplementation(() => {})

Bugsnag.start({
apiKey: 'aaaabbbbccccdddd0000111122223333',
// ordinarily after catching an uncaught exception we shut down the process,
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"build": "npm run clean && npm run build:esm2015 && npm run build:esm5",
"build:esm2015": "ngc -p tsconfig.json",
"build:esm5": "ngc -p tsconfig.esm5.json",
"test": "npm run build",
"test:types": "npm run build",
"postversion": "npm run build"
},
"author": "Bugsnag",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import plugin from '../'
import Client from '@bugsnag/core/client'

describe('plugin: console breadcrumbs', () => {
beforeAll(() => {
jest.spyOn(console, 'log').mockImplementation(() => {})
})

it('should leave a breadcrumb when console.log() is called', () => {
const c = new Client({ apiKey: 'aaaa-aaaa-aaaa-aaaa', plugins: [plugin] })
console.log('check 1, 2')
Expand Down
4 changes: 4 additions & 0 deletions packages/plugin-react/src/test/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ type FallbackComponentType = React.ComponentType<FallbackComponentProps>
// eslint-disable-next-line
const ErrorBoundary = client.getPlugin('react')!.createErrorBoundary()

beforeAll(() => {
jest.spyOn(console, 'error').mockImplementation(() => {})
})

beforeEach(() => (client._notify as jest.Mock).mockClear())

test('formatComponentStack(str)', () => {
Expand Down
4 changes: 4 additions & 0 deletions packages/plugin-vue/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import Client from '@bugsnag/core/client'
import Vue from 'vue'

describe('bugsnag vue', () => {
beforeAll(() => {
jest.spyOn(console, 'error').mockImplementation(() => {})
})

it('throws when missing Vue', () => {
expect(() => {
new BugsnagVuePlugin(undefined).load(new Client({ apiKey: 'API_KEYYY' }))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ declare global {
// we can only start bugsnag once per file, because it installs global handlers
// and doesn't have a way to uninstall itself
beforeAll(() => {
jest.spyOn(console, 'debug').mockImplementation(() => {})

// leaving the default handler intact causes simulated unhandled errors to fail tests
global.ErrorUtils.setGlobalHandler(() => {})
Bugsnag.start()
Expand Down Expand Up @@ -94,7 +96,6 @@ describe('@bugsnag/react-native: handled and unhandled errors', () => {
// @ts-ignore
'sdf'.sdflkj()
} catch (e) {
console.log(e)
rnPromise.reject(e)
}
setTimeout(() => {
Expand Down
4 changes: 4 additions & 0 deletions packages/react-native/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ jest.mock('react-native', () => ({
describe('react native notifier', () => {
let Bugsnag: typeof BugsnagReactNativeStatic

beforeAll(() => {
jest.spyOn(console, 'debug').mockImplementation(() => {})
})

beforeEach(() => {
jest.isolateModules(() => {
Bugsnag = require('..')
Expand Down

0 comments on commit f4b67be

Please sign in to comment.