Skip to content
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

Restore console mocks after running #3443

Merged
merged 9 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { stateModelFactory } from '.'
import BaseFeatureDetails from './BaseFeatureDetail'

test('open up a widget', async () => {
console.warn = jest.fn()
const pluginManager = new PluginManager([])

const Session = types.model({
Expand Down
2 changes: 1 addition & 1 deletion packages/core/PluginManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ export default class PluginManager {

// try to smooth over the case when no types are registered, mostly
// encountered in tests
if (pluggableTypes.length === 0) {
if (pluggableTypes.length === 0 && typeof jest === 'undefined') {
console.warn(
`No pluggable types found matching ('${groupName}','${fieldName}')`,
)
Expand Down
8 changes: 4 additions & 4 deletions packages/core/rpc/BaseRpcDriver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ export class MockRendererShort extends RpcMethodType {
}

test('test RPC driver operation timeout and worker replace', async () => {
console.error = jest.fn()
console.warn = jest.fn()
const consoleMock = jest.spyOn(console, 'error').mockImplementation()
expect.assertions(1)
const config = ConfigurationSchema('Mock', {}).create()
const driver = new MockRpcDriver({ config })
Expand All @@ -155,11 +154,11 @@ test('test RPC driver operation timeout and worker replace', async () => {
expect(`${e}`).toMatch(/operation timed out/)
}
await driver.call(pluginManager, 'sessionId', 'MockRenderShort', {}, {})
consoleMock.mockRestore()
})

test('remote abort', async () => {
console.error = jest.fn()
console.warn = jest.fn()
const consoleMock = jest.spyOn(console, 'error').mockImplementation()
expect.assertions(1)
const config = ConfigurationSchema('Mock', {}).create()
const driver = new MockRpcDriver({ config })
Expand All @@ -181,4 +180,5 @@ test('remote abort', async () => {
} catch (e) {
expect(`${e}`).toMatch(/abort/)
}
consoleMock.mockRestore()
})
7 changes: 3 additions & 4 deletions packages/core/ui/FatalErrorDialog.test.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import '@testing-library/jest-dom/extend-expect'
import { cleanup, fireEvent, render } from '@testing-library/react'
import React from 'react'
import { cleanup, fireEvent, render } from '@testing-library/react'
import FatalErrorDialog from './FatalErrorDialog'

afterEach(cleanup)

test('open fatal error dialog in web', async () => {
console.error = jest.fn()
const { findByTestId, getByText } = render(
<FatalErrorDialog
error="Hello"
resetButtonText="Reset Session"
onFactoryReset={() => (
<div>Placeholder for actual factory reset func</div>
Expand All @@ -25,9 +24,9 @@ test('open fatal error dialog in web', async () => {
})

test('open fatal error dialog in desktop', async () => {
console.error = jest.fn()
const { findByTestId, getByText } = render(
<FatalErrorDialog
error="Hello2"
onFactoryReset={() => (
<div>Placeholder for actual factory reset func</div>
)}
Expand Down
1 change: 0 additions & 1 deletion packages/core/ui/FatalErrorDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ const FatalErrorDialog = ({
onFactoryReset: Function
resetButtonText?: string
}) => {
console.error(error)
return (
<Dialog open>
<DialogTitle style={{ background: '#e88' }}>Fatal error</DialogTitle>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React from 'react'
import { render } from '@testing-library/react'
import { types } from 'mobx-state-tree'
import React from 'react'
import PluginManager from '@jbrowse/core/PluginManager'
import { ConfigurationSchema } from '@jbrowse/core/configuration'

// locals
import { stateModelFactory } from '.'
import ReactComponent from './AlignmentsFeatureDetail'

test('open up a widget', () => {
console.warn = jest.fn()
const pluginManager = new PluginManager([])

const Session = types.model({
Expand All @@ -17,6 +18,7 @@ test('open up a widget', () => {
})
const session = Session.create(
{
// @ts-ignore
widget: { type: 'AlignmentsFeatureWidget' },
},
{ pluginManager },
Expand Down
1 change: 0 additions & 1 deletion plugins/alignments/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { getSnapshot } from 'mobx-state-tree'
import ThisPlugin from '.'

test('plugin in a stock JBrowse', () => {
console.warn = jest.fn()
const pluginManager = new PluginManager([new ThisPlugin(), new SVG()])
pluginManager.createPluggableElements()
pluginManager.configure()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { getSnapshot } from 'mobx-state-tree'
import ThisPlugin from '.'

test('plugin in a stock JBrowse', () => {
console.warn = jest.fn()
const pluginManager = new PluginManager([new ThisPlugin()])
pluginManager.createPluggableElements()
pluginManager.configure()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ import { render, fireEvent } from '@testing-library/react'

import { ColorSlot } from './ColorEditor'

describe('ColorPicker widget', () => {
it('can change value via the text field', () => {
const myfn = jest.fn()
const { getByDisplayValue } = render(
<ColorSlot value="green" onChange={myfn} />,
)
const ret = getByDisplayValue('green')
fireEvent.change(ret, { target: { value: 'red' } })
expect(myfn).toHaveBeenCalledWith('red')
})
test('can change value via the text field', () => {
const myfn = jest.fn()
const { getByDisplayValue } = render(
<ColorSlot value="green" onChange={myfn} />,
)
const ret = getByDisplayValue('green')
fireEvent.change(ret, { target: { value: 'red' } })
expect(myfn).toHaveBeenCalledWith('red')
})
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ describe('ConfigurationEditor widget', () => {
})

it('renders with defaults of the PileupTrack schema', () => {
console.warn = jest.fn()
const pluginManager = new PluginManager([new Alignments(), new SVG()])
pluginManager.createPluggableElements()
pluginManager.configure()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@ import { getSnapshot } from 'mobx-state-tree'
import ThisPlugin from '.'

describe('Config editing', () => {
let pluginManager
let pluginManager: PluginManager

beforeAll(() => {
const originalConsoleWarn = console.warn
console.warn = jest.fn()
pluginManager = new PluginManager([new ThisPlugin()])
pluginManager.createPluggableElements()
pluginManager.configure()
console.warn = originalConsoleWarn
})

it("won't add if already added", () => {
Expand Down
19 changes: 17 additions & 2 deletions plugins/data-management/src/AddConnectionWidget/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
import { ConfigurationSchema } from '@jbrowse/core/configuration'
import { WidgetType } from '@jbrowse/core/pluggableElementTypes'
import PluginManager from '@jbrowse/core/PluginManager'
import { lazy } from 'react'

export { default as stateModel } from './model'
export const configSchema = ConfigurationSchema('AddConnectionWidget', {})
import stateModel from './model'
const configSchema = ConfigurationSchema('AddConnectionWidget', {})

export default (pluginManager: PluginManager) => {
pluginManager.addWidgetType(() => {
return new WidgetType({
name: 'AddConnectionWidget',
heading: 'Add a connection',
configSchema,
stateModel,
ReactComponent: lazy(() => import('./components/AddConnectionWidget')),
})
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,13 @@ function standardInitializer() {
const realLocation = window.location

// https://stackoverflow.com/a/60110508/2129219
function setWindowLoc(loc) {
function setWindowLoc(loc: string) {
// @ts-ignore
delete window.location
// @ts-ignore
window.location = new URL(loc)
}

const FakeViewModel = types.model('FakeView', {
id: types.identifier,
type: types.literal('FakeView'),
Expand All @@ -67,7 +70,7 @@ const FakeViewModel = types.model('FakeView', {
class FakeViewPlugin extends Plugin {
name = 'FakeViewPlugin'

install(pluginManager) {
install(pluginManager: PluginManager) {
pluginManager.addViewType(() => {
return new ViewType({
name: 'FakeView',
Expand All @@ -79,7 +82,7 @@ class FakeViewPlugin extends Plugin {
}

describe('tests on an LGV type system with view.assemblyNames, using URL', () => {
let session
let session: ReturnType<typeof standardInitializer>
beforeEach(() => {
session = standardInitializer()
})
Expand All @@ -89,7 +92,6 @@ describe('tests on an LGV type system with view.assemblyNames, using URL', () =>
})

it('adds relative URL (BAM)', () => {
console.warn = jest.fn()
const { widget } = session
widget.setTrackData({
uri: 'volvox-sorted.bam',
Expand Down Expand Up @@ -135,45 +137,40 @@ describe('tests on an LGV type system with view.assemblyNames, using URL', () =>
})
})

describe('tests on an view without view.assemblyNames', () => {
let session
beforeEach(() => {
const pluginManager = new PluginManager([new FakeViewPlugin()])
pluginManager.createPluggableElements()
pluginManager.configure()
const SessionModel = types.model({
view: FakeViewModel,
widget: stateModelFactory(pluginManager),
})
test('tests on an view without view.assemblyNames', () => {
const pluginManager = new PluginManager([new FakeViewPlugin()])
pluginManager.createPluggableElements()
pluginManager.configure()

// no assemblyNames on the view, just in case some view does not implement
// view.assemblyNames (it is just a convenience)
session = SessionModel.create({
view: {
type: 'FakeView',
id: 'testing',
},
widget: {
type: 'AddTrackWidget',
view: 'testing',
},
})
const SessionModel = types.model({
view: FakeViewModel,
widget: stateModelFactory(pluginManager),
})
// no assemblyNames on the view, just in case some view does not implement
// view.assemblyNames (it is just a convenience)
const session = SessionModel.create({
view: {
type: 'FakeView',
id: 'testing',
},
widget: {
type: 'AddTrackWidget',
view: 'testing',
},
})

it('adds url', () => {
const { widget } = session
widget.setTrackData({
uri: 'volvox-sorted.bam',
locationType: 'UriLocation',
})
expect(widget.trackName).toBe('volvox-sorted.bam')
expect(widget.isRelativeUrl).toBe(true)
expect(widget.assembly).toBe(undefined)
const { widget } = session
widget.setTrackData({
uri: 'volvox-sorted.bam',
locationType: 'UriLocation',
})
expect(widget.trackName).toBe('volvox-sorted.bam')
expect(widget.isRelativeUrl).toBe(true)
expect(widget.assembly).toBe(undefined)
})

describe('tests different file types', () => {
let session
let session: ReturnType<typeof standardInitializer>
beforeEach(() => {
session = standardInitializer()
})
Expand Down Expand Up @@ -229,7 +226,7 @@ describe('tests different file types', () => {
})

describe('tests localpath', () => {
let session
let session: ReturnType<typeof standardInitializer>
beforeEach(() => {
session = standardInitializer()
})
Expand Down
19 changes: 17 additions & 2 deletions plugins/data-management/src/AddTrackWidget/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
import { ConfigurationSchema } from '@jbrowse/core/configuration'
import { WidgetType } from '@jbrowse/core/pluggableElementTypes'
import PluginManager from '@jbrowse/core/PluginManager'
import { lazy } from 'react'

export { default as stateModelFactory } from './model'
export const configSchema = ConfigurationSchema('AddTrackWidget', {})
import stateModelFactory from './model'
const configSchema = ConfigurationSchema('AddTrackWidget', {})

export default (pluginManager: PluginManager) => {
pluginManager.addWidgetType(() => {
return new WidgetType({
name: 'AddTrackWidget',
heading: 'Add a track',
configSchema,
stateModel: stateModelFactory(pluginManager),
ReactComponent: lazy(() => import('./components/AddTrackWidget')),
})
})
}
Loading