Skip to content

Commit

Permalink
Revert "Chore/autumn clean (#1005)"
Browse files Browse the repository at this point in the history
This reverts commit 279272d.
  • Loading branch information
VikaCep committed Dec 19, 2024
1 parent 2df6b86 commit a033bd7
Show file tree
Hide file tree
Showing 18 changed files with 882 additions and 49 deletions.
21 changes: 21 additions & 0 deletions .release-it.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
// TODD: enable the before init hooks once grafana/toolkit can limit the jest workers
git: {
commitMessage: 'chore: update version',
tag: false,
push: false,
commit: false,
},
github: {
release: false,
},
npm: {
publish: false,
},
plugins: {
'@release-it/conventional-changelog': {
preset: 'angular',
infile: 'CHANGELOG.md',
},
},
};
730 changes: 730 additions & 0 deletions CHANGELOG_DEPRECATED.md

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions __mocks__/@grafana/faro-web-sdk.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
faro: {
api: {
pushMeasurement: jest.fn(() => console.log('hhhhhhiiiiii')),
pushEvent: jest.fn(),
pushError: jest.fn(),
},
},
isError: jest.fn(),
isObject: jest.fn(),
};
42 changes: 42 additions & 0 deletions __mocks__/@grafana/ui.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// @ts-ignore
window.__react_router_build__ = undefined;

const ui = jest.requireActual('@grafana/ui');
import React, { forwardRef } from 'react';

const Icon = forwardRef((props, ref) => <svg {...props} />);
Icon.displayName = 'Icon';

interface BigValueProps {
value: {
numeric: number;
text?: string;
title?: string;
};
}

export function BigValue({ value }: BigValueProps) {
return (
<div>
{/* {value.numeric} */}
{value.text && <span>{value.text}</span>}
{value.title && <label>{value.title}</label>}
</div>
);
}

// Monaco does not render with jest and is stuck at "Loading..."
// There doesn't seem to be a solution to this at this point,
// mocking it instead. Related github issue:
// https://github.com/suren-atoyan/monaco-react/issues/88
const CodeEditor = React.forwardRef((props: any, ref: any) => {
return <textarea ref={ref} data-testid="code-editor" onChange={props.onChange} value={props.value} />;
});
CodeEditor.displayName = 'CodeEditor';

module.exports = {
...ui,
Icon,
BigValue,
CodeEditor,
};
5 changes: 5 additions & 0 deletions __mocks__/components/SimpleMap/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from 'react';

export const SimpleMap = () => {
return <div>A pretty map</div>;
};
5 changes: 5 additions & 0 deletions __mocks__/grafana/app/core/app_events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const appEvents = {
emit: () => {},
};
// eslint-disable-next-line no-restricted-syntax
export default appEvents;
5 changes: 5 additions & 0 deletions cspell.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"ignorePaths": ["node_modules"],
"ignoreRegExpList": [".*"],
"words": ["grafana", "datasource", "datasources", "gifs", ".*"]
}
1 change: 1 addition & 0 deletions dummy.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// this file exists solely to trick the spell check. Delete this as soon as possible
9 changes: 4 additions & 5 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,17 @@ module.exports = {
...config.moduleNameMapper,
'^lodash-es$': 'lodash',
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga|md)$':
'<rootDir>/src/test/mocks/unsupported_file.js',
'^!raw-loader!*': '<rootDir>/src/test/mocks/rawLoader.js',
'^(.+)\\?raw$': '<rootDir>/src/test/mocks/rawLoader.js',
'<rootDir>/src/test/fileMock.js',
'^!raw-loader!*': '<rootDir>/src/test/rawLoaderMock.js',
'^(.+)\\?raw$': '<rootDir>/src/test/rawLoaderMock.js',
'^grafana/app/core/core$': '<rootDir>/src/test/mocks/grafana/app/core/core.js',
'^grafana/app/core/app_events$': '<rootDir>/src/test/mocks/grafana/app/core/app_events.js',
},
testTimeout: 30000,
// Inform jest to only transform specific node_module packages.
transform: {
...config.transform,
'^.+\\.mjs$': ['@swc/jest'],
'assets/snippets/.+\\.js$': '<rootDir>/src/test/mocks/rawLoader.js',
'assets/snippets/.+\\.js$': '<rootDir>/src/test/rawLoaderMock.js',
},
transformIgnorePatterns: [
nodeModulesToTransform([
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"release:test": "release-it --dry-run --ci --no-git.requireCleanWorkingDir",
"server": "docker compose up --build",
"sign": "npx --yes @grafana/sign-plugin@latest",
"spellcheck": "cspell -c cspell.config.json \"**/*.{ts,tsx,js,go,md,mdx,yml,yaml,json,scss,css}\"",
"test": "jest --all",
"test:changed": "jest --watch --onlyChanged",
"typecheck": "tsc --noEmit",
Expand Down
43 changes: 43 additions & 0 deletions src/components/Autosizer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React, { useEffect, useRef, useState } from 'react';
import { GrafanaTheme2 } from '@grafana/data';
import { useStyles2 } from '@grafana/ui';
import { css } from '@emotion/css';

interface ChildrenArgs {
width: number;
height: number;
}

interface Props {
children: (dimensions: ChildrenArgs) => JSX.Element;
}

const getStyles = (theme: GrafanaTheme2) => ({
fillContainer: css`
display: flex;
justify-content: center;
max-width: 1300px;
margin-left: auto;
margin-right: auto;
width: 100%;
`,
});

export const Autosizer = ({ children }: Props) => {
const el = useRef<HTMLDivElement>(null);
const styles = useStyles2(getStyles);
const [size, setSize] = useState({ width: 0, height: 0 });

useEffect(() => {
const rect = el.current?.getBoundingClientRect();
if (rect) {
setSize({ width: rect.width, height: rect.height });
}
}, [el]);

return (
<div className={styles.fillContainer} ref={el}>
{children(size)}
</div>
);
};
14 changes: 14 additions & 0 deletions src/components/__mocks__/Autosizer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';

interface ChildrenArgs {
width: number;
height: number;
}

interface Props {
children: (dimensions: ChildrenArgs) => JSX.Element;
}

export const Autosizer = ({ children }: Props) => {
return <div>{children({ width: 500, height: 500 })}</div>;
};
File renamed without changes.
6 changes: 0 additions & 6 deletions src/test/jest-setup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,3 @@ global.IntersectionObserver = jest.fn(() => ({
}));

import 'test/mocks/@grafana/runtime';
import 'test/mocks/@grafana/ui';
import 'test/mocks/components/SimpleMap';

// note there are some other mocks set up in jest.config.js
// for example the rawLoader, unsupported_file, grafana/app/core/core
// and grafana/app/core/app_events
30 changes: 0 additions & 30 deletions src/test/mocks/@grafana/ui.tsx

This file was deleted.

5 changes: 0 additions & 5 deletions src/test/mocks/components/SimpleMap.tsx

This file was deleted.

3 changes: 0 additions & 3 deletions src/test/mocks/grafana/app/core/app_events.js

This file was deleted.

File renamed without changes.

0 comments on commit a033bd7

Please sign in to comment.