Skip to content

Commit

Permalink
feat: flatten temp directory structure
Browse files Browse the repository at this point in the history
if every fixture is cleaned, there should be no extra directory left
  • Loading branch information
privatenumber committed Dec 5, 2022
1 parent 8edc7ba commit 452cf00
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { promises as fs } from 'fs';
import path from 'path';
import FsFixture from './fs-fixture';
import { temporaryDirectory, hasOwn, getId } from './utils';
import {
temporaryDirectory,
directoryNamespace,
hasOwn,
getId,
} from './utils';

export type { FsFixture };

Expand Down Expand Up @@ -42,7 +47,7 @@ function flattenFileTree(
export async function createFixture(
source?: string | FileTree,
) {
const fixturePath = path.join(temporaryDirectory, `fixture-${getId()}`);
const fixturePath = path.join(temporaryDirectory, `${directoryNamespace}-${getId()}`);

await fs.mkdir(fixturePath, {
recursive: true,
Expand Down
4 changes: 2 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fs from 'fs';
import path from 'path';
import os from 'os';

export const temporaryDirectory = path.join(fs.realpathSync(os.tmpdir()), 'test-fixtures', Date.now().toString());
export const temporaryDirectory = fs.realpathSync(os.tmpdir());
export const directoryNamespace = `fs-fixture-${Date.now()}`;

let id = 0;
export function getId() {
Expand Down

0 comments on commit 452cf00

Please sign in to comment.