Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add testplane support #29

Merged
merged 1 commit into from
Apr 22, 2024
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
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@

Common plugin for:

* [hermione](https://github.com/gemini-testing/hermione)
* [testplane](https://github.com/gemini-testing/testplane)
* [hermione](https://github.com/gemini-testing/testplane/tree/hermione)

which is intended to aggregate the results of tests running.

You can read more about hermione plugins [here](https://github.com/gemini-testing/hermione#plugins).
You can read more about testplane plugins [here](https://github.com/gemini-testing/testplane/blob/master/docs/config.md#plugins).

## Installation

Expand All @@ -27,6 +28,23 @@ Plugin has following configuration:
Also there is ability to override plugin parameters by CLI options or environment variables
(see [configparser](https://github.com/gemini-testing/configparser)).

### Testplane usage

Add plugin to your `testplane` config file:

```ts
export default {
// ...
plugins: {
'json-reporter/testplane': {
enabled: true,
path: 'my/custom/report.json'
}
},
//...
}
```

### Hermione usage

Add plugin to your `hermione` config file:
Expand Down
26 changes: 1 addition & 25 deletions hermione.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,3 @@
'use strict';

const Collector = require('./lib/collector');
const hermioneToolCollector = require('./lib/collector/tool/hermione');
const parseConfig = require('./lib/config');

module.exports = (hermione, opts) => {
const config = parseConfig(opts);

if (!config.enabled) {
return;
}

const collector = Collector.create(hermioneToolCollector, config);

hermione.on(hermione.events.TEST_PASS, (data) => collector.addSuccess(data));

hermione.on(hermione.events.TEST_FAIL, (data) => collector.addFail(data));

hermione.on(hermione.events.TEST_PENDING, (data) => collector.addSkipped(data));

hermione.on(hermione.events.RETRY, (data) => collector.addRetry(data));

hermione.on(hermione.events.ERROR, (err, data) => data && collector.addError(data));

hermione.on(hermione.events.RUNNER_END, () => collector.saveFile());
};
module.exports = require('./plugin');
File renamed without changes.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "json-reporter",
"version": "3.0.0",
"description": "Common plugin for gemini and hermione which is intended to aggregate the results of tests running",
"main": "hermione.js",
"description": "Common plugin for testplane and hermione which is intended to aggregate the results of tests running",
"main": "plugin.js",
"scripts": {
"lint": "eslint .",
"test": "npm run lint && npm run test-unit",
Expand All @@ -22,6 +22,7 @@
"node": ">= 18"
},
"keywords": [
"testplane",
"hermione",
"plugin",
"json-reporter"
Expand Down
27 changes: 27 additions & 0 deletions plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

./hermione.js -> ./plugin.js


const Collector = require('./lib/collector');
const toolCollector = require('./lib/collector/tool/testplane');
const parseConfig = require('./lib/config');

module.exports = (testplane, opts) => {
const config = parseConfig(opts);

if (!config.enabled) {
return;
}

const collector = Collector.create(toolCollector, config);

testplane.on(testplane.events.TEST_PASS, (data) => collector.addSuccess(data));

testplane.on(testplane.events.TEST_FAIL, (data) => collector.addFail(data));

testplane.on(testplane.events.TEST_PENDING, (data) => collector.addSkipped(data));

testplane.on(testplane.events.RETRY, (data) => collector.addRetry(data));

testplane.on(testplane.events.ERROR, (err, data) => data && collector.addError(data));

testplane.on(testplane.events.RUNNER_END, () => collector.saveFile());
};
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict';

const _ = require('lodash');
const hermioneToolCollector = require('../../../../lib/collector/tool/hermione');
const toolCollector = require('../../../../lib/collector/tool/testplane');
const utils = require('../../../../lib/collector/utils');

describe('collector/tool/hermione', () => {
describe('collector/tool/testplane', () => {
const sandbox = sinon.sandbox.create();

afterEach(() => sandbox.restore());
Expand All @@ -23,7 +23,7 @@ describe('collector/tool/hermione', () => {
it('should try to resolve "file" from test result', () => {
const data = mkDataStub_({file: '/cwd/file/path'});

hermioneToolCollector.configureTestResult(data);
toolCollector.configureTestResult(data);

assert.calledOnceWith(utils.getRelativePath, '/cwd/file/path');
});
Expand All @@ -34,7 +34,7 @@ describe('collector/tool/hermione', () => {
parent: {file: '/cwd/parent/file/path'}
});

hermioneToolCollector.configureTestResult(data);
toolCollector.configureTestResult(data);

assert.calledOnceWith(utils.getRelativePath, '/cwd/file/path');
});
Expand All @@ -45,7 +45,7 @@ describe('collector/tool/hermione', () => {
parent: {file: '/cwd/parent/file/path'}
});

hermioneToolCollector.configureTestResult(data);
toolCollector.configureTestResult(data);

assert.calledOnceWith(utils.getRelativePath, '/cwd/parent/file/path');
});
Expand All @@ -55,7 +55,7 @@ describe('collector/tool/hermione', () => {
meta: {}
});

const result = hermioneToolCollector.configureTestResult(data);
const result = toolCollector.configureTestResult(data);

assert.notProperty(result, 'url');
});
Expand All @@ -65,15 +65,15 @@ describe('collector/tool/hermione', () => {
meta: {url: 'http://example.com/some-path?query=string'}
});

const result = hermioneToolCollector.configureTestResult(data);
const result = toolCollector.configureTestResult(data);

assert.propertyVal(result, 'url', '/some-path?query=string');
});

it('should set "duration" to "null" if it does not specify', () => {
const data = mkDataStub_();

const result = hermioneToolCollector.configureTestResult(data);
const result = toolCollector.configureTestResult(data);

assert.propertyVal(result, 'duration', null);
});
Expand All @@ -92,7 +92,7 @@ describe('collector/tool/hermione', () => {

utils.getRelativePath.withArgs('/cwd/file/path').returns('file/path');

const result = hermioneToolCollector.configureTestResult(data);
const result = toolCollector.configureTestResult(data);

assert.deepEqual(result, {
suitePath: ['some full', 'title'],
Expand All @@ -107,19 +107,19 @@ describe('collector/tool/hermione', () => {
});

it('should not throw an error if test has no parent', () => {
assert.doesNotThrow(() => hermioneToolCollector.configureTestResult(mkDataStub_()));
assert.doesNotThrow(() => toolCollector.configureTestResult(mkDataStub_()));
});
});

describe('getSkipReason', () => {
it('should return default skip reason if "skipReason" is not specified', () => {
assert.strictEqual(hermioneToolCollector.getSkipReason({}), 'No skip reason');
assert.strictEqual(toolCollector.getSkipReason({}), 'No skip reason');
});

it('should return skip reason from test result', () => {
const data = {skipReason: 'test-comment'};

assert.strictEqual(hermioneToolCollector.getSkipReason(data), 'test-comment');
assert.strictEqual(toolCollector.getSkipReason(data), 'test-comment');
});

it('should return skip reason from "parent" if it does not exist in test result', () => {
Expand All @@ -128,7 +128,7 @@ describe('collector/tool/hermione', () => {
parent: {skipReason: 'suite-comment'}
};

assert.strictEqual(hermioneToolCollector.getSkipReason(data), 'suite-comment');
assert.strictEqual(toolCollector.getSkipReason(data), 'suite-comment');
});

it('should return skip reason from "parent" even if it exists in test result', () => {
Expand All @@ -137,7 +137,7 @@ describe('collector/tool/hermione', () => {
parent: {skipReason: 'suite-comment'}
};

assert.strictEqual(hermioneToolCollector.getSkipReason(data), 'suite-comment');
assert.strictEqual(toolCollector.getSkipReason(data), 'suite-comment');
});
});
});
30 changes: 15 additions & 15 deletions test/hermione.js → test/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ const EventEmitter = require('events').EventEmitter;
const proxyquire = require('proxyquire');

const Collector = require('../lib/collector');
const hermioneToolCollector = require('../lib/collector/tool/hermione');
const toolCollector = require('../lib/collector/tool/testplane');

describe('json-reporter/hermione', () => {
describe('json-reporter/plugin', () => {
const sandbox = sinon.sandbox.create();

let hermione;
let testplane;
let parseConfig;

const mkHermione_ = () => {
const mkTestplane_ = () => {
const emitter = new EventEmitter();

emitter.events = {
Expand All @@ -38,15 +38,15 @@ describe('json-reporter/hermione', () => {

parseConfig = sandbox.stub().returns(opts);

const hermioneReporter = proxyquire('../hermione', {
const reporter = proxyquire('../plugin', {
'./lib/config': parseConfig
});

return hermioneReporter(hermione, opts);
return reporter(testplane, opts);
};

beforeEach(() => {
hermione = mkHermione_();
testplane = mkTestplane_();
});

afterEach(() => sandbox.restore());
Expand All @@ -73,7 +73,7 @@ describe('json-reporter/hermione', () => {

assert.calledWith(
Collector.create,
hermioneToolCollector,
toolCollector,
{enabled: true, path: '/some/path'}
);
});
Expand All @@ -85,7 +85,7 @@ describe('json-reporter/hermione', () => {
const data = {foo: 'bar'};
sandbox.stub(Collector.prototype, 'addSuccess');

hermione.emit(hermione.events.TEST_PASS, data);
testplane.emit(testplane.events.TEST_PASS, data);

assert.calledOnceWith(Collector.prototype.addSuccess, data);
});
Expand All @@ -94,7 +94,7 @@ describe('json-reporter/hermione', () => {
const data = {foo: 'bar'};
sandbox.stub(Collector.prototype, 'addFail');

hermione.emit(hermione.events.TEST_FAIL, data);
testplane.emit(testplane.events.TEST_FAIL, data);

assert.calledOnceWith(Collector.prototype.addFail, data);
});
Expand All @@ -103,7 +103,7 @@ describe('json-reporter/hermione', () => {
const data = {foo: 'bar'};
sandbox.stub(Collector.prototype, 'addSkipped');

hermione.emit(hermione.events.TEST_PENDING, data);
testplane.emit(testplane.events.TEST_PENDING, data);

assert.calledOnceWith(Collector.prototype.addSkipped, data);
});
Expand All @@ -112,7 +112,7 @@ describe('json-reporter/hermione', () => {
const data = {foo: 'bar'};
sandbox.stub(Collector.prototype, 'addRetry');

hermione.emit(hermione.events.RETRY, data);
testplane.emit(testplane.events.RETRY, data);

assert.calledOnceWith(Collector.prototype.addRetry, data);
});
Expand All @@ -121,23 +121,23 @@ describe('json-reporter/hermione', () => {
const data = {foo: 'bar'};
sandbox.stub(Collector.prototype, 'addError');

hermione.emit(hermione.events.ERROR, 'some error', data);
testplane.emit(testplane.events.ERROR, 'some error', data);

assert.calledOnceWith(Collector.prototype.addError, data);
});

it('should do nothing for error which occurred without data', () => {
sandbox.stub(Collector.prototype, 'addError');

hermione.emit(hermione.events.ERROR, 'some error');
testplane.emit(testplane.events.ERROR, 'some error');

assert.notCalled(Collector.prototype.addError);
});

it('should save collected test data into file when the tests are completed', () => {
sandbox.stub(Collector.prototype, 'saveFile');

hermione.emit(hermione.events.RUNNER_END);
testplane.emit(testplane.events.RUNNER_END);

assert.calledOnce(Collector.prototype.saveFile);
});
Expand Down
3 changes: 3 additions & 0 deletions testplane.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

module.exports = require('./plugin');
Loading