Skip to content

Commit a8719b3

Browse files
committed
add tests
1 parent 8af1f1a commit a8719b3

File tree

4 files changed

+36
-7
lines changed

4 files changed

+36
-7
lines changed

packages/browser-repl/src/components/shell-output-line.spec.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,20 @@ describe('<ShellOutputLine />', () => {
139139
expect(wrapper.text()).to.contain('nested_documents\ndecimal128\ncoll\npeople_imported\ncats');
140140
});
141141

142+
it('renders StatsResult', () => {
143+
const wrapper = mount(<ShellOutputLine entry={{
144+
format: 'output',
145+
type: 'StatsResult',
146+
value: {
147+
c1: { metadata: 1 },
148+
c2: { metadata: 2 }
149+
}
150+
}} />);
151+
152+
expect(wrapper.text()).to.include('---');
153+
expect(wrapper.text()).to.include('metadata');
154+
});
155+
142156
it('renders an error', () => {
143157
const err = new Error('x');
144158
const wrapper = shallow(<ShellOutputLine entry={{ format: 'output', value: err }} />);

packages/browser-repl/src/components/shell-output-line.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { CursorIterationResultOutput } from './types/cursor-iteration-result-out
1414
import { ObjectOutput } from './types/object-output';
1515
import { SimpleTypeOutput } from './types/simple-type-output';
1616
import { ErrorOutput } from './types/error-output';
17+
import { inspect } from './utils/inspect';
1718

1819
const styles = require('./shell-output-line.less');
1920

@@ -57,10 +58,10 @@ export class ShellOutputLine extends Component<ShellOutputLineProps> {
5758
}
5859

5960
if (type === 'StatsResult') {
60-
const res = Object.keys(value).reduce((str, c) => {
61-
return `${str}\n${c}\n${value[c]}\n---\n`;
62-
}, '');
63-
return <pre>{res}</pre>;
61+
const res = Object.keys(value).map(c => {
62+
return `${c}\n${inspect(value[c])}`;
63+
}).join('\n---\n');
64+
return <SimpleTypeOutput value={res} />;
6465
}
6566

6667
if (type === 'ShowCollectionsResult') {

packages/cli-repl/src/format-output.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,20 @@ describe('formatOutput', () => {
115115
});
116116
});
117117

118+
context('when the result is StatsResult', () => {
119+
it('returns the --- separated list', () => {
120+
const output = stripAnsiColors(format({
121+
value: {
122+
c1: { metadata: 1 },
123+
c2: { metadata: 2 }
124+
},
125+
type: 'StatsResult'
126+
}));
127+
128+
expect(output).to.contain('c1\n{ metadata: 1 }\n---\nc2\n{ metadata: 2 }');
129+
});
130+
});
131+
118132
context('when the result is Help', () => {
119133
it('returns help text', () => {
120134
const output = stripAnsiColors(format({

packages/cli-repl/src/format-output.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ function formatDatabases(output): string {
7676
}
7777

7878
function formatStats(output): string {
79-
return Object.keys(output).reduce((str, c) => {
80-
return `${str}\n${c}\n${inspect(output[c])}\n---\n`;
81-
}, '');
79+
return Object.keys(output).map((c) => {
80+
return `${clr(c, ['bold', 'yellow'])}\n${inspect(output[c])}`;
81+
}).join('\n---\n');
8282
}
8383

8484
export function formatError(error): string {

0 commit comments

Comments
 (0)