strong-tie/inbound-calls
0
1'use strict'2 3const { test } = require('node:test')4const fp = require('../plugin')5 6test('webpack removes require.main.filename', t => {7 const filename = require.main.filename8 const info = console.info9 t.after(() => {10 require.main.filename = filename11 console.info = info12 })13 14 require.main.filename = null15 16 console.info = function (msg) {17 t.assert.fail('logged: ' + msg)18 }19 20 fp((fastify, opts, next) => {21 next()22 }, {23 fastify: '^5.0.0'24 })25})26 27test('support faux modules', (t) => {28 const plugin = fp((fastify, opts, next) => {29 next()30 })31 32 t.assert.strictEqual(plugin.default, plugin)33})34 35test('support faux modules does not override existing default field in babel module', (t) => {36 const module = {37 default: (fastify, opts, next) => next()38 }39 40 module.default.default = 'Existing default field'41 42 const plugin = fp(module)43 44 t.assert.strictEqual(plugin.default, 'Existing default field')45})46 47test('support ts named imports', (t) => {48 const plugin = fp((fastify, opts, next) => {49 next()50 }, {51 name: 'hello'52 })53 54 t.assert.strictEqual(plugin.hello, plugin)55})56 57test('from kebab-case to camelCase', (t) => {58 const plugin = fp((fastify, opts, next) => {59 next()60 }, {61 name: 'hello-world'62 })63 64 t.assert.strictEqual(plugin.helloWorld, plugin)65})66 67test('from @-prefixed named imports', (t) => {68 const plugin = fp((fastify, opts, next) => {69 next()70 }, {71 name: '@hello/world'72 })73 74 t.assert.strictEqual(plugin.helloWorld, plugin)75})76 77test('from @-prefixed named kebab-case to camelCase', (t) => {78 const plugin = fp((fastify, opts, next) => {79 next()80 }, {81 name: '@hello/my-world'82 })83 84 t.assert.strictEqual(plugin.helloMyWorld, plugin)85})86 87test('from kebab-case to camelCase multiple words', (t) => {88 const plugin = fp((fastify, opts, next) => {89 next()90 }, {91 name: 'hello-long-world'92 })93 94 t.assert.strictEqual(plugin.helloLongWorld, plugin)95})96 97test('from kebab-case to camelCase multiple words does not override', (t) => {98 const fn = (fastify, opts, next) => {99 next()100 }101 102 const foobar = {}103 fn.helloLongWorld = foobar104 105 const plugin = fp(fn, {106 name: 'hello-long-world'107 })108 109 t.assert.strictEqual(plugin.helloLongWorld, foobar)110})111 