Skip to content

Commit

Permalink
feat(core): The new StreamReporter helps to analyse issues that have …
Browse files Browse the repository at this point in the history
…occurred at runtime
  • Loading branch information
jan-molak committed Jun 23, 2019
1 parent 3dacda2 commit f96f9f8
Show file tree
Hide file tree
Showing 16 changed files with 38 additions and 37 deletions.
@@ -1,6 +1,6 @@
import { serenity } from '@serenity-js/core';
import { FileSystem, Path } from '@serenity-js/core/lib/io';
import { ArtifactArchiver, DebugReporter, SerenityBDDReporter } from '@serenity-js/core/lib/stage';
import { ArtifactArchiver, SerenityBDDReporter } from '@serenity-js/core/lib/stage';

import { setDefaultTimeout } from 'cucumber';

Expand All @@ -9,5 +9,4 @@ setDefaultTimeout(5000);
serenity.setTheStage(
new ArtifactArchiver(new FileSystem(new Path('./target/site/serenity'))),
new SerenityBDDReporter(),
// new DebugReporter(),
);
@@ -1,5 +1,5 @@
import { ChildProcessReporter } from '@integration/testing-tools';
import { DebugReporter, serenity, WithStage } from '@serenity-js/core';
import { serenity, StreamReporter, WithStage } from '@serenity-js/core';
import { Actors } from './Actors';

export = function () {
Expand All @@ -8,7 +8,7 @@ export = function () {

serenity.setTheStage(
new ChildProcessReporter(),
new DebugReporter(),
new StreamReporter(),
);

this.World = function (this: WithStage) {
Expand Down
@@ -1,5 +1,5 @@
import { ChildProcessReporter } from '@integration/testing-tools';
import { DebugReporter, serenity, WithStage } from '@serenity-js/core';
import { serenity, StreamReporter, WithStage } from '@serenity-js/core';
import { defineSupportCode } from 'cucumber';
import { Actors } from './Actors';

Expand All @@ -8,7 +8,7 @@ defineSupportCode(({ setDefaultTimeout, setWorldConstructor }) => {

serenity.setTheStage(
new ChildProcessReporter(),
new DebugReporter(),
new StreamReporter(),
);

setWorldConstructor(function (this: WithStage) {
Expand Down
@@ -1,5 +1,5 @@
import { ChildProcessReporter } from '@integration/testing-tools';
import { DebugReporter, serenity, WithStage } from '@serenity-js/core';
import { serenity, StreamReporter, WithStage } from '@serenity-js/core';
import { defineSupportCode } from 'cucumber';
import { Actors } from './Actors';

Expand All @@ -8,7 +8,7 @@ defineSupportCode(({ setDefaultTimeout, setWorldConstructor }) => {

serenity.setTheStage(
new ChildProcessReporter(),
new DebugReporter(),
new StreamReporter(),
);

setWorldConstructor(function (this: WithStage) {
Expand Down
@@ -1,13 +1,13 @@
import { ChildProcessReporter } from '@integration/testing-tools';
import { DebugReporter, serenity, WithStage } from '@serenity-js/core';
import { serenity, StreamReporter, WithStage } from '@serenity-js/core';
import { setDefaultTimeout, setWorldConstructor } from 'cucumber';
import { Actors } from './Actors';

setDefaultTimeout(5000);

serenity.setTheStage(
new ChildProcessReporter(),
new DebugReporter(),
new StreamReporter(),
);

setWorldConstructor(function (this: WithStage) {
Expand Down
@@ -1,13 +1,13 @@
import { ChildProcessReporter } from '@integration/testing-tools';
import { DebugReporter, serenity, WithStage } from '@serenity-js/core';
import { serenity, StreamReporter, WithStage } from '@serenity-js/core';
import { setDefaultTimeout, setWorldConstructor } from 'cucumber';
import { Actors } from './Actors';

setDefaultTimeout(5000);

serenity.setTheStage(
new ChildProcessReporter(),
new DebugReporter(),
new StreamReporter(),
);

setWorldConstructor(function (this: WithStage) {
Expand Down
5 changes: 2 additions & 3 deletions integration/cucumber/features/support/configure_serenity.ts
@@ -1,13 +1,12 @@
import { ChildProcessReporter } from '@integration/testing-tools';
import { serenity } from '@serenity-js/core';
import { DebugReporter } from '@serenity-js/core/lib/stage';
import { serenity, StreamReporter } from '@serenity-js/core';

export = function () {

this.setDefaultTimeout(5000);

serenity.setTheStage(
new ChildProcessReporter(),
new DebugReporter(),
new StreamReporter(),
);
};
3 changes: 1 addition & 2 deletions integration/cucumber/package.json
Expand Up @@ -16,8 +16,7 @@
"scripts": {
"clean": "rimraf lib",
"lint": "tslint --project tsconfig-lint.json --config ../../tslint.json --format stylish",
"test": "parallel-mocha --opts ../../mocha.opts 'spec/**/*.spec.*'",
"test:parallel": "mocha-parallel-tests --opts ../../mocha.opts 'spec/**/*.spec.*'"
"test": "parallel-mocha --opts ../../mocha.opts 'spec/**/*.spec.*'"
},
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions integration/jasmine/examples/setup.js
@@ -1,8 +1,8 @@
const
{ ChildProcessReporter } = require('@integration/testing-tools'),
{ serenity, DebugReporter } = require('@serenity-js/core');
{ serenity, StreamReporter } = require('@serenity-js/core');

serenity.setTheStage(
new ChildProcessReporter(),
new DebugReporter(),
new StreamReporter(),
);
3 changes: 1 addition & 2 deletions integration/jasmine/package.json
Expand Up @@ -16,8 +16,7 @@
"scripts": {
"clean": "rimraf lib",
"lint": "tslint --project tsconfig-lint.json --config ../../tslint.json --format stylish",
"test": "parallel-mocha --opts ../../mocha.opts 'spec/**/*.spec.*'",
"test:parallel": "mocha-parallel-tests --opts ../../mocha.opts 'spec/**/*.spec.*'"
"test": "parallel-mocha --opts ../../mocha.opts 'spec/**/*.spec.*'"
},
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions integration/protractor-jasmine/examples/protractor.conf.js
@@ -1,6 +1,6 @@
const
path = require('path'),
{ DebugReporter } = require('@serenity-js/core'),
{ StreamReporter } = require('@serenity-js/core'),
{ ChildProcessReporter } = require('@integration/testing-tools');

exports.config = {
Expand All @@ -20,7 +20,7 @@ exports.config = {
runner: 'jasmine',
crew: [
new ChildProcessReporter(),
new DebugReporter(),
new StreamReporter(),
]
},

Expand Down
3 changes: 1 addition & 2 deletions integration/protractor-jasmine/package.json
Expand Up @@ -16,8 +16,7 @@
"scripts": {
"clean": "rimraf lib",
"lint": "tslint --project tsconfig-lint.json --config ../../tslint.json --format stylish",
"test": "parallel-mocha --opts ../../mocha.opts 'spec/**/*.spec.*'",
"test:parallel": "mocha-parallel-tests --opts ../../mocha.opts 'spec/**/*.spec.*'"
"test": "mocha --opts ../../mocha.opts 'spec/**/*.spec.*'"
},
"repository": {
"type": "git",
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/stage/crew/debug-reporter/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/core/src/stage/crew/index.ts
@@ -1,4 +1,4 @@
export * from './artifact-archiver';
export * from './console-reporter';
export * from './debug-reporter';
export * from './stream-reporter';
export * from './serenity-bdd-reporter';
Expand Up @@ -5,21 +5,28 @@ import { StageCrewMember } from '../../StageCrewMember';

/**
* @desc
* Serialises all the {@link DomainEvent} objects it receives and outputs
* Serialises all the {@link DomainEvent} objects it receives and streams
* them as [ndjson](http://ndjson.org/)
* so that they can be analysed by the Serenity/JS team.
* to the output stream.
*
* @example <caption>Writing the DomainEvents to a file</caption>
* import { serenity } form '@serenity-js/core';
* @example <caption>Writing DomainEvents to standard output</caption>
* import { serenity, StreamReporter } form '@serenity-js/core';
*
* serenity.setTheStage(
* new StreamReporter(process.stdout),
* );
*
* @example <caption>Writing DomainEvents to a file</caption>
* import { serenity, StreamReporter } form '@serenity-js/core';
* import fs = require('fs');
*
* serenity.setTheStage(
* new DebugReporter(fs.createWriteStream('./debug-output.ndjson')),
* new StreamReporter(fs.createWriteStream('./debug-output.ndjson')),
* );
*
* @extends {StageCrewMember}
*/
export class DebugReporter implements StageCrewMember {
export class StreamReporter implements StageCrewMember {

/**
* @param {WriteStream} output - A WriteStream that should receive the output
Expand All @@ -41,18 +48,17 @@ export class DebugReporter implements StageCrewMember {
* @returns {StageCrewMember} - A new instance of this {@link StageCrewMember}
*/
assignedTo(stage: Stage): StageCrewMember {
return new DebugReporter(this.output, stage);
return new StreamReporter(this.output, stage);
}

/**
* @desc
* Handles {@link DomainEvent} objects emitted by the {@link Stage}
* this {@link StageCrewMember} is assigned to.
* Handles {@link DomainEvent} objects emitted by the {@link StageManager}.
*
* @see {@link StageCrewMember}
*
* @param {DomainEvent} event
* @returns void
* @returns {void}
*/
notifyOf(event: DomainEvent): void {
this.output.write(
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/stage/crew/stream-reporter/index.ts
@@ -0,0 +1 @@
export * from './StreamReporter';

0 comments on commit f96f9f8

Please sign in to comment.