CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-jest-circus

The next-gen flux-based test runner for Jest that provides test framework globals and event-driven test execution

82

1.90x
Overview
Eval results
Files

task.mdevals/scenario-9/

Flaky Test Handler

Build a test suite that uses automatic retry functionality to handle tests for a flaky API client.

Background

You are testing an API client that occasionally fails due to network issues. Rather than having your test suite fail on every transient error, you need to configure tests to automatically retry when they fail.

Requirements

Implement a test suite in test/api-client.test.js that:

  1. Configures automatic retries for tests using retry functionality
  2. Tests an API client with methods that may fail intermittently
  3. Validates that flaky operations eventually succeed after retries
  4. Handles tests with different retry counts based on operation type

Implementation Details

First, create a file src/api-client.js that exports an ApiClient class with the following behavior:

  • fetchUser(userId) - Returns user data { id: userId, name: "User" }, but fails ~50% of the time with "Network timeout"
  • fetchPosts(userId) - Returns posts array [{ id: 1, title: "Post" }], but fails ~50% of the time with "Service unavailable"
  • createPost(title) - Returns new post { id: 2, title }, but fails ~70% of the time with "Rate limited"

The simulated failures should be random to mimic real flaky behavior.

Test Cases

Write tests in test/api-client.test.js that cover the following scenarios:

  • Fetches user data successfully with automatic retries @test
  • Fetches user posts successfully with automatic retries @test
  • Creates a new post successfully with more retries due to higher failure rate @test

Configure retry counts appropriately: use 3 retries for most tests, but 5 retries for the highly flaky createPost test.

@generates

API

/**
 * API client with methods that may fail intermittently
 */
class ApiClient {
  /**
   * Fetches user data by ID
   * @param {string} userId - The user ID
   * @returns {Promise<object>} User data object
   */
  fetchUser(userId) {}

  /**
   * Fetches posts for a user
   * @param {string} userId - The user ID
   * @returns {Promise<array>} Array of post objects
   */
  fetchPosts(userId) {}

  /**
   * Creates a new post
   * @param {string} title - The post title
   * @returns {Promise<object>} Created post object
   */
  createPost(title) {}
}

module.exports = { ApiClient };

Dependencies { .dependencies }

jest { .dependency }

Provides the testing framework and retry functionality.

Install with Tessl CLI

npx tessl i tessl/npm-jest-circus

tile.json