Skip to content

Commit

Permalink
feat(plugin-testing): support -u option to update snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan committed Nov 30, 2023
1 parent fc1f36f commit 4ee1b3b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 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
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 4ee1b3b

Please sign in to comment.