Debian Codegraph @

walk-up-path/test/index.js

raw
1 import { posix, win32 } from 'path'
2 const path = {
3 mode: posix,
4 dirname: (...args) => path.mode.dirname(...args),
5 resolve: (...args) => path.mode.resolve(...args),
6 }
7
8 import t from 'tap'
9 const { walkUp } = await t.mockImport('../src/index.js', { path })
10
11 t.test('posix', async t => {
12 path.mode = posix
13 t.strictSame(
14 [...walkUp('/some/kinda/path')],
15 ['/some/kinda/path', '/some/kinda', '/some', '/']
16 )
17 t.strictSame([...walkUp('/')], ['/'])
18 t.strictSame(
19 [...walkUp('')],
20 [...walkUp(process.cwd().replace(/\\/g, '/'))]
21 )
22 })
23
24 t.test('win32', async t => {
25 path.mode = win32
26 t.strictSame(
27 [...walkUp('c:\\some\\kinda\\path')],
28 ['c:\\some\\kinda\\path', 'c:\\some\\kinda', 'c:\\some', 'c:\\']
29 )
30 t.strictSame(
31 [...walkUp('c:/some/kinda/path')],
32 ['c:\\some\\kinda\\path', 'c:\\some\\kinda', 'c:\\some', 'c:\\']
33 )
34 t.strictSame([...walkUp('/')], [path.resolve(process.cwd(), '/')])
35 t.strictSame([...walkUp('')], [...walkUp(process.cwd())])
36 })