(self, file_path: Union[pathlib.Path, str] = None)
| 91 | ) |
| 92 | |
| 93 | async def _do_stop_chunk(self, file_path: Union[pathlib.Path, str] = None) -> None: |
| 94 | self._reset_stack_counter() |
| 95 | |
| 96 | if not file_path: |
| 97 | # Not interested in any artifacts |
| 98 | await self._channel.send("tracingStopChunk", None, {"mode": "discard"}) |
| 99 | if self._stacks_id: |
| 100 | await self._connection.local_utils.trace_discarded(self._stacks_id) |
| 101 | return |
| 102 | |
| 103 | is_local = not self._connection.is_remote |
| 104 | |
| 105 | if is_local: |
| 106 | result = await self._channel.send_return_as_dict( |
| 107 | "tracingStopChunk", None, {"mode": "entries"} |
| 108 | ) |
| 109 | await self._connection.local_utils.zip( |
| 110 | { |
| 111 | "zipFile": str(file_path), |
| 112 | "entries": result["entries"], |
| 113 | "stacksId": self._stacks_id, |
| 114 | "mode": "write", |
| 115 | "includeSources": self._include_sources, |
| 116 | } |
| 117 | ) |
| 118 | return |
| 119 | |
| 120 | result = await self._channel.send_return_as_dict( |
| 121 | "tracingStopChunk", |
| 122 | None, |
| 123 | { |
| 124 | "mode": "archive", |
| 125 | }, |
| 126 | ) |
| 127 | |
| 128 | artifact = cast( |
| 129 | Optional[Artifact], |
| 130 | from_nullable_channel(result.get("artifact")), |
| 131 | ) |
| 132 | |
| 133 | # The artifact may be missing if the browser closed while stopping tracing. |
| 134 | if not artifact: |
| 135 | if self._stacks_id: |
| 136 | await self._connection.local_utils.trace_discarded(self._stacks_id) |
| 137 | return |
| 138 | |
| 139 | # Save trace to the final local file. |
| 140 | await artifact.save_as(file_path) |
| 141 | await artifact.delete() |
| 142 | |
| 143 | await self._connection.local_utils.zip( |
| 144 | { |
| 145 | "zipFile": str(file_path), |
| 146 | "entries": [], |
| 147 | "stacksId": self._stacks_id, |
| 148 | "mode": "append", |
| 149 | "includeSources": self._include_sources, |
| 150 | } |
no test coverage detected