Skip to content

Commit b015e77

Browse files
committed
update nf-test side quest
1 parent f9329fa commit b015e77

File tree

1 file changed

+23
-26
lines changed

1 file changed

+23
-26
lines changed

docs/side_quests/nf-test.md

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ nf-test generate pipeline main.nf
113113
```console title="Output"
114114
> nf-test generate pipeline main.nf
115115

116-
Load source file '/workspace/gitpod/hello-nextflow/hello-nf-test-part1/main.nf'
117-
Wrote pipeline test file '/workspace/gitpod/hello-nextflow/hello-nf-test-part1/tests/main.nf.test
116+
Load source file '/workspaces/training/side-quests/nf-test/main.nf'
117+
Wrote pipeline test file '/workspaces/training/side-quests/nf-test/tests/main.nf.test
118118

119119
SUCCESS: Generated 1 test files.
120120
```
@@ -348,12 +348,12 @@ then {
348348
then {
349349
assert workflow.success
350350
assert workflow.trace.tasks().size() == 6
351-
assert file("${params.outdir}/Bonjour-output.txt").exists()
352-
assert file("results/Hello-output.txt").exists()
353-
assert file("results/Holà-output.txt").exists()
354-
assert file("results/UPPER-Bonjour-output.txt").exists()
355-
assert file("results/UPPER-Hello-output.txt").exists()
356-
assert file("results/UPPER-Holà-output.txt").exists()
351+
assert file("$launchDir/results/Bonjour-output.txt").exists()
352+
assert file("$launchDir/results/Hello-output.txt").exists()
353+
assert file("$launchDir/results/Holà-output.txt").exists()
354+
assert file("$launchDir/results/UPPER-Bonjour-output.txt").exists()
355+
assert file("$launchDir/results/UPPER-Hello-output.txt").exists()
356+
assert file("$launchDir/results/UPPER-Holà-output.txt").exists()
357357
}
358358
```
359359

@@ -410,14 +410,14 @@ nf-test generate process main.nf
410410
```console title="Output"
411411
> nf-test generate process main.nf
412412

413-
Load source file '/workspace/gitpod/hello-nextflow/hello-nf-test-part1/main.nf'
414-
Wrote process test file '/workspace/gitpod/hello-nextflow/hello-nf-test-part1/tests/main.sayhello.nf.test
415-
Wrote process test file '/workspace/gitpod/hello-nextflow/hello-nf-test-part1/tests/main.converttoupper.nf.test
413+
Load source file '/workspaces/training/side-quests/nf-test/main.nf'
414+
Wrote process test file '/workspaces/training/side-quests/nf-test/tests/main.sayhello.nf.test
415+
Wrote process test file '/workspaces/training/side-quests/nf-test/tests/main.converttoupper.nf.test
416416

417417
SUCCESS: Generated 2 test files.
418418
```
419419

420-
Note we have created a test for the `converttoupper` process as well. We can ignore that for now and focus on the `sayhello` process in the `main.sayhello.nf.test` file.
420+
Let's focus for now and focus on the `sayhello` process in the `main.sayhello.nf.test` file.
421421

422422
Let's open the file and take a look at the contents.
423423

@@ -471,7 +471,7 @@ https://www.nf-test.com
471471

472472
Test Process sayHello
473473

474-
Test [f91a1bcd] 'Should run without failures' FAILED (1.347s)
474+
Test [1eaad118] 'Should run without failures' FAILED (4.876s)
475475

476476
Assertion failed:
477477

@@ -484,10 +484,15 @@ Test Process sayHello
484484

485485
Process `sayHello` declares 1 input channel but 0 were specified
486486

487-
-- Check script '/workspace/gitpod/hello-nextflow/hello-nf-test-part1/.nf-test-f91a1bcdafbf4c8bbd32858acdd8afd2.nf' at line: 38 or see '/workspace/gitpod/hello-nextflow/hello-nf-test-part1/.nf-test/tests/f91a1bcdafbf4c8bbd32858acdd8afd2/meta/nextflow.log' file for more details
487+
-- Check script '/workspaces/training/side-quests/nf-test/.nf-test-1eaad118145a1fd798cb07e7dd75d087.nf' at line: 38 or see '/workspaces/training/side-quests/nf-test/.nf-test/tests/1eaad118145a1fd798cb07e7dd75d087/meta/nextflow.log' file for more details
488488
Nextflow stderr:
489489

490-
FAILURE: Executed 1 tests in 1.35s (1 failed)
490+
Nextflow 24.10.4 is available - Please consider updating your version to it
491+
492+
493+
494+
495+
FAILURE: Executed 1 tests in 4.884s (1 failed)
491496
```
492497

493498
The test fails because the `sayHello` process declares 1 input channel but 0 were specified. Let's fix that by adding an input to the process. Remember from part 1, our `sayHello` process takes a single value input.
@@ -546,7 +551,7 @@ If we look at the `tests/main.sayhello.nf.test` file, we can see it uses a metho
546551
assert snapshot(process.out).match()
547552
```
548553

549-
This is a snapshot of the output of the `sayHello` process. Let's take a look at the contents of the snapshot file.
554+
This is telling nf-test to create a snapshot of the output of the `sayHello` process. Let's take a look at the contents of the snapshot file.
550555

551556
```console title="Snapshot file contents"
552557
code tests/main.sayhello.nf.test.snap
@@ -560,7 +565,7 @@ We won't print it here, but you should see a JSON file containing details of the
560565
]
561566
```
562567

563-
This represents the outputs created by the `sayHello` process, which we are testing explicitly. If we re-run the test, the program will check that the new output matches the output that was originally recorded. This is a quick, simple way of testing process outputs which is why nf-test provides it as a default.
568+
This represents the outputs created by the `sayHello` process, which we are testing explicitly. If we re-run the test, the program will check that the new output matches the output that was originally recorded. This is a quick, simple way of testing that process outputs don't change, which is why nf-test provides it as a default.
564569

565570
!!!warning
566571

@@ -569,7 +574,7 @@ This represents the outputs created by the `sayHello` process, which we are test
569574
If, in the course of future development, something in the code changes that causes the output to be different, the test will fail and we will have to determine whether the change is expected or not.
570575

571576
- If it turns out that something in the code broke, we will have to fix it, with the expectation that the fixed code will pass the test.
572-
- If it is an expected change (e.g., the tool has been improved and the results are better) then we will need to update the snapshot to accept the new output as the reference to match, using the parameter `--update-snapshot` when we run the test command.
577+
- If it is an expected change (e.g., the tool has been improved and the results are better) then we will need to update the snapshot to accept the new output as the reference to match. nf-test has a parameter `--update-snapshot` for this purpose.
573578

574579
For now though, we can run the test again and see the test should pass:
575580

@@ -776,11 +781,3 @@ Check that out! We ran 3 tests, 1 for each process and 1 for the whole pipeline
776781
### Takeaway
777782

778783
You know how to run tests for the entire repo with a single command.
779-
780-
### What's next?
781-
782-
This is a lot to learn, so celebrate and take a big break!
783-
784-
If you already know about Nextflow and wish to learn more about nf-test, skip to nf-test part 2 which uses more real world examples.
785-
786-
If you are still at the beginning of your Nextflow journey, you can continue to learn about containers.

0 commit comments

Comments
 (0)