Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)).
Expand All @@ -38,7 +39,8 @@ export default {
plugins: {
'json-reporter/testplane': {
enabled: true,
path: 'my/custom/report.json'
path: 'my/custom/report.json',
includeHistory: true
}
},
//...
Expand All @@ -55,7 +57,8 @@ module.exports = {
plugins: {
'json-reporter/hermione': {
enabled: true,
path: 'my/custom/report.json'
path: 'my/custom/report.json',
includeHistory: true
}
},
//...
Expand Down
2 changes: 1 addition & 1 deletion lib/collector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion lib/collector/tool/testplane.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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;
};

Expand Down
6 changes: 6 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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});
};
Expand Down
61 changes: 61 additions & 0 deletions test/lib/collector/tool/testplane.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
25 changes: 25 additions & 0 deletions test/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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);
});
});
});