Skip to content

Commit

Permalink
fix: do not passthrough parser events via TestParserApi
Browse files Browse the repository at this point in the history
BREAKING CHANGE: testParserApi object passed on BEFORE_FILE_READ event is no longer an EventEmitter
  • Loading branch information
j0tunn committed Jun 3, 2022
1 parent 39873d7 commit 5f26c80
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 64 deletions.
23 changes: 0 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ Hermione is a utility for integration testing of web pages using [WebdriverIO v7
- [Test Collection](#test-collection)
- [Test Parser API](#test-parser-api)
- [setController(name, methods)](#setcontrollername-methods)
- [events](#events)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

Expand Down Expand Up @@ -1610,25 +1609,3 @@ describe('foo', () => {
```
**Note**: controller will be removed as soon as current file will be parsed
#### events
Parser events list for subscription.
**Available events which are triggered in the TestParserAPI**
Event | Description
----------------- | -------------
`TEST` | Will be triggered on test parsing. The handler accepts test instance.
`SUITE` | Will be triggered on suite parsing. The handler accepts suite instance.
`HOOK` | Will be triggered on hook parsing. The handler accepts hook instance.
Example:
```js
// in plugin
hermione.on(hermione.events.BEFORE_FILE_READ, ({testParser}) => {
testParser.on(testParser.events.TEST, (test) => {
console.log('my awesome test:', test);
});
});
```
16 changes: 1 addition & 15 deletions lib/test-reader/test-parser-api.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,18 @@
'use strict';

const {EventEmitter} = require('events');
const _ = require('lodash');
const ParserEvents = require('./parser-events');
const RunnerEvents = require('../constants/runner-events');
const eventsUtils = require('gemini-core').events.utils;

module.exports = class TestParserAPI extends EventEmitter {
module.exports = class TestParserAPI {
static create(...args) {
return new this(...args);
}

constructor(parser, ctx) {
super();

this._ctx = ctx;
this._parser = parser;
this._delayedCalls = [];

eventsUtils.passthroughEvent(this._parser, this, [
ParserEvents.TEST,
ParserEvents.SUITE,
ParserEvents.HOOK
]);
}

get events() {
return ParserEvents;
}

setController(name, methods) {
Expand Down
26 changes: 0 additions & 26 deletions test/lib/test-reader/test-parser-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,12 @@ const TestParserAPI = require('lib/test-reader/test-parser-api');
const ParserEvents = require('lib/test-reader/parser-events');
const RunnerEvents = require('lib/constants/runner-events');
const {makeSuite, makeTest} = require('../../utils');
const eventsUtils = require('gemini-core').events.utils;

describe('test-reader/test-parser-api', () => {
const sandbox = sinon.sandbox.create();

const mkTestParser_ = () => {
return new EventEmitter();
};

afterEach(() => {
sandbox.restore();
});

describe('setController', () => {
it('should set appropriate controller to context', () => {
const hermione = {};
Expand Down Expand Up @@ -145,24 +138,5 @@ describe('test-reader/test-parser-api', () => {
assert.calledOnce(doStuff);
assert.calledOn(doStuff, test);
});

it('should pass through all parser events', () => {
const hermione = {};
const testParser = mkTestParser_();
const doStuff = sandbox.stub(eventsUtils, 'passthroughEvent');

const testParserAPI = TestParserAPI.create(testParser, hermione);

assert.calledOnceWith(
doStuff,
testParser,
testParserAPI,
[
ParserEvents.TEST,
ParserEvents.SUITE,
ParserEvents.HOOK
]
);
});
});
});

0 comments on commit 5f26c80

Please sign in to comment.