liudong
2023-05-29 340f156319b863525e50e900c58e59b86ecb3d5e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
var test = require('tape')
var walkBack = require('../')
 
test('basic', function (t) {
  t.plan(1)
 
  var filename = walkBack(__dirname + '/fixture/subdir', 'file.txt')
  t.ok(filename.search('walk-back/test/fixture/subdir/file.txt') > 0)
})
 
test('basic2', function (t) {
  t.plan(1)
 
  var filename = walkBack(__dirname + '/fixture', 'file.txt')
  t.ok(filename.search('walk-back/test/fixture/file.txt') > 0)
})
 
test('not found', function (t) {
  t.plan(1)
 
  var filename = walkBack(__dirname + '/fixture', 'adskjfhladfn')
  t.strictEqual(filename, null)
})
 
test('relative path', function (t) {
  t.plan(1)
 
  var filename = walkBack('.', 'test/fixture/subdir/file.txt')
  t.ok(filename && filename.search('walk-back/test/fixture/subdir/file.txt') > 0)
})
 
test('relative path 2', function (t) {
  t.plan(1)
 
  var filename = walkBack('./test/fixture/subdir', 'file.txt')
  t.ok(filename && filename.search('walk-back/test/fixture/subdir/file.txt') > 0)
})
 
test('startPath doesn\'t exist', function (t) {
  t.throws(function () {
    walkBack('slfnavnkln', 'file.txt')    
  })
  t.end()
})