Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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