diff --git a/index.js b/index.js index 763f576..e0ecc35 100644 --- a/index.js +++ b/index.js @@ -37,7 +37,7 @@ export const temporaryFileTask = async (callback, options) => runTask(temporaryF export function temporaryDirectory({prefix = ''} = {}) { const directory = getPath(prefix); - fs.mkdirSync(directory); + fs.mkdirSync(directory, {recursive: true}); return directory; } diff --git a/test.js b/test.js index a914a62..f3d08da 100644 --- a/test.js +++ b/test.js @@ -68,10 +68,16 @@ test('.task() - cleans up even if callback throws', async t => { }); test('.directory()', t => { - const prefix = 'name_'; + let prefix = 'name_'; t.true(temporaryDirectory().includes(tempDir)); t.true(path.basename(temporaryDirectory({prefix})).startsWith(prefix)); + + prefix = path.join('parent', 'name_'); + + t.true(temporaryDirectory().includes(tempDir)); + t.true(path.basename(temporaryDirectory({prefix})).startsWith(prefix.split(path.sep)[1])); + t.true(path.dirname(temporaryDirectory({prefix})).split(path.sep).pop() === prefix.split(path.sep)[0]); }); test('.directory.task()', async t => {