@approval-tests/approvals 7.5.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (196) hide show
  1. package/bin/help.md +31 -0
  2. package/bin/index.d.ts +2 -0
  3. package/bin/index.js +119 -0
  4. package/bin/index.ts +106 -0
  5. package/lib/AUtils.d.ts +9 -0
  6. package/lib/AUtils.js +175 -0
  7. package/lib/AUtils.ts +178 -0
  8. package/lib/Approvals.d.ts +104 -0
  9. package/lib/Approvals.js +280 -0
  10. package/lib/Approvals.ts +319 -0
  11. package/lib/Core/Namer.d.ts +5 -0
  12. package/lib/Core/Namer.js +11 -0
  13. package/lib/Core/Namer.ts +14 -0
  14. package/lib/Core/Options.d.ts +31 -0
  15. package/lib/Core/Options.js +74 -0
  16. package/lib/Core/Options.ts +94 -0
  17. package/lib/Core/Reporter.d.ts +6 -0
  18. package/lib/Core/Reporter.js +2 -0
  19. package/lib/Core/Reporter.ts +13 -0
  20. package/lib/Core/Writer.d.ts +4 -0
  21. package/lib/Core/Writer.js +2 -0
  22. package/lib/Core/Writer.ts +5 -0
  23. package/lib/DummyApprovedFiles/UnapprovedImage.png +0 -0
  24. package/lib/FileApprover.d.ts +9 -0
  25. package/lib/FileApprover.js +85 -0
  26. package/lib/FileApprover.ts +116 -0
  27. package/lib/FinalMessages.d.ts +5 -0
  28. package/lib/FinalMessages.js +17 -0
  29. package/lib/FinalMessages.ts +16 -0
  30. package/lib/Logs/ApprovedFileLog.d.ts +6 -0
  31. package/lib/Logs/ApprovedFileLog.js +68 -0
  32. package/lib/Logs/ApprovedFileLog.ts +38 -0
  33. package/lib/Logs/FailedFileLog.d.ts +7 -0
  34. package/lib/Logs/FailedFileLog.js +65 -0
  35. package/lib/Logs/FailedFileLog.ts +36 -0
  36. package/lib/Logs/LogUtils.d.ts +7 -0
  37. package/lib/Logs/LogUtils.js +56 -0
  38. package/lib/Logs/LogUtils.ts +44 -0
  39. package/lib/ManualNamer.d.ts +4 -0
  40. package/lib/ManualNamer.js +15 -0
  41. package/lib/ManualNamer.ts +12 -0
  42. package/lib/Namer.d.ts +9 -0
  43. package/lib/Namer.js +27 -0
  44. package/lib/Namer.ts +28 -0
  45. package/lib/Providers/BeforeEachVerifierBase.d.ts +2 -0
  46. package/lib/Providers/BeforeEachVerifierBase.js +82 -0
  47. package/lib/Providers/BeforeEachVerifierBase.ts +68 -0
  48. package/lib/Providers/Jest/CombinationApprovals.d.ts +14 -0
  49. package/lib/Providers/Jest/CombinationApprovals.js +44 -0
  50. package/lib/Providers/Jest/CombinationApprovals.ts +161 -0
  51. package/lib/Providers/Jest/JestApprovals.d.ts +4 -0
  52. package/lib/Providers/Jest/JestApprovals.js +73 -0
  53. package/lib/Providers/Jest/JestApprovals.ts +48 -0
  54. package/lib/Providers/Jest/JestNamer.d.ts +2 -0
  55. package/lib/Providers/Jest/JestNamer.js +18 -0
  56. package/lib/Providers/Jest/JestNamer.ts +15 -0
  57. package/lib/Providers/Jest/JestReporter.d.ts +7 -0
  58. package/lib/Providers/Jest/JestReporter.js +22 -0
  59. package/lib/Providers/Jest/JestReporter.ts +22 -0
  60. package/lib/Providers/Jest/JestSetup.d.ts +3 -0
  61. package/lib/Providers/Jest/JestSetup.js +41 -0
  62. package/lib/Providers/Jest/JestSetup.ts +40 -0
  63. package/lib/Providers/Mocha/MochaApprovals.d.ts +8 -0
  64. package/lib/Providers/Mocha/MochaApprovals.js +94 -0
  65. package/lib/Providers/Mocha/MochaApprovals.ts +70 -0
  66. package/lib/Providers/Mocha/MochaNamer.d.ts +9 -0
  67. package/lib/Providers/Mocha/MochaNamer.js +72 -0
  68. package/lib/Providers/Mocha/MochaNamer.ts +84 -0
  69. package/lib/Providers/Vitest/VitestApprovals.d.ts +4 -0
  70. package/lib/Providers/Vitest/VitestApprovals.js +62 -0
  71. package/lib/Providers/Vitest/VitestApprovals.ts +37 -0
  72. package/lib/Providers/Vitest/VitestNamer.d.ts +2 -0
  73. package/lib/Providers/Vitest/VitestNamer.js +17 -0
  74. package/lib/Providers/Vitest/VitestNamer.ts +21 -0
  75. package/lib/Providers/Vitest/VitestReporter.d.ts +7 -0
  76. package/lib/Providers/Vitest/VitestReporter.js +21 -0
  77. package/lib/Providers/Vitest/VitestReporter.ts +23 -0
  78. package/lib/Reporting/DiffReporterAggregate.d.ts +10 -0
  79. package/lib/Reporting/DiffReporterAggregate.js +28 -0
  80. package/lib/Reporting/DiffReporterAggregate.ts +36 -0
  81. package/lib/Reporting/GenericDiffReporterBase.d.ts +22 -0
  82. package/lib/Reporting/GenericDiffReporterBase.js +136 -0
  83. package/lib/Reporting/GenericDiffReporterBase.ts +154 -0
  84. package/lib/Reporting/ReportByOpeningTheReceivedFile.d.ts +7 -0
  85. package/lib/Reporting/ReportByOpeningTheReceivedFile.js +19 -0
  86. package/lib/Reporting/ReportByOpeningTheReceivedFile.ts +22 -0
  87. package/lib/Reporting/ReportLaunchingCircuitBreaker.d.ts +8 -0
  88. package/lib/Reporting/ReportLaunchingCircuitBreaker.js +37 -0
  89. package/lib/Reporting/ReportLaunchingCircuitBreaker.ts +40 -0
  90. package/lib/Reporting/ReporterFactory.d.ts +8 -0
  91. package/lib/Reporting/ReporterFactory.js +67 -0
  92. package/lib/Reporting/ReporterFactory.ts +85 -0
  93. package/lib/Reporting/Reporters/beyondcompareReporter.d.ts +4 -0
  94. package/lib/Reporting/Reporters/beyondcompareReporter.js +32 -0
  95. package/lib/Reporting/Reporters/beyondcompareReporter.ts +30 -0
  96. package/lib/Reporting/Reporters/codiumReporter.d.ts +5 -0
  97. package/lib/Reporting/Reporters/codiumReporter.js +25 -0
  98. package/lib/Reporting/Reporters/codiumReporter.ts +26 -0
  99. package/lib/Reporting/Reporters/copycommandReporter.d.ts +7 -0
  100. package/lib/Reporting/Reporters/copycommandReporter.js +40 -0
  101. package/lib/Reporting/Reporters/copycommandReporter.ts +46 -0
  102. package/lib/Reporting/Reporters/diffmergeReporter.d.ts +5 -0
  103. package/lib/Reporting/Reporters/diffmergeReporter.js +54 -0
  104. package/lib/Reporting/Reporters/diffmergeReporter.ts +25 -0
  105. package/lib/Reporting/Reporters/donothingReporter.d.ts +6 -0
  106. package/lib/Reporting/Reporters/donothingReporter.js +14 -0
  107. package/lib/Reporting/Reporters/donothingReporter.ts +13 -0
  108. package/lib/Reporting/Reporters/gitdiffReporter.d.ts +6 -0
  109. package/lib/Reporting/Reporters/gitdiffReporter.js +23 -0
  110. package/lib/Reporting/Reporters/gitdiffReporter.ts +28 -0
  111. package/lib/Reporting/Reporters/icdiffReporter.d.ts +4 -0
  112. package/lib/Reporting/Reporters/icdiffReporter.js +11 -0
  113. package/lib/Reporting/Reporters/icdiffReporter.ts +10 -0
  114. package/lib/Reporting/Reporters/kdiff3Reporter.d.ts +4 -0
  115. package/lib/Reporting/Reporters/kdiff3Reporter.js +11 -0
  116. package/lib/Reporting/Reporters/kdiff3Reporter.ts +10 -0
  117. package/lib/Reporting/Reporters/kompareReporter.d.ts +4 -0
  118. package/lib/Reporting/Reporters/kompareReporter.js +11 -0
  119. package/lib/Reporting/Reporters/kompareReporter.ts +10 -0
  120. package/lib/Reporting/Reporters/meldReporter.d.ts +4 -0
  121. package/lib/Reporting/Reporters/meldReporter.js +11 -0
  122. package/lib/Reporting/Reporters/meldReporter.ts +10 -0
  123. package/lib/Reporting/Reporters/multiReporter.d.ts +8 -0
  124. package/lib/Reporting/Reporters/multiReporter.js +49 -0
  125. package/lib/Reporting/Reporters/multiReporter.ts +55 -0
  126. package/lib/Reporting/Reporters/nodediffReporter.d.ts +7 -0
  127. package/lib/Reporting/Reporters/nodediffReporter.js +50 -0
  128. package/lib/Reporting/Reporters/nodediffReporter.ts +61 -0
  129. package/lib/Reporting/Reporters/opendiffReporter.d.ts +4 -0
  130. package/lib/Reporting/Reporters/opendiffReporter.js +11 -0
  131. package/lib/Reporting/Reporters/opendiffReporter.ts +10 -0
  132. package/lib/Reporting/Reporters/p4mergeReporter.d.ts +4 -0
  133. package/lib/Reporting/Reporters/p4mergeReporter.js +41 -0
  134. package/lib/Reporting/Reporters/p4mergeReporter.ts +39 -0
  135. package/lib/Reporting/Reporters/tortoisemergeReporter.d.ts +4 -0
  136. package/lib/Reporting/Reporters/tortoisemergeReporter.js +25 -0
  137. package/lib/Reporting/Reporters/tortoisemergeReporter.ts +25 -0
  138. package/lib/Reporting/Reporters/vimdiffReporter.d.ts +4 -0
  139. package/lib/Reporting/Reporters/vimdiffReporter.js +24 -0
  140. package/lib/Reporting/Reporters/vimdiffReporter.ts +25 -0
  141. package/lib/Reporting/Reporters/visualstudioReporter.d.ts +6 -0
  142. package/lib/Reporting/Reporters/visualstudioReporter.js +42 -0
  143. package/lib/Reporting/Reporters/visualstudioReporter.ts +48 -0
  144. package/lib/Reporting/Reporters/vscodeReporter.d.ts +5 -0
  145. package/lib/Reporting/Reporters/vscodeReporter.js +25 -0
  146. package/lib/Reporting/Reporters/vscodeReporter.ts +26 -0
  147. package/lib/Scrubbers/DateScrubber.d.ts +12 -0
  148. package/lib/Scrubbers/DateScrubber.js +67 -0
  149. package/lib/Scrubbers/DateScrubber.ts +83 -0
  150. package/lib/Scrubbers/Scrubbers.d.ts +20 -0
  151. package/lib/Scrubbers/Scrubbers.js +75 -0
  152. package/lib/Scrubbers/Scrubbers.ts +106 -0
  153. package/lib/StringWriter.d.ts +11 -0
  154. package/lib/StringWriter.js +82 -0
  155. package/lib/StringWriter.ts +73 -0
  156. package/lib/Utilities/ConsoleUtils.d.ts +4 -0
  157. package/lib/Utilities/ConsoleUtils.js +19 -0
  158. package/lib/Utilities/ConsoleUtils.ts +15 -0
  159. package/lib/Utilities/JestUtils.d.ts +3 -0
  160. package/lib/Utilities/JestUtils.js +9 -0
  161. package/lib/Utilities/JestUtils.ts +5 -0
  162. package/lib/Utilities/Logger/LoggingInstance.d.ts +32 -0
  163. package/lib/Utilities/Logger/LoggingInstance.js +214 -0
  164. package/lib/Utilities/Logger/LoggingInstance.ts +247 -0
  165. package/lib/Utilities/Logger/SimpleLogger.d.ts +23 -0
  166. package/lib/Utilities/Logger/SimpleLogger.js +61 -0
  167. package/lib/Utilities/Logger/SimpleLogger.ts +83 -0
  168. package/lib/Utilities/Logger/SimpleLoggerApprovals.d.ts +2 -0
  169. package/lib/Utilities/Logger/SimpleLoggerApprovals.js +12 -0
  170. package/lib/Utilities/Logger/SimpleLoggerApprovals.ts +15 -0
  171. package/lib/Utilities/Logger/StringWrapper.d.ts +6 -0
  172. package/lib/Utilities/Logger/StringWrapper.js +15 -0
  173. package/lib/Utilities/Logger/StringWrapper.ts +12 -0
  174. package/lib/Utilities/Logger/Wrapper.d.ts +14 -0
  175. package/lib/Utilities/Logger/Wrapper.js +27 -0
  176. package/lib/Utilities/Logger/Wrapper.ts +27 -0
  177. package/lib/Utilities/Printers.d.ts +4 -0
  178. package/lib/Utilities/Printers.js +52 -0
  179. package/lib/Utilities/Printers.ts +77 -0
  180. package/lib/Utilities/StringUtils.d.ts +3 -0
  181. package/lib/Utilities/StringUtils.js +12 -0
  182. package/lib/Utilities/StringUtils.ts +8 -0
  183. package/lib/Writers/BinaryWriter.d.ts +8 -0
  184. package/lib/Writers/BinaryWriter.js +63 -0
  185. package/lib/Writers/BinaryWriter.ts +31 -0
  186. package/lib/config.d.ts +22 -0
  187. package/lib/config.js +106 -0
  188. package/lib/config.ts +95 -0
  189. package/lib/osTools.d.ts +5 -0
  190. package/lib/osTools.js +11 -0
  191. package/lib/osTools.ts +11 -0
  192. package/lib/postRunCleanup.d.ts +1 -0
  193. package/lib/postRunCleanup.js +51 -0
  194. package/lib/postRunCleanup.ts +63 -0
  195. package/package.json +109 -0
  196. package/readme.md +557 -0
package/readme.md ADDED
@@ -0,0 +1,557 @@
1
+ # Approvals (Approval Tests for Node.js)
2
+
3
+ <!-- toc -->
4
+ ## Contents
5
+
6
+ * [Intro](#intro)
7
+ * [Badges](#badges)
8
+ * [Integrations](#integrations)
9
+ * [Getting Started](#getting-started)
10
+ * [Jest Typescript Starter Project](#jest-typescript-starter-project)
11
+ * [Mocha](#mocha)
12
+ * [Documentation](#documentation)
13
+ * [CLI](#cli)
14
+ * [Install Approvals CLI](#install-approvals-cli)
15
+ * [CLI Help](#cli-help)
16
+ * [Simple hello world](#simple-hello-world)
17
+ * [Specify diff reporter (great for C.I.)](#specify-diff-reporter-great-for-ci)
18
+ * [Multiple diff reporters](#multiple-diff-reporters)
19
+ * [Reporters](#reporters)
20
+ * [Built-In Reporters](#built-in-reporters)
21
+ * [Supported Diff Tools](#supported-diff-tools)
22
+ * [Custom Reporter](#custom-reporter)
23
+ * [Configuration](#configuration)
24
+ * [API](#api)
25
+ * [approvals](#approvals)
26
+ * [approvals.reporters](#approvalsreporters)
27
+ * [reporters.MultiReporter](#reportersmultireporter)
28
+ * [approvals~configure(overrideOptions)](#approvalsconfigureoverrideoptions)
29
+ * [approvals~getConfig(overrideOptions) ⇒ <code>Object</code>](#approvalsgetconfigoverrideoptions--codeobjectcode)
30
+ * [approvals~mocha(optionalBaseDir)](#approvalsmochaoptionalbasedir)
31
+ * [approvals~verifyAndScrub(dirName, testName, data, scrubber, optionsOverride)](#approvalsverifyandscrubdirname-testname-data-scrubber-optionsoverride)
32
+ * [approvals~verify(dirName, testName, data, optionsOverride)](#approvalsverifydirname-testname-data-optionsoverride)
33
+ * [approvals~verifyAsJSON(dirName, testName, data, optionsOverride)](#approvalsverifyasjsondirname-testname-data-optionsoverride)
34
+ * [approvals~verifyAsJSONAndScrub(dirName, testName, data, scrubber, optionsOverride)](#approvalsverifyasjsonandscrubdirname-testname-data-scrubber-optionsoverride)
35
+ * [approvals~verifyWithControl(namer, writer, [reporterFactory], [optionsOverride])](#approvalsverifywithcontrolnamer-writer-reporterfactory-optionsoverride)
36
+ * [Source Control](#source-control)
37
+ * [Git](#git)
38
+ * [Contributing](#contributing)
39
+ * [License](#license)<!-- endToc -->
40
+
41
+ <a name="intro" />
42
+
43
+ ## Intro
44
+
45
+ Approval Tests Library - **Capturing Human Intelligence**
46
+
47
+ What is an approval test? Check out a brief [overview here](http://staxmanade.com/2015/01/approval-tests---overview/) or learn more about Approvals at [approvaltests.com](http://approvaltests.com).
48
+
49
+ <a name="build-details" />
50
+
51
+ ## Badges
52
+
53
+ | Service | Status |
54
+ | ---------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
55
+ | Package | [@approval-tests/approvals on npm](https://www.npmjs.com/package/@approval-tests/approvals) |
56
+ | Github (Linux, Mac, Windows) | [![Build & Test](https://github.com/approvals/Approvals.NodeJS/actions/workflows/build-and-test.yml/badge.svg)](https://github.com/approvals/Approvals.NodeJS/actions/workflows/build-and-test.yml) |
57
+
58
+ <a name="integrations" />
59
+
60
+ ## Integrations
61
+
62
+ - [Mocha](http://mochajs.org/) tests, see the getting-started
63
+ - [Approvals API](#api) (`require('@approval-tests/approvals').verify(...)`)
64
+ - [Command line Utility](#cli)
65
+
66
+ <a name="getting-started" />
67
+
68
+ ## Getting Started
69
+
70
+ ### Jest Typescript Starter Project
71
+
72
+ If you want to jump start a new project, clone the [Jest Starter Project](https://github.com/approvals/ApprovalTests.TypeScript.Jest.StarterProject)
73
+
74
+ ### Mocha
75
+
76
+ Below is a simple getting started using Mocha.
77
+
78
+ 1. Create a project (folder)
79
+
80
+ ```shell
81
+ mkdir MyProject
82
+ cd MyProject
83
+ ```
84
+
85
+ 1. Install approvals
86
+
87
+ ```shell
88
+ npm install --save-dev @approval-tests/approvals
89
+ ```
90
+
91
+ 1. Install [Mocha](http://mochajs.org/) globally to execute our tests
92
+
93
+ ```shell
94
+ npm install -g mocha
95
+ ```
96
+
97
+ 1. Create a sample Mocha test file called `SimpleLogger.test.js`.
98
+
99
+ ```javascript
100
+ require("@approval-tests/approvals").mocha();
101
+
102
+ describe("When running some tests", function () {
103
+ it("should be able to use Approvals", function () {
104
+ var data = "Hello World!";
105
+ this.verify(data); // or this.verifyAsJSON(data)
106
+ });
107
+ });
108
+ ```
109
+
110
+ 1. Test the file with mocha.
111
+
112
+ ```shell
113
+ mocha SimpleLogger.test.js
114
+ ```
115
+
116
+ 1. You should be presented with a diff tool. (if not, you may need to install one?)
117
+
118
+ <a name="documentation">
119
+
120
+ ## Documentation
121
+
122
+ If using Jest, see [more documentation here](docs/README.md).
123
+
124
+ <a name="cli">
125
+
126
+ ## CLI
127
+
128
+ Approvals.NodeJS has a version that can be run as a command line tool.
129
+
130
+ You can check out the `Examples` section of the below CLI help. Or a blog post introducing the tool here: [Approval Tests - Command Line Tool (CLI)](http://staxmanade.com/2015/02/approval-tests---command-line-tool--cli-/).
131
+
132
+ ### Install Approvals CLI
133
+
134
+ ```
135
+ npm install -g @approval-tests/approvals
136
+ ```
137
+
138
+ ### CLI Help
139
+
140
+ By running `approvals --help`
141
+
142
+ <!--BEGIN-CLI-DOCS-->
143
+ <!-- GENERATED - DO NOT MODIFY API DOCS IN THIS README -->
144
+ <!-- Update docs in the source ./bin/help.md -->
145
+ ```
146
+
147
+ # Usage
148
+
149
+ `approvals testName [options]`
150
+
151
+ | Arg | Description |
152
+ | ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- |
153
+ | \*\*[-f | --forceapproveall]\*\* | Skip the approve step and apply the results to the .approved.txt file (good for a first time run) |
154
+ | [--reporter difftool] | supports multiple EX: `--reporter opendiff --reporter gitdiff` |
155
+ | [--outdir] | dir to place approval file - defaults to current directory |
156
+ | [--verbose] | extra debug info |
157
+ | TODO: | We need to extend the supported args to include other approval options. (file an [issue](https://github.com/approvals/Approvals.NodeJS/issues) if you need one that's not here) |
158
+
159
+ # Examples
160
+
161
+ ## Simple hello world
162
+
163
+ ```
164
+ echo 'Hello World!' | approvals helloWorldTest
165
+ ```
166
+
167
+ ## Specify diff reporter (great for C.I.)
168
+
169
+ ```
170
+ echo 'Hello World!' | approvals helloWorldTest --reporter gitdiff
171
+ ```
172
+
173
+ ## Multiple diff reporters
174
+
175
+ ```
176
+ echo 'Hello World!' | approvals helloWorldTest --reporter gitdiff --reporter p4merge
177
+ ```
178
+
179
+ ```
180
+
181
+ <!--END-CLI-DOCS-->
182
+
183
+ <a name="reporters" />
184
+
185
+ ## Reporters
186
+
187
+ ### Built-In Reporters
188
+
189
+ Any of the following reporter may suite your needs. Some support images, some only diffing text, some on mac and linux, some only on windows... Feel free to configure the system to automatically choose your favorite.
190
+
191
+ ## Supported Diff Tools
192
+
193
+ | approval name | Program | Windows | Mac/Linux | Notes |
194
+ | --------------- | ---------------------------------------------------------------------------------------------------------------- | :------: | :-------: | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
195
+ | `beyondcompare` | [Beyond Compare](http://www.scootersoftware.com/) | &#10003; | &#10003; | |
196
+ | `copycommand` | [git diff](http://git-scm.com/docs/git-diff) (console diff) | &#10003; | &#10003; | Great for C.I. builds runs. |
197
+ | `diffmerge` | [DiffMerge](https://sourcegear.com/diffmerge/) | &#10003; | &#10003; | |
198
+ | `donothing` | | &#10003; | &#10003; | This one does what it says - nothing. |
199
+ | `gitdiff` | [git diff](http://git-scm.com/docs/git-diff) (console diff) | &#10003; | &#10003; | Using git cli to diff files. Useful in C.I. builds |
200
+ | `icdiff` | [Icdiff](https://github.com/jeffkaufman/icdiff) | &#10003; | &#10003; | |
201
+ | `kdiff3` | [KDiff3](http://kdiff3.sourceforge.net/) | &#10003; | &#10003; | |
202
+ | `kompare` | [Kompare](https://www.kde.org/applications/development/kompare/) | ? | &#10003; | |
203
+ | `meld` | [Meld](http://meldmerge.org/) | &#10003; | &#10003; | |
204
+ | `multi` | | &#10003; | &#10003; | This allows you to run multiple reporters at the same time. EX: when verifying images, you might like to use `p4merge` along with the `copycommand` reporter to get the copy CLI command to approve an image as well as view the diff in a tool. |
205
+ | `nodediff` | [nodediff](https://github.com/kpdecker/jsdiff) (console diff) | &#10003; | &#10003; | colorized CLI output without a popup of a diff tool |
206
+ | `opendiff` | [opendiff](https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/opendiff.1.html) | | &#10003; | |
207
+ | `p4merge` | [p4merge](http://www.perforce.com/product/components/perforce-visual-merge-and-diff-tools) | &#10003; | &#10003; | |
208
+ | `tortoisemerge` | [Tortise merge](http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-dug-merge.html) | &#10003; | &#10003; | |
209
+ | `vimdiff` | | &#10003; | &#10003; | |
210
+ | `visualstudio` | [Visual Studio Diff tool](http://msdn.microsoft.com/en-us/library/bb385990.aspx) | &#10003; | |
211
+ | `vscode` | [Visual Studio Code Diff tool](https://code.visualstudio.com/) | &#10003; | &#10003; |
212
+ | `vscodium` | [VSCodium Diff tool](https://vscodium.com/) | &#10003; | &#10003; |
213
+
214
+ ### Custom Reporter
215
+
216
+ Along with the built-in reporters, you can create your own custom reporter just by taking this sample and filling out the interface with your custom reporters desired behavior.
217
+
218
+ ```
219
+ /* OR a custom reporter object. Below is an example custom reporter */
220
+ {
221
+ /**
222
+ * Determine if the file that needs to be reported on can be handled by this reporter object.
223
+ * @param {string} receivedFilePath - The path to a received file.
224
+ */
225
+ canReportOn(receivedFilePath) {
226
+ return true;
227
+ }
228
+
229
+ /**
230
+ * Apply the logic necessary to report a difference.
231
+ * EX:
232
+ * - Open a diff program using the approved & received files
233
+ * - Generate and email a report showing the differences.
234
+ * @param {string} approvedFilePath - The path to an approved file.
235
+ * @param {string} receivedFilePath - The path to a received file.
236
+ */
237
+ // Actually execute the diff against the two files
238
+ report(approvedFilePath, receivedFilePath) {
239
+ // Do some reporting.
240
+ // Typically by launching a diff tool
241
+ }
242
+ }
243
+ ```
244
+
245
+ <a name="configuration" />
246
+
247
+ ## Configuration
248
+
249
+ Or more, controlling the behavior of approvals through various tweaks to configuration.
250
+
251
+ Approvals uses the below configuration to drive its behavior. How you communicate that configuration to approvals can happen in several ways.
252
+
253
+ The default configuration as defined below can be overridden by using the following strategy.
254
+
255
+ > NOTE: Priority/order of config selection comes from the below list where the first item have the defined defaults and each next step having a potential to override the previous if a configuration value is specified.
256
+
257
+ 1. Starting with the defaults (as shown in the JS object below) this is defined in [lib/config.ts](lib/config.ts).
258
+ 1. We then take and override the defaults (and only the properties specified) with config in a yaml or json file in your home directory `~/.approvalsConfig`.
259
+ 1. You can then call [`approvals.configure({...})`](#module_approvals.configure).
260
+ 1. Then passing any specific configuration at the test level as the last parameter in the verify function `.verify(..., {...overridden config...});`. See [API](#api) for specific parameters.
261
+
262
+ Here's an example of using a single reporter `p4merge`, and overriding whatever is configured. This will only override this specific test.
263
+
264
+ ```javascript
265
+ it("should use a specific reporter", function () {
266
+ this.verify("some data", {
267
+ reporters: ["p4merge"],
268
+ });
269
+ });
270
+ ```
271
+
272
+ If you have the need to execute multiple reporters on a single failure.
273
+
274
+ Say you made an "awesomeDiffReporter" and wanted it to run that in combination with a "notifyTheBossViaEmailReporter" you can use the MultiReporter like below.
275
+
276
+ ```javascript
277
+ var approvals = require("@approval-tests/approvals");
278
+ var MultiReporter = approvals.reporters.MultiReporter;
279
+
280
+ it("should use a multiple reporters", function () {
281
+ this.verify("some data", {
282
+ reporters: [new MultiReporter(["p4merge", "copycommand"])],
283
+ });
284
+ });
285
+ ```
286
+
287
+ <!-- snippet: default_config -->
288
+ <a id='snippet-default_config'></a>
289
+ ```ts
290
+ export const defaultConfig: Config = {
291
+ reporters: [
292
+ "BeyondCompare",
293
+ "diffmerge",
294
+ "p4merge",
295
+ "tortoisemerge",
296
+ "nodediff",
297
+ "opendiff",
298
+ "gitdiff",
299
+ ],
300
+ normalizeLineEndingsTo: false,
301
+ failOnLineEndingDifferences: false,
302
+ appendEOL: true,
303
+ EOL: os.EOL,
304
+ errorOnStaleApprovedFiles: true,
305
+ shouldIgnoreStaleApprovedFile: () => false,
306
+ stripBOM: false,
307
+ forceApproveAll: false,
308
+ blockUntilReporterExits: false,
309
+ maxLaunches: 10,
310
+ };
311
+ ```
312
+ <sup><a href='/lib/config.ts#L25-L47' title='Snippet source file'>snippet source</a> | <a href='#snippet-default_config' title='Start of snippet'>anchor</a></sup>
313
+ <!-- endSnippet -->
314
+
315
+ <a name="api" />
316
+
317
+ ## API
318
+
319
+ <!--BEGIN-API-DOCS-->
320
+ <!-- GENERATED - DO NOT MODIFY API DOCS IN THIS README -->
321
+ <!-- Update docs in the source ./lib/Approvals.js -->
322
+
323
+ <a name="module_approvals"></a>
324
+
325
+ ## approvals
326
+ Approvals module.
327
+
328
+
329
+ * [approvals](#module_approvals)
330
+ * _static_
331
+ * [.reporters](#module_approvals.reporters)
332
+ * [.MultiReporter](#module_approvals.reporters.MultiReporter)
333
+ * _inner_
334
+ * [~configure(overrideOptions)](#module_approvals..configure)
335
+ * [~getConfig(overrideOptions)](#module_approvals..getConfig) ⇒ <code>Object</code>
336
+ * [~mocha(optionalBaseDir)](#module_approvals..mocha)
337
+ * [~verifyAndScrub(dirName, testName, data, scrubber, optionsOverride)](#module_approvals..verifyAndScrub)
338
+ * [~verify(dirName, testName, data, optionsOverride)](#module_approvals..verify)
339
+ * [~verifyAsJSON(dirName, testName, data, optionsOverride)](#module_approvals..verifyAsJSON)
340
+ * [~verifyAsJSONAndScrub(dirName, testName, data, scrubber, optionsOverride)](#module_approvals..verifyAsJSONAndScrub)
341
+ * [~verifyWithControl(namer, writer, [reporterFactory], [optionsOverride])](#module_approvals..verifyWithControl)
342
+
343
+ <a name="module_approvals.reporters"></a>
344
+
345
+ ### approvals.reporters
346
+ `reporters` gives access to the `MultiReporter`
347
+
348
+ **Kind**: static property of [<code>approvals</code>](#module_approvals)
349
+ **Example**
350
+ ```js
351
+ const MultiReporter = approvals.reporters.MultiReporter
352
+ ```
353
+ <a name="module_approvals.reporters.MultiReporter"></a>
354
+
355
+ #### reporters.MultiReporter
356
+ This allows access to the MultiReporter constructor.
357
+ You can use this to run multiple reporters at the same time.
358
+
359
+ **Kind**: static property of [<code>reporters</code>](#module_approvals.reporters)
360
+ **Example**
361
+ ```js
362
+ approvals.verify(__dirname, "multi-reporter-example", "some data", {
363
+ reporters: [
364
+ new MultiReporter('p4merge', 'copycommand')
365
+ ]
366
+ });
367
+ ```
368
+ <a name="module_approvals..configure"></a>
369
+
370
+ ### approvals~configure(overrideOptions)
371
+ Allows you to provide overrides to the default configuration.
372
+
373
+ **Kind**: inner method of [<code>approvals</code>](#module_approvals)
374
+
375
+ | Param | Type |
376
+ | --- | --- |
377
+ | overrideOptions | <code>\*</code> |
378
+
379
+ **Example**
380
+ ```js
381
+ const approvals = require('@approval-tests/approvals');
382
+ approvals.configure({
383
+ reporters: ['p4merge']
384
+ });
385
+ ```
386
+ <a name="module_approvals..getConfig"></a>
387
+
388
+ ### approvals~getConfig(overrideOptions) ⇒ <code>Object</code>
389
+ Allows the creation of an approvals configuration object using any passed in options to override the defaults.
390
+
391
+ **Kind**: inner method of [<code>approvals</code>](#module_approvals)
392
+ **Returns**: <code>Object</code> - approvals config object with any options overridden.
393
+
394
+ | Param | Type |
395
+ | --- | --- |
396
+ | overrideOptions | <code>Object</code> |
397
+
398
+ <a name="module_approvals..mocha"></a>
399
+
400
+ ### approvals~mocha(optionalBaseDir)
401
+ Configure approvals to hook into Mocha tests.
402
+
403
+ **Kind**: inner method of [<code>approvals</code>](#module_approvals)
404
+
405
+ | Param | Type | Description |
406
+ | --- | --- | --- |
407
+ | optionalBaseDir | <code>\*</code> | An optional folder to save approval files to. |
408
+
409
+ <a name="module_approvals..verifyAndScrub"></a>
410
+
411
+ ### approvals~verifyAndScrub(dirName, testName, data, scrubber, optionsOverride)
412
+ Use this to apply the scrubber function to any data before running verify.
413
+
414
+ **Kind**: inner method of [<code>approvals</code>](#module_approvals)
415
+
416
+ | Param | Type | Description |
417
+ | --- | --- | --- |
418
+ | dirName | <code>string</code> | Typically `__dirname` but could be the base-directory (anywhere) to store both approved and received files. |
419
+ | testName | <code>string</code> | A file name safe string to call the file associated with this test. |
420
+ | data | <code>string</code> \| <code>Buffer</code> | Either the string to save as a text file or a Buffer that represents an image |
421
+ | scrubber | <code>\*</code> | A function that takes a string and returns a string. Approvals will call this if it exists to scrub the "data" before writing to any files. |
422
+ | optionsOverride | <code>\*</code> | An object that can contain configurational overrides as defined in the approvals configuration object. |
423
+
424
+ **Example**
425
+ ```js
426
+ // basic approval test with a custom scrubber
427
+ const approvals = require('@approval-tests/approvals');
428
+ const scrubber = approvals.scrubbers.multiScrubber([
429
+ function (data) {
430
+ return (data || '').replace("some text", "some other text");
431
+ },
432
+ approvals.scrubbers.guidScrubber // to remove guids from the received data
433
+ });
434
+ approvals.verifyAndScrub(__dirname, 'sample-approval-test', "some text to verify", scrubber);
435
+ ```
436
+ <a name="module_approvals..verify"></a>
437
+
438
+ ### approvals~verify(dirName, testName, data, optionsOverride)
439
+ **Kind**: inner method of [<code>approvals</code>](#module_approvals)
440
+
441
+ | Param | Type | Description |
442
+ | --- | --- | --- |
443
+ | dirName | <code>string</code> | Typically `__dirname` but could be the base-directory (anywhere) to store both approved and received files. |
444
+ | testName | <code>string</code> | A file name save string to call the file associated with this test. |
445
+ | data | <code>string</code> \| <code>Buffer</code> | Either the string to save as a text file or a Buffer that represents an image |
446
+ | optionsOverride | <code>\*</code> | An object that can contain configurational overrides as defined in the approvals configuration object. |
447
+
448
+ **Example**
449
+ ```js
450
+ // basic approval test
451
+ const approvals = require('@approval-tests/approvals');
452
+ approvals.verify(__dirname, 'sample-approval-test', "some text to verify");
453
+ ```
454
+ **Example**
455
+ ```js
456
+ // basic approval test providing an option to override configuration
457
+ const approvals = require('@approval-tests/approvals');
458
+ approvals.verify(__dirname, 'sample-approval-test', "some text to verify", { normalizeLineEndingsTo: true });
459
+ ```
460
+ <a name="module_approvals..verifyAsJSON"></a>
461
+
462
+ ### approvals~verifyAsJSON(dirName, testName, data, optionsOverride)
463
+ You can pass as "data" any javascript object to be JSON.stringified and run verify against.
464
+
465
+ **Kind**: inner method of [<code>approvals</code>](#module_approvals)
466
+
467
+ | Param | Type | Description |
468
+ | --- | --- | --- |
469
+ | dirName | <code>string</code> | Typically `__dirname` but could be the base-directory (anywhere) to store both approved and received files. |
470
+ | testName | <code>string</code> | A file name safe string to call the file associated with this test. |
471
+ | data | <code>string</code> \| <code>Buffer</code> | This can be any JavaScript object/array that will be JSON.stringified before running verify |
472
+ | optionsOverride | <code>\*</code> | An object that can contain configurational overrides as defined in the approvals configuration object. |
473
+
474
+ **Example**
475
+ ```js
476
+ const approvals = require('@approval-tests/approvals');
477
+ approvals.verifyAndScrub(__dirname, 'sample-approval-test', { a: "some text in an object" });
478
+ ```
479
+ <a name="module_approvals..verifyAsJSONAndScrub"></a>
480
+
481
+ ### approvals~verifyAsJSONAndScrub(dirName, testName, data, scrubber, optionsOverride)
482
+ You can pass as "data" any javascript object to be JSON.stringified. Before we run verify the scrubber will be run against the complete string before running verify against it.
483
+
484
+ **Kind**: inner method of [<code>approvals</code>](#module_approvals)
485
+
486
+ | Param | Type | Description |
487
+ | --- | --- | --- |
488
+ | dirName | <code>string</code> | Typically `__dirname` but could be the base-directory (anywhere) to store both approved and received files. |
489
+ | testName | <code>string</code> | A file name safe string to call the file associated with this test. |
490
+ | data | <code>string</code> \| <code>Buffer</code> | This can be any JavaScript object/array that will be JSON.stringified before running verify |
491
+ | scrubber | <code>\*</code> | A function that takes a string and returns a string. Approvals will call this if it exists to scrub the "data" before writing to any files. |
492
+ | optionsOverride | <code>\*</code> | An object that can contain configurational overrides as defined in the approvals configuration object. |
493
+
494
+ **Example**
495
+ ```js
496
+ // basic approval test with a custom scrubber
497
+ const approvals = require('@approval-tests/approvals');
498
+ const scrubber = approvals.scrubbers.multiScrubber([
499
+ function (data) {
500
+ return (data || '').replace("some text", "some other text");
501
+ },
502
+ approvals.scrubbers.guidScrubber // to remove guids from the received data
503
+ });
504
+ approvals.verifyAndScrub(__dirname, 'sample-approval-test', { a: "some text in an object" }, scrubber);
505
+ ```
506
+ <a name="module_approvals..verifyWithControl"></a>
507
+
508
+ ### approvals~verifyWithControl(namer, writer, [reporterFactory], [optionsOverride])
509
+ This allows you to take full control of naming and writing files before verifying.
510
+
511
+ For an example that we use to generate the docs within the readme, check out the [test/readmeTests.mts](test/readmeTests.mts) in this project.
512
+
513
+ **Kind**: inner method of [<code>approvals</code>](#module_approvals)
514
+
515
+ | Param | Type |
516
+ | --- | --- |
517
+ | namer | <code>Object</code> |
518
+ | writer | <code>Object</code> |
519
+ | [reporterFactory] | <code>function</code> |
520
+ | [optionsOverride] | <code>Object</code> |
521
+
522
+
523
+
524
+ <!--END-API-DOCS-->
525
+
526
+ <a name="source-control" />
527
+
528
+ ## Source Control
529
+
530
+ The approvals tool generates 2 files and you likely want to ignore one and check in the other.
531
+
532
+ - `*.received.*` files should be **IGNORED**.
533
+ - `*.approved.*` You'll likely want to keep the approved files in source control.
534
+
535
+ ### Git
536
+
537
+ If you're using [Git](http://git-scm.com) add this to your `.gitignore`:
538
+
539
+ ```text
540
+ *.received.*
541
+ ```
542
+
543
+ Depending on your operating system and your `eol` settings in git, the diff output on a failed test might report each line as changed because of differences in line endings. To avoid this, consider fixating eol conversion to crlf for approved files by adding this line to your `.gitattributes` file:
544
+ ```text
545
+ *.approved.* eol=lf
546
+ ```
547
+
548
+ <a name="contributing" />
549
+
550
+ ## Contributing
551
+
552
+ Check out the [guidelines](CONTRIBUTING.md)!
553
+
554
+ ## License
555
+
556
+ Copyright (c) 2012-2017 Llewellyn Falco, Jason Jarrett
557
+ Licensed under the Apache license.