From c9f0e74e901f5816d4fad5ad6027f30e1bbb5988 Mon Sep 17 00:00:00 2001 From: isaryy Date: Mon, 15 Dec 2025 00:00:36 +0300 Subject: [PATCH 1/3] feat: add includeHistory option to include test history in report --- lib/collector/index.js | 2 +- lib/collector/tool/testplane.js | 6 ++- lib/config.js | 6 +++ test/lib/collector/tool/testplane.js | 61 ++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+), 2 deletions(-) diff --git a/lib/collector/index.js b/lib/collector/index.js index e3e8943..2298478 100644 --- a/lib/collector/index.js +++ b/lib/collector/index.js @@ -64,7 +64,7 @@ module.exports = class Collector { } _addTestResult(result, props) { - const configuredResult = this._toolCollector.configureTestResult(result); + const configuredResult = this._toolCollector.configureTestResult(result, this._config); const test = _.extend(configuredResult, props); this._dataCollector.append(test); diff --git a/lib/collector/tool/testplane.js b/lib/collector/tool/testplane.js index 007e1ba..ceb918e 100644 --- a/lib/collector/tool/testplane.js +++ b/lib/collector/tool/testplane.js @@ -4,7 +4,7 @@ const _ = require('lodash'); const url = require('url'); const utils = require('../utils'); -exports.configureTestResult = (result) => { +exports.configureTestResult = (result, config) => { const filePath = utils.getFilePath(result) || ''; const testResult = { suitePath: utils.getSuitePath(result), @@ -21,6 +21,10 @@ exports.configureTestResult = (result) => { testResult.url = url.parse(metaUrl).path; } + if (config && config.includeHistory && result.history) { + testResult.history = result.history; + } + return testResult; }; diff --git a/lib/config.js b/lib/config.js index 9a55c41..df43880 100644 --- a/lib/config.js +++ b/lib/config.js @@ -33,6 +33,12 @@ const getParser = () => { path: option({ defaultValue: 'json-reporter.json', validate: isString('path') + }), + includeHistory: option({ + defaultValue: false, + parseEnv: JSON.parse, + parseCli: JSON.parse, + validate: isBoolean('includeHistory') }) }), {envPrefix: ENV_PREFIX, cliPrefix: CLI_PREFIX}); }; diff --git a/test/lib/collector/tool/testplane.js b/test/lib/collector/tool/testplane.js index 2996ec5..19e4752 100644 --- a/test/lib/collector/tool/testplane.js +++ b/test/lib/collector/tool/testplane.js @@ -109,6 +109,67 @@ describe('collector/tool/testplane', () => { it('should not throw an error if test has no parent', () => { assert.doesNotThrow(() => toolCollector.configureTestResult(mkDataStub_())); }); + + it('should not add history if includeHistory is not enabled', () => { + const testSteps = [ + {n: 'click', a: ['.button'], ts: 1000, te: 1050, d: 50, s: 'b', c: [], o: false, g: false, f: false} + ]; + const data = mkDataStub_({ + history: testSteps + }); + + const result = toolCollector.configureTestResult(data, {includeHistory: false}); + + assert.notProperty(result, 'history'); + }); + + it('should add history if includeHistory is enabled and history exists', () => { + const testSteps = [ + { + n: 'click', + a: ['.button'], + ts: 1000, + te: 1050, + d: 50, + s: 'b', + c: [ + {n: 'wait', a: [], ts: 1005, te: 1045, d: 40, s: 'b', c: [], o: false, g: false, f: false} + ], + o: false, + g: true, + f: false + }, + { + n: 'type', + a: ['.input', 'text'], + ts: 1100, + te: 1150, + d: 50, + s: 'e', + c: [], + o: false, + g: false, + f: false + } + ]; + const data = mkDataStub_({ + history: testSteps + }); + + const result = toolCollector.configureTestResult(data, {includeHistory: true}); + + assert.propertyVal(result, 'history', testSteps); + assert.isArray(result.history); + }); + + it('should not add history if includeHistory is enabled but history does not exist', () => { + // @note history is not available for skipped tests and may be undefined + const data = mkDataStub_(); + + const result = toolCollector.configureTestResult(data, {includeHistory: true}); + + assert.notProperty(result, 'history'); + }); }); describe('getSkipReason', () => { From f815e18f256d3de440b94f7298c5d5995c52ee33 Mon Sep 17 00:00:00 2001 From: isaryy Date: Mon, 15 Dec 2025 00:15:11 +0300 Subject: [PATCH 2/3] test: add tests for includeHistory option in config --- test/lib/config.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/lib/config.js b/test/lib/config.js index 70ddb13..0d3de92 100644 --- a/test/lib/config.js +++ b/test/lib/config.js @@ -12,6 +12,7 @@ describe('config', () => { delete process.env['json_reporter_enabled']; delete process.env['json_reporter_path']; + delete process.env['json_reporter_include_history']; }); describe('enabled', () => { @@ -61,4 +62,28 @@ describe('config', () => { assert.equal(parseConfig({}).path, 'env/path/report.json'); }); }); + + describe('includeHistory', () => { + it('should be disabled by default', () => { + assert.isFalse(parseConfig({}).includeHistory); + }); + + it('should enable by configuration file', () => { + const config = parseConfig({includeHistory: true}); + + assert.isTrue(config.includeHistory); + }); + + it('should enable by cli', () => { + process.argv = process.argv.concat('--json-reporter-include-history', 'true'); + + assert.isTrue(parseConfig({}).includeHistory); + }); + + it('should enable by environment variable', () => { + process.env['json_reporter_include_history'] = 'true'; + + assert.isTrue(parseConfig({}).includeHistory); + }); + }); }); From 1e0514c61e911c45c349a296aa71da56635be251 Mon Sep 17 00:00:00 2001 From: isaryy Date: Tue, 16 Dec 2025 11:33:42 +0300 Subject: [PATCH 3/3] docs: add readme --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 512c52f..a579ad9 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ Plugin has following configuration: * **enabled** (optional) `Boolean` – enable/disable the plugin; by default plugin is enabled * **path** (optional) `String` - path for saving json report file; by default json report will be saved into `json-reporter.json` inside current work directory. +* **includeHistory** (optional) `Boolean` – include test execution history in the json report; by default history is not included. Note: history is not available for skipped tests and may be undefined. Also there is ability to override plugin parameters by CLI options or environment variables (see [configparser](https://github.com/gemini-testing/configparser)). @@ -38,7 +39,8 @@ export default { plugins: { 'json-reporter/testplane': { enabled: true, - path: 'my/custom/report.json' + path: 'my/custom/report.json', + includeHistory: true } }, //... @@ -55,7 +57,8 @@ module.exports = { plugins: { 'json-reporter/hermione': { enabled: true, - path: 'my/custom/report.json' + path: 'my/custom/report.json', + includeHistory: true } }, //...