From 6843f2f5644b23fcb80a7e9665690c5c1ffab7b9 Mon Sep 17 00:00:00 2001 From: Chakshu Gupta Date: Mon, 10 Jun 2024 19:54:53 +0530 Subject: [PATCH] fix(cloudformation-diff): format test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Currently, `yarn build` fails in '@aws-cdk-testing' package with following error because 'Received' string is formatted with `chalk.red` and 'Expected' string is by default formatted with `chalk.green`: ``` ✖ @aws-cdk/cloudformation-diff:test $ cdk-test FAIL test/format.test.ts ● format value can handle partial json strings expect(received).toEqual(expected) // deep equality Expected: "{\"nice\":\"great\",\"partialJson\":\"{\\\"wow\\\": \\\"great\"}" Received: "{\"nice\":\"great\",\"partialJson\":\"{\\\"wow\\\": \\\"great\"}" 6 | test('format value can handle partial json strings', () => { 7 | const output = formatter.formatValue({ nice: 'great', partialJson: '{"wow": "great' }, chalk.red); > 8 | expect(output).toEqual('{\"nice\":\"great\",\"partialJson\":\"{\\\"wow\\\": \\\"great\"}'); | ^ 9 | }); at Object. (test/format.test.ts:8:18) ``` - But as unit-test aims to test equality of strings in terms of content instead of color formatting, hence, it is better to utilise `toMatch` instead of `toEqual`. - Upon retesting, unit-test passed: ``` ✔ @aws-cdk/cloudformation-diff:build [local cache] ``` --- packages/@aws-cdk/cloudformation-diff/test/format.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/cloudformation-diff/test/format.test.ts b/packages/@aws-cdk/cloudformation-diff/test/format.test.ts index 6cd6d23d38b5f..b025688ef7668 100644 --- a/packages/@aws-cdk/cloudformation-diff/test/format.test.ts +++ b/packages/@aws-cdk/cloudformation-diff/test/format.test.ts @@ -5,5 +5,5 @@ const formatter = new Formatter(process.stdout, {}); test('format value can handle partial json strings', () => { const output = formatter.formatValue({ nice: 'great', partialJson: '{"wow": "great' }, chalk.red); - expect(output).toEqual('{\"nice\":\"great\",\"partialJson\":\"{\\\"wow\\\": \\\"great\"}'); + expect(output).toMatch('{\"nice\":\"great\",\"partialJson\":\"{\\\"wow\\\": \\\"great\"}'); }); \ No newline at end of file