|
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | | -import {expect} from "vitest"; |
17 | 16 | import {Recipe} from "../recipe"; |
18 | 17 | import {ExecutionContext} from "../execution"; |
19 | 18 | import {noopVisitor, TreeVisitor} from "../visitor"; |
@@ -145,7 +144,13 @@ export class RecipeSpec { |
145 | 144 | private async expectParsePrintIdempotence(parsed: [SourceSpec<any>, SourceFile][]) { |
146 | 145 | for (const [spec, sourceFile] of parsed) { |
147 | 146 | const beforeSource = dedent(spec.before!); |
148 | | - expect(await TreePrinters.print(sourceFile)).toEqual(beforeSource); |
| 147 | + const printed = await TreePrinters.print(sourceFile); |
| 148 | + if (printed !== beforeSource) { |
| 149 | + throw new Error( |
| 150 | + `Parse-print idempotence check failed.\n` + |
| 151 | + `Expected:\n${beforeSource}\n\nActual:\n${printed}` |
| 152 | + ); |
| 153 | + } |
149 | 154 | } |
150 | 155 | } |
151 | 156 |
|
@@ -206,12 +211,16 @@ export class RecipeSpec { |
206 | 211 | if (!after) { |
207 | 212 | throw new Error('Expected for recipe to have produced a change for file:\n' + trimIndent(spec.before)) |
208 | 213 | } |
209 | | - expect(after).toBeDefined(); |
210 | | - await new ValidateWhitespaceVisitor().visit(after!, this.executionContext); |
211 | | - const actualAfter = await TreePrinters.print(after!); |
| 214 | + await new ValidateWhitespaceVisitor().visit(after, this.executionContext); |
| 215 | + const actualAfter = await TreePrinters.print(after); |
212 | 216 | const afterSource = typeof spec.after === "function" ? |
213 | 217 | (spec.after as (actual: string) => string)(actualAfter) : spec.after as string; |
214 | | - expect(actualAfter).toEqual(afterSource); |
| 218 | + if (actualAfter !== afterSource) { |
| 219 | + throw new Error( |
| 220 | + `Recipe output does not match expected.\n` + |
| 221 | + `Expected:\n${afterSource}\n\nActual:\n${actualAfter}` |
| 222 | + ); |
| 223 | + } |
215 | 224 | if (spec.afterRecipe) { |
216 | 225 | await spec.afterRecipe(after); |
217 | 226 | } |
@@ -248,7 +257,11 @@ export class RecipeSpec { |
248 | 257 | class ValidateWhitespaceVisitor extends JavaScriptVisitor<ExecutionContext> { |
249 | 258 | public override async visitSpace(space: J.Space, p: ExecutionContext): Promise<J.Space> { |
250 | 259 | const ret = super.visitSpace(space, p); |
251 | | - expect(space.whitespace).toMatch(/^\s*$/); |
| 260 | + if (!/^\s*$/.test(space.whitespace)) { |
| 261 | + throw new Error( |
| 262 | + `Whitespace contains non-whitespace characters: ${JSON.stringify(space.whitespace)}` |
| 263 | + ); |
| 264 | + } |
252 | 265 | return ret; |
253 | 266 | } |
254 | 267 | } |
|
0 commit comments