diff --git a/src/createTeardown.test.ts b/src/createTeardown.test.ts index 36770fd..a1076a9 100644 --- a/src/createTeardown.test.ts +++ b/src/createTeardown.test.ts @@ -1,4 +1,5 @@ import * as fs from 'fs' +import * as path from 'path' import { createTeardown, addFile, addDirectory } from './createTeardown' const BASE_DIR = './tmp' @@ -149,3 +150,16 @@ test('removes a given file', async () => { await cleanup() }) + +test('supports absolute "baseDir" path', async () => { + const absolutePath = path.resolve(__dirname, 'tmp') + const { prepare, getPath, cleanup } = createTeardown( + absolutePath, + addFile('file.txt'), + ) + await prepare() + + expect(fs.existsSync(getPath('file.txt'))).toBe(true) + + await cleanup() +}) diff --git a/src/createTeardown.ts b/src/createTeardown.ts index 01ad1d6..12acc1f 100644 --- a/src/createTeardown.ts +++ b/src/createTeardown.ts @@ -68,7 +68,9 @@ export function createTeardown( baseDir: string, ...operations: TeardownOperation[] ): TeardownControls { - const absoluteBaseDir = path.resolve(process.cwd(), baseDir) + const absoluteBaseDir = path.isAbsolute(baseDir) + ? baseDir + : path.resolve(process.cwd(), baseDir) const api: TeardownControls = { prepare() {