From 9bf42eb86969e42b52b2db04a24d7c6b2e286d3c Mon Sep 17 00:00:00 2001 From: Oleksandr_Halichenko Date: Tue, 18 Apr 2023 18:54:12 +0300 Subject: [PATCH 1/2] fixed issue with $' replacement --- CHANGELOG.MD | 3 +++ formatter/formatter.js | 5 +++-- package-lock.json | 4 ++-- package.json | 2 +- test/features/Logs.feature | 3 +++ test/step_definitions/custom_steps.ts | 2 ++ 6 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.MD b/CHANGELOG.MD index bed4ebb..c1e5ea4 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -1,3 +1,6 @@ +# 0.0.11 +- fixed $' replace issue + # 0.0.10 - fixed issue of not escaped chars in logs diff --git a/formatter/formatter.js b/formatter/formatter.js index 0dbd59b..31e9e68 100644 --- a/formatter/formatter.js +++ b/formatter/formatter.js @@ -9,9 +9,10 @@ class HTMLFormatter extends JsonFormatter { const log = this.log.bind(this); this.log = function(json) { const htmlTemplate = fs.readFileSync(path.resolve(__dirname, './index.html'), 'utf-8'); + console.log(JSON.stringify(JSON.parse(json))) log(htmlTemplate - .replace('METADATA', JSON.stringify(this.metadata, null, 0)) - .replace('SOURCE_DATA', JSON.stringify(JSON.parse(json), null, 0))); + .replace('METADATA', () => JSON.stringify(this.metadata, null, 0)) + .replace('SOURCE_DATA', () => JSON.stringify(JSON.parse(json.replace(/\$/g, '$$')), null, 0))); } } diff --git a/package-lock.json b/package-lock.json index 62509da..a1c4250 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@qavajs/html-formatter", - "version": "0.0.10", + "version": "0.0.11", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@qavajs/html-formatter", - "version": "0.0.10", + "version": "0.0.11", "devDependencies": { "@babel/core": "^7.21.0", "@cucumber/cucumber": "^9.1.0", diff --git a/package.json b/package.json index 13f2365..92e0de3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@qavajs/html-formatter", - "version": "0.0.10", + "version": "0.0.11", "main": "formatter/formatter.js", "scripts": { "report:compile": "node test/compile_report.js", diff --git a/test/features/Logs.feature b/test/features/Logs.feature index 79c50eb..41beed2 100644 --- a/test/features/Logs.feature +++ b/test/features/Logs.feature @@ -5,3 +5,6 @@ Feature: Logs Scenario: scenario failed with logs And failed step with log + + Scenario: scenario dollar replace + And I expect 'some string' to match '^120$' diff --git a/test/step_definitions/custom_steps.ts b/test/step_definitions/custom_steps.ts index 3e1830d..3f8689b 100644 --- a/test/step_definitions/custom_steps.ts +++ b/test/step_definitions/custom_steps.ts @@ -60,3 +60,5 @@ When('failed step with log', function () { throw new Error('failed step'); }); +When(`I expect {string} to match {string}`, async function (one, two) {}); + From adfd8ed146885df8791037a53dc6b10f49318989 Mon Sep 17 00:00:00 2001 From: Oleksandr_Halichenko Date: Tue, 18 Apr 2023 18:55:59 +0300 Subject: [PATCH 2/2] fixed issue with $' replacement --- formatter/formatter.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/formatter/formatter.js b/formatter/formatter.js index 31e9e68..d84810c 100644 --- a/formatter/formatter.js +++ b/formatter/formatter.js @@ -9,10 +9,9 @@ class HTMLFormatter extends JsonFormatter { const log = this.log.bind(this); this.log = function(json) { const htmlTemplate = fs.readFileSync(path.resolve(__dirname, './index.html'), 'utf-8'); - console.log(JSON.stringify(JSON.parse(json))) log(htmlTemplate .replace('METADATA', () => JSON.stringify(this.metadata, null, 0)) - .replace('SOURCE_DATA', () => JSON.stringify(JSON.parse(json.replace(/\$/g, '$$')), null, 0))); + .replace('SOURCE_DATA', () => JSON.stringify(JSON.parse(json), null, 0))); } }