Skip to content

Commit

Permalink
[refactor paths tests] Re-use DEFAULT_PATHS object in more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Philzen committed Dec 30, 2024
1 parent 6988748 commit 8b7a4d6
Showing 1 changed file with 11 additions and 26 deletions.
37 changes: 11 additions & 26 deletions packages/project-config/src/__tests__/paths.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<string, null | string[]>,
},
web: {
routes: ['web', 'src', 'Routes.tsx'],
base: ['web'],
Expand Down Expand Up @@ -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<string, null | string[]>,
},
}

/**
Expand Down Expand Up @@ -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)
})
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
})
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
})
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
})
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 8b7a4d6

Please sign in to comment.