<commit_before>import { describe, it } from 'mocha';

import { Ability, Answerable, AssertionError, Cast, Duration, Expectation, Interaction, Question, Serenity, Timestamp, UsesAbilities, Wait } from '../../../src';
import { expect } from '../../expect';
import { Ensure } from '../Ensure';

/** @test {Wait} */
describe('Wait', () => {

    let serenity: Serenity;

    beforeEach(async () => {
        serenity = new Serenity();
        serenity.engage(Cast.whereEveryoneCan(new UseAStopwatch()))

        await serenity.theActorCalled('Wendy')
            .attemptsTo(
                Ensure.equal(Stopwatch.elapsedTime(), Duration.ofMilliseconds(0)),
            )
    });

    afterEach(() =>
        serenity.theActorCalled('Wendy')
            .attemptsTo(Stopwatch.stop())
    );

    describe('for', () => {

        /** @test {Wait.for} */
        it('pauses the actor flow for the length of an explicitly-set duration', () =>
            serenity.theActorCalled('Wendy')
                .attemptsTo(
                    Stopwatch.start(),
                    Wait.for(Duration.ofMilliseconds(100)),
                    Stopwatch.stop(),
                    Ensure.closeTo(Stopwatch.elapsedTime().inMilliseconds(), 100, 10),
                ));

        /** @test {Wait#toString} */
        it('provides a sensible description of the interaction being performed', () => {
            expect(Wait.for(Duration.ofMilliseconds(300)).toString())
                .to.equal(`#actor waits for 300ms`);
        });
    });

    describe('until', () => {

        /** @test {Wait.until} */
        it('pauses the actor flow until the expectation is met, polling for result every 500ms by default', () =>
            serenity.theActorCalled('Wendy')
                .attemptsTo(
                    Stopwatch.start(),
                    Wait.until(Stopwatch.elapsedTime().inMilliseconds().describedAs('elapsed time [ms]'), isGreaterThan(250)),
                    Stopwatch.stop(),
                    Ensure.closeTo(Stopwatch.elapsedTime().inMilliseconds(), 500, 10),
                    Ensure.lessThan(Stopwatch.elapsedTime().inMilliseconds(), 1000),
                ));

        /** @test {Wait.until} */
        it('pauses the actor flow until the expectation is met, with a configurable polling interval', () =>
            serenity.theActorCalled('Wendy')
                .attemptsTo(
                    Stopwatch.start(),
                    Wait.until(Stopwatch.elapsedTime().inMilliseconds().describedAs('elapsed time [ms]'), isGreaterThan(250)).pollingEvery(Duration.ofMilliseconds(50)),
                    Stopwatch.stop(),
                    Ensure.closeTo(Stopwatch.elapsedTime().inMilliseconds(), 250, 30),
                    Ensure.lessThan(Stopwatch.elapsedTime().inMilliseconds(), 500),
                ));
<commit_msg>test(core): adjusted timeout tolerance to account for the slower GitHub CI VMs<commit_after>import { describe, it } from 'mocha';

import { Ability, Answerable, AssertionError, Cast, Duration, Expectation, Interaction, Question, Serenity, Timestamp, UsesAbilities, Wait } from '../../../src';
import { expect } from '../../expect';
import { Ensure } from '../Ensure';

/** @test {Wait} */
describe('Wait', () => {

    let serenity: Serenity;

    beforeEach(async () => {
        serenity = new Serenity();
        serenity.engage(Cast.whereEveryoneCan(new UseAStopwatch()))

        await serenity.theActorCalled('Wendy')
            .attemptsTo(
                Ensure.equal(Stopwatch.elapsedTime(), Duration.ofMilliseconds(0)),
            )
    });

    afterEach(() =>
        serenity.theActorCalled('Wendy')
            .attemptsTo(Stopwatch.stop())
    );

    describe('for', () => {

        /** @test {Wait.for} */
        it('pauses the actor flow for the length of an explicitly-set duration', () =>
            serenity.theActorCalled('Wendy')
                .attemptsTo(
                    Stopwatch.start(),
                    Wait.for(Duration.ofMilliseconds(100)),
                    Stopwatch.stop(),
                    Ensure.closeTo(Stopwatch.elapsedTime().inMilliseconds(), 100, 10),
                ));

        /** @test {Wait#toString} */
        it('provides a sensible description of the interaction being performed', () => {
            expect(Wait.for(Duration.ofMilliseconds(300)).toString())
                .to.equal(`#actor waits for 300ms`);
        });
    });

    describe('until', () => {

        /** @test {Wait.until} */
        it('pauses the actor flow until the expectation is met, polling for result every 500ms by default', () =>
            serenity.theActorCalled('Wendy')
                .attemptsTo(
                    Stopwatch.start(),
                    Wait.until(Stopwatch.elapsedTime().inMilliseconds().describedAs('elapsed time [ms]'), isGreaterThan(250)),
                    Stopwatch.stop(),
                    Ensure.closeTo(Stopwatch.elapsedTime().inMilliseconds(), 500, 10),
                    Ensure.lessThan(Stopwatch.elapsedTime().inMilliseconds(), 1000),
                ));

        /** @test {Wait.until} */
        it('pauses the actor flow until the expectation is met, with a configurable polling interval', () =>
            serenity.theActorCalled('Wendy')
                .attemptsTo(
                    Stopwatch.start(),
                    Wait.until(Stopwatch.elapsedTime().inMilliseconds().describedAs('elapsed time [ms]'), isGreaterThan(250)).pollingEvery(Duration.ofMilliseconds(50)),
                    Stopwatch.stop(),
                    Ensure.closeTo(Stopwatch.elapsedTime().inMilliseconds(), 275, 30),
                    Ensure.lessThan(Stopwatch.elapsedTime().inMilliseconds(), 500),
                ));

{'fraction_non_alphanumeric': 0.143155331361976, 'fraction_numerical': 0.014959123325795791, 'mean_word_length': 2.0980603448275863, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1083336', 'n_tokens_mistral': 1660, 'n_tokens_neox': 1539, 'n_words': 305}