diff --git a/package-lock.json b/package-lock.json index 881e1c0e..4bae665b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -793,6 +793,17 @@ "@types/istanbul-reports": "^1.1.1", "@types/yargs": "^15.0.0", "chalk": "^3.0.0" + }, + "dependencies": { + "chalk": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz", + "integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==", + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + } } }, "@protobufjs/aspromise": { @@ -1889,9 +1900,10 @@ "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=" }, "chalk": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz", - "integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==", + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, "requires": { "ansi-styles": "^4.1.0", "supports-color": "^7.1.0" @@ -3263,6 +3275,17 @@ "diff-sequences": "^25.2.6", "jest-get-type": "^25.2.6", "pretty-format": "^25.5.0" + }, + "dependencies": { + "chalk": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz", + "integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==", + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + } } }, "jest-docblock": { diff --git a/package.json b/package.json index aea51df4..6bcac6df 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jest-cucumber", - "version": "3.0.1", + "version": "3.0.2", "description": "Execute Gherkin scenarios in Jest", "main": "dist/src/index.js", "typings": "dist/src/index.d.ts", @@ -27,6 +27,7 @@ "homepage": "https://github.com/bencompton/jest-cucumber#readme", "devDependencies": { "babel-jest": "^24.1.0", + "chalk": "^4.1.2", "ts-jest": "^26.1.4", "tslint": "^5.10.0", "typescript": "^3.3.3" diff --git a/src/validation/step-definition-validation.ts b/src/validation/step-definition-validation.ts index 20bb0949..a00873a0 100644 --- a/src/validation/step-definition-validation.ts +++ b/src/validation/step-definition-validation.ts @@ -1,6 +1,7 @@ import { ParsedScenario, ParsedScenarioOutline, ScenarioFromStepDefinitions, Options, ParsedStep } from '../models'; import { generateScenarioCode } from '../code-generation/scenario-generation'; import { generateStepCode } from '../code-generation/step-generation'; +import {green, red, bold, bgRed, black} from 'chalk'; export const matchSteps = (stepFromFeatureFile: string, stepMatcher: string | RegExp) => { if (typeof stepMatcher === 'string') { @@ -54,7 +55,16 @@ export const ensureFeatureFileAndStepDefinitionScenarioHaveSameSteps = ( if (!stepFromStepDefinitions || !matchSteps(parsedStep.stepText, stepFromStepDefinitions.stepMatcher)) { // tslint:disable-next-line:max-line-length - errors.push(`Expected step #${index + 1} in scenario "${parsedScenario.title}" to match "${parsedStep.stepText}". Try adding the following code:\n\n${generateStepCode(parsedScenario.steps, index)}`); + const errorCollection = [ + bgRed(bold(black(`Expected step ${`#${index + 1}`}`))), + ` in scenario `, + green(`"${parsedScenario.title}"`), + ` to match `, + red(`"${parsedStep.stepText}"`), + `. Try adding the following code:\n\n`, + green(generateStepCode(parsedScenario.steps, index)), + ]; + errors.push(errorCollection.join('')); } });