CoolFace
Apppublic

strong-tie/inbound-calls

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
plugin-name.test.js70 linesDownload Raw Back to test
1'use strict'2 3const { test } = require('tap')4const boot = require('..')5const { kPluginMeta } = require('../lib/symbols')6 7test('plugins get a name from the plugin metadata if it is set', async (t) => {8  t.plan(1)9  const app = boot()10 11  const func = (app, opts, next) => next()12  func[kPluginMeta] = { name: 'a-test-plugin' }13  app.use(func)14  await app.ready()15 16  t.match(app.toJSON(), {17    label: 'root',18    nodes: [19      { label: 'a-test-plugin' }20    ]21  })22})23 24test('plugins get a name from the options if theres no metadata', async (t) => {25  t.plan(1)26  const app = boot()27 28  function testPlugin (app, opts, next) { next() }29  app.use(testPlugin, { name: 'test registration options name' })30  await app.ready()31 32  t.match(app.toJSON(), {33    label: 'root',34    nodes: [35      { label: 'test registration options name' }36    ]37  })38})39 40test('plugins get a name from the function name if theres no name in the options and no metadata', async (t) => {41  t.plan(1)42  const app = boot()43 44  function testPlugin (app, opts, next) { next() }45  app.use(testPlugin)46  await app.ready()47 48  t.match(app.toJSON(), {49    label: 'root',50    nodes: [51      { label: 'testPlugin' }52    ]53  })54})55 56test('plugins get a name from the function source if theres no other option', async (t) => {57  t.plan(1)58  const app = boot()59 60  app.use((app, opts, next) => next())61  await app.ready()62 63  t.match(app.toJSON(), {64    label: 'root',65    nodes: [66      { label: '(app, opts, next) => next()' }67    ]68  })69})70