diff --git a/index.d.ts b/index.d.ts index c6ce538..aa17303 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/member-ordering */ import {Buffer} from 'node:buffer'; import {MergeExclusive, TypedArray} from 'type-fest'; @@ -41,132 +40,117 @@ The temporary path created by the function. Can be asynchronous. */ export type TaskCallback = (temporaryPath: string) => Promise | ReturnValueType; -declare const tempy: { - file: { - /** - The `callback` resolves with a temporary file path you can write to. The file is automatically cleaned up after the callback is executed. - - @returns A promise that resolves after the callback is executed and the file is cleaned up. - - @example - ``` - import tempy from 'tempy'; - - await tempy.file.task(tempFile => { - console.log(tempFile); - //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/4f504b9edb5ba0e89451617bf9f971dd' - }); - ``` - */ - task: (callback: TaskCallback, options?: FileOptions) => Promise; - - /** - Get a temporary file path you can write to. - - @example - ``` - import tempy from 'tempy'; - - tempy.file(); - //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/4f504b9edb5ba0e89451617bf9f971dd' - - tempy.file({extension: 'png'}); - //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/a9fb0decd08179eb6cf4691568aa2018.png' - - tempy.file({name: 'unicorn.png'}); - //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/f7f62bfd4e2a05f1589947647ed3f9ec/unicorn.png' - - tempy.directory(); - //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/2f3d094aec2cb1b93bb0f4cffce5ebd6' - ``` - */ - (options?: FileOptions): string; - }; - - directory: { - /** - The `callback` resolves with a temporary directory path you can write to. The directory is automatically cleaned up after the callback is executed. - - @returns A promise that resolves after the callback is executed and the directory is cleaned up. - - @example - ``` - import tempy from 'tempy'; - - await tempy.directory.task(tempDirectory => { - //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/2f3d094aec2cb1b93bb0f4cffce5ebd6' - }) - ``` - */ - task: (callback: TaskCallback, options?: DirectoryOptions) => Promise; - - /** - Get a temporary directory path. The directory is created for you. - - @example - ``` - import tempy from 'tempy'; - - tempy.directory(); - //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/2f3d094aec2cb1b93bb0f4cffce5ebd6' - - tempy.directory({prefix: 'a'}); - //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/name_3c085674ad31223b9653c88f725d6b41' - ``` - */ - (options?: DirectoryOptions): string; - }; - - write: { - /** - Write data to a random temp file. The file is automatically cleaned up after the callback is executed. - - @returns A promise that resolves after the callback is executed and the file is cleaned up. - - @example - ``` - import tempy from 'tempy'; - - await tempy.write.task('🦄', tempFile => { - //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/4f504b9edb5ba0e89451617bf9f971dd' - }); - ``` - */ - task: (fileContent: string | Buffer | TypedArray | DataView | NodeJS.ReadableStream, callback: TaskCallback, options?: FileOptions) => Promise; - - /** - Write data to a random temp file. - - @example - ``` - import tempy from 'tempy'; - - await tempy.write('🦄'); - //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/2f3d094aec2cb1b93bb0f4cffce5ebd6' - ``` - */ - (fileContent: string | Buffer | TypedArray | DataView | NodeJS.ReadableStream, options?: FileOptions): Promise; - }; +/** +Get a temporary file path you can write to. - /** - Synchronously write data to a random temp file. +@example +``` +import {temporaryFile, temporaryDirectory} from 'tempy'; + +temporaryFile(); +//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/4f504b9edb5ba0e89451617bf9f971dd' + +temporaryFile({extension: 'png'}); +//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/a9fb0decd08179eb6cf4691568aa2018.png' + +temporaryFile({name: 'unicorn.png'}); +//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/f7f62bfd4e2a05f1589947647ed3f9ec/unicorn.png' + +temporaryDirectory(); +//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/2f3d094aec2cb1b93bb0f4cffce5ebd6' +``` +*/ +export function temporaryFile(options?: FileOptions): string; + +/** +The `callback` resolves with a temporary file path you can write to. The file is automatically cleaned up after the callback is executed. + +@returns A promise that resolves after the callback is executed and the file is cleaned up. + +@example +``` +import {temporaryFileTask} from 'tempy'; + +await temporaryFileTask(tempFile => { + console.log(tempFile); + //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/4f504b9edb5ba0e89451617bf9f971dd' +}); +``` +*/ +export function temporaryFileTask(callback: TaskCallback, options?: FileOptions): Promise ; + +/** +Get a temporary directory path. The directory is created for you. + +@example +``` +import {temporaryDirectory} from 'tempy'; + +temporaryDirectory(); +//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/2f3d094aec2cb1b93bb0f4cffce5ebd6' + +temporaryDirectory({prefix: 'a'}); +//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/name_3c085674ad31223b9653c88f725d6b41' +``` +*/ +export function temporaryDirectory(options?: DirectoryOptions): string; + +/** +The `callback` resolves with a temporary directory path you can write to. The directory is automatically cleaned up after the callback is executed. - @example - ``` - import tempy from 'tempy'; +@returns A promise that resolves after the callback is executed and the directory is cleaned up. - tempy.writeSync('🦄'); +@example +``` +import {temporaryDirectoryTask} from 'tempy'; + +await temporaryDirectoryTask(tempDirectory => { //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/2f3d094aec2cb1b93bb0f4cffce5ebd6' - ``` - */ - writeSync: (fileContent: string | Buffer | TypedArray | DataView, options?: FileOptions) => string; +}) +``` +*/ +export function temporaryDirectoryTask(callback: TaskCallback, options?: DirectoryOptions): Promise; - /** - Get the root temporary directory path. +/** +Write data to a random temp file. - For example: `/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T`. - */ - readonly root: string; -}; +@example +``` +import {temporaryWrite} from 'tempy'; + +await temporaryWrite('🦄'); +//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/2f3d094aec2cb1b93bb0f4cffce5ebd6' +``` +*/ +export function temporaryWrite(fileContent: string | Buffer | TypedArray | DataView | NodeJS.ReadableStream, options?: FileOptions): Promise; + +/** +Write data to a random temp file. The file is automatically cleaned up after the callback is executed. + +@returns A promise that resolves after the callback is executed and the file is cleaned up. + +@example +``` +import {temporaryWriteTask} from 'tempy'; + +await temporaryWriteTask('🦄', tempFile => { + //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/4f504b9edb5ba0e89451617bf9f971dd' +}); +``` +*/ +export function temporaryWriteTask(fileContent: string | Buffer | TypedArray | DataView | NodeJS.ReadableStream, callback: TaskCallback, options?: FileOptions): Promise; + +/** +Synchronously write data to a random temp file. + +@example +``` +import {temporaryWriteSync} from 'tempy'; + +temporaryWriteSync('🦄'); +//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/2f3d094aec2cb1b93bb0f4cffce5ebd6' +``` +*/ +export function temporaryWriteSync(fileContent: string | Buffer | TypedArray | DataView, options?: FileOptions): string; -export default tempy; +export {default as rootTemporaryDirectory} from 'temp-dir'; diff --git a/index.js b/index.js index a34c2dc..a5cd982 100644 --- a/index.js +++ b/index.js @@ -5,7 +5,6 @@ import {promisify} from 'node:util'; import uniqueString from 'unique-string'; import tempDir from 'temp-dir'; import {isStream} from 'is-stream'; -import del from 'del'; // TODO: Replace this with `fs.rm` when targeting Node.js 14. const pipeline = promisify(stream.pipeline); // TODO: Use `node:stream/promises` when targeting Node.js 16. @@ -13,64 +12,49 @@ const getPath = (prefix = '') => path.join(tempDir, prefix + uniqueString()); const writeStream = async (filePath, data) => pipeline(data, fs.createWriteStream(filePath)); -const createTask = (tempyFunction, {extraArguments = 0} = {}) => async (...arguments_) => { - const [callback, options] = arguments_.slice(extraArguments); - const result = await tempyFunction(...arguments_.slice(0, extraArguments), options); - +async function runTask(temporaryPath, callback) { try { - return await callback(result); + return await callback(temporaryPath); } finally { - await del(result, {force: true}); + await fsPromises.rm(temporaryPath, {recursive: true, force: true}); } -}; - -const tempy = {}; +} -tempy.file = options => { - options = { - ...options, - }; - - if (options.name) { - if (options.extension !== undefined && options.extension !== null) { +export function temporaryFile({name, extension} = {}) { + if (name) { + if (extension !== undefined && extension !== null) { throw new Error('The `name` and `extension` options are mutually exclusive'); } - return path.join(tempy.directory(), options.name); + return path.join(temporaryDirectory(), name); } - return getPath() + (options.extension === undefined || options.extension === null ? '' : '.' + options.extension.replace(/^\./, '')); -}; + return getPath() + (extension === undefined || extension === null ? '' : '.' + extension.replace(/^\./, '')); +} -tempy.file.task = createTask(tempy.file); +export const temporaryFileTask = async (callback, options) => runTask(temporaryFile(options), callback); -tempy.directory = ({prefix = ''} = {}) => { +export function temporaryDirectory({prefix = ''} = {}) { const directory = getPath(prefix); fs.mkdirSync(directory); return directory; -}; +} -tempy.directory.task = createTask(tempy.directory); +export const temporaryDirectoryTask = async (callback, options) => runTask(temporaryDirectory(options), callback); -tempy.write = async (data, options) => { - const filename = tempy.file(options); - const write = isStream(data) ? writeStream : fsPromises.writeFile; - await write(filename, data); +export async function temporaryWrite(fileContent, options) { + const filename = temporaryFile(options); + const write = isStream(fileContent) ? writeStream : fsPromises.writeFile; + await write(filename, fileContent); return filename; -}; +} -tempy.write.task = createTask(tempy.write, {extraArguments: 1}); +export const temporaryWriteTask = async (fileContent, callback, options) => runTask(await temporaryWrite(fileContent, options), callback); -tempy.writeSync = (data, options) => { - const filename = tempy.file(options); - fs.writeFileSync(filename, data); +export function temporaryWriteSync(fileContent, options) { + const filename = temporaryFile(options); + fs.writeFileSync(filename, fileContent); return filename; -}; - -Object.defineProperty(tempy, 'root', { - get() { - return tempDir; - }, -}); +} -export default tempy; +export {default as rootTemporaryDirectory} from 'temp-dir'; diff --git a/index.test-d.ts b/index.test-d.ts index bab51e5..feec10d 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,31 +1,31 @@ import process from 'node:process'; import {Buffer} from 'node:buffer'; import {expectType, expectError} from 'tsd'; -import tempy, {FileOptions} from './index.js'; +import {temporaryFile, temporaryFileTask, temporaryDirectory, temporaryDirectoryTask, temporaryWrite, temporaryWriteTask, temporaryWriteSync, rootTemporaryDirectory, FileOptions} from './index.js'; const options: FileOptions = {}; // eslint-disable-line @typescript-eslint/no-unused-vars -expectType(tempy.directory()); -expectType(tempy.directory({prefix: 'name_'})); -expectType(tempy.file()); -expectType>(tempy.file.task(temporaryFile => { +expectType(temporaryDirectory()); +expectType(temporaryDirectory({prefix: 'name_'})); +expectType(temporaryFile()); +expectType>(temporaryFileTask(temporaryFile => { expectType(temporaryFile); })); -expectType>(tempy.directory.task(temporaryDirectory => { +expectType>(temporaryDirectoryTask(temporaryDirectory => { expectType(temporaryDirectory); })); -expectType(tempy.file({extension: 'png'})); -expectType(tempy.file({name: 'afile.txt'})); -expectError(tempy.file({extension: 'png', name: 'afile.txt'})); -expectType(tempy.root); +expectType(temporaryFile({extension: 'png'})); +expectType(temporaryFile({name: 'afile.txt'})); +expectError(temporaryFile({extension: 'png', name: 'afile.txt'})); +expectType(rootTemporaryDirectory); -expectType>(tempy.write('unicorn')); -expectType>(tempy.write('unicorn', {name: 'pony.png'})); -expectType>(tempy.write(process.stdin, {name: 'pony.png'})); // eslint-disable-line @typescript-eslint/no-unsafe-member-access -expectType>(tempy.write(Buffer.from('pony'), {name: 'pony.png'})); -expectType>(tempy.write.task('', temporaryFile => { +expectType>(temporaryWrite('unicorn')); +expectType>(temporaryWrite('unicorn', {name: 'pony.png'})); +expectType>(temporaryWrite(process.stdin, {name: 'pony.png'})); +expectType>(temporaryWrite(Buffer.from('pony'), {name: 'pony.png'})); +expectType>(temporaryWriteTask('', temporaryFile => { expectType(temporaryFile); })); -expectType(tempy.writeSync('unicorn')); -expectType(tempy.writeSync(Buffer.from('unicorn'))); -expectType(tempy.writeSync('unicorn', {name: 'pony.png'})); +expectType(temporaryWriteSync('unicorn')); +expectType(temporaryWriteSync(Buffer.from('unicorn'))); +expectType(temporaryWriteSync('unicorn', {name: 'pony.png'})); diff --git a/package.json b/package.json index b8e0879..0b83e96 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "type": "module", "exports": "./index.js", "engines": { - "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + "node": ">=14.14" }, "scripts": { "test": "xo && ava && tsd" @@ -37,17 +37,17 @@ "unique" ], "dependencies": { - "del": "^6.0.0", "is-stream": "^3.0.0", "temp-dir": "^2.0.0", - "type-fest": "^2.0.0", + "type-fest": "^2.12.2", "unique-string": "^3.0.0" }, "devDependencies": { - "ava": "^4.0.0-alpha.2", + "@types/node": "^17.0.24", + "ava": "^4.2.0", "path-exists": "^5.0.0", "touch": "^3.1.0", - "tsd": "^0.17.0", - "xo": "^0.44.0" + "tsd": "^0.20.0", + "xo": "^0.48.0" } } diff --git a/readme.md b/readme.md index ececb22..0dfebda 100644 --- a/readme.md +++ b/readme.md @@ -11,31 +11,31 @@ $ npm install tempy ## Usage ```js -import tempy from 'tempy'; +import {temporaryFile, temporaryDirectory} from 'tempy'; -tempy.file(); +temporaryFile(); //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/4f504b9edb5ba0e89451617bf9f971dd' -tempy.file({extension: 'png'}); +temporaryFile({extension: 'png'}); //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/a9fb0decd08179eb6cf4691568aa2018.png' -tempy.file({name: 'unicorn.png'}); +temporaryFile({name: 'unicorn.png'}); //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/f7f62bfd4e2a05f1589947647ed3f9ec/unicorn.png' -tempy.directory(); +temporaryDirectory(); //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/2f3d094aec2cb1b93bb0f4cffce5ebd6' -tempy.directory({prefix: 'name'}); +temporaryDirectory({prefix: 'name'}); //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/name_3c085674ad31223b9653c88f725d6b41' ``` ## API -### tempy.file(options?) +### temporaryFile(options?) Get a temporary file path you can write to. -### tempy.file.task(callback, options?) +### temporaryFileTask(callback, options?) The `callback` resolves with a temporary file path you can write to. The file is automatically cleaned up after the callback is executed. Returns a promise that resolves with the return value of the callback after it is executed and the file is cleaned up. @@ -63,11 +63,11 @@ Type: `string` Filename. Mutually exclusive with the `extension` option. -### tempy.directory(options?) +### temporaryDirectory(options?) Get a temporary directory path. The directory is created for you. -### tempy.directory.task(callback, options?) +### temporaryDirectoryTask(callback, options?) The `callback` resolves with a temporary directory path you can write to. The directory is automatically cleaned up after the callback is executed. Returns a promise that resolves with the return value of the callback after it is executed and the directory is cleaned up. @@ -91,11 +91,11 @@ Useful for testing by making it easier to identify cache directories that are cr *You usually won't need this option. Specify it only when actually needed.* -### tempy.write(fileContent, options?) +### temporaryWrite(fileContent, options?) Write data to a random temp file. -### tempy.write.task(fileContent, callback, options?) +### temporaryWriteTask(fileContent, callback, options?) Write data to a random temp file. The file is automatically cleaned up after the callback is executed. Returns a promise that resolves with the return value of the callback after it is executed and the file is cleaned up. @@ -115,7 +115,7 @@ A callback that is executed with the temp file path. Can be asynchronous. See [options](#options). -### tempy.writeSync(fileContent, options?) +### temporaryWriteSync(fileContent, options?) Synchronously write data to a random temp file. @@ -129,6 +129,6 @@ Data to write to the temp file. See [options](#options). -### tempy.root +### rootTemporaryDirectory Get the root temporary directory path. For example: `/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T` diff --git a/test.js b/test.js index 6246e14..9273945 100644 --- a/test.js +++ b/test.js @@ -6,38 +6,38 @@ import tempDir from 'temp-dir'; import {pathExists} from 'path-exists'; import touch from 'touch'; import test from 'ava'; -import tempy from './index.js'; +import {temporaryFile, temporaryFileTask, temporaryDirectory, temporaryDirectoryTask, temporaryWrite, temporaryWriteTask, temporaryWriteSync, rootTemporaryDirectory} from './index.js'; test('.file()', t => { - t.true(tempy.file().includes(tempDir)); - t.false(tempy.file().endsWith('.')); - t.false(tempy.file({extension: undefined}).endsWith('.')); - t.false(tempy.file({extension: null}).endsWith('.')); - t.true(tempy.file({extension: 'png'}).endsWith('.png')); - t.true(tempy.file({extension: '.png'}).endsWith('.png')); - t.false(tempy.file({extension: '.png'}).endsWith('..png')); - t.true(tempy.file({name: 'custom-name.md'}).endsWith('custom-name.md')); + t.true(temporaryFile().includes(tempDir)); + t.false(temporaryFile().endsWith('.')); + t.false(temporaryFile({extension: undefined}).endsWith('.')); + t.false(temporaryFile({extension: null}).endsWith('.')); + t.true(temporaryFile({extension: 'png'}).endsWith('.png')); + t.true(temporaryFile({extension: '.png'}).endsWith('.png')); + t.false(temporaryFile({extension: '.png'}).endsWith('..png')); + t.true(temporaryFile({name: 'custom-name.md'}).endsWith('custom-name.md')); t.throws(() => { - tempy.file({name: 'custom-name.md', extension: '.ext'}); + temporaryFile({name: 'custom-name.md', extension: '.ext'}); }); t.throws(() => { - tempy.file({name: 'custom-name.md', extension: ''}); + temporaryFile({name: 'custom-name.md', extension: ''}); }); t.notThrows(() => { - tempy.file({name: 'custom-name.md', extension: undefined}); + temporaryFile({name: 'custom-name.md', extension: undefined}); }); t.notThrows(() => { - tempy.file({name: 'custom-name.md', extension: null}); + temporaryFile({name: 'custom-name.md', extension: null}); }); }); test('.file.task()', async t => { let temporaryFilePath; - t.is(await tempy.file.task(async temporaryFile => { + t.is(await temporaryFileTask(async temporaryFile => { await touch(temporaryFile); temporaryFilePath = temporaryFile; return temporaryFile; @@ -47,7 +47,7 @@ test('.file.task()', async t => { test('.task() - cleans up even if callback throws', async t => { let temporaryDirectoryPath; - await t.throwsAsync(tempy.directory.task(async temporaryDirectory => { + await t.throwsAsync(temporaryDirectoryTask(async temporaryDirectory => { temporaryDirectoryPath = temporaryDirectory; throw new Error('Catch me if you can!'); }), { @@ -61,13 +61,13 @@ test('.task() - cleans up even if callback throws', async t => { test('.directory()', t => { const prefix = 'name_'; - t.true(tempy.directory().includes(tempDir)); - t.true(path.basename(tempy.directory({prefix})).startsWith(prefix)); + t.true(temporaryDirectory().includes(tempDir)); + t.true(path.basename(temporaryDirectory({prefix})).startsWith(prefix)); }); test('.directory.task()', async t => { let temporaryDirectoryPath; - t.is(await tempy.directory.task(async temporaryDirectory => { + t.is(await temporaryDirectoryTask(async temporaryDirectory => { temporaryDirectoryPath = temporaryDirectory; return temporaryDirectory; }), temporaryDirectoryPath); @@ -75,14 +75,14 @@ test('.directory.task()', async t => { }); test('.write(string)', async t => { - const filePath = await tempy.write('unicorn', {name: 'test.png'}); + const filePath = await temporaryWrite('unicorn', {name: 'test.png'}); t.is(fs.readFileSync(filePath, 'utf8'), 'unicorn'); t.is(path.basename(filePath), 'test.png'); }); test('.write.task(string)', async t => { let temporaryFilePath; - t.is(await tempy.write.task('', async temporaryFile => { + t.is(await temporaryWriteTask('', async temporaryFile => { temporaryFilePath = temporaryFile; return temporaryFile; }), temporaryFilePath); @@ -90,7 +90,7 @@ test('.write.task(string)', async t => { }); test('.write(buffer)', async t => { - const filePath = await tempy.write(Buffer.from('unicorn')); + const filePath = await temporaryWrite(Buffer.from('unicorn')); t.is(fs.readFileSync(filePath, 'utf8'), 'unicorn'); }); @@ -101,7 +101,7 @@ test('.write(stream)', async t => { readable.push('unicorn'); readable.push(null); // eslint-disable-line unicorn/no-array-push-push - const filePath = await tempy.write(readable); + const filePath = await temporaryWrite(readable); t.is(fs.readFileSync(filePath, 'utf8'), 'unicorn'); }); @@ -117,21 +117,17 @@ test('.write(stream) failing stream', async t => { readable.push(null); }); - await t.throwsAsync(tempy.write(readable), { + await t.throwsAsync(temporaryWrite(readable), { instanceOf: Error, message: 'Catch me if you can!', }); }); test('.writeSync()', t => { - t.is(fs.readFileSync(tempy.writeSync('unicorn'), 'utf8'), 'unicorn'); + t.is(fs.readFileSync(temporaryWriteSync('unicorn'), 'utf8'), 'unicorn'); }); test('.root', t => { - t.true(tempy.root.length > 0); - t.true(path.isAbsolute(tempy.root)); - - t.throws(() => { - tempy.root = 'foo'; - }); + t.true(rootTemporaryDirectory.length > 0); + t.true(path.isAbsolute(rootTemporaryDirectory)); });