From a8923cae08974d8d37f93ec20ad9d38dd3759fc7 Mon Sep 17 00:00:00 2001 From: neverland Date: Thu, 30 Nov 2023 14:15:12 +0800 Subject: [PATCH] feat(plugin-testing): support -u option to update snapshot (#5022) --- .changeset/twenty-ways-tickle.md | 7 +++++++ packages/document/main-doc/docs/en/apis/app/commands.mdx | 4 +++- packages/document/main-doc/docs/zh/apis/app/commands.mdx | 4 +++- .../module-doc/docs/en/guide/basic/command-preview.md | 4 +++- .../module-doc/docs/zh/guide/basic/command-preview.md | 4 +++- packages/runtime/plugin-testing/src/base/runJest.ts | 6 ++++++ packages/runtime/plugin-testing/src/cli/index.ts | 8 ++++++++ 7 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 .changeset/twenty-ways-tickle.md diff --git a/.changeset/twenty-ways-tickle.md b/.changeset/twenty-ways-tickle.md new file mode 100644 index 000000000000..ac56420911c5 --- /dev/null +++ b/.changeset/twenty-ways-tickle.md @@ -0,0 +1,7 @@ +--- +'@modern-js/plugin-testing': patch +--- + +feat(plugin-testing): support -u option to update snapshot + +feat(plugin-testing): 支持 -u 选项来更新快照 diff --git a/packages/document/main-doc/docs/en/apis/app/commands.mdx b/packages/document/main-doc/docs/en/apis/app/commands.mdx index 17af5d2bea8a..a09c8cb89fff 100644 --- a/packages/document/main-doc/docs/en/apis/app/commands.mdx +++ b/packages/document/main-doc/docs/en/apis/app/commands.mdx @@ -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 diff --git a/packages/document/main-doc/docs/zh/apis/app/commands.mdx b/packages/document/main-doc/docs/zh/apis/app/commands.mdx index 0f91f58911e0..68293fbd336a 100644 --- a/packages/document/main-doc/docs/zh/apis/app/commands.mdx +++ b/packages/document/main-doc/docs/zh/apis/app/commands.mdx @@ -278,7 +278,9 @@ Options: Usage: modern test [options] Options: - -h, --help 显示命令帮助 + -u --updateSnapshot 使用此选项来更新快照 + --watch 监视文件的变更并重新运行相关的测试 + -h, --help 显示命令帮助 ``` :::tip diff --git a/packages/document/module-doc/docs/en/guide/basic/command-preview.md b/packages/document/module-doc/docs/en/guide/basic/command-preview.md index e1568ed61147..3235392ba8f8 100644 --- a/packages/document/module-doc/docs/en/guide/basic/command-preview.md +++ b/packages/document/module-doc/docs/en/guide/basic/command-preview.md @@ -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. diff --git a/packages/document/module-doc/docs/zh/guide/basic/command-preview.md b/packages/document/module-doc/docs/zh/guide/basic/command-preview.md index ec224fa34b90..bbb20d500928 100644 --- a/packages/document/module-doc/docs/zh/guide/basic/command-preview.md +++ b/packages/document/module-doc/docs/zh/guide/basic/command-preview.md @@ -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` 命令。 diff --git a/packages/runtime/plugin-testing/src/base/runJest.ts b/packages/runtime/plugin-testing/src/base/runJest.ts index 42843a54e4e2..bc82fc924763 100644 --- a/packages/runtime/plugin-testing/src/base/runJest.ts +++ b/packages/runtime/plugin-testing/src/base/runJest.ts @@ -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; }; diff --git a/packages/runtime/plugin-testing/src/cli/index.ts b/packages/runtime/plugin-testing/src/cli/index.ts index debf9986b3e1..c289fd9edf47 100644 --- a/packages/runtime/plugin-testing/src/cli/index.ts +++ b/packages/runtime/plugin-testing/src/cli/index.ts @@ -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(' --[options]') .action(async () => {