Support `monaco-editor` in Jest
Description
If you try migrating the spec/javascripts/ide/components/repo_editor_spec.js to Jest, you'll quickly learn that monaco-editor is incompatible with Jest...
Test suite failed to run
Cannot find module 'monaco-editor' from 'editor_spec.js'
> 1 | import { editor as monacoEditor } from 'monaco-editor';
| ^
2 | import Editor from '~/ide/lib/editor';
3 | import { file } from '../helpers';
4 |
at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:230:17)
at Object.<anonymous> (spec/frontend/ide/lib/editor_spec.js:1:1)
This is probably related to us having a special Webpack loader for monaco...
Proposal
This comment implied that this might not be an issue with newer versions of monaco. If that doesn't work, we'll need to look at building a mock
UPDATE: We are past the version mentioned in the linked comment above, but are still having issues. See details in this note.
Context
The following discussion from !22095 (merged) should be addressed:
-
@pslaughter started a discussion: note: Had to revert migrating the following specs:
spec/javascripts/ide/components/activity_bar_spec.js spec/javascripts/ide/components/ide_tree_list_spec.js spec/javascripts/ide/components/repo_tab_spec.jsBecause for some reason the combination of specs + Karma's non-sandboxed environment caused
repo_editor_specto fail with some weird errors:Error: ModelService: Cannot add model because it already exists! 9644 at ModelServiceImpl.../../../node_modules/monaco-editor/esm/vs/editor/common/services/modelServiceImpl.js.ModelServiceImpl._createModelData (webpack:///builds/gitlab-org/gitlab/node_modules/monaco-editor/esm/vs/editor/common/services/modelServiceImpl.js:382:1 <- spec/javascripts/test_bundle.js:1535116:19) 9645 at ModelServiceImpl.../../../node_modules/monaco-editor/esm/vs/editor/common/services/modelServiceImpl.js.ModelServiceImpl.createModel (webpack:///builds/gitlab-org/gitlab/node_modules/monaco-editor/esm/vs/editor/common/services/modelServiceImpl.js:392:1 <- spec/javascripts/test_bundle.js:1535126:30) 9646 at doCreateModel (webpack:///builds/gitlab-org/gitlab/node_modules/monaco-editor/esm/vs/editor/standalone/browser/standaloneEditor.js:82:1 <- spec/javascripts/test_bundle.js:1574530:102) 9647 at Object.createModel (webpack:///builds/gitlab-org/gitlab/node_modules/monaco-editor/esm/vs/editor/standalone/browser/standaloneEditor.js:97:1 <- spec/javascripts/test_bundle.js:1574545:16) 9648 at new Model (webpack:///ide/lib/common/model.js:1132:1 <- spec/javascripts/test_bundle.js:2202524:69) 9649 at ModelManager.addModel (webpack:///ide/lib/common/model_manager.js:460:1 <- spec/javascripts/test_bundle.js:2203416:42) 9650 at UserContext.<anonymous> (webpack:///builds/gitlab-org/gitlab/spec/javascripts/ide/lib/common/model_manager_spec.js:79:1 <- spec/javascripts/test_buCreating a follow up issue for this...