Skip to content

Commit

Permalink
Merge pull request #13 from alibaba/unit-test
Browse files Browse the repository at this point in the history
better jest test environment
  • Loading branch information
HytonightYX authored Apr 18, 2022
2 parents 16e0d36 + d2a3611 commit 3a795ea
Show file tree
Hide file tree
Showing 12 changed files with 5,857 additions and 5,705 deletions.
1 change: 1 addition & 0 deletions __mocks__/styleMock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {};
File renamed without changes.
24 changes: 17 additions & 7 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
module.exports = {
const { pathsToModuleNameMapper } = require('ts-jest');
const { compilerOptions } = require('./tsconfig');

/** @type {import("ts-jest/dist/types").InitialOptionsTsJest} */
const config = {
preset: 'ts-jest',
// testEnvironment: 'node',
// testMatch: ['__tests__/*.[jt]s'],
// collectCoverageFrom: ['tests/**/*.{ts,tsx,js,jsx}'],
transform: { '.(ts|tsx)$': 'ts-jest/dist' },
// transformIgnorePatterns: ['[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$'],
// setupFilesAfterEnv: ['@testing-library/jest-dom/extend-expect'],
verbose: true,
testEnvironment: 'jsdom',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
setupFilesAfterEnv: ['@testing-library/jest-dom/extend-expect', './jest.setup.ts'],
moduleNameMapper: {
...pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>/' }),
'^lodash-es$': 'lodash',
},
coverageDirectory: 'coverage',
testMatch: ['<rootDir>/packages/core/**/?(*.)+(spec|test).[jt]s?(x)'],
};

module.exports = config;
Empty file added jest.setup.ts
Empty file.
30 changes: 22 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@
"build:core": "yarn workspace @rexd/core build",
"build:story": "yarn workspace story build",
"build:doc": "yarn workspace doc build",
"test": "yarn workspace @rexd/core test",
"test": "jest",
"test:watch": "yarn workspace @rexd/core test:watch",
"postinstall": "is-ci || husky install",
"version": "lerna version --conventional-commits",
"clean": "lerna clean && rr node_modules && yarn clean"
"clean": "lerna clean && rm -rf node_modules",
"update": "yarn run clean && yarn"
},
"workspaces": [
"packages/*"
],
"resolutions": {
"@types/react": "16.9.56",
"terser": "4.8.0"
"@types/react": "17.0.43",
"terser": "5.12.1"
},
"lint-staged": {
"*.{js,jsx,ts,tsx}": [
Expand All @@ -29,9 +30,21 @@
]
},
"devDependencies": {
"@babel/core": "^7.17.9",
"@babel/plugin-proposal-class-properties": "^7.16.7",
"@babel/preset-env": "^7.16.11",
"@babel/preset-react": "^7.16.7",
"@babel/preset-typescript": "^7.16.7",
"@commitlint/cli": "^12.1.1",
"@commitlint/config-conventional": "^12.1.1",
"@types/jest": "^26.0.13",
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^12.1.5",
"@testing-library/react-hooks": "^8.0.0",
"@testing-library/user-event": "^14.1.0",
"@types/jest": "^27.4.1",
"@types/react": "^17.0.43",
"@types/react-dom": "^17.0.15",
"@types/react-is": "^17.0.3",
"@typescript-eslint/eslint-plugin": "^4.14.2",
"@typescript-eslint/parser": "^4.14.2",
"copyfiles": "^2.4.1",
Expand All @@ -46,15 +59,16 @@
"eslint-plugin-testing-library": "^3.10.1",
"husky": "^6.0.0",
"is-ci": "^3.0.0",
"jest": "^26.4.2",
"jest": "^27.5.1",
"jest-styled-components": "^7.0.8",
"lerna": "^4.0.0",
"lint-staged": "^10.5.3",
"prettier": "^2.1.1",
"react": "^16.14.0",
"react-dom": "^16.14.0",
"rimraf": "^3.0.2",
"ts-jest": "^26.3.0",
"typescript": "~4.2",
"ts-jest": "^27.1.4",
"typescript": "^4.6.3",
"yarn": "^1.22.10"
},
"dependencies": {}
Expand Down
38 changes: 0 additions & 38 deletions packages/core/jest.config.js

This file was deleted.

18 changes: 1 addition & 17 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,5 @@
"react-is": "^16.8.6 || ^17.0.1",
"styled-components": "^4.4.1 || ^5.2.1"
},
"devDependencies": {
"@babel/plugin-proposal-class-properties": "^7.13.0",
"@testing-library/jest-dom": "^5.11.10",
"@testing-library/react": "^11.2.6",
"@testing-library/user-event": "^13.1.3",
"@types/react": "^16.9.56",
"@types/react-dom": "^16.9.9",
"@types/react-is": "16.7.1",
"babel-jest": "^26.6.3",
"jest-styled-components": "^7.0.3",
"react": "^16.14.0",
"react-dom": "^16.14.0",
"react-is": "^16.13.1",
"rimraf": "^3.0.2",
"styled-components": "^5.2.0",
"ts-jest": "^26.5.5"
}
"devDependencies": {}
}
1 change: 0 additions & 1 deletion packages/core/src/components/button/tests/button.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import '@testing-library/jest-dom/extend-expect';
import 'jest-styled-components';
import { Button } from '../';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ export const OverlayGlobalStyles = createGlobalStyle<{ colorMode: ColorMode }>`
}
.rex-fullscreen-popup-panel {
min-width: 30%;
min-width: 70%;
max-width: 90%;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
// @ts-nocheck

import {
rgba,
colors,
borders,
shadows,
sizes,
radii,
space,
colors,
fontSizes,
getToken,
getTokenValue,
radii,
rgba,
shadows,
sizes,
space,
} from '../design-token-helpers';

test('rgba', () => {
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"@rexd/core": ["packages/core/src/index.ts"],
"@rexd/icon": ["packages/icon/src/index.ts"]
}
}
},
"exclude": ["node_modules"]
}
Loading

0 comments on commit 3a795ea

Please sign in to comment.