Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support assert.expect with reruns #18

Merged
merged 1 commit into from
Nov 6, 2024
Merged

feat: support assert.expect with reruns #18

merged 1 commit into from
Nov 6, 2024

Conversation

jembezmamy
Copy link
Collaborator

This MR adds support for assert.expect.

Currently assert.expect counts all assertions including these performed in previous tries:

  retry('should pass with retries', function (assert, currentRun) {
    assert.expect(2)
    assert.ok(true) // run twice
    if (currentRun === 1) { throw new Error('fail') }
    assert.ok(true) // run once
  })

In this example the total number of assertions is 3: 1 for the first run + 2 for the second one. The test fails even though the second attempt should be considered successful.

To mitigate this issue, I proxy the expect method and add the number of the assertions already performed in the previous runs:

  expectFn (target) {
    return count => {
      target.expect(count + target.test.assertions.length)
    }
  }

Copy link
Owner

@mrloop mrloop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Could you add a more complex test with different with more failures on different runs? Something like:

  retry('should pass with retries', function (assert, currentRun) {
    calls.push(['with', currentRun])

    assert.expect(3)
    assert.ok(true)
    if (currentRun === 1) { throw new Error('fail') }
    assert.ok(true)
    if (currentRun === 2) { throw new Error('fail') }
    assert.ok(true)
  })

@jembezmamy
Copy link
Collaborator Author

Good point, I made the test case more complex 👍

@mrloop mrloop added the bug Something isn't working label Nov 6, 2024
@mrloop
Copy link
Owner

mrloop commented Nov 6, 2024

Great thanks

@mrloop mrloop merged commit abdd018 into master Nov 6, 2024
1 check passed
@mrloop mrloop added enhancement New feature or request and removed bug Something isn't working labels Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants