How to use @serenity-js/core - 10 common examples

To help you get started, we’ve selected a few @serenity-js/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jan-molak / serenity-js / packages / protractor / spec / adapter / reporter / ProtractorReporter.spec.ts View on Github external
let reporter:           ProtractorReporter,
        protractorRunner:   Runner,
        serenity:           Serenity;

    beforeEach(() => {
        protractorRunner    = sinon.createStubInstance(Runner);
        reporter            = new ProtractorReporter(protractorRunner);
        serenity            = new Serenity();

        serenity.setTheStage(reporter);
    });

    const details = new ScenarioDetails(
        new Name('scenario name'),
        new Category('scenario category'),
        new FileSystemLocation(new Path('./some/scenario.spec.ts')),
    );

    /** @test {ProtractorReporter} */
    it('ignores events outcomes Protractor doesn\'t care about', () => {

        expect(reporter.notifyOf(new SceneFinished(details, new ExecutionSkipped()))).to.be.undefined;  // tslint:disable-line:no-unused-expression

        expect(reporter.report()).to.deep.equal({
            failedCount: 0,
            specResults: [],
        });
    });

    /** @test {ProtractorReporter} */
    it('ignores domain events Protractor doesn\'t care about', () => {
github jan-molak / serenity-js / packages / protractor / spec / adapter / reporter / ProtractorReporter.spec.ts View on Github external
it('ignores events outcomes Protractor doesn\'t care about', () => {

        expect(reporter.notifyOf(new SceneFinished(details, new ExecutionSkipped()))).to.be.undefined;  // tslint:disable-line:no-unused-expression

        expect(reporter.report()).to.deep.equal({
            failedCount: 0,
            specResults: [],
        });
    });
github jan-molak / serenity-js / packages / serenity-bdd / spec / stage / crew / serenity-bdd-reporter / SerenityBDDReporter.spec.ts View on Github external
it('has been compromised', () => {

                // const assertionError = new AssertionError('expected true to equal false', false, true);
                const assertionError = new TestCompromisedError('expected true to equal false');

                given(reporter).isNotifiedOfFollowingEvents(
                    new SceneFinished(defaultCardScenario, new ExecutionCompromised(assertionError)),
                    new TestRunFinished(),
                );

                report = stageManager.notifyOf.firstCall.lastArg.artifact.map(_ => _);

                expect(report.result).to.equal('COMPROMISED');
                expect(report.testFailureCause.errorType).to.equal('TestCompromisedError');
                expect(report.testFailureCause.message).to.equal('expected true to equal false');
                expect(report.testFailureCause.stackTrace).to.be.an('array');
            });
github jan-molak / serenity-js / packages / assertions / spec / Ensure.spec.ts View on Github external
actual: 'not-name',
        artifact: { expected: `'name'`, actual: `'not-name'` },
    }, {
        description: 'list',
        expected: [{ name: 'Bob' }, { name: 'Alice' }],
        actual: [{ name: 'Alice' }],
        artifact: { expected: `[\n  { name: 'Bob' },\n  { name: 'Alice' }\n]`, actual: `[\n  { name: 'Alice' }\n]` },
    }, {
        description: 'promise',
        expected: Promise.resolve(true),
        actual: Promise.resolve(false),
        artifact: { expected: `true`, actual: `false` },
    }, {
        description: 'question',
        expected: Question.about('some value', actor => true),
        actual: Question.about('some value', actor => false),
        artifact: { expected: 'true', actual: 'false' },
    }]).
    /** @test {Ensure.that} */
    it('emits an artifact describing the actual and expected values', ({ actual, expected, artifact }) => {
        const recorder = new EventRecorder();
        theStage.assign(recorder);

        return expect(Enrique.attemptsTo(
            Ensure.that(actual, equals(expected)),  // we don't care about the expectation itself in this test
        )).to.be.rejected.then(() =>
            PickEvent.from(recorder.events)
                .next(ActivityRelatedArtifactGenerated, e => e.artifact.map(value => {
                    expect(value.expected).to.equal(artifact.expected);
                    expect(value.actual).to.equal(artifact.actual);
                })),
        );
github jan-molak / serenity-js / packages / serenity-bdd / spec / stage / crew / serenity-bdd-reporter / SerenityBDDReporter.spec.ts View on Github external
it('has been compromised', () => {

                // const assertionError = new AssertionError('expected true to equal false', false, true);
                const assertionError = new TestCompromisedError('expected true to equal false');

                given(reporter).isNotifiedOfFollowingEvents(
                    new SceneFinished(defaultCardScenario, new ExecutionCompromised(assertionError)),
                    new TestRunFinished(),
                );

                report = stageManager.notifyOf.firstCall.lastArg.artifact.map(_ => _);

                expect(report.result).to.equal('COMPROMISED');
                expect(report.testFailureCause.errorType).to.equal('TestCompromisedError');
                expect(report.testFailureCause.message).to.equal('expected true to equal false');
                expect(report.testFailureCause.stackTrace).to.be.an('array');
            });
github jan-molak / serenity-js / packages / protractor / spec / adapter / reporter / ProtractorReporter.spec.ts View on Github external
let reporter:           ProtractorReporter,
        protractorRunner:   Runner,
        serenity:           Serenity;

    beforeEach(() => {
        protractorRunner    = sinon.createStubInstance(Runner);
        reporter            = new ProtractorReporter(protractorRunner);
        serenity            = new Serenity();

        serenity.setTheStage(reporter);
    });

    const details = new ScenarioDetails(
        new Name('scenario name'),
        new Category('scenario category'),
        new FileSystemLocation(new Path('./some/scenario.spec.ts')),
    );

    /** @test {ProtractorReporter} */
    it('ignores events outcomes Protractor doesn\'t care about', () => {

        expect(reporter.notifyOf(new SceneFinished(details, new ExecutionSkipped()))).to.be.undefined;  // tslint:disable-line:no-unused-expression

        expect(reporter.report()).to.deep.equal({
            failedCount: 0,
            specResults: [],
        });
    });

    /** @test {ProtractorReporter} */
    it('ignores domain events Protractor doesn\'t care about', () => {
github jan-molak / serenity-js / packages / protractor / spec / adapter / ProtractorFrameworkAdapter.spec.ts View on Github external
.reduce((previous, current) => previous.then(() => {

                    const scenario = sample(current);

                    const details = new ScenarioDetails(
                        new Name(scenario.name),
                        new Category(scenario.category),
                        new FileSystemLocation(new Path(scenario.path)),
                    );

                    this.serenityInstance.announce(new SceneStarts(
                        details,
                        this.serenityInstance.currentTime(),
                    ));

                    // ... an actual test operunner would now execute the test and then announce the outcome

                    this.serenityInstance.announce(
                        new SceneFinished(details, scenario.outcome, this.serenityInstance.currentTime()),
                    );

                    return this.serenityInstance.waitForNextCue();

                }), Promise.resolve(void 0));
github jan-molak / serenity-js / packages / serenity-bdd / spec / stage / crew / serenity-bdd-reporter / SerenityBDDReporter / reporting_scene_sequences.spec.ts View on Github external
),
                ),
                new SceneStarts(scenario1),
                new SceneFinished(scenario1, new ExecutionSuccessful()),
            new SceneSequenceDetected(sequence),
                new SceneTemplateDetected(template),
                new SceneParametersDetected(
                    scenario2,
                    new ScenarioParameters(
                        new Name('Serenity/JS contributors'),
                        new Description(`Some of the people who have contributed their time and talent to the Serenity/JS project`),
                        { Developer: 'wakaleo', Twitter_Handle: '@wakaleo' },
                    ),
                ),
                new SceneStarts(scenario2),
                new SceneFinished(scenario2, new ExecutionSuccessful()),
            new TestRunFinished(),
        );

        const report: SerenityBDDReport = stageManager.notifyOf.firstCall.lastArg.artifact.map(_ => _);

        expect(report.name).to.equal(name.value);
        expect(report.dataTable).to.exist;  // tslint:disable-line:no-unused-expression
        expect(report.dataTable.scenarioOutline).to.equal(template.value);
        expect(report.dataTable.headers).to.deep.equal([
            'Developer',
            'Twitter_Handle',
        ]);

        expect(report.dataTable.dataSetDescriptors).to.deep.equal([{
            startRow: 0,
            rowCount: 2,
github jan-molak / serenity-js / packages / protractor / spec / adapter / ProtractorFrameworkAdapter.spec.ts View on Github external
const details = new ScenarioDetails(
                        new Name(scenario.name),
                        new Category(scenario.category),
                        new FileSystemLocation(new Path(scenario.path)),
                    );

                    this.serenityInstance.announce(new SceneStarts(
                        details,
                        this.serenityInstance.currentTime(),
                    ));

                    // ... an actual test operunner would now execute the test and then announce the outcome

                    this.serenityInstance.announce(
                        new SceneFinished(details, scenario.outcome, this.serenityInstance.currentTime()),
                    );

                    return this.serenityInstance.waitForNextCue();

                }), Promise.resolve(void 0));
        }
github jan-molak / serenity-js / packages / protractor / src / stage / Photographer.ts View on Github external
.when(InteractionFinished,   ({ value, outcome }: InteractionFinished) => {
                // todo: clean up
                if (this.stage.theShowHasStarted() && outcome.isWorseThan(ImplementationPending)) {

                    const id = CorrelationId.create();

                    this.stage.manager.notifyOf(new AsyncOperationAttempted(
                        new Description(`[${ this.constructor.name }] Taking screenshot of '${ value.name.value }'...`),
                        id,
                    ));

                    BrowseTheWeb.as(this.stage.theActorInTheSpotlight()).takeScreenshot()
                        .then(screenshot => {
                            this.stage.manager.notifyOf(new ArtifactGenerated(
                                value.name,
                                Photo.fromBase64(screenshot),
                            ));

                            this.stage.manager.notifyOf(new AsyncOperationCompleted(
                                new Description(`[${ this.constructor.name }] Took screenshot of '${ value.name.value }'`),
                                id,
                            ));
                        })
                        .catch(error => {