Skip to content

Commit

Permalink
. e d updated README.md file and bump version to v0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
yelmuratoff committed May 19, 2024
1 parent acec64d commit 7b03039
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 26 deletions.
47 changes: 23 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ In normal unit testing, you say `expect(person.getAge(), 5)`. Approvals allow yo

I am writing an implementation of **[Approval Tests](https://approvaltests.com/)** in Dart. If anyone wants to help, please **[text](https://t.me/yelmuratoff)** me. 🙏

<!-- At the moment the package is **in development** and <u>not ready</u> to use. 🚧 -->
## 📋 How it works

- If the changed results match the approved file perfectly, the test passes.
- If there's a difference, a reporter tool will highlight the mismatch and the test fails.

## 📦 Installation

Expand All @@ -62,6 +65,16 @@ It comes ready with:

## 📚 How to use

In order to use Approval Tests, the user needs to:

1. Set up a test: This involves importing the Approval Tests library into your own code.

2. Optionally, set up a reporter: Reporters are tools that highlight differences between approved and received files when a test fails. Although not necessary, they make it significantly easier to see what changes have caused a test to fail. The default reporter is the `CommandLineReporter`. You can also use the `DiffReporter` to compare the files in your IDE.

3. Manage the "approved" file: When the test is run for the first time, an approved file is created automatically. This file will represent the expected outcome. Once the test results in a favorable outcome, the approved file should be updated to reflect these changes. A little bit below I wrote how to do it.

This setup is useful because it shortens feedback loops, saving developers time by only highlighting what has been altered rather than requiring them to parse through their entire output to see what effect their changes had.

### Approving Results

Approving results just means saving the `.approved.txt` file with your desired results.
Expand Down Expand Up @@ -115,39 +128,25 @@ this will result in the following file
#### • Via file rename
You can just rename the `.received` file to `.approved`.

### Comparators
### Reporters

You can use different comparators to compare files. The default is `CommandLineComparator` which compares files in the console.
Reporters are the part of Approval Tests that launch diff tools when things do not match. They are the part of the system that makes it easy to see what has changed.

There are several reporters available in the package:
- `CommandLineReporter` - This is the default reporter, which will output the diff in the terminal.
- `DiffReporter` - This reporter will open the Diff Tool in your IDE.
- For Diff Reporter I using the default paths to the IDE, if something didn't work then you in the console see the expected correct path to the IDE and specify customDiffInfo. You can also contact me for help.

<img src="https://github.com/yelmuratoff/packages_assets/blob/main/assets/approval_tests/diff_command_line.png?raw=true" alt="CommandLineComparator img" title="ApprovalTests" style="max-width: 500px;">


To use `IDEComparator` you just need to add it to `options`:
To use `DiffReporter` you just need to add it to `options`:
```dart
options: const Options(
comparator: IDEComparator(
ide: ComparatorIDE.visualStudioCode,
),
reporter: const DiffReporter(),
),
```

But before you add an `IDEComparator` you need to do the initial customization:

- **Visual Studio Code**
- For this method to work, you need to have Visual Studio Code installed on your machine.
- And you need to have the `code` command available in your terminal.
- To enable the `code` command, press `Cmd + Shift + P` and type `Shell Command: Install 'code' command in PATH`.

- **IntelliJ IDEA**
- For this method to work, you need to have IntelliJ IDEA installed on your machine.
- And you need to have the `idea` command available in your terminal.
- To enable the `idea` command, you need to create the command-line launcher using `Tools - Create Command-line Launcher` in IntelliJ IDEA.

- **Android Studio**
- For this method to work, you need to have Android Studio installed on your machine.
- And you need to have the `studio` command available in your terminal.
- To enable the `studio` command, you need to create the command-line launcher using `Tools - Create Command-line Launcher` in Android Studio.

<div style="display: flex; justify-content: center; align-items: center;">
<img src="https://github.com/yelmuratoff/packages_assets/blob/main/assets/approval_tests/diff_tool_vs_code.png?raw=true" alt="Visual Studio code img" style="width: 45%;margin-right: 1%;" />
<img src="https://github.com/yelmuratoff/packages_assets/blob/main/assets/approval_tests/diff_tool_studio.png?raw=true" alt="Android Studio img" style="width: 45%;" />
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# * 0.0.4 for a minor release.
name: approval_tests
description: Approval Tests implementation in Dart. Inspired by ApprovalTests.
version: 0.4.6
version: 0.5.0
repository: https://github.com/approvals/ApprovalTests.Dart
homepage: https://github.com/approvals/ApprovalTests.Dart.git
issue_tracker: https://github.com/approvals/ApprovalTests.Dart/issues
Expand Down
3 changes: 3 additions & 0 deletions test/example/example_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ void main() {

Approvals.verifyAsJson(
complexObject,
options: const Options(
approveResult: true,
),
);
});
}
Expand Down
4 changes: 3 additions & 1 deletion test/groups/minor_tests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ void main() {
'Hello W0rld',
'verify',
deleteReceivedFile: false,
reporter: const DiffReporter(),
reporter: const DiffReporter(
ide: ComparatorIDE.studio, // ComparatorIDE.vsCode
),
),
throwsA(isA<DoesntMatchException>()),
);
Expand Down

0 comments on commit 7b03039

Please sign in to comment.