Skip to content

Commit fdc4c1f

Browse files
authored
fix(browser-repl): account for node-runtime-worker-thread-specific result rendering MONGOSH-1323 (#1452)
d1278ec attempted to address MONGOSH-1323 but failed to do so properly because node-runtime-worker-thread adjusts behavior so that most values result in reporting a `string` result back to the frontend.
1 parent 539a7a6 commit fdc4c1f

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ import { ErrorOutput } from './types/error-output';
1212

1313
describe('<ShellOutputLine />', () => {
1414
it('renders a string value', () => {
15-
const wrapper = shallow(<ShellOutputLine entry={{ format: 'output', value: 'some text' }} />);
15+
const wrapper = mount(<ShellOutputLine entry={{ format: 'output', value: 'some text' }} />);
16+
expect(wrapper.find('pre')).to.have.lengthOf(1);
17+
expect(wrapper.text()).to.contain('some text');
18+
});
19+
20+
it('renders a pre-inspected string value from node-runtime-worker-thread', () => {
21+
const wrapper = shallow(<ShellOutputLine entry={{ format: 'output', value: 'some text', type: 'InspectResult' }} />);
1622
expect(wrapper.find(SimpleTypeOutput)).to.have.lengthOf(1);
1723
});
1824

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ export class ShellOutputLine extends Component<ShellOutputLineProps> {
5959
return <pre>{value}</pre>;
6060
}
6161

62-
if (typeof value === 'string' && !type) {
62+
// 'InspectResult' is a special value used by node-runtime-worker-thread
63+
// which indicates that the value has already been inspect()ed prior to
64+
// serialization, in which case we also want to print its raw contents
65+
// rather than calling inspect() again;
66+
if (typeof value === 'string' && type === 'InspectResult') {
6367
return <SimpleTypeOutput value={value} raw />;
6468
}
6569

@@ -115,9 +119,10 @@ export class ShellOutputLine extends Component<ShellOutputLineProps> {
115119
}
116120

117121
private isPreformattedResult(value: any, type?: string | null): boolean {
118-
return typeof value === 'string' &&
119-
type === 'Database' ||
120-
type === 'Collection';
122+
return typeof value === 'string' && (
123+
type === 'Database' ||
124+
type === 'Collection' ||
125+
!type);
121126
}
122127

123128
private isPrimitiveOrFunction(value: any): boolean {

0 commit comments

Comments
 (0)