Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ggt directory code and tests #972

Merged
merged 5 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions spec/__support__/files.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import fs from "fs-extra";
import path from "node:path";

export type Files = Record<string, string>;

export const writeDir = async (dir: string, files: Files): Promise<void> => {
await fs.ensureDir(dir);

for (const [filepath, content] of Object.entries(files)) {
if (filepath.endsWith("/")) {
await fs.ensureDir(path.join(dir, filepath));
} else {
await fs.outputFile(path.join(dir, filepath), content);
}
}
};
39 changes: 39 additions & 0 deletions spec/__support__/paths.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import path from "node:path";
import { assert, expect } from "vitest";

/**
* Returns the path to a test directory within tmp/spec/ based on the
* current test name and optional segments.
*
* @param segments - Optional path segments to append to the test
* directory path.
* @returns The path to the test directory.
* @example
* // file: spec/some/test.spec.ts
* testDirPath("foo/bar", "baz.txt"); // => tmp/spec/some/test.spec.ts/foo/bar/baz.txt
*/
export const testDirPath = (...segments: string[]): string => {
const currentTestName = expect.getState().currentTestName;
assert(currentTestName, "expected currentTestName to be defined");

const [testFile, ...rest] = currentTestName.split(" > ");
const describes = rest.length > 1 ? rest.slice(0, -1).join("/") : "";
const testName = rest.at(-1)?.replace(/[^\s\w-]/g, "");
assert(testFile && testName, "expected test file and test name to be defined");

return path.join(__dirname, "../../tmp/", testFile, describes, testName, ...segments);
};

const fixturesDirPath = (...segments: string[]): string => {
return path.join(__dirname, "../__fixtures__", ...segments);
};

/**
* Returns an absolute path to the `app` fixture directory.
*
* @param segments - Additional segments to append to the path.
* @returns The path to the `app` fixture directory.
*/
export const appFixturePath = (...segments: string[]): string => {
return fixturesDirPath("app", ...segments);
};
2 changes: 1 addition & 1 deletion spec/commands/sync.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
PUBLISH_FILE_SYNC_EVENTS_MUTATION,
REMOTE_FILES_VERSION_QUERY,
REMOTE_FILE_SYNC_EVENTS_SUBSCRIPTION,
} from "../../src/services/filesync.js";
} from "../../src/services/filesync/filesync.js";
import { isFunction, isNil, isString } from "../../src/services/is.js";
import { noop } from "../../src/services/noop.js";
import { sleep, sleepUntil } from "../../src/services/sleep.js";
Expand Down
457 changes: 457 additions & 0 deletions spec/services/filesync/__snapshots__/directory.spec.ts.snap

Large diffs are not rendered by default.

Loading