import { test, describe } from "bun:test"; import assert from "node:assert"; import path from "node:path"; const isWindows = process.platform === "win32"; describe("path", () => { test("errors", () => { // Test thrown TypeErrors const typeErrorTests = [true, false, 7, null, {}, undefined, [], NaN]; function fail(fn) { const args = Array.from(arguments).slice(1); assert.throws( () => { fn.apply(null, args); }, { code: "ERR_INVALID_ARG_TYPE", name: "TypeError" }, ); } for (const test of typeErrorTests) { for (const namespace of [path.posix, path.win32]) { fail(namespace.join, test); fail(namespace.resolve, test); fail(namespace.normalize, test); fail(namespace.isAbsolute, test); fail(namespace.relative, test, "foo"); fail(namespace.relative, "foo", test); fail(namespace.parse, test); fail(namespace.dirname, test); fail(namespace.basename, test); fail(namespace.extname, test); // Undefined is a valid value as the second argument to basename if (test !== undefined) { fail(namespace.basename, "foo", test); } } } }); test("path.sep", () => { // path.sep tests // windows assert.strictEqual(path.win32.sep, "\\"); // posix assert.strictEqual(path.posix.sep, "/"); }); test("path.delimiter", () => { // path.delimiter tests // windows assert.strictEqual(path.win32.delimiter, ";"); // posix assert.strictEqual(path.posix.delimiter, ":"); if (isWindows) assert.strictEqual(path, path.win32); else assert.strictEqual(path, path.posix); }); });