diff --git a/README.md b/README.md index 3c07e61..512c52f 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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: diff --git a/hermione.js b/hermione.js index 57271ce..39a26a3 100644 --- a/hermione.js +++ b/hermione.js @@ -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'); diff --git a/lib/collector/tool/hermione.js b/lib/collector/tool/testplane.js similarity index 100% rename from lib/collector/tool/hermione.js rename to lib/collector/tool/testplane.js diff --git a/package.json b/package.json index 3c9376f..db2f500 100644 --- a/package.json +++ b/package.json @@ -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", @@ -22,6 +22,7 @@ "node": ">= 18" }, "keywords": [ + "testplane", "hermione", "plugin", "json-reporter" diff --git a/plugin.js b/plugin.js new file mode 100644 index 0000000..1e013ee --- /dev/null +++ b/plugin.js @@ -0,0 +1,27 @@ +'use strict'; + +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()); +}; diff --git a/test/lib/collector/tool/hermione.js b/test/lib/collector/tool/testplane.js similarity index 78% rename from test/lib/collector/tool/hermione.js rename to test/lib/collector/tool/testplane.js index 3424776..2996ec5 100644 --- a/test/lib/collector/tool/hermione.js +++ b/test/lib/collector/tool/testplane.js @@ -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()); @@ -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'); }); @@ -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'); }); @@ -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'); }); @@ -55,7 +55,7 @@ describe('collector/tool/hermione', () => { meta: {} }); - const result = hermioneToolCollector.configureTestResult(data); + const result = toolCollector.configureTestResult(data); assert.notProperty(result, 'url'); }); @@ -65,7 +65,7 @@ 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'); }); @@ -73,7 +73,7 @@ describe('collector/tool/hermione', () => { 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); }); @@ -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'], @@ -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', () => { @@ -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', () => { @@ -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'); }); }); }); diff --git a/test/hermione.js b/test/plugin.js similarity index 82% rename from test/hermione.js rename to test/plugin.js index 0cae864..4f22c01 100644 --- a/test/hermione.js +++ b/test/plugin.js @@ -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 = { @@ -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()); @@ -73,7 +73,7 @@ describe('json-reporter/hermione', () => { assert.calledWith( Collector.create, - hermioneToolCollector, + toolCollector, {enabled: true, path: '/some/path'} ); }); @@ -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); }); @@ -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); }); @@ -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); }); @@ -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); }); @@ -121,7 +121,7 @@ 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); }); @@ -129,7 +129,7 @@ describe('json-reporter/hermione', () => { 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); }); @@ -137,7 +137,7 @@ describe('json-reporter/hermione', () => { 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); }); diff --git a/testplane.js b/testplane.js new file mode 100644 index 0000000..39a26a3 --- /dev/null +++ b/testplane.js @@ -0,0 +1,3 @@ +'use strict'; + +module.exports = require('./plugin');