You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
We build all of our files in one CI/CD job and then execute some (integration) tests later on a differing file structure.
Because the SnapshotFullName "FolderPath" uses the stack information (build time file location) and is absolute to the build time file system, the test fails since it can't locate the snapshot.
To Reproduce
Steps to reproduce the behavior:
Make a snapshot test
Build it and run the test to produce a snapshot
Copy the entire project somewhere else and run off of the copied build (/bin/Release/whatever/something.dll)
Test Fails
Expected behavior
The test should pass since the snapshot exists relative to the project still
Additional context
I have a workaround that our team uses that so far seems to be pretty effective... Essentially I modify the paths to absolute, but relative to the runtime. I imagine there's a "more correct" approach, but this was the best I could come up with quickly.
public static class Snapshot
{
public static void Match(object snapshot, Func<MatchOptions, MatchOptions> matchOptions = null)
{
var snapshotFullName = Snapshooter.MSTest.Snapshot.FullName();
var fileName = snapshotFullName.Filename;
string localizedPathSplit = GetRuntimePath(snapshotFullName);
var snapshotNameFull = new SnapshotFullName(fileName, localizedPathSplit);
Snapshooter.MSTest.Snapshot.Match(snapshot, snapshotNameFull, matchOptions);
}
private static string GetRuntimePath(SnapshotFullName snapshotFullName)
{
string projectName = Assembly.GetEntryAssembly().GetName().Name;
var pathSplit = snapshotFullName.FolderPath.Split(new[] { '\\', '/' }, StringSplitOptions.RemoveEmptyEntries);
var projectPosition = Array.FindIndex(pathSplit, x => string.Equals(x, projectName, StringComparison.InvariantCultureIgnoreCase));
var paths = pathSplit.Skip(projectPosition).ToArray();
var localizedPathSplit = Path.Combine("../../../", Path.Combine(paths)); // chop off /bin/Release/net9.0
return localizedPathSplit;
}
}
The text was updated successfully, but these errors were encountered:
Describe the bug
We build all of our files in one CI/CD job and then execute some (integration) tests later on a differing file structure.
Because the SnapshotFullName "FolderPath" uses the stack information (build time file location) and is absolute to the build time file system, the test fails since it can't locate the snapshot.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
The test should pass since the snapshot exists relative to the project still
Additional context
I have a workaround that our team uses that so far seems to be pretty effective... Essentially I modify the paths to absolute, but relative to the runtime. I imagine there's a "more correct" approach, but this was the best I could come up with quickly.
The text was updated successfully, but these errors were encountered: