Testing Path-to-Glob Pattern Conversion in uni-app
This test suite validates the pathToGlob utility function in the uni-app framework, which handles path-to-glob pattern conversion across different operating systems. The tests ensure reliable path manipulation for both Unix and Windows environments while maintaining proper glob pattern generation.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
dcloudio/uni-app
packages/uni-cli-shared/__tests__/pathToGlob.spec.ts
import { pathToGlob } from '../src/utils'
describe('pathToGlob', () => {
it('path in unix', () => {
expect(pathToGlob('/test', '**/*.js')).toBe('/test/**/*.js')
expect(pathToGlob('/test(1', '**/*.js')).toBe('/test[(]1/**/*.js')
expect(
pathToGlob('/test(1', '**/*.js', { escape: true, windows: false })
).toBe('/test\\(1/**/*.js')
})
it('path in windows', () => {
expect(pathToGlob('C:\\\\test\\test', '**/*.js', { windows: true })).toBe(
'C:/test/test/**/*.js'
)
expect(pathToGlob('C:\\\\test\\test(1', '**/*.js', { windows: true })).toBe(
'C:/test/test[(]1/**/*.js'
)
expect(
pathToGlob('C:\\\\test\\test(1', '**/*.js', {
windows: true,
escape: true,
})
).toBe('C:/test/test[(]1/**/*.js')
})
})