From 7b0303908b58c595058adb009fe7cc14c0ffc8a6 Mon Sep 17 00:00:00 2001 From: Yelaman Yelmuratov Date: Mon, 20 May 2024 00:44:44 +0500 Subject: [PATCH] . e d updated README.md file and bump version to v0.5.0 --- README.md | 47 +++++++++++++++++----------------- pubspec.yaml | 2 +- test/example/example_test.dart | 3 +++ test/groups/minor_tests.dart | 4 ++- 4 files changed, 30 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index a4aa172..b747500 100644 --- a/README.md +++ b/README.md @@ -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. 🙏 - +## 📋 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 @@ -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. @@ -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. CommandLineComparator img -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. -
Visual Studio code img Android Studio img diff --git a/pubspec.yaml b/pubspec.yaml index 4a2cf41..6c302b5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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 diff --git a/test/example/example_test.dart b/test/example/example_test.dart index 9284f8b..270e773 100644 --- a/test/example/example_test.dart +++ b/test/example/example_test.dart @@ -12,6 +12,9 @@ void main() { Approvals.verifyAsJson( complexObject, + options: const Options( + approveResult: true, + ), ); }); } diff --git a/test/groups/minor_tests.dart b/test/groups/minor_tests.dart index 96fafe1..a9739e3 100644 --- a/test/groups/minor_tests.dart +++ b/test/groups/minor_tests.dart @@ -61,7 +61,9 @@ void main() { 'Hello W0rld', 'verify', deleteReceivedFile: false, - reporter: const DiffReporter(), + reporter: const DiffReporter( + ide: ComparatorIDE.studio, // ComparatorIDE.vsCode + ), ), throwsA(isA()), );