From 562d4ef5e9558fdc4c0cfb853fc448d256892d60 Mon Sep 17 00:00:00 2001 From: Sergei Zharinov Date: Sat, 27 Nov 2021 08:54:06 +0300 Subject: [PATCH] test(util/sanitize): Improve test for sanitize function (#12860) --- lib/util/__snapshots__/sanitize.spec.ts.snap | 3 --- lib/util/sanitize.spec.ts | 15 +++++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) delete mode 100644 lib/util/__snapshots__/sanitize.spec.ts.snap diff --git a/lib/util/__snapshots__/sanitize.spec.ts.snap b/lib/util/__snapshots__/sanitize.spec.ts.snap deleted file mode 100644 index a2b1fff385f13c..00000000000000 --- a/lib/util/__snapshots__/sanitize.spec.ts.snap +++ /dev/null @@ -1,3 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`util/sanitize sanitizes secrets from strings 1`] = `"My token is **redacted**, username is \\"userabc\\" and password is \\"**redacted**\\" (hashed: **redacted**)"`; diff --git a/lib/util/sanitize.spec.ts b/lib/util/sanitize.spec.ts index c3d96fb9d59fee..15068a9d9db91b 100644 --- a/lib/util/sanitize.spec.ts +++ b/lib/util/sanitize.spec.ts @@ -16,11 +16,14 @@ describe('util/sanitize', () => { const hashed = Buffer.from(`${username}:${password}`).toString('base64'); add(hashed); add(password); - // FIXME: explicit assert condition - expect( - sanitize( - `My token is ${token}, username is "${username}" and password is "${password}" (hashed: ${hashed})` - ) - ).toMatchSnapshot(); + + const input = `My token is ${token}, username is "${username}" and password is "${password}" (hashed: ${hashed})`; + const output = + 'My token is **redacted**, username is "userabc" and password is "**redacted**" (hashed: **redacted**)'; + expect(sanitize(input)).toBe(output); + + const inputX2 = [input, input].join('\n'); + const outputX2 = [output, output].join('\n'); + expect(sanitize(inputX2)).toBe(outputX2); }); });