swift-testing icon indicating copy to clipboard operation
swift-testing copied to clipboard

Add image attachments support for Wasm (JavaScript)

Open grynspan opened this issue 1 month ago • 2 comments

This issue tracks adding AttachableAsImage support on Wasm via JavaScript bridging.

Standardized JavaScript has several classes (types? prototypes? whatever the JS terminology is) that represent images that can be serialized. For example, HTMLCanvasElement has a toBlob() function that converts the contents of the canvas to PNG, JPEG, etc.

We would need to be able to link to JavaScriptKit in some fashion and would need to see how HTMLCanvasElement is represented on the Swift side before we could add protocol conformances: it's possible we would need to add blanket conformance for JSObject via isInstanceOf(_:).

grynspan avatar Oct 31 '25 15:10 grynspan

As JavaScriptKit is a separate package and is not available in either Swift toolchain or Swift SDK, I don't think adding any dependencies on it is feasible. It would be great for Testing to provide an abstract enough protocol that JavaScriptKit could provide an implementation of.

MaxDesiatov avatar Oct 31 '25 15:10 MaxDesiatov

The protocol described in ST-0017 should be sufficiently abstract. It may be the case that the code in question lives in the JavaScriptKit package rather than here, and just leverages that protocol. That's perfectly fine. This issue tracks the effort overall rather than a specific solution. :)

grynspan avatar Oct 31 '25 19:10 grynspan