Skip to content

Commit e33ab22

Browse files
committed
feat(useTemporaryDirectory): Make writeFile return the absolute path to the file
1 parent e701b38 commit e33ab22

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ Returns an object with the following members:
2727

2828
- `path`: The absolute path to the temporary directory.
2929
- `writeFile(filePath, fileContents)`: Write a file with path relative to the
30-
temporary directory. Any leading whitespace in the file contents is stripped.
31-
If the file starts with a shebang, it is given executable permissions.
30+
temporary directory, returning the absolute path to the file. Any leading
31+
whitespace in the file contents is stripped. If the file starts with a
32+
shebang, it is given executable permissions.
3233

3334
```js
3435
import process from 'node:process'

use-temporary-directory/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import stripIndent from 'strip-indent'
2424
*
2525
* @return {Promise<{
2626
* path: string,
27-
* writeFile(filePath: string, fileContents: string): Promise<void>
27+
* writeFile(filePath: string, fileContents: string): Promise<string>
2828
* }>} an object allowing manipulation of files within the directory.
2929
*/
3030
export default async function (t, options) {
@@ -49,6 +49,8 @@ export default async function (t, options) {
4949
if (contents.startsWith('#!')) {
5050
await fs.chmod(absolutePath, 0o755)
5151
}
52+
53+
return absolutePath
5254
},
5355
}
5456
}

use-temporary-directory/index.test.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ test.serial('creating a directory', async (t) => {
1414
const stats = await fs.stat(directory.path)
1515
t.true(stats.isDirectory())
1616

17-
await directory.writeFile(
18-
'file.txt',
19-
`
20-
Hello World!
21-
`,
17+
t.is(
18+
await directory.writeFile(
19+
'file.txt',
20+
`
21+
Hello World!
22+
`,
23+
),
24+
path.join(directory.path, 'file.txt'),
2225
)
2326

2427
t.is(

0 commit comments

Comments
 (0)