Skip to content

Commit

Permalink
✨ feat: 添加测试
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Feb 15, 2021
1 parent a4c04f6 commit 70fd0da
Show file tree
Hide file tree
Showing 13 changed files with 149 additions and 196 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
# monorepo-template

![][license-url] [![Coverage][coverage]][codecov-url]

[![ docs by dumi][dumi-url]](https://d.umijs.org/) [![Build With father][father-url]](https://github.com/umijs/father/) [![lerna](https://img.shields.io/badge/maintained%20with-lerna-cc00ff.svg)][lerna-url] [![typedoc](https://img.shields.io/badge/API%20by-typedoc-9600ff.svg)](https://typedoc.org/)

[![Gitmoji][gitmoji]] [gitmoji-url] [![semantic-release][semantic-release]][semantic-release-repo]

<!-- umi url -->

[lerna-url]: https://lernajs.io/
[dumi-url]: https://img.shields.io/badge/docs%20by-dumi-blue
[father-url]: https://img.shields.io/badge/build%20with-father-028fe4.svg

<!-- badage url -->

[gitmoji]: https://img.shields.io/badge/gitmoji-%20😜%20😍-FFDD67.svg
[gitmoji-url]: https://gitmoji.carloscuesta.me/
[semantic-release]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
[semantic-release-repo]: https://github.com/semantic-release/semantic-release
[license-url]: https://img.shields.io/github/license/arvinxx/gitmoji-commit-workflow

<!-- Github CI -->

[test-ci]: https://github.com/arvinxx/monorepo-template/workflows/Test%20CI/badge.svg
[release-ci]: https://github.com/arvinxx/monorepo-template/workflows/Release%20CI/badge.svg
[test-ci-url]: https://github.com/arvinxx/monorepo-template/actions?query=workflow%3A%22Test+CI%22
[deploy-ci-url]: https://github.com/arvinxx/monorepo-template/actions?query=workflow%3A%22Release+CI%22
[coverage]: https://codecov.io/gh/arvinxx/monorepo-template/branch/master/graph/badge.svg
[codecov-url]: https://codecov.io/gh/arvinxx/monorepo-template/branch/master

## License

[MIT](./LICENSE) ® Arvin Xu
2 changes: 1 addition & 1 deletion jest.config.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const baseConfig: Config.InitialOptions = {
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
verbose: true,
moduleNameMapper: {
'^foo/(.*)$': '<rootDir>/packages/foo/src/$1',
'@arvinxu/modules-foo': '<rootDir>/packages/foo/src',
},
rootDir: path.resolve(__dirname, '.'),
globals: {
Expand Down
2 changes: 1 addition & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import baseConfig from './jest.config.base';

const config: Config.InitialOptions = {
...baseConfig,
projects: ['<rootDir>/packages/*/jest.config.js'],
projects: ['<rootDir>/packages/*/jest.config.ts'],
moduleDirectories: ['node_modules'],
collectCoverageFrom: ['<rootDir>/packages/*/src/**/*.ts'],
coverageDirectory: '<rootDir>/coverage/',
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"devDependencies": {
"@babel/core": "^7.8.3",
"@babel/plugin-proposal-object-rest-spread": "^7.8.3",
"@babel/plugin-transform-react-jsx": "^7.12.16",
"@babel/preset-env": "^7.8.3",
"@babel/preset-react": "^7.8.3",
"@babel/preset-typescript": "^7.8.3",
Expand All @@ -79,6 +80,7 @@
"babel-loader": "^8.1.0",
"babel-plugin-add-module-exports": "^1.0.4",
"babel-plugin-import": "^1.12.2",
"babel-plugin-module-resolver": "^4.1.0",
"commitlint": "^11.0.0",
"commitlint-config-cz": "^0.13.1",
"commitlint-config-gitmoji": "^2.2.1",
Expand Down
19 changes: 19 additions & 0 deletions packages/foo/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"presets": [
"@babel/preset-react",
"@babel/preset-env",
"@babel/preset-typescript"
],
"plugins": [
[
"module-resolver",
{
"root": ["./"],
"alias": {
"@arvinxu/modules-foo": "./src"
}
}
],
"@babel/plugin-transform-react-jsx"
]
}
16 changes: 16 additions & 0 deletions packages/foo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# @arvinxu/modules-foo

[![NPM version][version-image]][version-url] [![NPM downloads][download-image]][download-url]

a commitlint plugin to add gitmoji check rule

## License

[MIT](../../LICENSE) ® Arvin Xu

<!-- npm url -->

[version-image]: http://img.shields.io/npm/v/@arvinxu/modules-foo.svg?color=deepgreen&label=latest
[version-url]: http://npmjs.org/package/@arvinxu/modules-foo
[download-image]: https://img.shields.io/npm/dm/@arvinxu/modules-foo.svg
[download-url]: https://npmjs.org/package/@arvinxu/modules-foo
16 changes: 16 additions & 0 deletions packages/foo/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { Config } from '@jest/types';
import base from '../../jest.config';

const packageName = '@arvinxu/modules-foo';

const root = '<rootDir>/packages/foo';

const config: Config.InitialOptions = {
...base,
rootDir: '../..',
roots: [root],
name: packageName,
displayName: packageName,
};

export default config;
14 changes: 5 additions & 9 deletions packages/foo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,12 @@
"access": "public"
},
"dependencies": {
"@sigi/core": "^2.4.4",
"@sigi/devtool": "^2.4.4",
"@sigi/react": "^2.5.0",
"ahooks": "^2.7.1",
"lodash": "^4.17.20",
"react": "^16.9.0",
"react-dom": "^16.9.0",
"react-intl": "^5.10.1"
"react": "^17.0.1",
"react-dom": "^17.0.1"
},
"scripts": {
"build": "father-build"
"build": "father-build",
"test": "jest",
"cov": "jest --coverage"
}
}
1 change: 1 addition & 0 deletions packages/foo/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import React from 'react';
import type { FC } from 'react';

const Foo: FC = () => {
Expand Down
7 changes: 7 additions & 0 deletions packages/foo/tests/__snapshots__/index.spec.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Foo 1`] = `
<div>
Hello!
</div>
`;
10 changes: 10 additions & 0 deletions packages/foo/tests/index.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import renderer from 'react-test-renderer';

import Foo from '@arvinxu/modules-foo';

test('Foo', () => {
const component = renderer.create(<Foo />);
const tree = component.toJSON();
expect(tree).toMatchSnapshot();
});
5 changes: 3 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
//
/* Alias 路径 */
"baseUrl": ".",
"paths": {},

"paths": {
"@arvinxu/modules-foo": ["./packages/foo/src"]
},
/* 类型 */
"skipLibCheck": true
}
Expand Down
Loading

0 comments on commit 70fd0da

Please sign in to comment.