Skip to content

Commit

Permalink
Supports absolute path as the "baseDir"
Browse files Browse the repository at this point in the history
  • Loading branch information
kettanaito committed Aug 25, 2021
1 parent 9f2bad9 commit 61cd82e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/createTeardown.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as fs from 'fs'
import * as path from 'path'
import { createTeardown, addFile, addDirectory } from './createTeardown'

const BASE_DIR = './tmp'
Expand Down Expand Up @@ -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()
})
4 changes: 3 additions & 1 deletion src/createTeardown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 61cd82e

Please sign in to comment.