BarredEwe / Prefire

🔥 A library based on SwiftUI Preview, for easy generation: Playbook view, Snapshot and Accessibility tests
Apache License 2.0
290 stars 18 forks source link

Spaces in #Preview name break the PreviewTests.generated file #50

Closed ynnckcmprnl closed 6 months ago

ynnckcmprnl commented 6 months ago

Context 🕵️‍♀️

I'm integrating Prefire 2.2.1 in a SwiftUI Design System package.

What 🌱

A space in the preview name isn't escaped or replaced with an underscore, causing compile errors in the generated code. Compile error: Found an unexpected second identifier in function declaration; is there an accidental break?

Example:

#Preview("Redacted regular") {
    ...
}

Generates:

func test_Redacted regular_Preview() {
        let preview = {
            ...
        }

        if let failure = assertSnapshots(matching: AnyView(preview()), name: "Redacted regular", isScreen: true, device: deviceConfig) {
            XCTFail(failure)
        }
    }
ynnckcmprnl commented 6 months ago

Weird enough, I have a few #Previews with spaces in the name for which Prefire doesn't generate any code at all.

BarredEwe commented 6 months ago

@ynnckcmprnl Thanks for starting the issue! I posted a new version with a fix for this: https://github.com/BarredEwe/Prefire/releases/tag/2.3.0

ynnckcmprnl commented 6 months ago

I tried with the 2.3.0 release. But it's not generating test code for all my #Preview's, something I encountered with previous versions too. I can't quite put my finger on it why, but I'm missing snapshots of previews and can't seem to trigger the generation of the test code in PreviewTests.generated.

BarredEwe commented 6 months ago

I tried with the 2.3.0 release. But it's not generating test code for all my #Preview's, something I encountered with previous versions too. I can't quite put my finger on it why, but I'm missing snapshots of previews and can't seem to trigger the generation of the test code in PreviewTests.generated.

I figured out what the problem was. I'll need some time to fix it.

BarredEwe commented 6 months ago

I tried with the 2.3.0 release. But it's not generating test code for all my #Preview's, something I encountered with previous versions too. I can't quite put my finger on it why, but I'm missing snapshots of previews and can't seem to trigger the generation of the test code in PreviewTests.generated.

I managed to fix this. You can already try the fix in the new release: https://github.com/BarredEwe/Prefire/releases/tag/2.4.0

davidnext commented 6 months ago

I tried with the 2.3.0 release. But it's not generating test code for all my #Preview's, something I encountered with previous versions too. I can't quite put my finger on it why, but I'm missing snapshots of previews and can't seem to trigger the generation of the test code in PreviewTests.generated.

I am facing the same issue. No generated tests for #Preview. Default PreviewProvider works fine.

Update: It is indeed fixed with 2.4.0

BarredEwe commented 6 months ago

I am closing the issue, as the problem has been solved ✅