File size: 1,499 Bytes
23ac194
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
'use strict'

const { test } = require('tap')
const boot = require('..')
const { kPluginMeta } = require('../lib/symbols')

test('plugins get a name from the plugin metadata if it is set', async (t) => {
  t.plan(1)
  const app = boot()

  const func = (app, opts, next) => next()
  func[kPluginMeta] = { name: 'a-test-plugin' }
  app.use(func)
  await app.ready()

  t.match(app.toJSON(), {
    label: 'root',
    nodes: [
      { label: 'a-test-plugin' }
    ]
  })
})

test('plugins get a name from the options if theres no metadata', async (t) => {
  t.plan(1)
  const app = boot()

  function testPlugin (app, opts, next) { next() }
  app.use(testPlugin, { name: 'test registration options name' })
  await app.ready()

  t.match(app.toJSON(), {
    label: 'root',
    nodes: [
      { label: 'test registration options name' }
    ]
  })
})

test('plugins get a name from the function name if theres no name in the options and no metadata', async (t) => {
  t.plan(1)
  const app = boot()

  function testPlugin (app, opts, next) { next() }
  app.use(testPlugin)
  await app.ready()

  t.match(app.toJSON(), {
    label: 'root',
    nodes: [
      { label: 'testPlugin' }
    ]
  })
})

test('plugins get a name from the function source if theres no other option', async (t) => {
  t.plan(1)
  const app = boot()

  app.use((app, opts, next) => next())
  await app.ready()

  t.match(app.toJSON(), {
    label: 'root',
    nodes: [
      { label: '(app, opts, next) => next()' }
    ]
  })
})