From 03e3c5274c4cf2ffd6a998892cac85c0ee1a67d3 Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Tue, 2 Jan 2024 20:51:05 +0100 Subject: [PATCH] Use regex to make test pass in VSCode (#9791) --- .../dataMigrate/src/__tests__/install.test.ts | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/packages/cli-packages/dataMigrate/src/__tests__/install.test.ts b/packages/cli-packages/dataMigrate/src/__tests__/install.test.ts index e7eb5165d42c..378cb0eef95e 100644 --- a/packages/cli-packages/dataMigrate/src/__tests__/install.test.ts +++ b/packages/cli-packages/dataMigrate/src/__tests__/install.test.ts @@ -1,3 +1,5 @@ +import type yargs from 'yargs' + import * as installCommand from '../commands/install' import { handler as dataMigrateInstallHandler } from '../commands/installHandler.js' @@ -24,12 +26,24 @@ describe('install', () => { }) it('`builder` has an epilogue', () => { - const yargs = { epilogue: jest.fn() } - // @ts-expect-error this is a test file; epilogue is the only thing `builder` calls right now + // The typecasting here is to make TS happy when calling `builder(yargs)` + // further down. We know that only `epilogue` will be called. + const yargs = { epilogue: jest.fn() } as unknown as yargs.Argv + installCommand.builder(yargs) - expect(yargs.epilogue).toBeCalledWith( - // eslint-disable-next-line no-irregular-whitespace - 'Also see the Redwood CLI Reference (​https://redwoodjs.com/docs/cli-commands#datamigrate-install​)' + + // The epilogue is a string that contains a link to the docs. The string + // contains special control characters when rendered in a terminal that + // supports clickable links. We use regular expressions and wildcards here + // to avoid having to match control characters that might not even always + // be there + expect(yargs.epilogue).toHaveBeenCalledWith( + expect.stringMatching(/Also see the .*Redwood CLI Reference.*/) + ) + expect(yargs.epilogue).toHaveBeenCalledWith( + expect.stringMatching( + /https:\/\/redwoodjs\.com\/docs\/cli-commands#datamigrate-install/ + ) ) })