Skip to content

Commit da6a986

Browse files
authored
Fix ace editor warnings in test suite by addressing webpack issue (#2982)
1 parent 62f5a83 commit da6a986

File tree

6 files changed

+14
-37
lines changed

6 files changed

+14
-37
lines changed

craco.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ const cracoConfig = {
143143
),
144144
'^.+\\.module\\.(css|sass|scss)$'
145145
];
146-
jestConfig.moduleNameMapper['ace-builds'] = '<rootDir>/node_modules/ace-builds';
147146
jestConfig.moduleNameMapper['unist-util-visit-parents/do-not-use-color'] =
148147
'<rootDir>/node_modules/unist-util-visit-parents/lib';
149148
jestConfig.moduleNameMapper['vfile/do-not-use-conditional-minpath'] =

src/commons/assessmentWorkspace/__tests__/AssessmentWorkspace.tsx

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { act, render, screen } from '@testing-library/react';
2-
import { require as acequire } from 'ace-builds';
32
import { Provider } from 'react-redux';
43
import { createMemoryRouter, RouterProvider } from 'react-router';
54
import { mockInitialStore } from 'src/commons/mocks/StoreMocks';
@@ -10,12 +9,6 @@ import { EditorBinding, WorkspaceSettingsContext } from 'src/commons/WorkspaceSe
109
import { mockAssessments } from '../../mocks/AssessmentMocks';
1110
import AssessmentWorkspace, { AssessmentWorkspaceProps } from '../AssessmentWorkspace';
1211

13-
jest.mock('ace-builds', () => ({
14-
...jest.requireActual('ace-builds'),
15-
require: jest.fn()
16-
}));
17-
const acequireMock = acequire as jest.Mock;
18-
1912
const defaultProps = assertType<AssessmentWorkspaceProps>()({
2013
assessmentId: 0,
2114
needsPassword: false,
@@ -114,13 +107,6 @@ const getGradingResultTab = (tree: HTMLElement) => tree.querySelector('.GradingR
114107
const getContestVotingTab = (tree: HTMLElement) => tree.querySelector('.ContestEntryVoting');
115108

116109
describe('AssessmentWorkspace', () => {
117-
beforeEach(() => {
118-
acequireMock.mockReturnValue({
119-
Mode: jest.fn(),
120-
setCompleters: jest.fn()
121-
});
122-
});
123-
124110
test('AssessmentWorkspace page "loading" content renders correctly', async () => {
125111
const app = createMemoryRouterWithRoutes(mockUndefinedAssessmentWorkspaceProps);
126112
const tree = await renderTreeJson(app);

src/commons/editor/Editor.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
11
/* eslint-disable simple-import-sort/imports */
2+
3+
// Next line necessary to prevent "ReferenceError: ace is not defined" error.
4+
// See https://github.com/securingsincity/react-ace/issues/1233 (although there is no explanation).
5+
import 'ace-builds/src-noconflict/ace';
26
import 'ace-builds/src-noconflict/ext-language_tools';
37
import 'ace-builds/src-noconflict/ext-searchbox';
48
import 'ace-builds/src-noconflict/ext-settings_menu';
59
import 'js-slang/dist/editors/ace/theme/source';
610

11+
/**
12+
* ace-builds/webpack-resolver is causing some issues in the testing environment.
13+
* Without it, we have to manually import the following keybindings to ensure they are packaged
14+
* together with the editor during lazy loading.
15+
*
16+
* Supersedes changes from: https://github.com/source-academy/frontend/issues/2543
17+
*/
18+
import 'ace-builds/src-noconflict/keybinding-vim';
19+
import 'ace-builds/src-noconflict/keybinding-emacs';
20+
721
import { Card } from '@blueprintjs/core';
822
import * as AceBuilds from 'ace-builds';
923
import { Ace, require as acequire, createEditSession } from 'ace-builds';

src/commons/editor/EditorContainer.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
// Necessary to prevent "ReferenceError: ace is not defined" error.
2-
// See https://github.com/securingsincity/react-ace/issues/1233 (although there is no explanation).
3-
import 'ace-builds/src-noconflict/ace';
4-
// For webpack to resolve properly during lazy loading (see https://github.com/source-academy/frontend/issues/2543)
5-
import 'ace-builds/webpack-resolver';
6-
71
import _ from 'lodash';
82
import React from 'react';
93

src/pages/playground/__tests__/Playground.tsx

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Router } from '@remix-run/router';
22
import { act, render } from '@testing-library/react';
3-
import { require as acequire } from 'ace-builds';
43
import { FSModule } from 'browserfs/dist/node/core/FS';
54
import { Chapter } from 'js-slang/dist/types';
65
import { Provider } from 'react-redux';
@@ -21,13 +20,6 @@ import Playground, { handleHash } from '../Playground';
2120
(window as any).Inspector = jest.fn();
2221
(window as any).Inspector.highlightClean = jest.fn();
2322

24-
jest.mock('ace-builds', () => ({
25-
...jest.requireActual('ace-builds'),
26-
require: jest.fn()
27-
}));
28-
29-
const acequireMock = acequire as jest.Mock;
30-
3123
// Using @testing-library/react to render snapshot instead of react-test-renderer
3224
// as the useRefs require the notion of React DOM
3325
const renderTree = async (router: Router) => {
@@ -61,10 +53,6 @@ describe('Playground tests', () => {
6153
)
6254
}
6355
];
64-
acequireMock.mockReturnValue({
65-
Mode: jest.fn(),
66-
setCompleters: jest.fn()
67-
});
6856
});
6957

7058
test('Playground renders correctly', async () => {

src/pages/sicp/subcomponents/__tests__/CodeSnippet.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
import 'ace-builds';
2-
import 'ace-builds/webpack-resolver';
3-
import 'ace-builds/src-noconflict/ace';
4-
51
import lzString from 'lz-string';
62
import { shallowRender } from 'src/commons/utils/TestUtils';
73

0 commit comments

Comments
 (0)