GeezerVison is showing github.com — test: clarify usage of tmpdir.refresh() · nodejs/node@776ef11
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: test/common/README.md +6-1Lines changed: 6 additions & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -944,13 +944,18 @@ The realpath of the testing temporary directory. |
944 | 944 |
|
945 | 945 | Deletes and recreates the testing temporary directory. |
946 | 946 |
|
947 | | -The first time `refresh()` runs, it adds a listener to process `'exit'` that |
| 947 | +The first time `refresh()` runs, it adds a listener to process `'exit'` that |
948 | 948 | cleans the temporary directory. Thus, every file under `tmpdir.path` needs to |
949 | 949 | be closed before the test completes. A good way to do this is to add a |
950 | 950 | listener to process `'beforeExit'`. If a file needs to be left open until |
951 | 951 | Node.js completes, use a child process and call `refresh()` only in the |
952 | 952 | parent. |
953 | 953 |
|
| 954 | +It is usually only necessary to call `refresh()` once in a test file. |
| 955 | +Avoid calling it more than once in an asynchronous context as one call |
| 956 | +might refresh the temporary directory of a different context, causing |
| 957 | +the test to fail somewhat mysteriously. |
| 958 | + |
954 | 959 | ## UDP pair helper |
955 | 960 |
|
956 | 961 | The `common/udppair` module exports a function `makeUDPPair` and a class |
|