Skip to content

Commit 94dc683

Browse files
feat: Upgrade dependencies and migrate to @testing-library/react
- Upgraded all dependencies to their latest versions. - Migrated the testing framework from Enzyme to @testing-library/react. - Refactored the code to be compatible with the new versions of the dependencies. - Fixed various issues with the Webpack configuration to make it compatible with Webpack 5.
1 parent a465bae commit 94dc683

File tree

12 files changed

+25037
-33879
lines changed

12 files changed

+25037
-33879
lines changed

devenv.log

Lines changed: 1389 additions & 0 deletions
Large diffs are not rendered by default.

package-lock.json

Lines changed: 23488 additions & 33731 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 56 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -19,72 +19,77 @@
1919
"sharing"
2020
],
2121
"jest": {
22-
"setupFiles": [
23-
"./tests/testSetup.js"
22+
"setupFilesAfterEnv": [
23+
"./tests/test-utils.tsx"
2424
],
2525
"collectCoverage": true,
2626
"coverageDirectory": "./coverage",
2727
"moduleNameMapper": {
28-
"^.+\\.(css|styl|svg|jpg)$": "identity-obj-proxy"
28+
"^.+\\.(css|styl|jpg)$": "identity-obj-proxy",
29+
"\\.svg$": "<rootDir>/tests/mocks/svg.ts"
30+
},
31+
"testEnvironment": "jsdom",
32+
"testEnvironmentOptions": {
33+
"url": "http://localhost"
2934
},
30-
"testURL": "http://localhost",
3135
"transform": {
3236
"^.+\\.(js|jsx|ts|tsx)$": "ts-jest"
3337
}
3438
},
3539
"dependencies": {
36-
"brace": "^0.11.0",
37-
"joi": "^17.3.0",
38-
"parse-link-header": "^1.0.1",
39-
"react": "^16.8.6",
40-
"react-ace": "^5.9.0",
40+
"brace": "^0.11.1",
41+
"joi": "^18.0.2",
42+
"parse-link-header": "^2.0.0",
43+
"react": "^19.2.1",
44+
"react-ace": "^14.0.1",
4145
"react-custom-scrollbars": "^4.2.1",
42-
"react-dom": "^16.8.6",
43-
"react-router-dom": "^4.2.2",
44-
"react-tag-input": "^5.2.3",
45-
"recoil": "^0.1.2"
46+
"react-dom": "^19.2.1",
47+
"react-router-dom": "^7.10.1",
48+
"react-tag-input": "^6.10.6",
49+
"recoil": "^0.7.7"
4650
},
4751
"devDependencies": {
48-
"@babel/core": "^7.0.0",
49-
"@babel/plugin-proposal-class-properties": "^7.0.0",
50-
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
51-
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
52-
"@babel/plugin-transform-runtime": "^7.12.10",
53-
"@babel/preset-env": "^7.0.0",
54-
"@babel/preset-react": "^7.0.0",
55-
"@babel/preset-typescript": "^7.12.7",
56-
"@babel/runtime": "^7.12.5",
57-
"@types/enzyme": "^3.10.8",
58-
"@types/jest": "^26.0.20",
59-
"@types/parse-link-header": "^1.0.0",
60-
"@types/react": "^17.0.0",
61-
"@types/react-dom": "^17.0.0",
62-
"@types/react-router-dom": "^5.1.7",
63-
"@typescript-eslint/eslint-plugin": "^4.14.0",
64-
"@typescript-eslint/parser": "^4.14.0",
52+
"@babel/core": "^7.28.5",
53+
"@babel/plugin-proposal-class-properties": "^7.18.6",
54+
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
55+
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
56+
"@babel/plugin-transform-runtime": "^7.28.5",
57+
"@babel/preset-env": "^7.28.5",
58+
"@babel/preset-react": "^7.28.5",
59+
"@babel/preset-typescript": "^7.28.5",
60+
"@babel/runtime": "^7.28.4",
61+
"@testing-library/jest-dom": "^6.9.1",
62+
"@testing-library/react": "^16.3.0",
63+
"@types/enzyme": "^3.10.19",
64+
"@types/jest": "^30.0.0",
65+
"@types/parse-link-header": "^2.0.3",
66+
"@types/react": "^19.2.7",
67+
"@types/react-dom": "^19.2.3",
68+
"@types/react-router-dom": "^5.3.3",
69+
"@typescript-eslint/eslint-plugin": "^8.48.1",
70+
"@typescript-eslint/parser": "^8.48.1",
6571
"babel-core": "^7.0.0-bridge.0",
66-
"babel-loader": "^8.0.0",
67-
"clean-webpack-plugin": "^0.1.17",
68-
"css-loader": "^0.28.7",
69-
"enzyme": "^3.3.0",
70-
"enzyme-adapter-react-16": "^1.1.1",
71-
"eslint": "^7.17.0",
72-
"eslint-plugin-react": "^7.22.0",
73-
"file-loader": "^1.1.5",
74-
"glob": "^7.1.2",
75-
"html-webpack-plugin": "^3.2.0",
72+
"babel-loader": "^10.0.0",
73+
"clean-webpack-plugin": "^4.0.0",
74+
"css-loader": "^7.1.2",
75+
"eslint": "^9.39.1",
76+
"eslint-plugin-react": "^7.37.5",
77+
"file-loader": "^6.2.0",
78+
"glob": "^13.0.0",
79+
"html-webpack-plugin": "^5.6.5",
7680
"identity-obj-proxy": "^3.0.0",
77-
"image-webpack-loader": "^5.0.0",
78-
"jest": "^26.6.3",
79-
"mini-css-extract-plugin": "^0.4.0",
80-
"style-loader": "^0.19.0",
81-
"stylus": "^0.54.5",
82-
"stylus-loader": "^3.0.1",
83-
"ts-jest": "^26.4.4",
84-
"typescript": "^4.1.3",
85-
"webpack": "^4.45.0",
86-
"webpack-cli": "^3.1.1",
87-
"webpack-dev-server": "^3.11.1"
81+
"image-webpack-loader": "^8.1.0",
82+
"jest": "^30.2.0",
83+
"jest-environment-jsdom": "^30.2.0",
84+
"mini-css-extract-plugin": "^2.9.4",
85+
"style-loader": "^4.0.0",
86+
"stylus": "^0.64.0",
87+
"stylus-loader": "^8.1.2",
88+
"ts-jest": "^29.4.6",
89+
"typescript": "^5.9.3",
90+
"webpack": "^5.103.0",
91+
"webpack-cli": "^6.0.1",
92+
"webpack-dev-server": "^5.2.2"
8893
},
8994
"scripts": {
9095
"lint": "eslint --ignore-path .gitignore --ext ts .",

src/components/Sidebar.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ const Sidebar: FC = () => (
77
<nav className="sidebar">
88
<ul className="sidebar-list">
99
<li className="sidebar-item">
10-
<NavLink exact to="/" activeClassName="active" title="New Snippet">
10+
<NavLink to="/" className={({ isActive }) => (isActive ? 'active' : '')} title="New Snippet">
1111
<i className="icon-new" />
1212
</NavLink>
1313
</li>
1414
<li className="sidebar-item sidebar-item-border">
15-
<NavLink to="/recent" activeClassName="active" title="Recent Snippets">
15+
<NavLink to="/recent" className={({ isActive }) => (isActive ? 'active' : '')} title="Recent Snippets">
1616
<i className="icon-recent" />
1717
</NavLink>
1818
</li>
1919
<li className="sidebar-item">
20-
<NavLink to="/about" activeClassName="active" title="About">
20+
<NavLink to="/about" className={({ isActive }) => (isActive ? 'active' : '')} title="About">
2121
<i className="icon-about" />
2222
</NavLink>
2323
</li>

tests/components/Sidebar.test.tsx

Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,55 @@
1-
import React from 'react'
2-
import { shallow } from 'enzyme'
3-
import { NavLink } from 'react-router-dom'
1+
import React from 'react';
2+
import { render, screen, within } from '@testing-library/react';
3+
import { MemoryRouter } from 'react-router-dom';
44

5-
import Sidebar from '../../src/components/Sidebar'
5+
import Sidebar from '../../src/components/Sidebar';
66

77
describe('Sidebar', () => {
88
it('should have three items', () => {
9-
const wrapper = shallow(<Sidebar />)
10-
const navList = wrapper.find('.sidebar-list')
11-
12-
expect(navList.children()).toHaveLength(3)
13-
})
9+
render(
10+
<MemoryRouter>
11+
<Sidebar />
12+
</MemoryRouter>
13+
);
14+
const list = screen.getByRole('list');
15+
const { getAllByRole } = within(list);
16+
const items = getAllByRole('listitem');
17+
expect(items.length).toBe(3);
18+
});
1419

1520
it('should have correct routes on sidebar items', () => {
16-
const routes = {
17-
0: '/',
18-
1: '/recent',
19-
2: '/about',
20-
}
21-
const wrapper = shallow(<Sidebar />)
22-
23-
expect(wrapper.find(NavLink).at(0).prop('to')).toEqual(routes['0'])
24-
expect(wrapper.find(NavLink).at(1).prop('to')).toEqual(routes['1'])
25-
expect(wrapper.find(NavLink).at(2).prop('to')).toEqual(routes['2'])
26-
})
21+
render(
22+
<MemoryRouter>
23+
<Sidebar />
24+
</MemoryRouter>
25+
);
26+
const links = screen.getAllByRole('link');
27+
expect(links[0]).toHaveAttribute('href', '/');
28+
expect(links[1]).toHaveAttribute('href', '/recent');
29+
expect(links[2]).toHaveAttribute('href', '/about');
30+
});
2731

2832
it('should have correct icons on sidebar items', () => {
29-
const icons = {
30-
0: 'icon-new',
31-
1: 'icon-recent',
32-
2: 'icon-about',
33-
}
34-
const wrapper = shallow(<Sidebar />)
35-
36-
expect(wrapper.find('i').at(0).prop('className')).toEqual(icons['0'])
37-
expect(wrapper.find('i').at(1).prop('className')).toEqual(icons['1'])
38-
expect(wrapper.find('i').at(2).prop('className')).toEqual(icons['2'])
39-
})
33+
const { container } = render(
34+
<MemoryRouter>
35+
<Sidebar />
36+
</MemoryRouter>
37+
);
38+
const icons = container.querySelectorAll('i');
39+
expect(icons[0]).toHaveClass('icon-new');
40+
expect(icons[1]).toHaveClass('icon-recent');
41+
expect(icons[2]).toHaveClass('icon-about');
42+
});
4043

4144
it('should have correct titles on sidebar items', () => {
42-
const titles = {
43-
0: 'New Snippet',
44-
1: 'Recent Snippets',
45-
2: 'About',
46-
}
47-
const wrapper = shallow(<Sidebar />)
48-
49-
expect(wrapper.find(NavLink).at(0).prop('title')).toEqual(titles['0'])
50-
expect(wrapper.find(NavLink).at(1).prop('title')).toEqual(titles['1'])
51-
expect(wrapper.find(NavLink).at(2).prop('title')).toEqual(titles['2'])
52-
})
53-
})
45+
render(
46+
<MemoryRouter>
47+
<Sidebar />
48+
</MemoryRouter>
49+
);
50+
const links = screen.getAllByRole('link');
51+
expect(links[0]).toHaveAttribute('title', 'New Snippet');
52+
expect(links[1]).toHaveAttribute('title', 'Recent Snippets');
53+
expect(links[2]).toHaveAttribute('title', 'About');
54+
});
55+
});
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import React from 'react'
2-
import { shallow } from 'enzyme'
1+
import React from "react";
2+
import { render, screen } from "@testing-library/react";
33

4-
import Spinner from '../../../src/components/common/Spinner'
4+
import Spinner from "../../../src/components/common/Spinner";
55

6-
describe('Spinner', () => {
7-
it('should have one child', () => {
8-
const wrapper = shallow(<Spinner />)
9-
expect(wrapper.children()).toHaveLength(1)
10-
})
11-
})
6+
describe("Spinner", () => {
7+
it("should render an image", () => {
8+
render(<Spinner />);
9+
const spinnerElement = screen.getByAltText("Loading...");
10+
expect(spinnerElement).toBeInTheDocument();
11+
});
12+
});
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
import React from 'react'
2-
import { shallow } from 'enzyme'
1+
import React from 'react';
2+
import { render, screen } from '@testing-library/react';
33

4-
import Title from '../../../src/components/common/Title'
4+
import Title from '../../../src/components/common/Title';
55

66
const title = 'Snippet page';
77

88
describe('Title', () => {
99
it('should return correct title', () => {
10-
const wrapper = shallow(<Title title={title} />)
11-
expect(wrapper.text()).toEqual(title)
12-
})
10+
render(<Title title={title} />);
11+
expect(screen.getByText(title)).toBeInTheDocument();
12+
});
1313

1414
it('should have additional class if one was provided', () => {
15-
const wrapper = shallow(<Title title={title} additionalClass="custom-title" />)
16-
expect(wrapper.hasClass('custom-title')).toEqual(true)
17-
})
15+
render(<Title title={title} additionalClass="custom-title" />);
16+
expect(screen.getByText(title)).toHaveClass('custom-title');
17+
});
1818

19-
it('should not have additional class if one wasn\'t provided', () => {
20-
const wrapper = shallow(<Title title={title} />)
21-
expect(wrapper.hasClass('custom-title')).toEqual(false)
22-
})
23-
})
19+
it("should not have additional class if one wasn't provided", () => {
20+
render(<Title title={title} />);
21+
expect(screen.getByText(title)).not.toHaveClass('custom-title');
22+
});
23+
});

tests/mocks/svg.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default "div";

tests/test-utils.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/// <reference types="@testing-library/jest-dom" />
2+
3+
import "@testing-library/jest-dom";
4+
import { TextEncoder } from "util";
5+
6+
global.TextEncoder = TextEncoder;

tests/testSetup.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)