Skip to content

Option to overwrite artifacts if they exist #3311

@SMJ93

Description

@SMJ93

Describe your idea

It would be great if we overwrite artifacts such as screenshots or videos by passing through a flag e.g. --overwrite-artifacts.

I've managed to get this working locally by adding the following patch to node_modules/detox/src/artifacts/templates/artifact/FileArtifact.js -> moveTemporaryFile method:

diff --git a/node_modules/detox/src/artifacts/templates/artifact/FileArtifact.js b/node_modules/detox/src/artifacts/templates/artifact/FileArtifact.js
index 7f07040..593662d 100644
--- a/node_modules/detox/src/artifacts/templates/artifact/FileArtifact.js
+++ b/node_modules/detox/src/artifacts/templates/artifact/FileArtifact.js
@@ -87,6 +87,12 @@ class FileArtifact extends Artifact {
       return true;
     }
 
+    if (await fs.exists(destination)) {
+      logger.debug({ event: 'MOVE_FILE_OVERWRITE' }, `moving "${source}" to ${destination}`);
+      await fs.move(source, destination, { overwrite: true });
+      return true;
+    }
+
     logger.warn({ event: 'MOVE_FILE_EXISTS' }, `cannot overwrite: "${source}" => "${destination}"`);
     await fs.remove(source);
     return false;

It checks if the file exists at the destination and then passes through the flag option overwrite: true to fs.move

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions