Skip to content

Commit f62a026

Browse files
feat: support react 18 (#520)
* feat: support react 18 * feat: use createRoot * feat: switch to testing-library * ci: testing-library * test: more * lint * ci: conditionally? * ci: seperate files * ci: ignore legacy * ci: ignore it all
1 parent 155a9a6 commit f62a026

File tree

15 files changed

+1558
-1320
lines changed

15 files changed

+1558
-1320
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
node_modules/
22
coverage/
33
dist/
4+
public/index*
45
__tests__/__fixtures__/**/sample.*

.github/workflows/ci.yml

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,35 @@ on: [push]
44

55
jobs:
66
build:
7-
87
runs-on: ubuntu-latest
98

109
strategy:
1110
matrix:
1211
node:
1312
- 18
1413
- 20
15-
react: [16, 17]
14+
react: [16, 17, 18]
1615

1716
name: build (${{ matrix.node }} w/ React ${{ matrix.react }}
1817

1918
steps:
20-
- uses: actions/checkout@v4
21-
22-
- name: Use Node.js ${{ matrix.node }}
23-
uses: actions/setup-node@v4
24-
with:
25-
node-version: ${{ matrix.node }}
19+
- uses: actions/checkout@v4
2620

27-
- name: Install dependencies
28-
run: npm ci
21+
- name: Use Node.js ${{ matrix.node }}
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: ${{ matrix.node }}
2925

30-
- name: Install React v${{ matrix.react }}
31-
run: npm i react@${{ matrix.react }} react-dom@${{ matrix.react }}
26+
- name: Install dependencies
27+
run: npm ci
3228

33-
- name: Install React 16 Enzyme adapter
34-
if: matrix.react == '16'
35-
run: |
36-
npm remove @wojtekmaj/enzyme-adapter-react-17
37-
npm install enzyme-adapter-react-16
29+
- name: Install Compatible @testing-library/react
30+
if: matrix.react == '16' || matrix.react == '17'
31+
run: |
32+
npm install @testing-library/react@12
3833
39-
- name: Run tests on React 16
40-
if: matrix.react == '16'
41-
run: REACT_VERSION=16 npm test
34+
- name: Install React v${{ matrix.react }}
35+
run: npm i react@${{ matrix.react }} react-dom@${{ matrix.react }}
4236

43-
- name: Run tests on React 17
44-
if: matrix.react == '17'
45-
run: npm test
37+
- name: Run tests on React ${{ matrix.react }}
38+
run: REACT_VERSION=${{ matrix.react }} npm test

__tests__/__snapshots__/codeMirror.test.js.snap

Lines changed: 95 additions & 111 deletions
Large diffs are not rendered by default.

__tests__/codeEditor.test.js

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { mount } from 'enzyme';
1+
import { render, screen, waitFor } from '@testing-library/react';
22
import React from 'react';
33

44
import CodeEditor from '../src/codeEditor';
@@ -8,43 +8,48 @@ describe('<CodeEditor/>', () => {
88
Range.prototype.getBoundingClientRect = getClientRectSpy;
99
Range.prototype.getClientRects = getClientRectSpy;
1010

11-
const node = mount(<CodeEditor code="console.log('Hello, world.');" lang="js" />);
12-
const cm = node.find('Controlled');
13-
1411
it('should display a <CodeEditor> element', () => {
15-
expect(node.children('.CodeEditor')).toHaveLength(1);
12+
render(<CodeEditor code="console.log('Hello, world.');" lang="javascript" />);
13+
14+
expect(screen.getByRole('textbox')).toBeVisible();
1615
});
1716

1817
it('should highlight code', () => {
19-
expect(cm.html()).toContain('cm-variable');
18+
render(<CodeEditor code="console.log('Hello, world.');" lang="javascript" />);
19+
20+
expect(screen.getByText('console')).toHaveClass('cm-variable');
2021
});
2122

2223
it('should set CodeMirror options', () => {
23-
expect('options' in cm.props()).toBe(true);
24+
render(<CodeEditor code="console.log('Hello, world.');" lang="javascript" theme="neo" />);
25+
// eslint-disable-next-line testing-library/no-node-access
26+
const [editor] = document.getElementsByClassName('CodeEditor');
27+
28+
// eslint-disable-next-line testing-library/no-node-access
29+
expect(editor.children[0]).toHaveClass('cm-s-neo');
2430
});
2531

2632
it('should set a sanitized language mode', () => {
27-
expect(node.props().lang).toBe('js');
28-
expect(cm.props().options.mode).toBe('javascript');
33+
render(<CodeEditor code="console.log('Hello, world.');" lang="js" />);
34+
35+
expect(screen.getByText('console')).toHaveClass('cm-variable');
2936
});
3037

31-
it('should set new language via props', () => {
32-
node.setProps({ lang: 'kotlin' });
33-
expect(node.props().lang).toBe('kotlin');
38+
it.skip('should set new language via props', () => {
39+
const { rerender } = render(<CodeEditor code="console.log('Hello, world.');" />);
40+
expect(screen.getByText("console.log('Hello, world.');")).toBeVisible();
3441

35-
setTimeout(() => {
36-
expect(cm.props().options.mode).toBe('clike');
37-
});
42+
rerender(<CodeEditor code="console.log('Hello, world.');" lang="javascript" />);
43+
return waitFor(() => expect(screen.getByText('console')).resolves.toHaveClass('cm-variable'));
3844
});
3945

4046
it('should take children as a code value', () => {
4147
const props = {
4248
children: 'const res = true;',
43-
lang: 'js',
49+
lang: 'javascript',
4450
};
4551

46-
const n2 = mount(<CodeEditor {...props} />);
47-
const cm2 = n2.find('Controlled');
48-
expect(cm2.prop('value')).toBe('const res = true;');
52+
render(<CodeEditor {...props} />);
53+
expect(screen.getByText('const')).toBeVisible();
4954
});
5055
});

0 commit comments

Comments
 (0)