From f3352560e0614a3fbab2c2db38178ddb8af4cc16 Mon Sep 17 00:00:00 2001 From: Bereket Engida Date: Sat, 26 Oct 2024 16:55:52 +0300 Subject: [PATCH] chore:lint --- packages/cli/src/utils/get-config.ts | 9 +- packages/cli/test/getConfig.test.ts | 205 +++++++++++++++++---------- 2 files changed, 135 insertions(+), 79 deletions(-) diff --git a/packages/cli/src/utils/get-config.ts b/packages/cli/src/utils/get-config.ts index 5447c71a56..3950413dd3 100644 --- a/packages/cli/src/utils/get-config.ts +++ b/packages/cli/src/utils/get-config.ts @@ -49,10 +49,13 @@ function getPathAliases(cwd: string): Record | null { for (const [alias, aliasPaths] of obj) { for (const aliasedPath of aliasPaths) { const resolvedBaseUrl = path.join(cwd, baseUrl); - const finalAlias = alias.slice(-1) === "*" ? alias.slice(0,-1) : alias; - const finalAliasedPath = aliasedPath.slice(-1) === "*" ? aliasedPath.slice(0,-1) : aliasedPath; + const finalAlias = alias.slice(-1) === "*" ? alias.slice(0, -1) : alias; + const finalAliasedPath = + aliasedPath.slice(-1) === "*" + ? aliasedPath.slice(0, -1) + : aliasedPath; - result[finalAlias || ""] = path.join(resolvedBaseUrl,finalAliasedPath); + result[finalAlias || ""] = path.join(resolvedBaseUrl, finalAliasedPath); } } addSvelteKitEnvModules(result); diff --git a/packages/cli/test/getConfig.test.ts b/packages/cli/test/getConfig.test.ts index 257aea145d..2c72ec2349 100644 --- a/packages/cli/test/getConfig.test.ts +++ b/packages/cli/test/getConfig.test.ts @@ -1,17 +1,17 @@ -import {afterEach, beforeEach, describe, expect, it} from "vitest"; +import { afterEach, beforeEach, describe, expect, it } from "vitest"; -import {test} from "vitest"; +import { test } from "vitest"; import os from "node:os"; import fs from "node:fs/promises"; import path from "node:path"; -import {getConfig} from "../src/utils/get-config"; +import { getConfig } from "../src/utils/get-config"; interface TmpDirFixture { tmpdir: string; } async function createTempDir() { - const tmpdir = path.join(process.cwd(), 'test', "getConfig_test-"); + const tmpdir = path.join(process.cwd(), "test", "getConfig_test-"); return await fs.mkdtemp(tmpdir); } @@ -21,30 +21,31 @@ export const tmpdirTest = test.extend({ await use(directory); - await fs.rm(directory, {recursive: true}); + await fs.rm(directory, { recursive: true }); }, }); -let tmpDir = '.'; +let tmpDir = "."; describe("getConfig", async () => { beforeEach(async () => { const tmp = path.join(process.cwd(), "getConfig_test-"); tmpDir = await fs.mkdtemp(tmp); - }) + }); afterEach(async () => { - await fs.rm(tmpDir, {recursive: true}); - }) + await fs.rm(tmpDir, { recursive: true }); + }); it("should resolve resolver type alias", async () => { - const authPath = path.join(tmpDir, 'server', 'auth'); - const dbPath = path.join(tmpDir, 'server', 'db'); - await fs.mkdir(authPath, {recursive: true}); - await fs.mkdir(dbPath, {recursive: true}); + const authPath = path.join(tmpDir, "server", "auth"); + const dbPath = path.join(tmpDir, "server", "db"); + await fs.mkdir(authPath, { recursive: true }); + await fs.mkdir(dbPath, { recursive: true }); //create dummy tsconfig.json - await fs.writeFile(path.join(tmpDir, "tsconfig.json"), + await fs.writeFile( + path.join(tmpDir, "tsconfig.json"), `{ "compilerOptions": { /* Path Aliases */ @@ -53,10 +54,12 @@ describe("getConfig", async () => { "@server/*": ["./server/*"] } } - }`); + }`, + ); //create dummy auth.ts - await fs.writeFile(path.join(authPath, "auth.ts"), + await fs.writeFile( + path.join(authPath, "auth.ts"), `import {betterAuth} from "better-auth"; import {prismaAdapter} from "better-auth/adapters/prisma"; import {db} from "@server/db/db"; @@ -68,29 +71,36 @@ describe("getConfig", async () => { emailAndPassword: { enabled: true, } - })`); + })`, + ); //create dummy db.ts - await fs.writeFile(path.join(dbPath, "db.ts"), + await fs.writeFile( + path.join(dbPath, "db.ts"), `class PrismaClient { constructor() {} } - export const db = new PrismaClient()`); + export const db = new PrismaClient()`, + ); - const config = await getConfig({cwd: tmpDir, configPath: 'server/auth/auth.ts'}) + const config = await getConfig({ + cwd: tmpDir, + configPath: "server/auth/auth.ts", + }); expect(config).not.toBe(null); }); it("should resolve direct alias", async () => { - const authPath = path.join(tmpDir, 'server', 'auth'); - const dbPath = path.join(tmpDir, 'server', 'db'); - await fs.mkdir(authPath, {recursive: true}); - await fs.mkdir(dbPath, {recursive: true}); + const authPath = path.join(tmpDir, "server", "auth"); + const dbPath = path.join(tmpDir, "server", "db"); + await fs.mkdir(authPath, { recursive: true }); + await fs.mkdir(dbPath, { recursive: true }); //create dummy tsconfig.json - await fs.writeFile(path.join(tmpDir, "tsconfig.json"), + await fs.writeFile( + path.join(tmpDir, "tsconfig.json"), `{ "compilerOptions": { /* Path Aliases */ @@ -99,10 +109,12 @@ describe("getConfig", async () => { "prismaDbClient": ["./server/db/db"] } } - }`); + }`, + ); //create dummy auth.ts - await fs.writeFile(path.join(authPath, "auth.ts"), + await fs.writeFile( + path.join(authPath, "auth.ts"), `import {betterAuth} from "better-auth"; import {prismaAdapter} from "better-auth/adapters/prisma"; import {db} from "prismaDbClient"; @@ -114,29 +126,36 @@ describe("getConfig", async () => { emailAndPassword: { enabled: true, } - })`); + })`, + ); //create dummy db.ts - await fs.writeFile(path.join(dbPath, "db.ts"), + await fs.writeFile( + path.join(dbPath, "db.ts"), `class PrismaClient { constructor() {} } - export const db = new PrismaClient()`); + export const db = new PrismaClient()`, + ); - const config = await getConfig({cwd: tmpDir, configPath: 'server/auth/auth.ts'}) + const config = await getConfig({ + cwd: tmpDir, + configPath: "server/auth/auth.ts", + }); expect(config).not.toBe(null); }); it("should resolve resolver type alias with relative path", async () => { - const authPath = path.join(tmpDir, 'test','server', 'auth'); - const dbPath = path.join(tmpDir, 'test','server', 'db'); - await fs.mkdir(authPath, {recursive: true}); - await fs.mkdir(dbPath, {recursive: true}); + const authPath = path.join(tmpDir, "test", "server", "auth"); + const dbPath = path.join(tmpDir, "test", "server", "db"); + await fs.mkdir(authPath, { recursive: true }); + await fs.mkdir(dbPath, { recursive: true }); //create dummy tsconfig.json - await fs.writeFile(path.join(tmpDir, "tsconfig.json"), + await fs.writeFile( + path.join(tmpDir, "tsconfig.json"), `{ "compilerOptions": { /* Path Aliases */ @@ -145,10 +164,12 @@ describe("getConfig", async () => { "@server/*": ["./server/*"] } } - }`); + }`, + ); //create dummy auth.ts - await fs.writeFile(path.join(authPath, "auth.ts"), + await fs.writeFile( + path.join(authPath, "auth.ts"), `import {betterAuth} from "better-auth"; import {prismaAdapter} from "better-auth/adapters/prisma"; import {db} from "@server/db/db"; @@ -160,29 +181,36 @@ describe("getConfig", async () => { emailAndPassword: { enabled: true, } - })`); + })`, + ); //create dummy db.ts - await fs.writeFile(path.join(dbPath, "db.ts"), + await fs.writeFile( + path.join(dbPath, "db.ts"), `class PrismaClient { constructor() {} } - export const db = new PrismaClient()`); + export const db = new PrismaClient()`, + ); - const config = await getConfig({cwd: tmpDir, configPath: 'test/server/auth/auth.ts'}) + const config = await getConfig({ + cwd: tmpDir, + configPath: "test/server/auth/auth.ts", + }); expect(config).not.toBe(null); }); it("should resolve direct alias with relative path", async () => { - const authPath = path.join(tmpDir, 'test','server', 'auth'); - const dbPath = path.join(tmpDir, 'test','server', 'db'); - await fs.mkdir(authPath, {recursive: true}); - await fs.mkdir(dbPath, {recursive: true}); + const authPath = path.join(tmpDir, "test", "server", "auth"); + const dbPath = path.join(tmpDir, "test", "server", "db"); + await fs.mkdir(authPath, { recursive: true }); + await fs.mkdir(dbPath, { recursive: true }); //create dummy tsconfig.json - await fs.writeFile(path.join(tmpDir, "tsconfig.json"), + await fs.writeFile( + path.join(tmpDir, "tsconfig.json"), `{ "compilerOptions": { /* Path Aliases */ @@ -191,10 +219,12 @@ describe("getConfig", async () => { "prismaDbClient": ["./server/db/db"] } } - }`); + }`, + ); //create dummy auth.ts - await fs.writeFile(path.join(authPath, "auth.ts"), + await fs.writeFile( + path.join(authPath, "auth.ts"), `import {betterAuth} from "better-auth"; import {prismaAdapter} from "better-auth/adapters/prisma"; import {db} from "prismaDbClient"; @@ -206,29 +236,36 @@ describe("getConfig", async () => { emailAndPassword: { enabled: true, } - })`); + })`, + ); //create dummy db.ts - await fs.writeFile(path.join(dbPath, "db.ts"), + await fs.writeFile( + path.join(dbPath, "db.ts"), `class PrismaClient { constructor() {} } - export const db = new PrismaClient()`); + export const db = new PrismaClient()`, + ); - const config = await getConfig({cwd: tmpDir, configPath: 'test/server/auth/auth.ts'}) + const config = await getConfig({ + cwd: tmpDir, + configPath: "test/server/auth/auth.ts", + }); expect(config).not.toBe(null); }); it("should resolve with relative import", async () => { - const authPath = path.join(tmpDir, 'test','server', 'auth'); - const dbPath = path.join(tmpDir, 'test','server', 'db'); - await fs.mkdir(authPath, {recursive: true}); - await fs.mkdir(dbPath, {recursive: true}); + const authPath = path.join(tmpDir, "test", "server", "auth"); + const dbPath = path.join(tmpDir, "test", "server", "db"); + await fs.mkdir(authPath, { recursive: true }); + await fs.mkdir(dbPath, { recursive: true }); //create dummy tsconfig.json - await fs.writeFile(path.join(tmpDir, "tsconfig.json"), + await fs.writeFile( + path.join(tmpDir, "tsconfig.json"), `{ "compilerOptions": { /* Path Aliases */ @@ -237,10 +274,12 @@ describe("getConfig", async () => { "prismaDbClient": ["./server/db/db"] } } - }`); + }`, + ); //create dummy auth.ts - await fs.writeFile(path.join(authPath, "auth.ts"), + await fs.writeFile( + path.join(authPath, "auth.ts"), `import {betterAuth} from "better-auth"; import {prismaAdapter} from "better-auth/adapters/prisma"; import {db} from "../db/db"; @@ -252,29 +291,36 @@ describe("getConfig", async () => { emailAndPassword: { enabled: true, } - })`); + })`, + ); //create dummy db.ts - await fs.writeFile(path.join(dbPath, "db.ts"), + await fs.writeFile( + path.join(dbPath, "db.ts"), `class PrismaClient { constructor() {} } - export const db = new PrismaClient()`); + export const db = new PrismaClient()`, + ); - const config = await getConfig({cwd: tmpDir, configPath: 'test/server/auth/auth.ts'}) + const config = await getConfig({ + cwd: tmpDir, + configPath: "test/server/auth/auth.ts", + }); expect(config).not.toBe(null); }); it("should error with invalid alias", async () => { - const authPath = path.join(tmpDir, 'server', 'auth'); - const dbPath = path.join(tmpDir, 'server', 'db'); - await fs.mkdir(authPath, {recursive: true}); - await fs.mkdir(dbPath, {recursive: true}); + const authPath = path.join(tmpDir, "server", "auth"); + const dbPath = path.join(tmpDir, "server", "db"); + await fs.mkdir(authPath, { recursive: true }); + await fs.mkdir(dbPath, { recursive: true }); //create dummy tsconfig.json - await fs.writeFile(path.join(tmpDir, "tsconfig.json"), + await fs.writeFile( + path.join(tmpDir, "tsconfig.json"), `{ "compilerOptions": { /* Path Aliases */ @@ -283,10 +329,12 @@ describe("getConfig", async () => { "@server/*": ["./PathIsInvalid/*"] } } - }`); + }`, + ); //create dummy auth.ts - await fs.writeFile(path.join(authPath, "auth.ts"), + await fs.writeFile( + path.join(authPath, "auth.ts"), `import {betterAuth} from "better-auth"; import {prismaAdapter} from "better-auth/adapters/prisma"; import {db} from "@server/db/db"; @@ -298,16 +346,21 @@ describe("getConfig", async () => { emailAndPassword: { enabled: true, } - })`); + })`, + ); //create dummy db.ts - await fs.writeFile(path.join(dbPath, "db.ts"), + await fs.writeFile( + path.join(dbPath, "db.ts"), `class PrismaClient { constructor() {} } - export const db = new PrismaClient()`); + export const db = new PrismaClient()`, + ); - await expect(() => getConfig({cwd: tmpDir, configPath: 'server/auth/auth.ts'})).rejects.toThrowError(); + await expect(() => + getConfig({ cwd: tmpDir, configPath: "server/auth/auth.ts" }), + ).rejects.toThrowError(); }); -}) +});