From 8b7a4d60976304c9cbd4bdc198e7512e0ef7f6c8 Mon Sep 17 00:00:00 2001 From: Philzen Date: Mon, 30 Dec 2024 03:35:15 +0100 Subject: [PATCH] [refactor paths tests] Re-use DEFAULT_PATHS object in more tests --- .../src/__tests__/paths.test.ts | 37 ++++++------------- 1 file changed, 11 insertions(+), 26 deletions(-) diff --git a/packages/project-config/src/__tests__/paths.test.ts b/packages/project-config/src/__tests__/paths.test.ts index 608492a13027..7ae0e96ea57c 100644 --- a/packages/project-config/src/__tests__/paths.test.ts +++ b/packages/project-config/src/__tests__/paths.test.ts @@ -13,6 +13,7 @@ import { } from '../paths' const RWJS_CWD = process.env.RWJS_CWD + /** * All paths relevant to the redwood stack as defined in * {@link ../paths | paths.ts}, relative from project root @@ -52,7 +53,7 @@ const DEFAULT_PATHS = { jobsConfig: ['api', 'src', 'lib', 'jobs'], distJobsConfig: ['api', 'dist', 'lib', 'jobs'], logger: ['api', 'src', 'lib', 'logger.ts'], - } as Record, + }, web: { routes: ['web', 'src', 'Routes.tsx'], base: ['web'], @@ -84,7 +85,7 @@ const DEFAULT_PATHS = { entryClient: ['web', 'src', 'entry.client.tsx'], // new vite/stream entry point for client entryServer: ['web', 'src', 'entry.server'], graphql: ['web', 'src', 'graphql'], - } as Record, + }, } /** @@ -136,11 +137,7 @@ describe('paths', () => { it('finds the correct base directory from a file', () => { const projectFilePath = path.join( - FIXTURE_BASEDIR, - 'web', - 'src', - 'pages', - 'AboutPage', + ...[FIXTURE_BASEDIR, ...DEFAULT_PATHS.web.pages, 'AboutPage'], ) expect(getBaseDirFromFile(projectFilePath)).toBe(FIXTURE_BASEDIR) }) @@ -180,7 +177,7 @@ describe('paths', () => { describe('processPagesDir', () => { it('it accurately finds and names the pages', () => { - const pagesDir = path.join(FIXTURE_BASEDIR, 'web', 'src', 'pages') + const pagesDir = path.join(FIXTURE_BASEDIR, ...DEFAULT_PATHS.web.pages) const pages = processPagesDir(pagesDir) @@ -278,11 +275,7 @@ describe('paths', () => { it('finds the correct base directory from a file', () => { const projectFilePath = path.join( - FIXTURE_BASEDIR, - 'web', - 'src', - 'pages', - 'AboutPage', + ...[FIXTURE_BASEDIR, ...DEFAULT_PATHS.web.pages, 'AboutPage'], ) expect(getBaseDirFromFile(projectFilePath)).toBe(FIXTURE_BASEDIR) }) @@ -322,7 +315,7 @@ describe('paths', () => { describe('processPagesDir', () => { it('it accurately finds and names the pages', () => { - const pagesDir = path.join(FIXTURE_BASEDIR, 'web', 'src', 'pages') + const pagesDir = path.join(FIXTURE_BASEDIR, ...DEFAULT_PATHS.web.pages) const pages = processPagesDir(pagesDir) @@ -466,11 +459,7 @@ describe('paths', () => { it('finds the correct base directory from a file', () => { const projectFilePath = path.join( - FIXTURE_BASEDIR, - 'web', - 'src', - 'pages', - 'AboutPage', + ...[FIXTURE_BASEDIR, ...DEFAULT_PATHS.web.pages, 'AboutPage'], ) expect(getBaseDirFromFile(projectFilePath)).toBe(FIXTURE_BASEDIR) }) @@ -511,7 +500,7 @@ describe('paths', () => { describe('processPagesDir', () => { it('it accurately finds and names the pages', () => { - const pagesDir = path.join(FIXTURE_BASEDIR, 'web', 'src', 'pages') + const pagesDir = path.join(FIXTURE_BASEDIR, ...DEFAULT_PATHS.web.pages) const pages = processPagesDir(pagesDir) @@ -616,11 +605,7 @@ describe('paths', () => { it('finds the correct base directory from a file', () => { const projectFilePath = path.join( - FIXTURE_BASEDIR, - 'web', - 'src', - 'pages', - 'AboutPage', + ...[FIXTURE_BASEDIR, ...DEFAULT_PATHS.web.pages, 'AboutPage'], ) expect(getBaseDirFromFile(projectFilePath)).toBe(FIXTURE_BASEDIR) }) @@ -657,7 +642,7 @@ describe('paths', () => { describe('processPagesDir', () => { it('it accurately finds and names the pages', () => { - const pagesDir = path.join(FIXTURE_BASEDIR, 'web', 'src', 'pages') + const pagesDir = path.join(FIXTURE_BASEDIR, ...DEFAULT_PATHS.web.pages) const pages = processPagesDir(pagesDir)