-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
502 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# @umijs/plugin-test | ||
|
||
> @umijs/plugin-test. | ||
See our website [@umijs/plugin-test](https://umijs.org/plugins/plugin-test) for more information. | ||
|
||
## Install | ||
|
||
Using npm: | ||
|
||
```bash | ||
$ npm install --save-dev @umijs/plugin-test | ||
``` | ||
|
||
or using yarn: | ||
|
||
```bash | ||
$ yarn add @umijs/plugin-test --dev | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# @umijs/plugin-test | ||
|
||
## 启用方式 | ||
|
||
默认开启。 | ||
|
||
## 介绍 | ||
|
||
基于 jest 提供 `umi test` 命令。 | ||
|
||
包含以下特性, | ||
|
||
- 支持 lerna 包,可以针对子包测试和生成覆盖率 | ||
- 支持 TypeScript | ||
- 内置以下补丁 | ||
- core-js/stable | ||
- regenerator-runtime/runtime | ||
- whatwg-fetch | ||
- 支持通过 jest.config.json 和 package.json 中的 jest 属性进行配置,前者优先级更高 | ||
- jest.config.json 中的配置项支持函数的形式 | ||
|
||
## 使用 | ||
|
||
```bash | ||
$ umi-test | ||
|
||
# watch mode | ||
$ umi-test -w | ||
$ umi-test --watch | ||
|
||
# collect coverage | ||
$ umi-test --coverage | ||
|
||
# print debug info | ||
$ umi-test --debug | ||
|
||
# test specified package for lerna package | ||
$ umi-test --package name | ||
|
||
# don't do e2e test | ||
$ umi-test --no-e2e | ||
``` | ||
|
||
## 配置 | ||
|
||
通过 jest.config.js 实现配置的目的,比如: | ||
|
||
```js | ||
module.exports = { | ||
moduleNameMapper: { | ||
'^umi$': require.resolve('umi'), | ||
}, | ||
}; | ||
``` | ||
|
||
但有时你会希望保留 umi-test 内置的配置,只做扩展,我们也函数的形式,比如: | ||
|
||
```js | ||
module.exports = { | ||
moduleNameMapper(memo) { | ||
return { | ||
...memo, | ||
'^umi$': require.resolve('umi'), | ||
}; | ||
}, | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "@umijs/plugin-test", | ||
"version": "1.0.0-beta.1", | ||
"description": "@umijs/plugin-test", | ||
"main": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"files": [ | ||
"lib", | ||
"src" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/umijs/plugins" | ||
}, | ||
"keywords": [ | ||
"umi" | ||
], | ||
"authors": [ | ||
"chencheng <sorrycc@gmail.com> (https://github.com/sorrycc)" | ||
], | ||
"license": "MIT", | ||
"bugs": "http://github.com/umijs/plugins/issues", | ||
"homepage": "https://github.com/umijs/plugins/tree/master/packages/plugin-test#readme", | ||
"peerDependencies": { | ||
"umi": "3.x" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"@umijs/test": "^3.0.7" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { IApi, utils } from 'umi'; | ||
|
||
export default (api: IApi) => { | ||
api.registerCommand({ | ||
name: 'test', | ||
description: 'test with jest', | ||
details: ` | ||
$ umi-test | ||
# watch mode | ||
$ umi-test -w | ||
$ umi-test --watch | ||
# collect coverage | ||
$ umi-test --coverage | ||
# print debug info | ||
$ umi-test --debug | ||
# test specified package for lerna package | ||
$ umi-test --package name | ||
# don't do e2e test | ||
$ umi-test --no-e2e | ||
`, | ||
async fn() { | ||
const args = utils.yParser(process.argv.slice(3), { | ||
alias: { | ||
watch: ['w'], | ||
version: ['v'], | ||
}, | ||
boolean: ['coverage', 'watch', 'version', 'debug', 'e2e'], | ||
default: { | ||
e2e: true, | ||
}, | ||
}); | ||
|
||
require('@umijs/test') | ||
.default(args) | ||
.catch((e: Error) => { | ||
console.error(utils.chalk.red(e)); | ||
process.exit(1); | ||
}); | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.