Skip to content

Commit 5702253

Browse files
Ali(Ako) Hosseinimatin-deriv
Ali(Ako) Hosseini
andauthored
Ako/ RTL and Jest improvements (deriv-com#4211)
* input id's added to make html's for(htmlFor) attribute work. * JEST todo's added for personal details component different landings * redundant text removed * Extra jest/react-testing-library added functionalities added * Jest base configuration moved to root level package * Simple tests written for personal details form * Personal details test todos updated * package lock updated * comments added to setupTests * comments added to setupTests files * redundant test todos removed * all of package-lock.json files regenerated * Revert "all of package-lock.json files regenerated" This reverts commit 0dcb670. * package-locks regenerated * Revert "package-locks regenerated" This reverts commit a368e55. * package-locks regenerated again * unchanged package-lock change reverted. * useless jest config removed * nit space removed from package.json * package-lock reverted * package locks removed * CssMinimizerPlugin used instead of OptimizeCssAssetsPlugin * copyWebpackPlugin configurations improved * CssMinimizerPlugin used to support webpack 5 * packages updated to satisfy new node14.17.1 needs also smartcharts updated to latest version * package-locks of packages removed and root repo package-lock updated. * core package webpack config updated. * e2e tests package-lock regenerated * packages version inconsistency fixed * copyWebpackPlugin configuration improved * smartcharts chunk config problem fixed * Merge branch 'update-node-npm-webpack-to-latest-version' into RTL-and-jest-configs-improvements # Conflicts: # package-lock.json # package.json # packages/account/package.json # packages/dashboard/package-lock.json # packages/indicators/package-lock.json # packages/p2p/package-lock.json # packages/shared/package-lock.json * react and react-dom added to root package for testing library * chore: revert unwanted changes * chore: revert unwanted changes * chore: packages moved based on eslint error * feat: add babel-jest * Merge branch 'master' of https://github.com/binary-com/deriv-app into RTL-JEST-improvements * revert unneeded changes Co-authored-by: Matin shafiei <[email protected]>
1 parent e3a05f0 commit 5702253

16 files changed

+3831
-802
lines changed

jest.config.base.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/** This config file is for packages in monorepo
2+
Universal configurations should go here
3+
*/
4+
5+
module.exports = {
6+
testRegex: "(/__tests__/.*|(\\.)(test|spec))\\.js?$",
7+
// This is needed to transform es modules imported from node_modules of the target component.
8+
transformIgnorePatterns: [
9+
"/node_modules/(?!react-virtualized).+\\.js$",
10+
],
11+
setupFiles: [
12+
"<rootDir>/../../jest.setup.js",
13+
],
14+
setupFilesAfterEnv:[
15+
"<rootDir>/../../setupTests.js",
16+
],
17+
};

jest.config.js

+3-16
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,11 @@ module.exports = {
44
coverageReporters: ['lcov'],
55
coverageDirectory: './coverage/',
66
clearMocks: true,
7-
projects: [
8-
'<rootDir>/packages/account/jest.config.js',
9-
'<rootDir>/packages/shared/jest.config.js',
10-
'<rootDir>/packages/trader/jest.config.js',
11-
'<rootDir>/packages/core/jest.config.js',
12-
],
13-
setupFiles: [
14-
"<rootDir>/jest.setup.js",
15-
],
16-
testRegex: [
17-
'__tests__',
18-
'.*.spec.js',
19-
],
7+
projects: ['<rootDir>/packages/*/jest.config.js'],
208
transform: {
219
'^.+\\.jsx?$': 'babel-jest',
2210
'^.+/es/^.+$': 'babel-jest',
2311
},
24-
transformIgnorePatterns: [
25-
"/node_modules/(?!react-virtualized).+\\.js$",
26-
],
12+
testRegex: ['__tests__', '.*.spec.js'],
13+
transformIgnorePatterns: ['/node_modules/(?!react-virtualized).+\\.js$'],
2714
};

package-lock.json

+3,762-747
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+10-2
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,24 @@
2121
"@testing-library/react": "^12.0.0",
2222
"babel-eslint": "^10.1.0",
2323
"babel-polyfill": "^6.26.0",
24+
"chai": "^4.2.0",
2425
"eslint": "^7.18.0",
2526
"eslint-config-airbnb-base": "^14.2.1",
2627
"eslint-config-binary": "^1.0.2",
2728
"eslint-config-prettier": "^7.2.0",
2829
"eslint-formatter-pretty": "^4.0.0",
2930
"eslint-import-resolver-webpack": "^0.13.0",
3031
"eslint-plugin-import": "^2.23.4",
32+
"eslint-plugin-jest-dom": "^3.8.1",
3133
"eslint-plugin-prettier": "^3.3.1",
3234
"eslint-plugin-react": "^7.22.0",
3335
"eslint-plugin-react-hooks": "^4.2.0",
36+
"eslint-plugin-testing-library": "^4.2.0",
3437
"husky": "^4.2.5",
3538
"jest": "^26.4.2",
3639
"lerna": "^3.22.0",
3740
"lint-staged": "^10.4.0",
41+
"mocha": "^7.1.1",
3842
"postcss": "^8.3.6",
3943
"prettier": "^2.1.2",
4044
"react-test-renderer": "^16.13.1",
@@ -84,9 +88,13 @@
8488
}
8589
},
8690
"dependencies": {
91+
"@testing-library/jest-dom": "^5.12.0",
92+
"babel-jest": "^27.3.1",
93+
"dotenv": "^8.2.0",
94+
"jest-chain": "^1.1.5",
95+
"jest-extended": "^0.11.5",
8796
"react": "^16.14.0",
88-
"react-dom": "^16.14.0",
89-
"dotenv": "^8.2.0"
97+
"react-dom": "^16.14.0"
9098
},
9199
"optionalDependencies": {
92100
"fsevents": "^2.3.2"

packages/account/jest.config.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
const baseConfigForPackages = require('../../jest.config.base');
2+
13
module.exports = {
4+
...baseConfigForPackages,
25
moduleNameMapper: {
36
'\\.s(c|a)ss$': '<rootDir>/../../__mocks__/styleMock.js',
47
'^.+\\.svg$': '<rootDir>/../../__mocks__/styleMock.js',
@@ -11,8 +14,4 @@ module.exports = {
1114
'^Sections/(.*)$': '<rootDir>/src/Sections/$1',
1215
'^Sections$': '<rootDir>/src/Sections/index.js',
1316
},
14-
testRegex: '(/__tests__/.*|(\\.)(test|spec))\\.js?$',
15-
setupFiles: ['<rootDir>/../../jest.setup.js'],
16-
// This is needed to transform es modules imported from node_modules of the target component.
17-
transformIgnorePatterns: ['/node_modules/(?!react-virtualized).+\\.js$'],
1817
};

packages/bot-web-ui/package.json

-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
"license": "MIT",
3737
"devDependencies": {
3838
"babel-eslint": "^10.1.0",
39-
"babel-jest": "^26.5.2",
4039
"babel-loader": "^8.1.0",
4140
"chai": "^4.2.0",
4241
"clean-webpack-plugin": "^3.0.0",
@@ -51,7 +50,6 @@
5150
"eslint-plugin-prettier": "^3.3.1",
5251
"eslint-plugin-react": "^7.22.0",
5352
"eslint-plugin-react-hooks": "^4.2.0",
54-
"jest": "^26.4.2",
5553
"lint-staged": "^10.4.0",
5654
"loader-utils": "^1.1.0",
5755
"mini-css-extract-plugin": "^1.3.4",

packages/core/jest.config.js

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
const baseConfigForPackages = require('../../jest.config.base');
2+
13
module.exports = {
4+
...baseConfigForPackages,
25
moduleNameMapper: {
36
"\\.s(c|a)ss$": "<rootDir>/../../__mocks__/styleMock.js",
47
"^.+\\.svg$": "<rootDir>/../../__mocks__/styleMock.js",
@@ -14,12 +17,4 @@ module.exports = {
1417
'^Services$': "<rootDir>/src/Services/index.js",
1518
'^Stores\/(.*)$': "<rootDir>/src/Stores/$1",
1619
},
17-
testRegex: "(/__tests__/.*|(\\.)(test|spec))\\.js?$",
18-
setupFiles: [
19-
"<rootDir>/../../jest.setup.js",
20-
],
21-
// This is needed to transform es modules imported from node_modules of the target component.
22-
transformIgnorePatterns: [
23-
"/node_modules/(?!react-virtualized).+\\.js$",
24-
],
2520
};

packages/dashboard/jest.config.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
const baseConfigForPackages = require('../../jest.config.base');
2+
13
module.exports = {
4+
...baseConfigForPackages,
25
moduleNameMapper: {
36
'\\.s(c|a)ss$': '<rootDir>/../../__mocks__/styleMock.js',
47
'^.+\\.svg$': '<rootDir>/../../__mocks__/styleMock.js',
@@ -9,9 +12,4 @@ module.exports = {
912
'^Types/(.*)$': '<rootDir>/src/types/$1',
1013
'^Utils/(.*)$': '<rootDir>/src/utils/$1',
1114
},
12-
testRegex: '(/__tests__/.*|(\\.)(test|spec))\\.js?$',
13-
setupFiles: ['<rootDir>/../../jest.setup.js'],
14-
15-
// This is needed to transform es modules imported from node_modules of the target component.
16-
transformIgnorePatterns: ['/node_modules/(?!react-virtualized).+\\.js$'],
1715
};

packages/dashboard/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
"@typescript-eslint/eslint-plugin": "^4.10.0",
6767
"@typescript-eslint/parser": "^4.10.0",
6868
"babel-core": "^6.26.3",
69-
"babel-jest": "^26.5.2",
7069
"babel-loader": "^8.1.0",
7170
"chai": "^4.2.0",
7271
"concurrently": "^5.3.0",

packages/indicators/jest.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
const baseConfigForPackages = require('../../jest.config.base');
2+
13
module.exports = {
4+
...baseConfigForPackages,
25
transform: {
36
'^.+\\.jsx?$': 'babel-jest',
47
},

packages/indicators/package.json

-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
"devDependencies": {
3535
"@babel/preset-env": "^7.12.11",
3636
"babel-eslint": "^10.1.0",
37-
"babel-jest": "^26.5.2",
38-
"jest": "^26.4.2",
3937
"eslint-plugin-prettier": "^3.3.1",
4038
"eslint-config-prettier": "^7.2.0",
4139
"eslint-config-airbnb-base": "^14.2.1",

packages/p2p/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
"@deriv/publisher": "0.0.1-beta4",
6565
"babel-core": "^6.26.3",
6666
"babel-eslint": "^10.1.0",
67-
"babel-jest": "^26.5.2",
6867
"babel-loader": "^8.1.0",
6968
"chai": "^4.2.0",
7069
"commander": "^3.0.2",

packages/shared/jest.config.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1+
const baseConfigForPackages = require('../../jest.config.base');
2+
13
module.exports = {
4+
...baseConfigForPackages,
25
moduleNameMapper: {
36
"\\.s(c|a)ss$": "<rootDir>/../../__mocks__/styleMock.js",
47
"^.+\\.svg$": "<rootDir>/../../__mocks__/styleMock.js",
58
},
6-
testRegex: "(/__tests__/.*|(\\.)(test|spec))\\.js?$",
7-
setupFiles: [
8-
"<rootDir>/../../jest.setup.js",
9-
],
109
};

packages/shared/package.json

-2
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@
3030
"url": "https://github.com/binary-com/deriv-app/issues"
3131
},
3232
"devDependencies": {
33-
"babel-jest": "^26.5.2",
3433
"chai": "^4.2.0",
35-
"jest": "^26.4.2",
3634
"jsdom": "^16.2.1",
3735
"moment": "^2.24.0"
3836
},

packages/trader/jest.config.js

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
const baseConfigForPackages = require('../../jest.config.base');
2+
13
module.exports = {
4+
...baseConfigForPackages,
25
moduleNameMapper: {
36
"\\.s(c|a)ss$": "<rootDir>/../../__mocks__/styleMock.js",
47
"^.+\\.svg$": "<rootDir>/../../__mocks__/styleMock.js",
@@ -13,12 +16,4 @@ module.exports = {
1316
'^Services\/(.*)$': "<rootDir>/src/Services/$1",
1417
'^Stores\/(.*)$': "<rootDir>/src/Stores/$1",
1518
},
16-
testRegex: "(/__tests__/.*|(\\.)(test|spec))\\.js?$",
17-
setupFiles: [
18-
"<rootDir>/../../jest.setup.js",
19-
],
20-
// This is needed to transform es modules imported from node_modules of the target component.
21-
transformIgnorePatterns: [
22-
"/node_modules/(?!react-virtualized).+\\.js$",
23-
],
2419
};

setupTests.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* This file created to use in `setupFilesAfterEnv` in jest setup
3+
* For more info about it please check the link below
4+
* https://jestjs.io/docs/configuration#setupfilesafterenv-array
5+
* */
6+
7+
/** provides a set of custom jest matchers that you can use to extend jest.
8+
* These will make your tests more declarative, clear to read and to maintain. */
9+
import '@testing-library/jest-dom';
10+
import '@testing-library/jest-dom/extend-expect'
11+
12+
/**
13+
* jest-extended aims to add additional matchers to Jest's default ones making it easy to test everything raised_hands
14+
*/
15+
import 'jest-extended';
16+
17+
18+
/**
19+
* Chain Jest matchers together to write easier matchers and reduce code.
20+
*/
21+
import 'jest-chain';

0 commit comments

Comments
 (0)