Skip to content

Commit

Permalink
fix(cli/jest): add watchAll mode
Browse files Browse the repository at this point in the history
affects: @varlet/cli, @varlet/ui
  • Loading branch information
haoziqaq committed Nov 20, 2021
1 parent 9d43aed commit 84ebb4e
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 8 deletions.
2 changes: 2 additions & 0 deletions packages/varlet-cli/README.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ varlet-cli test

```shell
varlet-cli test -w
or
varlet-cli test -wa
```

#### Lint code
Expand Down
2 changes: 2 additions & 0 deletions packages/varlet-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ varlet-cli test

```shell
varlet-cli test -w
or
varlet-cli test -wa
```

#### 检查代码
Expand Down
4 changes: 3 additions & 1 deletion packages/varlet-cli/generators/sfc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ yarn test
#### Run unit test in watch mode

```shell
yarn test:watch
yarn test:watch
or
yarn test:watchAll
```

#### Quickly create a component folder
Expand Down
3 changes: 2 additions & 1 deletion packages/varlet-cli/generators/sfc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"genAllLog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
"release": "yarn compile && release-it",
"test": "varlet-cli jest",
"test:watch": "varlet-cli jest -w"
"test:watch": "varlet-cli jest -w",
"test:watchAll": "varlet-cli jest -wa"
},
"peerDependencies": {
"vue": "^3.2.0"
Expand Down
4 changes: 3 additions & 1 deletion packages/varlet-cli/generators/tsx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ yarn test
#### Run unit test in watch mode

```shell
yarn test:watch
yarn test:watch
or
yarn test:watchAll
```

#### Quickly create a component folder
Expand Down
3 changes: 2 additions & 1 deletion packages/varlet-cli/generators/tsx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"genAllLog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
"release": "yarn compile && release-it",
"test": "varlet-cli jest",
"test:watch": "varlet-cli jest -w"
"test:watch": "varlet-cli jest -w",
"test:watchAll": "varlet-cli jest -wa"
},
"peerDependencies": {
"vue": "^3.2.0"
Expand Down
3 changes: 2 additions & 1 deletion packages/varlet-cli/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ program.command('create <name>').description('Create a component directory').act
program
.command('jest')
.description('Run Jest in work directory')
.option('-w, --watch', 'Watch files change auto jest')
.option('-w, --watch', 'Watch files for changes and rerun tests related to changed files')
.option('-wa, --watchAll', 'Watch files for changes and rerun all tests when something changes')
.option('-c, --component <componentName>', 'Test a specific component')
.option('-cc --clearCache', 'Clear test cache')
.action(jest_1.jest);
Expand Down
10 changes: 9 additions & 1 deletion packages/varlet-cli/src/commands/jest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@ import logger from '../shared/logger'
import { runCLI } from 'jest'
import { CWD, JEST_CONFIG } from '../shared/constant'

export async function jest(cmd: { watch?: boolean; component?: string; clearCache?: boolean }) {
interface JestCommandOptions {
watch?: boolean
watchAll?: boolean
component?: string
clearCache?: boolean
}

export async function jest(cmd: JestCommandOptions) {
process.env.NODE_ENV = 'test'

const config = {
rootDir: CWD,
watch: cmd.watch,
watchAll: cmd.watchAll,
clearCache: cmd.clearCache,
config: JEST_CONFIG,
testRegex: cmd.component && `${cmd.component}/__tests__/.*.spec.[jt]s?$`,
Expand Down
3 changes: 2 additions & 1 deletion packages/varlet-cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ program.command('create <name>').description('Create a component directory').act
program
.command('jest')
.description('Run Jest in work directory')
.option('-w, --watch', 'Watch files change auto jest')
.option('-w, --watch', 'Watch files for changes and rerun tests related to changed files')
.option('-wa, --watchAll', 'Watch files for changes and rerun all tests when something changes')
.option('-c, --component <componentName>', 'Test a specific component')
.option('-cc --clearCache', 'Clear test cache')
.action(jest)
Expand Down
2 changes: 2 additions & 0 deletions packages/varlet-ui/docs/cli.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ varlet-cli test

```shell
varlet-cli test -w
or
varlet-cli test -wa
```

#### Lint code
Expand Down
2 changes: 2 additions & 0 deletions packages/varlet-ui/docs/cli.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ varlet-cli test

```shell
varlet-cli test -w
or
varlet-cli test -wa
```

#### 检查代码
Expand Down
3 changes: 2 additions & 1 deletion packages/varlet-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"compile": "varlet-cli compile",
"create": "varlet-cli create",
"test": "varlet-cli jest",
"test:watch": "varlet-cli jest -w"
"test:watch": "varlet-cli jest -w",
"test:watchAll": "varlet-cli jest -wa"
},
"peerDependencies": {
"vue": "^3.2.0"
Expand Down

0 comments on commit 84ebb4e

Please sign in to comment.