aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/packages/turbo-test-utils/src/useFixtures.ts
diff options
context:
space:
mode:
author简律纯 <i@jyunko.cn>2023-11-03 21:25:40 +0800
committer简律纯 <i@jyunko.cn>2023-11-03 21:25:40 +0800
commit9029588590bea8b10451575c5142dcde77ecd1b5 (patch)
tree04cf8aee56c23fd225ff19d340f7cee621d874ef /packages/turbo-test-utils/src/useFixtures.ts
parent94071d7ce16c56641d67d488e2bac6be84ffe731 (diff)
downloadHydroRoll-9029588590bea8b10451575c5142dcde77ecd1b5.tar.gz
HydroRoll-9029588590bea8b10451575c5142dcde77ecd1b5.zip
chore: delete useless files
Diffstat (limited to 'packages/turbo-test-utils/src/useFixtures.ts')
-rw-r--r--packages/turbo-test-utils/src/useFixtures.ts89
1 files changed, 0 insertions, 89 deletions
diff --git a/packages/turbo-test-utils/src/useFixtures.ts b/packages/turbo-test-utils/src/useFixtures.ts
deleted file mode 100644
index 2c47f5a..0000000
--- a/packages/turbo-test-utils/src/useFixtures.ts
+++ /dev/null
@@ -1,89 +0,0 @@
-import { v4 as uuidv4 } from "uuid";
-import path from "path";
-import fs from "fs-extra";
-import yaml from "js-yaml";
-import JSON5 from "json5";
-
-export default function setupTestFixtures({
- directory,
- test = "",
-}: {
- directory: string;
- test?: string;
-}) {
- const fixtures: Array<string> = [];
- const parentDirectory = path.join(directory, test ? test : "test-runs");
-
- afterEach(() => {
- fixtures.forEach((fixture) => {
- fs.rmSync(fixture, { recursive: true, force: true });
- });
- });
-
- afterAll(() => {
- fs.rmSync(parentDirectory, { recursive: true, force: true });
- });
-
- const useFixture = ({ fixture }: { fixture: string }) => {
- const directoryName = uuidv4();
- const testDirectory = path.join(parentDirectory, directoryName);
- if (!fs.existsSync(testDirectory)) {
- fs.mkdirSync(testDirectory, { recursive: true });
- }
- // keep track of it
- fixtures.push(testDirectory);
-
- // copy fixture to test directory
- const fixturePath = path.join(directory, "__fixtures__", test, fixture);
- fs.copySync(fixturePath, testDirectory, {
- recursive: true,
- });
-
- const getFilePath = (filename: string) => {
- return path.isAbsolute(filename)
- ? filename
- : path.join(testDirectory, filename);
- };
-
- const readGenerator = (method: (filePath: string) => unknown) => {
- return <T>(filename: string) => {
- try {
- return method(getFilePath(filename)) as T;
- } catch (e) {
- return undefined;
- }
- };
- };
-
- const write = (
- filename: string,
- content: string | NodeJS.ArrayBufferView
- ) => {
- fs.writeFileSync(getFilePath(filename), content);
- };
-
- const exists = (filename: string): boolean => {
- return fs.existsSync(getFilePath(filename));
- };
-
- const read = readGenerator((filePath) => fs.readFileSync(filePath, "utf8"));
- const readJson = readGenerator((filePath) =>
- JSON5.parse(fs.readFileSync(filePath, "utf8"))
- );
- const readYaml = readGenerator((filePath) =>
- yaml.load(fs.readFileSync(filePath, "utf8"))
- );
-
- return {
- root: testDirectory,
- read,
- readJson,
- readYaml,
- write,
- exists,
- directoryName,
- };
- };
-
- return { useFixture };
-}