Skip to content

Commit

Permalink
improve tests: replace rootDir with systemDrive(). Add expected error…
Browse files Browse the repository at this point in the history
… regex pattern.
  • Loading branch information
mceachen committed Dec 16, 2024
1 parent e81bba1 commit 3fdfd60
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/test-utils/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { mkdirSync } from "node:fs";
import { homedir } from "node:os";
import { join } from "node:path";
import { env, platform } from "node:process";
import { normalizePath } from "../path.js";
import { isMacOS, isWindows } from "../platform.js";
import { toNotBlank } from "../string.js";

Expand All @@ -18,7 +19,7 @@ export function describePlatform(...supported: NodeJS.Platform[]) {

export function systemDrive() {
if (isWindows) {
return toNotBlank(env["SystemDrive"] ?? "") ?? "C:\\";
return normalizePath(toNotBlank(env["SystemDrive"] ?? "") ?? "C:\\") as string;
} else {
return "/";
}
Expand Down
15 changes: 7 additions & 8 deletions src/volume_metadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// src/volume_metadata.test.ts

import { jest } from "@jest/globals";
import { join } from "node:path";
import { compact, times } from "./array.js";
import { TimeoutError } from "./async.js";
import {
Expand All @@ -15,11 +16,13 @@ import { IncludeSystemVolumesDefault } from "./options.js";
import { isLinux, isMacOS, isWindows } from "./platform.js";
import { pickRandom, randomLetter, randomLetters, shuffle } from "./random.js";
import { assertMetadata } from "./test-utils/assert.js";
import { systemDrive } from "./test-utils/platform.js";
import { MiB } from "./units.js";

const rootPath = systemDrive();

describe("Volume Metadata", () => {
it("should get root filesystem metadata", async () => {
const rootPath = isWindows ? "C:\\" : "/";
const metadata = await getVolumeMetadata(rootPath);

console.dir(metadata);
Expand Down Expand Up @@ -168,8 +171,6 @@ describe("getAllVolumeMetadata()", () => {

if (!isWindows) {
describe("Timeout Handling", () => {
const rootPath = isWindows ? "C:\\" : "/";

it("should handle getVolumeMountPoints() timeout", async () => {
await expect(getVolumeMountPoints({ timeoutMs: 1 })).rejects.toThrow(
/timeout/i,
Expand All @@ -187,18 +188,16 @@ if (!isWindows) {
describe("Error Handling", () => {
it("should handle invalid paths appropriately", async () => {
const invalidPaths = [
isWindows ? "A:\\" : "/nonexistent",
isWindows
? "C:\\Really_Invalid_Path_123456789"
: "/really/invalid/path/123456789",
isWindows ? "A:\\" : "/nonexistent-root-directory",
join(rootPath, "nonexistent", "path", "123456789"),
"",
null,
undefined,
];

for (const path of invalidPaths) {
await expect(getVolumeMetadata(path as string)).rejects.toThrow(
/ENOENT|invalid|not accessible/i,
/ENOENT|invalid|not accessible|opendir/i,
);
}
});
Expand Down

0 comments on commit 3fdfd60

Please sign in to comment.