From 61cd82e8faa9e18cfeed32550f37f2ba4512090e Mon Sep 17 00:00:00 2001 From: Artem Zakharchenko Date: Wed, 25 Aug 2021 14:41:22 +0200 Subject: [PATCH] Supports absolute path as the "baseDir" --- src/createTeardown.test.ts | 14 ++++++++++++++ src/createTeardown.ts | 4 +++- 2 files changed, 17 insertions(+), 1 deletion(-) 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() {