From 734278e4dfb9879e0fde49a013abeb92471edbb7 Mon Sep 17 00:00:00 2001 From: aurelien-reeves Date: Tue, 20 Jul 2021 09:34:10 +0200 Subject: [PATCH] Use npm package reindent-template-literals --- package.json | 1 + .../helpers/gherkin_document_parser_spec.ts | 2 +- src/formatter/helpers/issue_helpers_spec.ts | 3 +- src/formatter/progress_formatter_spec.ts | 3 +- .../javascript_snippet_syntax_spec.ts | 2 +- src/formatter/usage_formatter_spec.ts | 3 +- test/formatter_helpers.ts | 41 ------------------- yarn.lock | 5 +++ 8 files changed, 14 insertions(+), 46 deletions(-) diff --git a/package.json b/package.json index c3d6e0ef1..33923800f 100644 --- a/package.json +++ b/package.json @@ -245,6 +245,7 @@ "mustache": "4.2.0", "nyc": "15.1.0", "prettier": "2.3.2", + "reindent-template-literals": "^1.0.0", "semver": "7.3.5", "sinon": "11.1.1", "sinon-chai": "3.7.0", diff --git a/src/formatter/helpers/gherkin_document_parser_spec.ts b/src/formatter/helpers/gherkin_document_parser_spec.ts index 51016c999..8bea18ee7 100644 --- a/src/formatter/helpers/gherkin_document_parser_spec.ts +++ b/src/formatter/helpers/gherkin_document_parser_spec.ts @@ -12,7 +12,7 @@ import { } from '../../../test/gherkin_helpers' import * as messages from '@cucumber/messages' import IGherkinDocument = messages.GherkinDocument -import { reindent } from '../../../test/formatter_helpers' +import { reindent } from 'reindent-template-literals' describe('GherkinDocumentParser', () => { describe('getGherkinStepMap', () => { diff --git a/src/formatter/helpers/issue_helpers_spec.ts b/src/formatter/helpers/issue_helpers_spec.ts index 43eb638cf..61c5dc4e3 100644 --- a/src/formatter/helpers/issue_helpers_spec.ts +++ b/src/formatter/helpers/issue_helpers_spec.ts @@ -3,7 +3,8 @@ import { expect } from 'chai' import getColorFns from '../get_color_fns' import { formatIssue } from './issue_helpers' import figures from 'figures' -import { getTestCaseAttempts, reindent } from '../../../test/formatter_helpers' +import { getTestCaseAttempts } from '../../../test/formatter_helpers' +import { reindent } from 'reindent-template-literals' import { getBaseSupportCodeLibrary } from '../../../test/fixtures/steps' import FormatterBuilder from '../builder' diff --git a/src/formatter/progress_formatter_spec.ts b/src/formatter/progress_formatter_spec.ts index e59012d48..d7078e624 100644 --- a/src/formatter/progress_formatter_spec.ts +++ b/src/formatter/progress_formatter_spec.ts @@ -1,7 +1,8 @@ import { afterEach, beforeEach, describe, it } from 'mocha' import { expect } from 'chai' import { getBaseSupportCodeLibrary } from '../../test/fixtures/steps' -import { testFormatter, reindent } from '../../test/formatter_helpers' +import { testFormatter } from '../../test/formatter_helpers' +import { reindent } from 'reindent-template-literals' import figures from 'figures' import FakeTimers, { InstalledClock } from '@sinonjs/fake-timers' import timeMethods from '../time' diff --git a/src/formatter/step_definition_snippet_builder/javascript_snippet_syntax_spec.ts b/src/formatter/step_definition_snippet_builder/javascript_snippet_syntax_spec.ts index f3a8bea4a..18fcf7781 100644 --- a/src/formatter/step_definition_snippet_builder/javascript_snippet_syntax_spec.ts +++ b/src/formatter/step_definition_snippet_builder/javascript_snippet_syntax_spec.ts @@ -8,7 +8,7 @@ import { CucumberExpressionGenerator, ParameterTypeRegistry, } from '@cucumber/cucumber-expressions' -import { reindent } from '../../../test/formatter_helpers' +import { reindent } from 'reindent-template-literals' function generateExpressions(text: string): readonly GeneratedExpression[] { const parameterTypeRegistry = new ParameterTypeRegistry() diff --git a/src/formatter/usage_formatter_spec.ts b/src/formatter/usage_formatter_spec.ts index 10a848e58..752611bce 100644 --- a/src/formatter/usage_formatter_spec.ts +++ b/src/formatter/usage_formatter_spec.ts @@ -3,7 +3,8 @@ import { expect } from 'chai' import FakeTimers, { InstalledClock } from '@sinonjs/fake-timers' import timeMethods from '../time' import { getUsageSupportCodeLibrary } from '../../test/fixtures/usage_steps' -import { testFormatter, reindent } from '../../test/formatter_helpers' +import { testFormatter } from '../../test/formatter_helpers' +import { reindent } from 'reindent-template-literals' describe('UsageFormatter', () => { let clock: InstalledClock diff --git a/test/formatter_helpers.ts b/test/formatter_helpers.ts index ed904099e..6b1005de4 100644 --- a/test/formatter_helpers.ts +++ b/test/formatter_helpers.ts @@ -173,44 +173,3 @@ export function normalizeSummaryDuration(output: string): string { '' ) } - -/** - * Removes the indentation of the given string based on the indentation of its first line. - * - * It removes the first line if it is empty so it is not needed for it to be escaped. - * - * @example - * { - * const reindented = reindent(` - * Expected output - * Expected indented output - * Another line - * `) - * - * const expected = `\ - * Expected output - * Expected indented output - * Another line - * ` - * expect(reindented).to.eql(expected) - * } - */ -export function reindent(original: string): string { - const lines = original.replace(/^\n/, '').split(`\n`) - const numberOfSpaceToRemove = lines[0].search(/\S|$/) - const spacesToRemove = Array(numberOfSpaceToRemove + 1).join(' ') - - return lines - .map((line, index) => { - if (index === lines.length - 1 && line.trim() === '') { - return '' - } - - if (line.startsWith(spacesToRemove)) { - return line.replace(spacesToRemove, '') - } - - return line - }) - .join('\n') -} diff --git a/yarn.lock b/yarn.lock index 4c39c0b43..969b81292 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3431,6 +3431,11 @@ regexpp@^3.0.0, regexpp@^3.1.0: resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-3.1.0.tgz#206d0ad0a5648cffbdb8ae46438f3dc51c9f78e2" integrity sha512-ZOIzd8yVsQQA7j8GCSlPGXwg5PfmA1mrq0JP4nGhh54LaKN3xdai/vHUDu74pKwV8OxseMS65u2NImosQcSD0Q== +reindent-template-literals@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/reindent-template-literals/-/reindent-template-literals-1.0.0.tgz#7c6fa92f825f342515ea6e1c9e0cbe2d8671ce3c" + integrity sha512-q5ttxEAkS6dWL3oGyQS5wnvwZc2zzOpE679uZLAS0izTk6c1LkC7S4q6ca6gq/hL2Cokw1ozInee/mkPsXW4WA== + release-zalgo@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/release-zalgo/-/release-zalgo-1.0.0.tgz#09700b7e5074329739330e535c5a90fb67851730"