Skip to content

Commit fcad45d

Browse files
refactor: clear screen and create directories for components and utils
1 parent 7c78acd commit fcad45d

10 files changed

Lines changed: 38 additions & 7 deletions

File tree

eslint.config.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default defineConfig([
3636
...globals.vitest,
3737
},
3838
parserOptions: {
39-
project: ['tsconfig.build.json', 'tsconfig.test.json'],
39+
project: ['tsconfig.test.json'],
4040
tsconfigRootDir: import.meta.dirname,
4141
},
4242
},

src/cli.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { type MockInstance, vi } from 'vitest';
22

3-
const { outputHelp, parse, render } = vi.hoisted(() => ({
3+
const { clearScreen, outputHelp, parse, render } = vi.hoisted(() => ({
4+
clearScreen: vi.fn(),
45
outputHelp: vi.fn(),
56
parse: vi.fn(),
67
render: vi.fn(),
78
}));
89

10+
vi.mock('./utils', () => ({ clear: clearScreen }));
911
vi.mock('ink', () => ({ render }));
1012

1113
vi.mock('cac', () => ({
@@ -35,6 +37,7 @@ describe('cli', () => {
3537

3638
it('renders TUI with no args', () => {
3739
main([]);
40+
expect(clearScreen).toHaveBeenCalledOnce();
3841
expect(render).toHaveBeenCalledOnce();
3942
expect(parse).not.toHaveBeenCalled();
4043
});

src/cli.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import cac from 'cac';
44
import { render } from 'ink';
55

66
import pkg from '../package.json' with { type: 'json' };
7-
import App from './App';
7+
import { App } from './components';
8+
import { clear } from './utils';
89

910
const cli = cac('code-ollama');
1011

@@ -13,6 +14,7 @@ cli.help();
1314

1415
export function main(args: string[] = process.argv.slice(2)): void {
1516
if (!args.length) {
17+
clear();
1618
render(<App />);
1719
return;
1820
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { render } from 'ink-testing-library';
22

3-
import App from './App';
3+
import { App } from './App';
44

55
describe('App', () => {
66
it('renders', () => {

src/App.tsx renamed to src/components/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Box, Text } from 'ink';
22

3-
export default function App() {
3+
export function App() {
44
return (
55
<Box>
66
<Text>🦙 code-ollama</Text>

src/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { App } from './App';

src/utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { clear } from './screen';

src/utils/screen.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { type MockInstance, vi } from 'vitest';
2+
3+
import { clear } from './screen';
4+
5+
describe('clear', () => {
6+
let stdoutSpy: MockInstance<typeof process.stdout.write>;
7+
8+
beforeEach(() => {
9+
stdoutSpy = vi
10+
.spyOn(process.stdout, 'write')
11+
.mockImplementation(() => true);
12+
});
13+
14+
afterEach(() => {
15+
stdoutSpy.mockRestore();
16+
});
17+
18+
it('writes reset escape sequence to stdout', () => {
19+
clear();
20+
expect(stdoutSpy).toHaveBeenCalledWith('\x1Bc');
21+
});
22+
});

src/utils/screen.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function clear(): void {
2+
process.stdout.write('\x1Bc');
3+
}

vite.config.mts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ export default defineConfig({
2626

2727
test: {
2828
globals: true,
29-
exclude: ['dist/**', 'node_modules/**'],
3029
coverage: {
3130
include: ['src'],
32-
exclude: ['src/**/*.test.ts', 'src/**/*.test.tsx'],
31+
exclude: ['src/**/*.test.ts', 'src/**/*.test.tsx', 'src/**/index.ts'],
3332
thresholds: {
3433
100: true,
3534
},

0 commit comments

Comments
 (0)