Skip to content

Intermittent Issue: E2E Test Failures in Likeline #1

@pmartinsdev

Description

@pmartinsdev

Hello Likeline community,

I'm encountering an intriguing problem while working on the end-to-end (E2E) tests for the Likeline project and would like to share it with you to gain valuable insights and solution suggestions.

The Problem:

During the development of E2E tests for Likeline, I've encountered an issue where the tests exhibit intermittent behavior. Specifically, the E2E tests sometimes run perfectly with a 100% success rate, but other times, they fail unexpectedly.

Context:

  1. E2E tests are essential to ensure the quality and reliability of the Likeline application.
  2. I'm currently using the supertest and jest libraries to implement and run the E2E tests.
  3. The tests involve interacting with the application's endpoints, simulating real user flows.

Problem Details:

  1. The intermittent behavior of E2E tests is frustrating, as they can pass correctly in one run but fail inexplicably in another.
  2. There appears to be variability in the success of the tests, without a clear logic behind these fluctuations.
  3. Tests that use the same logic and sequence of steps sometimes yield different results.

Temporary Solution:

In order to move forward with development and achieve more consistent results in the E2E tests, I've implemented a temporary workaround. I've separated the tests into a new context, using an alternative implementation for the FileService logic.

Steps Taken:

  1. I created a new implementation for the tests, where the FileService logic was replaced with a mock.
  2. I ensured that tests in this new implementation used the alternative logic to avoid potential issues related to interacting with the actual file system.
  3. I conditionally implemented the use of the new implementation only during the execution of E2E tests.

Code Example (New Test Implementation):

import { FileService } from "@domains/interfaces/file-service";

@injectable()
class MockFileService implements FileService {
  async saveFile(tempFilename: string, filename: string): Promise<string> {
    // Alternative implementation for tests
    return path.join(UPLOADS_FOLDER, filename);
  }

  async deleteFile(filename: string): Promise<void> {
    // Alternative implementation for tests
    // Simulating file deletion
  }
}

Code Example ( Container injecting registration )

// Conditional registration of the service
if (process.env.NODE_ENV === 'test') {
  container.registerSingleton<FileService>('FileService', MockFileService);
} else {
  container.registerSingleton<FileService>('FileService', FSFileService);
}

Help Request:

Despite the temporary solution, I'm still seeking community guidance to fully understand and resolve this intermittent issue in the Likeline E2E tests. If you've encountered similar situations or have relevant knowledge to share, I'd greatly appreciate your input.

Repository: Likeline

Thank you in advance for any contributions or suggestions that can help me identify the root cause and find a definitive solution to this unstable behavior in the tests.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions