Nf-test: Capture all process/workflow outputs without capturing md5sums of files in snapshots

nf-test snapshots automatically create md5sums of files when they get an absolute path to a file. This can cause some issues when the output files are not 100% stable between reruns (e.g. when the date is included somewhere in the file). This snippet shows other easy ways to check your files.

Check if the file exists

The easiest way is to simply check the existence of the file. I personally prefer to also snapshot the filename to make sure the filename is correct. The filename will only be shown if the file exists.

You can add an assert that looks like this to your main.nf.test file:

assert snapshot(
    process.out.<emit_name>.collect { it.collect { it instanceof String && file(it).exists() ? file(it).name : it }}
).match()

Keep in mind that you should change <emit_name> with whatever the name of your output emit name is.

An example snapshot from this snippet:

Check the contents of the file

A slight variation of the previous snippet can be used to check the content of these files. (Mind that this snippet does not work for files that aren’t plain text)

assert snapshot(
    process.out.<emit_name>.collect { it.collect { it instanceof String && file(it).exists() ? file(it).text.split("\n")[-8..-1] : it }}
).match()

This snippet shows the last 8 lines of the file. You can change this by adjusting the values in [-8..-1].

An example snapshot from this snippet:

3 Likes