Skip to content

Commit

Permalink
feat(serenity-bdd): upgraded Serenity BDD to 4.0.44
Browse files Browse the repository at this point in the history
Serenity BDD 4.0.44 brings improved support for nested requirements reporting
  • Loading branch information
jan-molak committed Jan 24, 2024
1 parent 7196b01 commit 4e2f1e3
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 14 deletions.
@@ -0,0 +1,11 @@
import { describe, it } from '@serenity-js/playwright-test';

describe('My feature', () => {

describe('A scenario', () => {

it('passes', async ({ actorCalled }) => {
// no-op, passing
});
});
});
40 changes: 40 additions & 0 deletions integration/playwright-test/spec/requirement_tag_reporting.spec.ts
@@ -0,0 +1,40 @@
import { expect, ifExitCodeIsOtherThan, logOutput, PickEvent } from '@integration/testing-tools';
import { Timestamp } from '@serenity-js/core';
import { SceneFinished, SceneFinishes, SceneStarts, SceneTagged, TestRunFinished, TestRunFinishes, TestRunnerDetected, TestRunStarts } from '@serenity-js/core/lib/events';
import { CorrelationId, ExecutionSuccessful, FeatureTag, Name } from '@serenity-js/core/lib/model';
import { describe, it } from 'mocha';

import { playwrightTest } from '../src/playwright-test';

describe('@serenity-js/playwright-test', function () {

it('recognises a passing scenario', () => playwrightTest('--project=default', 'passing.spec.ts')
.then(ifExitCodeIsOtherThan(0, logOutput))
.then(result => {

expect(result.exitCode).to.equal(0);

let currentSceneId: CorrelationId;

PickEvent.from(result.events)
.next(TestRunStarts, event => expect(event.timestamp).to.be.instanceof(Timestamp))
.next(SceneStarts, event => {
expect(event.details.name).to.equal(new Name('A scenario passes'));
currentSceneId = event.sceneId;
})
.next(SceneTagged, event => expect(event.tag).to.equal(new FeatureTag('Playwright Test reporting')))
.next(TestRunnerDetected, event => expect(event.name).to.equal(new Name('Playwright')))

// triggered by requiring actorCalled
.next(SceneFinishes, event => {
expect(event.sceneId).to.equal(currentSceneId);
})
.next(SceneFinished, event => {
expect(event.sceneId).to.equal(currentSceneId);
expect(event.outcome).to.equal(new ExecutionSuccessful());
})
.next(TestRunFinishes, event => expect(event.timestamp).to.be.instanceof(Timestamp))
.next(TestRunFinished, event => expect(event.timestamp).to.be.instanceof(Timestamp))
;
}));
});
@@ -1,10 +1,9 @@
import { expect } from '@integration/testing-tools';
import { FileSystem, Path } from '@serenity-js/core/lib/io';
import { describe, it } from 'mocha';
import { given } from 'mocha-testdata';
import type { JSONObject } from 'tiny-types';

import { SpecDirectory } from '../../../src/stage/crew/serenity-bdd-reporter/SpecDirectory';
import { FileSystem, Path, SpecDirectory } from '../../src/io';
import { expect } from '../expect';

// eslint-disable-next-line @typescript-eslint/no-var-requires
const { memfs } = require('memfs'); // Typings incorrectly assume the presence of "dom" lib
Expand Down
@@ -1,5 +1,5 @@
import type { FileSystem} from '@serenity-js/core/lib/io';
import { Path } from '@serenity-js/core/lib/io';
import type { FileSystem} from './FileSystem';
import { Path } from './Path';

export class SpecDirectory {

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/io/index.ts
Expand Up @@ -10,4 +10,5 @@ export * from './inspectedObject';
export * from './loader';
export * from './Path';
export * from './reflection';
export * from './SpecDirectory';
export * from './trimmed';
9 changes: 6 additions & 3 deletions packages/serenity-bdd/src/cli/commands/run.ts
@@ -1,8 +1,8 @@
import { actorCalled, configure } from '@serenity-js/core';
import { FileSystem, Path } from '@serenity-js/core/lib/io';
import { FileSystem, Path, SpecDirectory } from '@serenity-js/core/lib/io';
import * as path from 'path'; // eslint-disable-line unicorn/import-style
import * as process from 'process';

import { SpecDirectory } from '../../stage/crew/serenity-bdd-reporter/SpecDirectory';
import type { Argv } from '../Argv';
import { defaults } from '../defaults';
import { formatError } from '../io';
Expand Down Expand Up @@ -85,9 +85,12 @@ export = {
await actor.attemptsTo(
InvokeSerenityBDD.at(pathToArtifact)
.withProperties(SystemProperties.of({
'serenity.compress.filenames': `${ argv.shortFilenames }`,
'LOG_LEVEL': argv.log,
'logback.configurationFile': path.resolve(moduleRoot, './resources/logback.config.xml'),
'serenity.compress.filenames': `${ argv.shortFilenames }`,
// Serenity BDD requires both --features and this property for FeatureFilePath to work
// see https://github.com/serenity-bdd/serenity-core/blob/a997617f5a43b5d46a3a81da875b8f850a9c21ab/serenity-model/src/main/java/net/thucydides/model/requirements/FeatureFilePath.java#L10
'serenity.features.directory': argv.features,
}))
.withArguments(SerenityBDDArguments.from(argv)),
);
Expand Down
2 changes: 1 addition & 1 deletion packages/serenity-bdd/src/cli/defaults.ts
Expand Up @@ -14,7 +14,7 @@
* @public
*/
export const defaults = {
artifact: 'net.serenity-bdd:serenity-cli:jar:4.0.43',
artifact: 'net.serenity-bdd:serenity-cli:jar:4.0.44',
repository: 'https://repo1.maven.org/maven2/',
cacheDir: 'node_modules/@serenity-js/serenity-bdd/cache',
sourceDir: 'target/site/serenity',
Expand Down
Expand Up @@ -3,13 +3,12 @@ import { ConfigurationError, DomainEventQueues } from '@serenity-js/core';
import type { DomainEvent } from '@serenity-js/core/lib/events';
import { ArtifactGenerated, AsyncOperationAttempted, AsyncOperationCompleted, AsyncOperationFailed, TestRunFinishes } from '@serenity-js/core/lib/events';
import type { FileSystem } from '@serenity-js/core/lib/io';
import { Path } from '@serenity-js/core/lib/io';
import { Path, SpecDirectory } from '@serenity-js/core/lib/io';
import { CorrelationId, Description, Name } from '@serenity-js/core/lib/model';
import { ensure, isDefined } from 'tiny-types';

import { EventQueueProcessors } from './processors';
import type { SerenityBDDReporterConfig } from './SerenityBDDReporterConfig';
import { SpecDirectory } from './SpecDirectory';

/**
* A {@apilink StageCrewMember} that produces [Serenity BDD](http://serenity-bdd.info/)-standard JSON reports
Expand Down
Expand Up @@ -24,6 +24,7 @@ export function tagOf<Context extends SerenityBDDReportContext>(tag: Tag): (cont

const themeTag = {
...tagReportFor(tag),
name: join('/', displayNameOfRecorded(ThemeTag, context.report.tags), tag.name),
displayName: tag.name,
};

Expand Down Expand Up @@ -163,7 +164,7 @@ function appendIfNotPresent(commaSeparatedStringOrEmpty: string, item: string):
function tagReportFor(tag: Tag): serenitybdd.TagSchema {
return {
...tag.toJSON(),
displayName: tag.name.replace(/_+/, ' '),
displayName: tag.name.replaceAll(/_+/g, ' '),
}
}

Expand All @@ -175,8 +176,10 @@ function unique(items: string[]) {
return [...new Set(items)];
}

function displayNameOfRecorded(typeOfTag: { Type: string }, tags: serenitybdd.TagSchema[]) {
function displayNameOfRecorded(typeOfTag: { Type: string }, tags: serenitybdd.TagSchema[]): string {
const found = (tags || []).find(t => t.type === typeOfTag.Type);

return found && found.displayName;
return found
? found.displayName
: '';
}

0 comments on commit 4e2f1e3

Please sign in to comment.