Skip to content

Commit

Permalink
feat(plugin-testing): support -u option to update snapshot (#5022)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Nov 30, 2023
1 parent b182eb2 commit a8923ca
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 4 deletions.
7 changes: 7 additions & 0 deletions .changeset/twenty-ways-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@modern-js/plugin-testing': patch
---

feat(plugin-testing): support -u option to update snapshot

feat(plugin-testing): 支持 -u 选项来更新快照
4 changes: 3 additions & 1 deletion packages/document/main-doc/docs/en/apis/app/commands.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,9 @@ Normally, only the part of the code modified by this commit needs to be checked
Usage: modern test [options]

Options:
-h, --help show command help
-u --updateSnapshot use this flag to re-record snapshots.
--watch watch files for changes and rerun tests related to changed files.
-h, --help show command help
```

:::tip
Expand Down
4 changes: 3 additions & 1 deletion packages/document/main-doc/docs/zh/apis/app/commands.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,9 @@ Options:
Usage: modern test [options]

Options:
-h, --help 显示命令帮助
-u --updateSnapshot 使用此选项来更新快照
--watch 监视文件的变更并重新运行相关的测试
-h, --help 显示命令帮助
```

:::tip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ The officially supported debugging tool is [Rspress](https://rspress.dev/), so y
Usage: modern test [options]

Options:
-h, --help display help for command
-u --updateSnapshot use this flag to re-record snapshots.
--watch watch files for changes and rerun tests related to changed files.
-h, --help show command help
```

You need to execute `modern new` to turn on the test function before you can execute the `modern test` command.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ Modern.js Module 提供了使用调试工具的能力,可以通过 `modern dev
Usage: modern test [options]

Options:
-h, --help display help for command
-u --updateSnapshot 使用此选项来更新快照
--watch 监视文件的变更并重新运行相关的测试
-h, --help 显示命令帮助
```

需要先执行 `modern new` 开启测试功能,然后才可以执行 `modern test` 命令。
Expand Down
6 changes: 6 additions & 0 deletions packages/runtime/plugin-testing/src/base/runJest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ const buildArgv = async (
result.config = JSON.stringify(config);
}

// `-u` is the shorthand of `--updateSnapshot`
if (result.u === true) {
result.updateSnapshot = true;
delete result.u;
}

return result;
};

Expand Down
8 changes: 8 additions & 0 deletions packages/runtime/plugin-testing/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ export const testingPlugin = (): CliPlugin<{
commands: ({ program }: any) => {
program
.command('test')
.option(
'-u --updateSnapshot',
'use this flag to re-record snapshots',
)
.option(
'--watch',
'watch files for changes and rerun tests related to changed files',
)
.allowUnknownOption()
.usage('<regexForTestFiles> --[options]')
.action(async () => {
Expand Down

0 comments on commit a8923ca

Please sign in to comment.