Merge pull request #13633 from backstage/rugvip/nolog
packages: clean up log output in tests
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/config-loader': patch
|
||||
---
|
||||
|
||||
No longer log when reloading remote config.
|
||||
@@ -287,13 +287,10 @@ export async function loadConfig(
|
||||
let handle: NodeJS.Timeout | undefined;
|
||||
try {
|
||||
handle = setInterval(async () => {
|
||||
console.info(`Checking for config update`);
|
||||
const newRemoteConfigs = await loadRemoteConfigFiles();
|
||||
if (await hasConfigChanged(remoteConfigs, newRemoteConfigs)) {
|
||||
remoteConfigs = newRemoteConfigs;
|
||||
console.info(`Remote config change, reloading config ...`);
|
||||
watchProp.onChange([...remoteConfigs, ...fileConfigs, ...envConfigs]);
|
||||
console.info(`Remote config reloaded`);
|
||||
}
|
||||
}, remoteProp.reloadIntervalSeconds * 1000);
|
||||
} catch (error) {
|
||||
@@ -303,7 +300,6 @@ export async function loadConfig(
|
||||
if (watchProp.stopSignal) {
|
||||
watchProp.stopSignal.then(() => {
|
||||
if (handle !== undefined) {
|
||||
console.info(`Stopping remote config watch`);
|
||||
clearInterval(handle);
|
||||
handle = undefined;
|
||||
}
|
||||
|
||||
@@ -251,7 +251,6 @@ describe.each(['beta', 'stable'])('react-router %s', rrVersion => {
|
||||
|
||||
await new Promise(r => setTimeout(r, 500));
|
||||
|
||||
rendered.debug();
|
||||
await expect(
|
||||
rendered.findByText('Path at inside: /foo/bar'),
|
||||
).resolves.toBeInTheDocument();
|
||||
@@ -344,7 +343,6 @@ describe.each(['beta', 'stable'])('react-router %s', rrVersion => {
|
||||
await expect(
|
||||
rendered.findByText('Path at inside: /foo/blob/baz'),
|
||||
).resolves.toBeInTheDocument();
|
||||
rendered.debug();
|
||||
});
|
||||
|
||||
it('should throw errors for routing to other routeRefs with unsupported parameters', () => {
|
||||
@@ -352,6 +350,7 @@ describe.each(['beta', 'stable'])('react-router %s', rrVersion => {
|
||||
const root = (
|
||||
<MemoryRouter initialEntries={['/']}>
|
||||
<Routes>
|
||||
<Route path="/" element={<div />} />
|
||||
<Route path="foo:id" element={<ExtensionPage3 />}>
|
||||
<Route
|
||||
path="bar"
|
||||
|
||||
@@ -294,13 +294,13 @@ describe('discovery', () => {
|
||||
await expect(
|
||||
rendered.findByText('Path at inside: /foo/blob/baz'),
|
||||
).resolves.toBeInTheDocument();
|
||||
rendered.debug();
|
||||
});
|
||||
|
||||
it('should throw errors for routing to other routeRefs with unsupported parameters', () => {
|
||||
const root = (
|
||||
<MemoryRouter initialEntries={['/']}>
|
||||
<Routes>
|
||||
<Route path="/" element={<div />} />
|
||||
<Route path="foo:id" element={<ExtensionPage3 />}>
|
||||
<Route
|
||||
path="bar"
|
||||
|
||||
@@ -38,7 +38,7 @@ const id = {
|
||||
|
||||
const setEdge = jest.fn();
|
||||
const renderElement = jest.fn((props: RenderLabelProps) => (
|
||||
<text>{props.edge.label}</text>
|
||||
<div>{props.edge.label}</div>
|
||||
));
|
||||
|
||||
const minProps = {
|
||||
@@ -53,8 +53,7 @@ const edgeWithLabel = { ...edge, label };
|
||||
|
||||
describe('<Edge />', () => {
|
||||
beforeEach(() => {
|
||||
// jsdom does not support SVG elements so we have to fall back to HTMLUnknownElement
|
||||
Object.defineProperty(window.HTMLUnknownElement.prototype, 'getBBox', {
|
||||
Object.defineProperty(window.SVGElement.prototype, 'getBBox', {
|
||||
value: () => ({ width: 100, height: 100 }),
|
||||
configurable: true,
|
||||
});
|
||||
@@ -63,26 +62,40 @@ describe('<Edge />', () => {
|
||||
afterEach(jest.clearAllMocks);
|
||||
|
||||
it('does not render the supplied label element if label is missing', () => {
|
||||
const { container } = render(<Edge {...minProps} />);
|
||||
const { container } = render(
|
||||
<svg>
|
||||
<Edge {...minProps} />
|
||||
</svg>,
|
||||
);
|
||||
expect(container.getElementsByTagName('g')).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('renders the supplied label element if label is present', () => {
|
||||
const { getByText } = render(<Edge {...minProps} edge={edgeWithLabel} />);
|
||||
const { getByText } = render(
|
||||
<svg>
|
||||
<Edge {...minProps} edge={edgeWithLabel} />
|
||||
</svg>,
|
||||
);
|
||||
expect(getByText(label)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('passes down edge properties to the render method if label is present', () => {
|
||||
const edgeWithRandomProp = { ...edge, label, randomProp: true };
|
||||
render(
|
||||
<Edge {...minProps} render={renderElement} edge={edgeWithRandomProp} />,
|
||||
<svg>
|
||||
<Edge {...minProps} render={renderElement} edge={edgeWithRandomProp} />
|
||||
</svg>,
|
||||
);
|
||||
|
||||
expect(renderElement).toHaveBeenCalledWith({ edge: edgeWithRandomProp });
|
||||
});
|
||||
|
||||
it('calls setEdge with edge ID and actual label size after rendering', () => {
|
||||
const { getByText } = render(<Edge {...minProps} edge={edgeWithLabel} />);
|
||||
const { getByText } = render(
|
||||
<svg>
|
||||
<Edge {...minProps} edge={edgeWithLabel} />
|
||||
</svg>,
|
||||
);
|
||||
expect(getByText(label)).toBeInTheDocument();
|
||||
|
||||
// Updates the edge in the graph
|
||||
|
||||
@@ -23,7 +23,7 @@ import { RenderNodeProps } from './types';
|
||||
const node = { id: 'abc', x: 0, y: 0, width: 0, height: 0 };
|
||||
const setNode = jest.fn(() => new dagre.graphlib.Graph());
|
||||
const renderElement = jest.fn((props: RenderNodeProps) => (
|
||||
<text>{props.node.id}</text>
|
||||
<div>{props.node.id}</div>
|
||||
));
|
||||
|
||||
const minProps = {
|
||||
@@ -34,8 +34,7 @@ const minProps = {
|
||||
|
||||
describe('<Node />', () => {
|
||||
beforeEach(() => {
|
||||
// jsdom does not support SVG elements so we have to fall back to HTMLUnknownElement
|
||||
Object.defineProperty(window.HTMLUnknownElement.prototype, 'getBBox', {
|
||||
Object.defineProperty(window.SVGElement.prototype, 'getBBox', {
|
||||
value: () => ({ width: 100, height: 100 }),
|
||||
configurable: true,
|
||||
});
|
||||
@@ -44,19 +43,31 @@ describe('<Node />', () => {
|
||||
afterEach(jest.clearAllMocks);
|
||||
|
||||
it('renders the supplied element', () => {
|
||||
const { getByText } = render(<Node {...minProps} />);
|
||||
const { getByText } = render(
|
||||
<svg>
|
||||
<Node {...minProps} />
|
||||
</svg>,
|
||||
);
|
||||
expect(getByText(minProps.node.id)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('passes down node properties to the render method', () => {
|
||||
const nodeWithRandomProp = { ...node, randomProp: true };
|
||||
render(<Node {...minProps} node={nodeWithRandomProp} />);
|
||||
render(
|
||||
<svg>
|
||||
<Node {...minProps} node={nodeWithRandomProp} />
|
||||
</svg>,
|
||||
);
|
||||
|
||||
expect(renderElement).toHaveBeenCalledWith({ node: nodeWithRandomProp });
|
||||
});
|
||||
|
||||
it('calls setNode with node ID and actual size after rendering', () => {
|
||||
const { getByText } = render(<Node {...minProps} />);
|
||||
const { getByText } = render(
|
||||
<svg>
|
||||
<Node {...minProps} />
|
||||
</svg>,
|
||||
);
|
||||
expect(getByText(minProps.node.id)).toBeInTheDocument();
|
||||
|
||||
// Updates the node in the graph
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { renderInTestApp } from '@backstage/test-utils';
|
||||
import { renderInTestApp, withLogCollector } from '@backstage/test-utils';
|
||||
|
||||
import { GaugeCard } from './GaugeCard';
|
||||
|
||||
@@ -40,7 +40,12 @@ describe('<GaugeCard />', () => {
|
||||
|
||||
it('handles invalid numbers', async () => {
|
||||
const badProps = { title: 'Tingle upgrade', progress: 'hejjo' } as any;
|
||||
const { getByText } = await renderInTestApp(<GaugeCard {...badProps} />);
|
||||
expect(getByText(/N\/A.*/)).toBeInTheDocument();
|
||||
const { error } = await withLogCollector(async () => {
|
||||
const { getByText } = await renderInTestApp(<GaugeCard {...badProps} />);
|
||||
expect(getByText(/N\/A.*/)).toBeInTheDocument();
|
||||
});
|
||||
expect(error).toEqual([
|
||||
expect.stringMatching(/^Warning: `NaN` is an invalid value/),
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -58,6 +58,7 @@ describe('<HeaderTabs />', () => {
|
||||
const TextualBadge = React.forwardRef<HTMLSpanElement>((props, ref) => (
|
||||
<Badge
|
||||
classes={useStyles()}
|
||||
overlap="rectangular"
|
||||
color="secondary"
|
||||
badgeContent="three new alarms"
|
||||
>
|
||||
|
||||
@@ -14,7 +14,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { renderWithEffects, TestApiProvider } from '@backstage/test-utils';
|
||||
import {
|
||||
renderWithEffects,
|
||||
TestApiProvider,
|
||||
withLogCollector,
|
||||
} from '@backstage/test-utils';
|
||||
import { HomepageTimer } from './HomepageTimer';
|
||||
import React from 'react';
|
||||
import { lightTheme } from '@backstage/theme';
|
||||
@@ -35,13 +39,18 @@ it('changes default timezone to GMT', async () => {
|
||||
context: 'test',
|
||||
});
|
||||
|
||||
const rendered = await renderWithEffects(
|
||||
<ThemeProvider theme={lightTheme}>
|
||||
<TestApiProvider apis={[[configApiRef, configApi]]}>
|
||||
<HomepageTimer />
|
||||
</TestApiProvider>
|
||||
</ThemeProvider>,
|
||||
);
|
||||
const { warn } = await withLogCollector(async () => {
|
||||
const rendered = await renderWithEffects(
|
||||
<ThemeProvider theme={lightTheme}>
|
||||
<TestApiProvider apis={[[configApiRef, configApi]]}>
|
||||
<HomepageTimer />
|
||||
</TestApiProvider>
|
||||
</ThemeProvider>,
|
||||
);
|
||||
|
||||
expect(rendered.getByText('GMT')).toBeInTheDocument();
|
||||
expect(rendered.getByText('GMT')).toBeInTheDocument();
|
||||
});
|
||||
expect(warn).toEqual([
|
||||
'The timezone America/New_Pork is invalid. Defaulting to GMT',
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -61,11 +61,19 @@ describe('extensions', () => {
|
||||
const Component = () => <div />;
|
||||
const routeRef = createRouteRef({ id: 'foo' });
|
||||
|
||||
const extension1 = createComponentExtension({
|
||||
component: {
|
||||
sync: Component,
|
||||
},
|
||||
let extension1: ReturnType<typeof createComponentExtension>;
|
||||
const { warn } = withLogCollector(['warn'], () => {
|
||||
extension1 = createComponentExtension({
|
||||
component: {
|
||||
sync: Component,
|
||||
},
|
||||
});
|
||||
});
|
||||
expect(warn).toEqual([
|
||||
expect.stringMatching(
|
||||
/^Declaring extensions without name is DEPRECATED. /,
|
||||
),
|
||||
]);
|
||||
|
||||
const extension2 = createRoutableExtension({
|
||||
name: 'Extension2',
|
||||
@@ -73,7 +81,7 @@ describe('extensions', () => {
|
||||
mountPoint: routeRef,
|
||||
});
|
||||
|
||||
const ExtensionComponent1 = plugin.provide(extension1);
|
||||
const ExtensionComponent1 = plugin.provide(extension1!);
|
||||
const ExtensionComponent2 = plugin.provide(extension2);
|
||||
|
||||
const element1 = <ExtensionComponent1 />;
|
||||
|
||||
@@ -19,6 +19,7 @@ import mockFs from 'mock-fs';
|
||||
import child_process from 'child_process';
|
||||
import path from 'path';
|
||||
import {
|
||||
Task,
|
||||
buildAppTask,
|
||||
checkAppExistsTask,
|
||||
checkPathExistsTask,
|
||||
@@ -27,6 +28,13 @@ import {
|
||||
templatingTask,
|
||||
} from './tasks';
|
||||
|
||||
jest.spyOn(Task, 'log').mockReturnValue(undefined);
|
||||
jest.spyOn(Task, 'error').mockReturnValue(undefined);
|
||||
jest.spyOn(Task, 'section').mockReturnValue(undefined);
|
||||
jest
|
||||
.spyOn(Task, 'forItem')
|
||||
.mockImplementation((_a, _b, taskFunc) => taskFunc());
|
||||
|
||||
jest.mock('child_process');
|
||||
|
||||
// By mocking this the filesystem mocks won't mess with reading all of the package.jsons
|
||||
|
||||
Reference in New Issue
Block a user