• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

electron / fiddle / 16349153970

17 Jul 2025 03:21PM UTC coverage: 80.235% (-7.8%) from 87.992%
16349153970

push

github

web-flow
test: switch to Vitest (#1718)

* test: switch to Vitest

* chore: update code comment

Co-authored-by: Kevin Cui <158blackhole@gmail.com>

* test: make use of vi.useFakeTimers to improve test

---------

Co-authored-by: Kevin Cui <158blackhole@gmail.com>

1520 of 1645 branches covered (92.4%)

Branch coverage included in aggregate %.

15 of 16 new or added lines in 12 files covered. (93.75%)

504 existing lines in 45 files now uncovered.

8807 of 11226 relevant lines covered (78.45%)

32.71 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.15
/src/renderer/components/editor.tsx
1
// Credit goes in large part to https://github.com/superRaytin/react-monaco-editor,
2
// this component is a changed version of it.
3

4
import * as React from 'react';
1✔
5

6
import * as MonacoType from 'monaco-editor';
7

8
import { EditorId } from '../../interfaces';
9
import { AppState } from '../state';
10
import { monacoLanguage } from '../utils/editor-utils';
1✔
11

12
interface EditorProps {
13
  readonly appState: AppState;
14
  readonly id: EditorId;
15
  readonly monaco: typeof MonacoType;
16
  monacoOptions: MonacoType.editor.IEditorOptions;
17
  editorDidMount?: (editor: MonacoType.editor.IStandaloneCodeEditor) => void;
18
  onChange?: (
19
    value: string,
20
    event: MonacoType.editor.IModelContentChangedEvent,
21
  ) => void;
22
  setFocused: (id: EditorId) => void;
23
}
24

25
export class Editor extends React.Component<EditorProps> {
1✔
26
  public editor?: MonacoType.editor.IStandaloneCodeEditor;
9✔
27
  public language = 'javascript';
9✔
28
  public value = '';
9✔
29

30
  private containerRef = React.createRef<HTMLDivElement>();
9✔
31

32
  constructor(props: EditorProps) {
9✔
33
    super(props);
9✔
34

35
    this.language = monacoLanguage(props.id);
9✔
36
  }
9✔
37

38
  public shouldComponentUpdate() {
9✔
39
    return false;
1✔
40
  }
1✔
41

42
  public async componentDidMount() {
9✔
43
    await this.initMonaco();
9✔
44
  }
9✔
45

46
  public componentWillUnmount() {
9✔
47
    this.destroyMonaco();
2✔
48
  }
2✔
49

50
  /**
51
   * Handle the editor having been mounted. This refers to Monaco's
52
   * mount, not React's.
53
   */
54
  public async editorDidMount(editor: MonacoType.editor.IStandaloneCodeEditor) {
9✔
55
    const { appState, editorDidMount, id } = this.props;
9✔
56
    const { editorMosaic } = appState;
9✔
57

58
    editorMosaic.addEditor(id, editor);
9✔
59

60
    // And notify others
61
    if (editorDidMount) {
9✔
62
      editorDidMount(editor);
9✔
63
    }
9✔
64

65
    // Click file tree, if the file is hidden, focus it
66
    // Because you can't focus immediately after redisplay, you must wait until the mount is complete
67
    if (editorMosaic.focusedFile === id) {
9!
68
      editor.focus();
×
69
      this.props.setFocused(id);
×
UNCOV
70
    }
×
71
  }
9✔
72

73
  /**
74
   * Initialize Monaco.
75
   */
76
  public async initMonaco() {
9✔
77
    const { monaco, monacoOptions: monacoOptions, appState } = this.props;
9✔
78
    const ref = this.containerRef.current;
9✔
79

80
    const { fontFamily, fontSize } = appState;
9✔
81

82
    if (ref) {
9✔
83
      this.editor = monaco.editor.create(
9✔
84
        ref,
9✔
85
        {
9✔
86
          automaticLayout: true,
9✔
87
          language: this.language,
9✔
88
          theme: 'main',
9✔
89
          fontFamily,
9✔
90
          fontSize,
9✔
91
          contextmenu: false,
9✔
92
          model: null,
9✔
93
          ...monacoOptions,
9✔
94
        },
9✔
95
        {
9✔
96
          openerService: this.openerService(),
9✔
97
        },
9✔
98
      );
9✔
99

100
      // mark this editor as focused whenever it is
101
      this.editor.onDidFocusEditorText(() => {
9✔
102
        const { id, setFocused } = this.props;
×
103
        setFocused(id);
×
104
      });
9✔
105

106
      await this.editorDidMount(this.editor);
9✔
107
    }
9✔
108
  }
9✔
109

110
  /**
111
   * Destroy Monaco.
112
   */
113
  public destroyMonaco() {
9✔
114
    if (typeof this.editor !== 'undefined') {
2✔
115
      console.log('Editor: Disposing');
2✔
116
      this.editor.dispose();
2✔
117
    }
2✔
118
  }
2✔
119

120
  /**
121
   * Implements external url handling for Monaco.
122
   */
123
  private openerService() {
9✔
124
    const { appState } = this.props;
9✔
125

126
    return {
9✔
127
      open: (url: string) => {
9✔
128
        appState
×
UNCOV
129
          .showConfirmDialog({
×
UNCOV
130
            label: `Open ${url} in external browser?`,
×
UNCOV
131
            ok: 'Open',
×
UNCOV
132
          })
×
UNCOV
133
          .then((open) => {
×
134
            if (open) window.open(url);
×
UNCOV
135
          });
×
UNCOV
136
      },
×
137
    };
9✔
138
  }
9✔
139

140
  public render() {
9✔
141
    return (
9✔
142
      <div
9✔
143
        className="editorContainer"
9✔
144
        data-testid="editorContainer"
9✔
145
        ref={this.containerRef}
9✔
146
      />
9✔
147
    );
148
  }
9✔
149
}
9✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc