Skip to content

Commit

Permalink
[refactor paths tests] Condense test code for readability & conciseness
Browse files Browse the repository at this point in the history
  • Loading branch information
Philzen committed Jan 6, 2025
1 parent 90f4a0c commit eeab5db
Showing 1 changed file with 38 additions and 105 deletions.
143 changes: 38 additions & 105 deletions packages/project-config/src/__tests__/paths.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,8 @@ describe('paths', () => {
process.env.RWJS_CWD = RWJS_CWD
})

it('finds the correct base directory', () => {
expect(getBaseDir()).toBe(FIXTURE_BASEDIR)
})
it('finds the correct base directory', () =>
expect(getBaseDir()).toBe(FIXTURE_BASEDIR))

it('finds the correct base directory from a file', () => {
const projectFilePath = path.join(
Expand Down Expand Up @@ -169,16 +168,12 @@ describe('paths', () => {

it('switches windows slashes in import statements', () => {
const originalPlatform = process.platform
Object.defineProperty(process, 'platform', {
value: 'win32',
})
Object.defineProperty(process, 'platform', { value: 'win32' })

const inputPath = 'C:\\Users\\Bob\\dev\\Redwood\\UserPage\\UserPage'
const outputPath = importStatementPath(inputPath)

Object.defineProperty(process, 'platform', {
value: originalPlatform,
})
Object.defineProperty(process, 'platform', { value: originalPlatform })

expect(outputPath).toEqual('C:/Users/Bob/dev/Redwood/UserPage/UserPage')
})
Expand Down Expand Up @@ -224,48 +219,36 @@ describe('paths', () => {
describe('ensurePosixPath', () => {
it('Returns unmodified input if not on Windows', () => {
const originalPlatform = process.platform
Object.defineProperty(process, 'platform', {
value: 'NotWindows',
})
Object.defineProperty(process, 'platform', { value: 'NotWindows' })

const testPath = 'X:\\some\\weird\\path'
const posixPath = ensurePosixPath(testPath)

Object.defineProperty(process, 'platform', {
value: originalPlatform,
})
Object.defineProperty(process, 'platform', { value: originalPlatform })

expect(posixPath).toEqual(testPath)
})

it('Transforms paths on Windows', () => {
const originalPlatform = process.platform
Object.defineProperty(process, 'platform', {
value: 'win32',
})
Object.defineProperty(process, 'platform', { value: 'win32' })

const testPath = '..\\some\\relative\\path'
const posixPath = ensurePosixPath(testPath)

Object.defineProperty(process, 'platform', {
value: originalPlatform,
})
Object.defineProperty(process, 'platform', { value: originalPlatform })

expect(posixPath).toEqual('../some/relative/path')
})

it('Handles drive letters', () => {
const originalPlatform = process.platform
Object.defineProperty(process, 'platform', {
value: 'win32',
})
Object.defineProperty(process, 'platform', { value: 'win32' })

const testPath = 'C:\\some\\full\\path\\to\\file.ext'
const posixPath = ensurePosixPath(testPath)

Object.defineProperty(process, 'platform', {
value: originalPlatform,
})
Object.defineProperty(process, 'platform', { value: originalPlatform })

expect(posixPath).toEqual('/c/some/full/path/to/file.ext')
})
Expand All @@ -290,9 +273,8 @@ describe('paths', () => {
process.env.RWJS_CWD = RWJS_CWD
})

it('finds the correct base directory', () => {
expect(getBaseDir()).toBe(FIXTURE_BASEDIR)
})
it('finds the correct base directory', () =>
expect(getBaseDir()).toBe(FIXTURE_BASEDIR))

it('finds the correct base directory from a file', () => {
const projectFilePath = path.join(
Expand Down Expand Up @@ -328,16 +310,12 @@ describe('paths', () => {

it('switches windows slashes in import statements', () => {
const originalPlatform = process.platform
Object.defineProperty(process, 'platform', {
value: 'win32',
})
Object.defineProperty(process, 'platform', { value: 'win32' })

const inputPath = 'C:\\Users\\Bob\\dev\\Redwood\\UserPage\\UserPage'
const outputPath = importStatementPath(inputPath)

Object.defineProperty(process, 'platform', {
value: originalPlatform,
})
Object.defineProperty(process, 'platform', { value: originalPlatform })

expect(outputPath).toEqual('C:/Users/Bob/dev/Redwood/UserPage/UserPage')
})
Expand Down Expand Up @@ -429,48 +407,36 @@ describe('paths', () => {
describe('ensurePosixPath', () => {
it('Returns unmodified input if not on Windows', () => {
const originalPlatform = process.platform
Object.defineProperty(process, 'platform', {
value: 'NotWindows',
})
Object.defineProperty(process, 'platform', { value: 'NotWindows' })

const testPath = 'X:\\some\\weird\\path'
const posixPath = ensurePosixPath(testPath)

Object.defineProperty(process, 'platform', {
value: originalPlatform,
})
Object.defineProperty(process, 'platform', { value: originalPlatform })

expect(posixPath).toEqual(testPath)
})

it('Transforms paths on Windows', () => {
const originalPlatform = process.platform
Object.defineProperty(process, 'platform', {
value: 'win32',
})
Object.defineProperty(process, 'platform', { value: 'win32' })

const testPath = '..\\some\\relative\\path'
const posixPath = ensurePosixPath(testPath)

Object.defineProperty(process, 'platform', {
value: originalPlatform,
})
Object.defineProperty(process, 'platform', { value: originalPlatform })

expect(posixPath).toEqual('../some/relative/path')
})

it('Handles drive letters', () => {
const originalPlatform = process.platform
Object.defineProperty(process, 'platform', {
value: 'win32',
})
Object.defineProperty(process, 'platform', { value: 'win32' })

const testPath = 'C:\\some\\full\\path\\to\\file.ext'
const posixPath = ensurePosixPath(testPath)

Object.defineProperty(process, 'platform', {
value: originalPlatform,
})
Object.defineProperty(process, 'platform', { value: originalPlatform })

expect(posixPath).toEqual('/c/some/full/path/to/file.ext')
})
Expand All @@ -495,9 +461,8 @@ describe('paths', () => {
process.env.RWJS_CWD = RWJS_CWD
})

it('finds the correct base directory', () => {
expect(getBaseDir()).toBe(FIXTURE_BASEDIR)
})
it('finds the correct base directory', () =>
expect(getBaseDir()).toBe(FIXTURE_BASEDIR))

it('finds the correct base directory from a file', () => {
const projectFilePath = path.join(
Expand Down Expand Up @@ -534,16 +499,12 @@ describe('paths', () => {

it('switches windows slashes in import statements', () => {
const originalPlatform = process.platform
Object.defineProperty(process, 'platform', {
value: 'win32',
})
Object.defineProperty(process, 'platform', { value: 'win32' })

const inputPath = 'C:\\Users\\Bob\\dev\\Redwood\\UserPage\\UserPage'
const outputPath = importStatementPath(inputPath)

Object.defineProperty(process, 'platform', {
value: originalPlatform,
})
Object.defineProperty(process, 'platform', { value: originalPlatform })

expect(outputPath).toEqual('C:/Users/Bob/dev/Redwood/UserPage/UserPage')
})
Expand Down Expand Up @@ -595,48 +556,36 @@ describe('paths', () => {
describe('ensurePosixPath', () => {
it('Returns unmodified input if not on Windows', () => {
const originalPlatform = process.platform
Object.defineProperty(process, 'platform', {
value: 'NotWindows',
})
Object.defineProperty(process, 'platform', { value: 'NotWindows' })

const testPath = 'X:\\some\\weird\\path'
const posixPath = ensurePosixPath(testPath)

Object.defineProperty(process, 'platform', {
value: originalPlatform,
})
Object.defineProperty(process, 'platform', { value: originalPlatform })

expect(posixPath).toEqual(testPath)
})

it('Transforms paths on Windows', () => {
const originalPlatform = process.platform
Object.defineProperty(process, 'platform', {
value: 'win32',
})
Object.defineProperty(process, 'platform', { value: 'win32' })

const testPath = '..\\some\\relative\\path'
const posixPath = ensurePosixPath(testPath)

Object.defineProperty(process, 'platform', {
value: originalPlatform,
})
Object.defineProperty(process, 'platform', { value: originalPlatform })

expect(posixPath).toEqual('../some/relative/path')
})

it('Handles drive letters', () => {
const originalPlatform = process.platform
Object.defineProperty(process, 'platform', {
value: 'win32',
})
Object.defineProperty(process, 'platform', { value: 'win32' })

const testPath = 'C:\\some\\full\\path\\to\\file.ext'
const posixPath = ensurePosixPath(testPath)

Object.defineProperty(process, 'platform', {
value: originalPlatform,
})
Object.defineProperty(process, 'platform', { value: originalPlatform })

expect(posixPath).toEqual('/c/some/full/path/to/file.ext')
})
Expand Down Expand Up @@ -696,16 +645,12 @@ describe('paths', () => {

it('switches windows slashes in import statements', () => {
const originalPlatform = process.platform
Object.defineProperty(process, 'platform', {
value: 'win32',
})
Object.defineProperty(process, 'platform', { value: 'win32' })

const inputPath = 'C:\\Users\\Bob\\dev\\Redwood\\UserPage\\UserPage'
const outputPath = importStatementPath(inputPath)

Object.defineProperty(process, 'platform', {
value: originalPlatform,
})
Object.defineProperty(process, 'platform', { value: originalPlatform })

expect(outputPath).toEqual('C:/Users/Bob/dev/Redwood/UserPage/UserPage')
})
Expand Down Expand Up @@ -812,48 +757,36 @@ describe('paths', () => {
describe('ensurePosixPath', () => {
it('Returns unmodified input if not on Windows', () => {
const originalPlatform = process.platform
Object.defineProperty(process, 'platform', {
value: 'NotWindows',
})
Object.defineProperty(process, 'platform', { value: 'NotWindows' })

const testPath = 'X:\\some\\weird\\path'
const posixPath = ensurePosixPath(testPath)

Object.defineProperty(process, 'platform', {
value: originalPlatform,
})
Object.defineProperty(process, 'platform', { value: originalPlatform })

expect(posixPath).toEqual(testPath)
})

it('Transforms paths on Windows', () => {
const originalPlatform = process.platform
Object.defineProperty(process, 'platform', {
value: 'win32',
})
Object.defineProperty(process, 'platform', { value: 'win32' })

const testPath = '..\\some\\relative\\path'
const posixPath = ensurePosixPath(testPath)

Object.defineProperty(process, 'platform', {
value: originalPlatform,
})
Object.defineProperty(process, 'platform', { value: originalPlatform })

expect(posixPath).toEqual('../some/relative/path')
})

it('Handles drive letters', () => {
const originalPlatform = process.platform
Object.defineProperty(process, 'platform', {
value: 'win32',
})
Object.defineProperty(process, 'platform', { value: 'win32' })

const testPath = 'C:\\some\\full\\path\\to\\file.ext'
const posixPath = ensurePosixPath(testPath)

Object.defineProperty(process, 'platform', {
value: originalPlatform,
})
Object.defineProperty(process, 'platform', { value: originalPlatform })

expect(posixPath).toEqual('/c/some/full/path/to/file.ext')
})
Expand Down

0 comments on commit eeab5db

Please sign in to comment.