wzp
2021-05-13 7d694a9113118daec5be7ac224dab46a3b20f106
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
'use strict'
 
const t = require('tap')
const test = t.test
const FindMyWay = require('../')
const noop = () => {}
 
test('Defining static route after parametric - 1', t => {
  t.plan(3)
  const findMyWay = FindMyWay()
 
  findMyWay.on('GET', '/static', noop)
  findMyWay.on('GET', '/:param', noop)
 
  t.ok(findMyWay.find('GET', '/static'))
  t.ok(findMyWay.find('GET', '/para'))
  t.ok(findMyWay.find('GET', '/s'))
})
 
test('Defining static route after parametric - 2', t => {
  t.plan(3)
  const findMyWay = FindMyWay()
 
  findMyWay.on('GET', '/:param', noop)
  findMyWay.on('GET', '/static', noop)
 
  t.ok(findMyWay.find('GET', '/static'))
  t.ok(findMyWay.find('GET', '/para'))
  t.ok(findMyWay.find('GET', '/s'))
})
 
test('Defining static route after parametric - 3', t => {
  t.plan(4)
  const findMyWay = FindMyWay()
 
  findMyWay.on('GET', '/:param', noop)
  findMyWay.on('GET', '/static', noop)
  findMyWay.on('GET', '/other', noop)
 
  t.ok(findMyWay.find('GET', '/static'))
  t.ok(findMyWay.find('GET', '/para'))
  t.ok(findMyWay.find('GET', '/s'))
  t.ok(findMyWay.find('GET', '/o'))
})
 
test('Defining static route after parametric - 4', t => {
  t.plan(4)
  const findMyWay = FindMyWay()
 
  findMyWay.on('GET', '/static', noop)
  findMyWay.on('GET', '/other', noop)
  findMyWay.on('GET', '/:param', noop)
 
  t.ok(findMyWay.find('GET', '/static'))
  t.ok(findMyWay.find('GET', '/para'))
  t.ok(findMyWay.find('GET', '/s'))
  t.ok(findMyWay.find('GET', '/o'))
})
 
test('Defining static route after parametric - 5', t => {
  t.plan(4)
  const findMyWay = FindMyWay()
 
  findMyWay.on('GET', '/static', noop)
  findMyWay.on('GET', '/:param', noop)
  findMyWay.on('GET', '/other', noop)
 
  t.ok(findMyWay.find('GET', '/static'))
  t.ok(findMyWay.find('GET', '/para'))
  t.ok(findMyWay.find('GET', '/s'))
  t.ok(findMyWay.find('GET', '/o'))
})
 
test('Should produce the same tree - 1', t => {
  t.plan(1)
  const findMyWay1 = FindMyWay()
  const findMyWay2 = FindMyWay()
 
  findMyWay1.on('GET', '/static', noop)
  findMyWay1.on('GET', '/:param', noop)
 
  findMyWay2.on('GET', '/:param', noop)
  findMyWay2.on('GET', '/static', noop)
 
  t.deepEqual(findMyWay1.tree, findMyWay2.tree)
})
 
test('Should produce the same tree - 2', t => {
  t.plan(3)
  const findMyWay1 = FindMyWay()
  const findMyWay2 = FindMyWay()
  const findMyWay3 = FindMyWay()
 
  findMyWay1.on('GET', '/:param', noop)
  findMyWay1.on('GET', '/static', noop)
  findMyWay1.on('GET', '/other', noop)
 
  findMyWay2.on('GET', '/static', noop)
  findMyWay2.on('GET', '/:param', noop)
  findMyWay2.on('GET', '/other', noop)
 
  findMyWay3.on('GET', '/static', noop)
  findMyWay3.on('GET', '/other', noop)
  findMyWay3.on('GET', '/:param', noop)
 
  t.deepEqual(findMyWay1.tree, findMyWay2.tree)
  t.deepEqual(findMyWay2.tree, findMyWay3.tree)
  t.deepEqual(findMyWay1.tree, findMyWay3.tree)
})