From 684fa20d1e7124ddb3af5182f835937c61f75c7b Mon Sep 17 00:00:00 2001 From: Ahmed Elywa Date: Wed, 10 Aug 2022 22:18:18 +0200 Subject: [PATCH] fix: remove colors from the the result to fix the local test (#225) * remove colors from the the result to fix the local test * eslint-disable-next-line no-control-regex --- tests/checks/PrismaClientOnContext.test.ts | 6 +++++- tsconfig.json | 2 +- utils/ansiEscapeSequencePattern.ts | 5 +++++ 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 utils/ansiEscapeSequencePattern.ts diff --git a/tests/checks/PrismaClientOnContext.test.ts b/tests/checks/PrismaClientOnContext.test.ts index 056448a64..3b031f537 100644 --- a/tests/checks/PrismaClientOnContext.test.ts +++ b/tests/checks/PrismaClientOnContext.test.ts @@ -1,6 +1,7 @@ import gql from 'graphql-tag' import { objectType, queryType } from 'nexus' import { testIntegration, TestIntegrationParams, testIntegrationPartial } from '../__helpers__/testers' +import { ansiEscapeSequencePattern } from '../../utils/ansiEscapeSequencePattern' const base = testIntegrationPartial({ database: ` @@ -96,7 +97,10 @@ describe('instanceOf_duckType_fallback strategy:', () => { // The emitted error contains a path that isn't stable across the CI/CI matrix. Needs to be processed. expect(result) { if (result.logs[0]) { - result.logs[0] = result.logs[0]!.replace(/(.*imported from).*(is not the.*)/, '$1 $2') + result.logs[0] = result.logs[0]!.replace( + /(.*imported from).*(is not the.*)/, + '$1 $2' + ).replace(ansiEscapeSequencePattern, '') } expect(result.logs).toMatchSnapshot(`logs`) expect(result.graphqlSchemaSDL).toMatchSnapshot(`graphqlSchemaSDL`) diff --git a/tsconfig.json b/tsconfig.json index 04eb8948f..596d0fdf1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -29,6 +29,6 @@ ".nexus-prisma": [".nexus-prisma"] } }, - "include": ["src", "tests", "scripts"], + "include": ["src", "tests", "scripts", "utils"], "exclude": ["dist-*", "tests/e2e/fixtures", "docs"] } diff --git a/utils/ansiEscapeSequencePattern.ts b/utils/ansiEscapeSequencePattern.ts new file mode 100644 index 000000000..a6d3914ba --- /dev/null +++ b/utils/ansiEscapeSequencePattern.ts @@ -0,0 +1,5 @@ +/** + * @see https://stackoverflow.com/questions/4842424/list-of-ansi-color-escape-sequences + */ +// eslint-disable-next-line no-control-regex +export const ansiEscapeSequencePattern = /\x1b\[[0-9]+m/g