Skip to content

Commit

Permalink
test: improve treatPathSep spec coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
scolladon committed Mar 18, 2024
1 parent 2cb8500 commit 9429d9b
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions __tests__/unit/lib/utils/fsUtils.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
'use strict'
import { sep } from 'path'

import { expect, jest, describe, it } from '@jest/globals'
import { Stats, stat, readFile as fsReadFile } from 'fs-extra'

import { PATH_SEP } from '../../../../src/constant/fsConstants'
import {
dirExists,
fileExists,
Expand Down Expand Up @@ -192,40 +191,51 @@ describe('readFile', () => {
})
})

describe('treatPathSep', () => {
it(`replace / by ${sep}`, () => {
describe.each(['/', '\\'])('treatPathSep', sep => {
it(`replace %s by ${PATH_SEP}`, () => {
// Arrange
const input = `test${sep + sep + sep}test${sep + sep}test${sep}test`

// Act
const result = treatPathSep(input)

// Assert
expect(result).toBe(`test${PATH_SEP}test${PATH_SEP}test${PATH_SEP}test`)
})

it(`keeps the leading %`, () => {
// Arrange
const input = 'test///test//test/test'
const input = `${sep}test${sep}test`

// Act
const result = treatPathSep(input)

// Assert
expect(result).toBe(`test${sep}test${sep}test${sep}test`)
expect(result).toBe(`${PATH_SEP}test${PATH_SEP}test`)
})

it(`replace \\ by ${sep}`, () => {
it(`keeps the trailing %`, () => {
// Arrange
const input = 'test\\\\\\test\\\\test\\test'
const input = `test${sep}test${sep}`

// Act
const result = treatPathSep(input)

// Assert
expect(result).toBe(`test${sep}test${sep}test${sep}test`)
expect(result).toBe(`test${PATH_SEP}test${PATH_SEP}`)
})
})

describe('sanitizePath', () => {
it(`returns path with '${sep}' separator`, () => {
it(`returns path with '${PATH_SEP}' separator`, () => {
// Arrange
const input = 'test\\test/test'

// Act
const result = sanitizePath(input)

// Assert
expect(result).toBe(`test${sep}test${sep}test`)
expect(result).toBe(`test${PATH_SEP}test${PATH_SEP}test`)
})

it(`normalize path`, () => {
Expand All @@ -236,7 +246,7 @@ describe('sanitizePath', () => {
const result = sanitizePath(input)

// Assert
expect(result).toBe(`test${sep}test`)
expect(result).toBe(`test${PATH_SEP}test`)
})

it('return empty string when data is empty string', () => {
Expand Down

0 comments on commit 9429d9b

Please sign in to comment.