Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable SnapshotDirectory to support Xcode cloud workflow #716

Closed
wants to merge 3 commits into from

Conversation

rcarver
Copy link

@rcarver rcarver commented Feb 28, 2023

Following the thread in #553 it seems there are two steps to using snapshots on Xcode cloud:

  1. Snapshot files must be found in the ci_scripts directory, which is the only set of files available during a test run. This can be done via symlink.
  2. assertSnapshot must be called with a snapshotDirectory argument pointing to the location of the file's snapshots within the ci_scripts directory.

The project I'm working with has many swift packages, many of which use snapshots. I wanted a way to run the snapshot tests on Xcode cloud without changing the local workflow.

This change allows configuration of the snapshot directory via ENV var, with an option specifically for this workflow.


1. Symlink snapshots

This script finds all __Snapshot__ directories and symlinks them into ci_scripts/snapshots. Run it from your project root.

#!/bin/sh
set -e
snapshots=ci_scripts/snapshots
search_path_from_snapshots=../..
rm -rf $snapshots
mkdir $snapshots
cd $snapshots
find $search_path_from_snapshots -type d -name "__Snapshots__" | grep -v .build | while read dir; do
    parent=$(dirname "$dir")
    parent_name=${parent##*/}
    echo $parent_name $dir
    ln -s "$dir" "$parent_name"
done

2. Configure the snapshots location for CI

Set an ENV var to change where the library finds snapshots:

SNAPSHOTTESTING_PACKAGE_PATH=/Volumes/workspace/respository/ci_scripts/snapshots

Note - I'm currently setting this in a Test Plan, but I think it can be set in a Scheme. Ideally in the Xcode cloud Workflow setup but those vars don't seem to be available to the test run?

The result is that snapshots from all packages are flattened and symlinked into the ci_scripts dir, then SnapshotTesting constructs a matching path for assertion when run via CI.

@jdowd7
Copy link

jdowd7 commented May 9, 2023

@rcarver used your fork, tried to implement per above... script works great, and my build is as expected.
But when I run tests I get the below:

image

@rcarver
Copy link
Author

rcarver commented May 10, 2023

@jdowd7 strange! I actually moved this code into a separate repo if you want to try it that way? Based on that error I'd try a clean build and restart Xcode.

Closing this PR since the standalone approach works well.

@rcarver rcarver closed this May 10, 2023
@jdowd7
Copy link

jdowd7 commented May 10, 2023

@rcarver thanks! I'll give this a try.
Drop in meaning manually import and not using SPM?

@rcarver
Copy link
Author

rcarver commented May 10, 2023

@jdowd7 yes use via SPM. It defines a new assertSnapshots function so you should just be able to swap import SnapshotTesting to import SnapshotTestingEnvOverlay

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants