How to use tiny-types - 10 common examples

To help you get started, we’ve selected a few tiny-types 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 / core / src / screenplay / activities / OutcomeMatcher.ts View on Github external
outcomeFor(error: Error | any): ProblemIndication {
        return match(error)
            .when(ImplementationPendingError, _ => new ImplementationPending(error))
            .when(TestCompromisedError, _ => new ExecutionCompromised(error))
            .when(AssertionError, _ => new ExecutionFailedWithAssertionError(error))
            .when(Error, _ => /AssertionError/.test(error.constructor.name) // mocha
                    ? new ExecutionFailedWithAssertionError(error)
                    : new ExecutionFailedWithError(error))
            .else(_ => new ExecutionFailedWithError(error));
    }
}
github jan-molak / serenity-js / packages / cucumber / src / listeners / CucumberEventProtocolAdapter.ts View on Github external
eventBroadcaster.on('test-step-finished', ({ index, result, testCase }) => {

                ensure('test-step-finished :: index', index, isDefined());
                ensure('test-step-finished :: result', result, isDefined());
                ensure('test-step-finished :: testCase', testCase, isDefined());

                const
                    map      = cache.get(new Path(testCase.sourceLocation.uri)),
                    scenario = map.get(Scenario).onLine(testCase.sourceLocation.line),
                    step     = scenario.steps[index];

                if (step instanceof Step) { // ignore hooks
                    notifier.stepFinished(step, this.outcomeFrom(result));
                }
            });
github jan-molak / serenity-js / packages / protractor / src / stage / Photographer.ts View on Github external
notifyOf(event: DomainEvent): void {
        match(event)
            .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),
github jan-molak / serenity-js / packages / console-reporter / src / stage / crew / console-reporter / ConsoleReporter.ts View on Github external
notifyOf(event: DomainEvent): void {
        match(event)
            .when(SceneStarts, (e: SceneStarts) => {

                this.firstError = new FirstError();
                this.startTimes.recordStartOf(e);

                // Print scenario header
                this.printer.println(this.theme.separator('-'));
                this.printer.println(e.value.location.path.value, e.value.location.line ? `:${ e.value.location.line }` : '');
                this.printer.println();
                this.printer.println(this.theme.heading(e.value.category.value, ': ', e.value.name.value));
                this.printer.println();

            })
            .when(TaskStarts, (e: TaskStarts) => {

                this.printer.indent();
github jan-molak / serenity-js / packages / core / src / model / Timestamp.ts View on Github external
function isInstanceOf(type: Function & (new (...args: any[]) => T)): Predicate {                                           // tslint:disable-line:ban-types
    return Predicate.to(`be an instance of ${ type.name }`, (value: T) =>
        value instanceof type);
}
github jan-molak / serenity-js / packages / core / src / model / tags / Tags.ts View on Github external
public static from(text: string): Tag[] {
        const [ , type, val ] = Tags.Pattern.exec(text);

        return match(type.toLowerCase())
            .when('manual',     _ => [ new ManualTag() ])
            .when(/issues?/,    _ => val.split(',').map(value => new IssueTag(value.trim())))
            .else(value           => [ new ArbitraryTag(value.trim()) ]);
    }
}
github jan-molak / serenity-js / packages / core / src / model / Photo.ts View on Github external
function looksLikeBase64Encoded(): Predicate {
    const regex = /^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$/;

    return Predicate.to(`be an ISO-8601-compliant date`, (value: string) => regex.test(value));
}
github jan-molak / serenity-js / packages / assertions / spec / expectations / equals.spec.ts View on Github external
describe('equals', () => {

    const Astrid = stage().theActorCalled('Astrid');

    class Name extends TinyTypeOf() {}

    given([
        { description: 'string',    expected: 'hello',          actual: 'hello'             },
        { description: 'number',    expected: 42,               actual: 42                  },
        { description: 'boolean',   expected: false,            actual: false               },
        { description: 'object',    expected: { k: 'v' },       actual: { k: 'v' }          },
        { description: 'TinyType',  expected: new Name('Jan'),  actual: new Name('Jan')     },
        { description: 'array',     expected: [ null, 2, '3' ], actual: [ null, 2, '3' ]    },
        { description: 'Date',      expected: new Date('Jan 27, 2019'), actual: new Date('Jan 27, 2019') },
    ]).
    it('compares the value of "actual" and "expected" and allows for the actor flow to continue when they match', ({ actual, expected }) => {
        return expect(Astrid.attemptsTo(
            Ensure.that(actual, equals(expected)),
        )).to.be.fulfilled;
    });
github jan-molak / serenity-js / packages / core / src / stage / crew / artifact-archiver / Hash.ts View on Github external
constructor(public readonly value: string) {
        super();
        ensure(this.constructor.name, value, isDefined());
    }
github jan-molak / serenity-js / packages / core / src / events / ActivityStarts.ts View on Github external
constructor(
        public readonly value: ActivityDetails,
        timestamp?: Timestamp,
    ) {
        super(timestamp);
        ensure('value', value, isDefined());
    }
}