path.test.ts
This file
Path
src/middleware/serve-static/path.test.ts
50 lines · 1.4 KiB · TypeScript
Last changed by
Not known.
History of this fileTake it
The walk stopped after 200 commits: lines older than f0b094d point at it.
Merge commit from forkYusuke Wadabefore adoptionf0b094d
lines 1–50why, one step back1import { join as posixJoin } from 'node:path/posix'2import { defaultJoin } from './path'34describe('defaultJoin', () => {5 describe('Comparison with node:path/posix.join', () => {6 it('Should behave like path.posix.join for all path operations', () => {7 const testCases = [8 // Basic path joining9 ['/home/yusuke/work/app/public', 'static/main.html'],10 ['public', 'sub/', 'file.html'],11 ['', 'file.html'],12 ['public', ''],13 ['public/', 'file.html'],14 ['public', 'static', 'main.html'],15 ['assets', 'images', 'logo.png'],1617 // Parent directory references18 ['public', '../parent/file.html'],19 ['public', '../../grandparent/file.html'],20 ['/abs/path', '../relative.html'],21 ['a/b', '../c'],22 ['a/b/c', '../../d'],2324 // Current directory references25 ['./public', 'static/main.html'],26 ['public', './file.html'],27 ['./public', '/absolute/path.html'],28 ['.', 'file.html'],29 ['public/.', 'file.html'],3031 // Edge cases32 [],33 ['.'],34 [''],35 ['/'],36 ['a', 'b', 'c'],3738 // Backslash handling (security)39 ['static', 'test\\file.txt'],40 ['public', 'path\\with\\backslash'],41 ]4243 testCases.forEach(([...args]) => {44 const expected = posixJoin(...args)45 const actual = defaultJoin(...args)46 expect(actual).toBe(expected)47 })48 })49 })50})