-
Notifications
You must be signed in to change notification settings - Fork 0
Description
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:
- E2E tests are essential to ensure the quality and reliability of the Likeline application.
- I'm currently using the supertest and jest libraries to implement and run the E2E tests.
- The tests involve interacting with the application's endpoints, simulating real user flows.
Problem Details:
- The intermittent behavior of E2E tests is frustrating, as they can pass correctly in one run but fail inexplicably in another.
- There appears to be variability in the success of the tests, without a clear logic behind these fluctuations.
- 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:
- I created a new implementation for the tests, where the
FileServicelogic was replaced with a mock. - I ensured that tests in this new implementation used the alternative logic to avoid potential issues related to interacting with the actual file system.
- 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.