Skip to content

Commit 4a08572

Browse files
committed
test(many): reduce console spam during test runs
fix some warning and stub out console for codemods unit tests so there are less console messages when running tests
1 parent 96914f0 commit 4a08572

File tree

5 files changed

+175
-25
lines changed

5 files changed

+175
-25
lines changed

packages/ui-codemods/lib/__node_tests__/codemodHelpers.test.tsx

Lines changed: 111 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,28 @@ import {
3535
removeAllChildren,
3636
findElement
3737
} from '../utils/codemodHelpers'
38-
import { expect } from 'vitest'
38+
import { expect, type MockInstance, vi } from 'vitest'
3939

4040
describe('test codemod helpers', () => {
41+
let consoleLogMock: ReturnType<typeof vi.spyOn>
42+
let consoleWarningMock: ReturnType<typeof vi.spyOn>
43+
44+
beforeEach(() => {
45+
// Mocking console to prevent test output pollution
46+
// comment these out to see the test output
47+
consoleLogMock = vi
48+
.spyOn(console, 'log')
49+
.mockImplementation(() => {}) as MockInstance
50+
consoleWarningMock = vi
51+
.spyOn(console, 'warn')
52+
.mockImplementation(() => {}) as MockInstance
53+
})
54+
55+
afterEach(() => {
56+
consoleLogMock.mockRestore()
57+
consoleWarningMock.mockRestore()
58+
})
59+
4160
it('test findElement', () => {
4261
// Test finding simple elements by tag name
4362
const source = `
@@ -536,7 +555,13 @@ import { Modal } from "@instructure/ui-modal";`)
536555
}
537556
`
538557
let root = j(source)
539-
let result = renameImportAndUsages(j, root, 'oldName', 'newName', '@import-path')
558+
let result = renameImportAndUsages(
559+
j,
560+
root,
561+
'oldName',
562+
'newName',
563+
'@import-path'
564+
)
540565

541566
expect(result).toBe(true)
542567
expect(root.toSource()).toBe(`
@@ -562,7 +587,13 @@ import { Modal } from "@instructure/ui-modal";`)
562587
}
563588
`
564589
root = j(source)
565-
result = renameImportAndUsages(j, root, 'oldName', 'newName', '@import-path')
590+
result = renameImportAndUsages(
591+
j,
592+
root,
593+
'oldName',
594+
'newName',
595+
'@import-path'
596+
)
566597

567598
expect(result).toBe(true)
568599
expect(root.toSource()).toBe(`
@@ -586,7 +617,13 @@ import { Modal } from "@instructure/ui-modal";`)
586617
}
587618
`
588619
root = j.withParser('tsx')(source)
589-
result = renameImportAndUsages(j, root, 'oldName', 'newName', '@import-path')
620+
result = renameImportAndUsages(
621+
j,
622+
root,
623+
'oldName',
624+
'newName',
625+
'@import-path'
626+
)
590627

591628
expect(result).toBe(true)
592629
expect(root.toSource()).toBe(`
@@ -609,7 +646,13 @@ import { Modal } from "@instructure/ui-modal";`)
609646
}
610647
`
611648
root = j(source)
612-
result = renameImportAndUsages(j, root, 'oldName', 'newName', '@import-path')
649+
result = renameImportAndUsages(
650+
j,
651+
root,
652+
'oldName',
653+
'newName',
654+
'@import-path'
655+
)
613656

614657
expect(result).toBe(true)
615658
expect(root.toSource()).toBe(`
@@ -632,7 +675,13 @@ import { Modal } from "@instructure/ui-modal";`)
632675
`
633676
root = j(source)
634677
const originalSource = root.toSource()
635-
result = renameImportAndUsages(j, root, 'oldName', 'newName', '@import-path')
678+
result = renameImportAndUsages(
679+
j,
680+
root,
681+
'oldName',
682+
'newName',
683+
'@import-path'
684+
)
636685

637686
expect(result).toBe(false)
638687
expect(root.toSource()).toBe(originalSource)
@@ -649,7 +698,13 @@ import { Modal } from "@instructure/ui-modal";`)
649698
}
650699
`
651700
root = j(source)
652-
result = renameImportAndUsages(j, root, 'oldName', 'newName', '@import-path')
701+
result = renameImportAndUsages(
702+
j,
703+
root,
704+
'oldName',
705+
'newName',
706+
'@import-path'
707+
)
653708

654709
expect(result).toBe(true)
655710
expect(root.toSource()).toBe(`
@@ -673,7 +728,13 @@ import { Modal } from "@instructure/ui-modal";`)
673728
}
674729
`
675730
root = j(source)
676-
result = renameImportAndUsages(j, root, 'oldName', 'newName', '@import-path')
731+
result = renameImportAndUsages(
732+
j,
733+
root,
734+
'oldName',
735+
'newName',
736+
'@import-path'
737+
)
677738

678739
expect(result).toBe(true)
679740
expect(root.toSource()).toBe(`
@@ -696,7 +757,13 @@ import { Modal } from "@instructure/ui-modal";`)
696757
}
697758
`
698759
root = j(source)
699-
result = renameImportAndUsages(j, root, 'oldName', 'newName', '@import-path')
760+
result = renameImportAndUsages(
761+
j,
762+
root,
763+
'oldName',
764+
'newName',
765+
'@import-path'
766+
)
700767

701768
expect(result).toBe(true)
702769
expect(root.toSource()).toBe(`
@@ -723,7 +790,13 @@ import { Modal } from "@instructure/ui-modal";`)
723790
}
724791
`
725792
root = j(source)
726-
result = renameImportAndUsages(j, root, 'Button', 'PrimaryButton', '@instructure/ui-buttons')
793+
result = renameImportAndUsages(
794+
j,
795+
root,
796+
'Button',
797+
'PrimaryButton',
798+
'@instructure/ui-buttons'
799+
)
727800

728801
expect(result).toBe(true)
729802
expect(root.toSource()).toBe(`
@@ -748,7 +821,13 @@ import { Modal } from "@instructure/ui-modal";`)
748821
}
749822
`
750823
root = j(source)
751-
result = renameImportAndUsages(j, root, 'Button', 'PrimaryButton', '@instructure/ui-buttons')
824+
result = renameImportAndUsages(
825+
j,
826+
root,
827+
'Button',
828+
'PrimaryButton',
829+
'@instructure/ui-buttons'
830+
)
752831

753832
expect(result).toBe(true)
754833
expect(root.toSource()).toBe(`
@@ -769,7 +848,13 @@ import { Modal } from "@instructure/ui-modal";`)
769848
}
770849
`
771850
root = j(source)
772-
result = renameImportAndUsages(j, root, 'Button', 'PrimaryButton', '@instructure/ui-buttons')
851+
result = renameImportAndUsages(
852+
j,
853+
root,
854+
'Button',
855+
'PrimaryButton',
856+
'@instructure/ui-buttons'
857+
)
773858

774859
expect(result).toBe(true)
775860
expect(root.toSource()).toBe(`
@@ -795,7 +880,13 @@ import { Modal } from "@instructure/ui-modal";`)
795880
}
796881
`
797882
root = j(source)
798-
result = renameImportAndUsages(j, root, 'Button', 'PrimaryButton', '@instructure/ui-buttons')
883+
result = renameImportAndUsages(
884+
j,
885+
root,
886+
'Button',
887+
'PrimaryButton',
888+
'@instructure/ui-buttons'
889+
)
799890

800891
expect(result).toBe(true)
801892
expect(root.toSource()).toBe(`
@@ -826,7 +917,13 @@ import { Modal } from "@instructure/ui-modal";`)
826917
}
827918
`
828919
root = j(source)
829-
result = renameImportAndUsages(j, root, 'Button', 'PrimaryButton', '@instructure/ui-buttons')
920+
result = renameImportAndUsages(
921+
j,
922+
root,
923+
'Button',
924+
'PrimaryButton',
925+
'@instructure/ui-buttons'
926+
)
830927

831928
expect(result).toBe(false)
832929
expect(root.toSource()).toBe(source)

packages/ui-codemods/lib/__node_tests__/codemods.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,28 @@ import renameCanvasThemesCodemod from '../renameCanvasThemesCodemod'
2929
import renameGetComputedStyleToGetCSSStyleDeclaration from '../renameGetComputedStyleToGetCSSStyleDeclaration'
3030
import warnTableCaptionMissing from '../warnTableCaptionMissing'
3131
import warnCodeEditorRemoved from '../warnCodeEditorRemoved'
32+
import { type MockInstance, vi } from 'vitest'
3233

3334
describe('test codemods', () => {
35+
let consoleLogMock: ReturnType<typeof vi.spyOn>
36+
let consoleWarningMock: ReturnType<typeof vi.spyOn>
37+
38+
beforeEach(() => {
39+
// Mocking console to prevent test output pollution
40+
// comment these out to see the test output
41+
consoleLogMock = vi
42+
.spyOn(console, 'log')
43+
.mockImplementation(() => {}) as MockInstance
44+
consoleWarningMock = vi
45+
.spyOn(console, 'warn')
46+
.mockImplementation(() => {}) as MockInstance
47+
})
48+
49+
afterEach(() => {
50+
consoleLogMock.mockRestore()
51+
consoleWarningMock.mockRestore()
52+
})
53+
3454
it('test InstUI v10 color codemods', () => {
3555
runTest(updateV10Breaking)
3656
})

packages/ui-file-drop/src/FileDrop/__tests__/FileDrop.test.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ import '@testing-library/jest-dom'
2929

3030
import { FileDrop } from '../index'
3131
import { FileDropProps } from '../props'
32+
import { act } from 'react'
3233

3334
describe('<FileDrop/>', () => {
3435
it('should focus the input when focus is called', async () => {
35-
let inputEl: any
36+
let inputEl: HTMLInputElement | null | undefined
3637
const { container } = render(
3738
<FileDrop
3839
renderLabel="filedrop"
@@ -42,9 +43,9 @@ describe('<FileDrop/>', () => {
4243
/>
4344
)
4445
const input = container.querySelector('input[class$="-fileDrop__input"]')
45-
46-
inputEl.focus()
47-
46+
act(() => {
47+
inputEl!.focus()
48+
})
4849
expect(input).toHaveFocus()
4950
})
5051

packages/ui-options/src/Options/__tests__/Options.test.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,10 @@ describe('<Options />', () => {
125125

126126
it('should render nested options properly', async () => {
127127
const { container } = render(
128-
<Options data-testId="outer-list">
128+
<Options data-testid="outer-list">
129129
<Options.Item>Option one </Options.Item>
130130
<Options.Item>Option two </Options.Item>
131-
<Options renderLabel={'Nested list'} data-testId="nested-list">
131+
<Options renderLabel={'Nested list'} data-testid="nested-list">
132132
<Options.Item>Nested option one </Options.Item>
133133
<Options.Item>Nested option two </Options.Item>
134134
</Options>
@@ -168,7 +168,10 @@ describe('<Options />', () => {
168168
</Options>
169169
)
170170

171-
// axe-check is more strict now, and expects "list" role to have "listitem" children, but we use "role='none'" children. After discussing it with the A11y team, we agreed to ignore this error because the screen readers can read the component perfectly.
171+
// axe-check is more strict now, and expects "list" role to have "listitem"
172+
// children, but we use "role='none'" children. After discussing it with
173+
// the A11y team, we agreed to ignore this error because the screen readers
174+
// can read the component perfectly.
172175
// TODO: try to remove this ignore if axe-check is updated and isn't this strict anymore
173176
// https://dequeuniversity.com/rules/axe/4.6/aria-required-children?application=axeAPI
174177
const axeCheck = await runAxeCheck(container, {

packages/ui-range-input/src/RangeInput/__tests__/RangeInput.test.tsx

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@ import { RangeInput } from '../index'
3232
describe('<RangeInput />', () => {
3333
it('renders an input with type "range"', async () => {
3434
const { container } = render(
35-
<RangeInput label="Opacity" name="opacity" max={100} min={0} />
35+
<RangeInput
36+
label="Opacity"
37+
name="opacity"
38+
max={100}
39+
min={0}
40+
displayValue={false}
41+
/>
3642
)
3743

3844
const label = container.querySelector('[class$="-formFieldLayout__label"]')
@@ -111,14 +117,30 @@ describe('<RangeInput />', () => {
111117
})
112118

113119
it('sets min value', async () => {
114-
render(<RangeInput label="Opacity" name="opacity" max={100} min={25} />)
120+
render(
121+
<RangeInput
122+
label="Opacity"
123+
name="opacity"
124+
max={100}
125+
min={25}
126+
displayValue={false}
127+
/>
128+
)
115129
const input = screen.getByLabelText('Opacity')
116130

117131
expect(input).toHaveAttribute('min', '25')
118132
})
119133

120134
it('sets max value', async () => {
121-
render(<RangeInput label="Opacity" name="opacity" max={75} min={0} />)
135+
render(
136+
<RangeInput
137+
label="Opacity"
138+
name="opacity"
139+
max={75}
140+
min={0}
141+
displayValue={false}
142+
/>
143+
)
122144

123145
const input = screen.getByLabelText('Opacity')
124146

@@ -127,7 +149,14 @@ describe('<RangeInput />', () => {
127149

128150
it('sets step value', async () => {
129151
render(
130-
<RangeInput label="Opacity" name="opacity" max={100} min={0} step={5} />
152+
<RangeInput
153+
label="Opacity"
154+
name="opacity"
155+
max={100}
156+
min={0}
157+
step={5}
158+
displayValue={false}
159+
/>
131160
)
132161
const input = screen.getByLabelText('Opacity')
133162

0 commit comments

Comments
 (0)