Skip to content

Commit

Permalink
perf: add typescript support (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
abolkog committed Jul 26, 2024
1 parent 4b7a7ec commit 0ba37f2
Show file tree
Hide file tree
Showing 31 changed files with 6,164 additions and 19,010 deletions.
1 change: 1 addition & 0 deletions .github/workflows/pull_requests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
id: coverage
with:
output: report-markdown
test-script: npm test -- --ci --json --coverage --testLocationInResults --outputFile=report.json
- name: Publish Coverage
uses: marocchino/sticky-pull-request-comment@v2
with:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ jobs:
node-version-file: '.nvmrc'
- run: npm ci
- run: npm run build --if-present
- run: npm run test:coverage --if-present
- run: npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v18.15.0
v20.11.0
File renamed without changes.
1 change: 1 addition & 0 deletions config/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ module.exports = {
loader: 'file-loader',
},
],
noParse: [require.resolve('typescript/lib/typescript.js')],
},
resolve: {
modules: ['src', 'node_modules'],
Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = {
coverageThreshold: {
global: {
statements: 63,
branches: 60,
branches: 50,
functions: 63,
lines: 61,
},
Expand Down
24,802 changes: 6,090 additions & 18,712 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"start": "NODE_ENV=development webpack serve",
"build": "NODE_ENV=production webpack",
"test": "jest",
"test:watch": "jest test --watch",
"test:coverage": "jest test --coverage . --silent",
"test:watch": "jest test --watch",
"test:coverage": "jest test --coverage . --silent --watch",
"prepare": "husky install",
"pre-commit": "lint-staged",
"lint": "eslint src/**/*.{ts,tsx} --fix"
Expand Down Expand Up @@ -42,9 +42,9 @@
},
"dependencies": {
"@testing-library/jest-dom": "^5.16.5",
"axios": "^0.21.4",
"axios": "^1.7.2",
"date-fns": "^2.29.3",
"gh-pages": "^3.2.3",
"gh-pages": "^6.1.1",
"github-fork-ribbon-css": "^0.2.3",
"lodash": "^4.17.21",
"luxon": "^1.28.0",
Expand Down Expand Up @@ -95,7 +95,7 @@
"lint-staged": "^13.0.2",
"mini-css-extract-plugin": "^2.6.1",
"prettier": "^2.3.2",
"semantic-release": "^21.0.0",
"semantic-release": "^24.0.0",
"ts-jest": "^29.0.1",
"ts-loader": "^9.3.1",
"webpack": "^5.74.0",
Expand Down
11 changes: 1 addition & 10 deletions src/components/ActionButton/ActionButton.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,13 @@ const buttonTestId = 'actionbutton-button';
const iconTestId = 'actionbutton-icon';
describe('<ActionButton />', () => {
const onClick = jest.fn();
it('render reset button when button type is reset', () => {
render(<ActionButton onClick={onClick} type="reset" />);
const button = screen.getByTestId(`${buttonTestId}-reset`);
const icon = screen.getByTestId(iconTestId);

expect(button.textContent?.trim()).toEqual('Reset');
expect(button).toHaveClass('btn-danger');
expect(icon).toHaveClass('fa-redo');
});

it('render clear button when button type is clear', () => {
render(<ActionButton onClick={onClick} type="clear" />);
const button = screen.getByTestId(`${buttonTestId}-clear`);
const icon = screen.getByTestId(iconTestId);

expect(button.textContent?.trim()).toEqual('Clear');
expect(button.textContent?.trim()).toEqual('Clear result');
expect(button).toHaveClass('btn-info');
expect(icon).toHaveClass('fa-trash');
});
Expand Down
8 changes: 1 addition & 7 deletions src/components/ActionButton/ActionButton.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
const ButtonProps: Record<ActionButtonType, ActionButtonTypeProps> = {
reset: {
title: 'Reset',
className: 'btn btn-danger',
icon: 'fas fa-redo',
toolTip: 'Clear code in editor and result',
},
clear: {
title: 'Clear',
title: 'Clear result',
icon: 'fas fa-trash',
className: 'btn btn-info',
toolTip: 'Clear result (CtrCmd + l)',
Expand Down
2 changes: 1 addition & 1 deletion src/components/ActionButton/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type ActionButtonType = 'execute' | 'reset' | 'clear';
type ActionButtonType = 'execute' | 'clear';

interface ActionButtonProps {
type: ActionButtonType;
Expand Down
17 changes: 7 additions & 10 deletions src/components/App/App.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { createRef, useContext, useEffect, useState } from 'react';
import { useContext, useEffect, useState } from 'react';
import Header from 'components/Header';
import useResizer from 'hooks/useResizer';
import About from 'components/About';
import Tab from 'components/Tab';
import { editorTab, consoleTab } from 'components/App/tabs';
import { AppContext } from 'context/AppContext';
import { AppAactions } from 'context/Reducer';
import ContextMenu from 'components/ContextMenu';
import JsonView from 'components/JsonView';
import CodeEditor from 'components/CodeEditor';
import Console from 'components/Console';

const width = 1400;

const App: React.FC = () => {
const { dispatch } = useContext(AppContext);
const [position, setPosition] = useState<MenuPosition | null>(null);
const resizerRef = createRef<HTMLDivElement>();
const { width } = useResizer(resizerRef);

useEffect(() => {
const consoleProxy = console.log;
Expand All @@ -35,14 +34,12 @@ const App: React.FC = () => {

<div className="appConainer">
<div style={{ width }}>
<Tab tab={editorTab} />
<CodeEditor />
</div>

<div className="resizer" ref={resizerRef} />

<div style={{ width: window.innerWidth - width - 20 }}>
<div style={{ height: '100%' }} onContextMenu={handleContextMenu}>
<Tab tab={consoleTab} />
<Console />
</div>
</div>
</div>
Expand Down
18 changes: 0 additions & 18 deletions src/components/App/tabs.ts

This file was deleted.

5 changes: 3 additions & 2 deletions src/components/CodeEditor/CodeEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const CodeEditor: React.FC = () => {
const initEditor = () => {
const editorConfig = {
value: '',
language: 'javascript',
language: 'typescript',
fontSize: 20,
theme: state.theme,
minimap: {
Expand All @@ -28,7 +28,7 @@ const CodeEditor: React.FC = () => {
editorConfig
);

monaco.editor.setModelLanguage(editorInstance.getModel()!, 'javascript');
monaco.editor.setModelLanguage(editorInstance.getModel()!, 'typescript');

editorInstance.layout();

Expand Down Expand Up @@ -72,6 +72,7 @@ const CodeEditor: React.FC = () => {
useEffect(() => {
editor?.updateOptions({ theme: state.theme });
}, [state.theme]);

useEffect(() => {
editor?.setValue(state.codeSample);
}, [state.codeSample]);
Expand Down
7 changes: 4 additions & 3 deletions src/components/Console/Console.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import { AppContext } from 'context/AppContext';

const Console: React.FC = () => {
const { state } = useContext(AppContext);
const { result, error } = state;
const { result, error, theme } = state;
const extraClass = theme === 'vs-light' ? 'console-light' : '';

const createKey = (index: number) => {
return `key${index}`;
};

if (error) {
return (
<div style={{ width: '100%', height: '90%' }} className="console">
<div className="console">
<div data-testid="console-error" className="error">
{error}
</div>
Expand All @@ -21,7 +22,7 @@ const Console: React.FC = () => {
}

return (
<div data-testid="console-result" className="console">
<div data-testid="console-result" className={`console ${extraClass}`}>
{result.map((item, index) => {
const resut = !_.isString(item) ? JSON.stringify(item) : item;
return (
Expand Down
8 changes: 0 additions & 8 deletions src/components/Header/Header.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,6 @@ describe('<Header />', () => {
});
});

it('dispatch reset action when reset button is clicked', () => {
jest.spyOn(global, 'confirm' as any).mockReturnValueOnce(true);
fireEvent.click(screen.getByTestId('actionbutton-button-reset'));
expect(dispatch).toHaveBeenCalledWith({
type: AppAactions.RESET_ALL,
});
});

it('dispatch load code sample on sample change', () => {
fireEvent.change(screen.getByTestId('header-code-selector'), {
target: { value: 'Axios' },
Expand Down
10 changes: 1 addition & 9 deletions src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ const Header: React.FC = () => {
const { runCode } = useCodeRunner();
const { theme, codeSampleName } = state;

const handleReset = () => {
// eslint-disable-next-line no-restricted-globals
const answer = confirm('This will clear history and code. Are you sure?');
if (answer) {
dispatch({ type: AppAactions.RESET_ALL });
}
};
const handleChange = (e: ChangeEvent<HTMLSelectElement>) => {
const {
target: { value },
Expand Down Expand Up @@ -78,6 +71,7 @@ const Header: React.FC = () => {

<div className="btn-group" role="group">
{EDITOR_THEMES.map(item => (
// eslint-disable-next-line jsx-a11y/control-has-associated-label
<button
key={item.id}
type="button"
Expand All @@ -96,8 +90,6 @@ const Header: React.FC = () => {
</button>
))}
</div>
<span style={{ marginLeft: 20, marginRight: 20 }} />
<ActionButton type="reset" onClick={handleReset} />

<span style={{ marginLeft: 20, marginRight: 20 }} />
<ActionButton
Expand Down
41 changes: 0 additions & 41 deletions src/components/Tab/Tab.spec.tsx

This file was deleted.

42 changes: 0 additions & 42 deletions src/components/Tab/Tab.tsx

This file was deleted.

1 change: 0 additions & 1 deletion src/components/Tab/index.tsx

This file was deleted.

13 changes: 0 additions & 13 deletions src/components/Tab/types.d.ts

This file was deleted.

22 changes: 0 additions & 22 deletions src/components/TabIcon/TabIcon.spec.tsx

This file was deleted.

Loading

0 comments on commit 0ba37f2

Please sign in to comment.