@@ -21,96 +21,49 @@ const UNWRAPPED_METHODS = METHODS.concat([
21
21
] )
22
22
const UNWRAPPED_STATIC_METHODS = [ 'url' ]
23
23
24
- tap . test ( 'koa-router' , function tests ( t ) {
25
- var helper = utils . TestAgent . makeInstrumented ( )
26
- t . teardown ( function ( ) {
27
- helper . unload ( )
28
- } )
29
- helper . registerInstrumentation ( {
30
- type : 'web-framework' ,
31
- moduleName : 'koa-router' ,
32
- onRequire : instrumentation
33
- } )
34
-
35
- t . test ( 'mounting paramware' , function ( t ) {
36
- var Router = require ( 'koa-router' )
37
- var router = new Router ( )
38
- router . param ( 'second' , function ( ) { } )
39
- t . type ( router . params . second . __NR_original , 'function' , 'param function should be wrapped' )
40
- t . end ( )
41
- } )
24
+ const koaRouterMods = [ 'koa-router' , '@koa/router' ]
42
25
43
- t . test ( 'methods' , function ( t ) {
44
- var Router = require ( 'koa-router' )
45
- WRAPPED_METHODS . forEach ( function checkWrapped ( method ) {
46
- t . type (
47
- Router . prototype [ method ] . __NR_original ,
48
- 'function' ,
49
- method + ' should be a wrapped method on the prototype'
50
- )
26
+ koaRouterMods . forEach ( ( koaRouterMod ) => {
27
+ tap . test ( koaRouterMod , function tests ( t ) {
28
+ const helper = utils . TestAgent . makeInstrumented ( )
29
+ t . teardown ( function ( ) {
30
+ helper . unload ( )
51
31
} )
52
- UNWRAPPED_METHODS . forEach ( function checkUnwrapped ( method ) {
53
- t . type (
54
- Router . prototype [ method ] . __NR_original ,
55
- 'undefined' ,
56
- method + ' should be a unwrapped method on the prototype'
57
- )
58
- } )
59
- UNWRAPPED_STATIC_METHODS . forEach ( function checkUnwrappedStatic ( method ) {
60
- t . type (
61
- Router [ method ] . __NR_original ,
62
- 'undefined' ,
63
- method + ' should be an unwrapped static method'
64
- )
65
- } )
66
- t . end ( )
67
- } )
68
- t . autoend ( )
69
- } )
32
+ const shim = helper . getShim ( )
70
33
71
- tap . test ( '@koa/router' , function tests ( t ) {
72
- var helper = utils . TestAgent . makeInstrumented ( )
73
- t . teardown ( function ( ) {
74
- helper . unload ( )
75
- } )
76
- helper . registerInstrumentation ( {
77
- type : 'web-framework' ,
78
- moduleName : '@koa/router' ,
79
- onRequire : instrumentation
80
- } )
81
-
82
- t . test ( 'mounting paramware' , function ( t ) {
83
- var Router = require ( '@koa/router' )
84
- var router = new Router ( )
85
- router . param ( 'second' , function ( ) { } )
86
- t . type ( router . params . second . __NR_original , 'function' , 'param function should be wrapped' )
87
- t . end ( )
88
- } )
89
-
90
- t . test ( 'methods' , function ( t ) {
91
- var Router = require ( '@koa/router' )
92
- WRAPPED_METHODS . forEach ( function checkWrapped ( method ) {
93
- t . type (
94
- Router . prototype [ method ] . __NR_original ,
95
- 'function' ,
96
- method + ' should be a wrapped method on the prototype'
97
- )
34
+ helper . registerInstrumentation ( {
35
+ type : 'web-framework' ,
36
+ moduleName : koaRouterMod ,
37
+ onRequire : instrumentation
98
38
} )
99
- UNWRAPPED_METHODS . forEach ( function checkUnwrapped ( method ) {
100
- t . type (
101
- Router . prototype [ method ] . __NR_original ,
102
- 'undefined' ,
103
- method + ' should be a unwrapped method on the prototype'
104
- )
39
+
40
+ t . test ( 'mounting paramware' , function ( t ) {
41
+ var Router = require ( koaRouterMod )
42
+ var router = new Router ( )
43
+ router . param ( 'second' , function ( ) { } )
44
+ t . ok ( shim . isWrapped ( router . params . second ) , 'param function should be wrapped' )
45
+ t . end ( )
105
46
} )
106
- UNWRAPPED_STATIC_METHODS . forEach ( function checkUnwrappedStatic ( method ) {
107
- t . type (
108
- Router [ method ] . __NR_original ,
109
- 'undefined' ,
110
- method + ' should be an unwrapped static method'
111
- )
47
+
48
+ t . test ( 'methods' , function ( t ) {
49
+ var Router = require ( koaRouterMod )
50
+ WRAPPED_METHODS . forEach ( function checkWrapped ( method ) {
51
+ t . ok (
52
+ shim . isWrapped ( Router . prototype [ method ] ) ,
53
+ method + ' should be a wrapped method on the prototype'
54
+ )
55
+ } )
56
+ UNWRAPPED_METHODS . forEach ( function checkUnwrapped ( method ) {
57
+ t . not (
58
+ shim . isWrapped ( Router . prototype [ method ] ) ,
59
+ method + ' should be a unwrapped method on the prototype'
60
+ )
61
+ } )
62
+ UNWRAPPED_STATIC_METHODS . forEach ( function checkUnwrappedStatic ( method ) {
63
+ t . not ( shim . isWrapped ( Router [ method ] ) , method + ' should be an unwrapped static method' )
64
+ } )
65
+ t . end ( )
112
66
} )
113
- t . end ( )
67
+ t . autoend ( )
114
68
} )
115
- t . autoend ( )
116
69
} )
0 commit comments