CoolFace
Apppublic

strong-tie/inbound-calls

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
load-plugin.test.js124 linesDownload Raw Back to test
1'use strict'2 3const fastq = require('fastq')4const boot = require('..')5const { test } = require('tap')6const { Plugin } = require('../lib/plugin')7 8test('successfully load a plugin with sync function', (t) => {9  t.plan(1)10  const app = boot({})11 12  const plugin = new Plugin(fastq(app, app._loadPluginNextTick, 1), function (instance, opts, done) {13    done()14  }, false, 0)15 16  app._loadPlugin(plugin, function (err) {17    t.equal(err, undefined)18  })19})20 21test('catch an error when loading a plugin with sync function', (t) => {22  t.plan(1)23  const app = boot({})24 25  const plugin = new Plugin(fastq(app, app._loadPluginNextTick, 1), function (instance, opts, done) {26    done(Error('ArbitraryError'))27  }, false, 0)28 29  app._loadPlugin(plugin, function (err) {30    t.equal(err.message, 'ArbitraryError')31  })32})33 34test('successfully load a plugin with sync function without done as a parameter', (t) => {35  t.plan(1)36  const app = boot({})37 38  const plugin = new Plugin(fastq(app, app._loadPluginNextTick, 1), function (instance, opts) { }, false, 0)39 40  app._loadPlugin(plugin, function (err) {41    t.equal(err, undefined)42  })43})44 45test('successfully load a plugin with async function', (t) => {46  t.plan(1)47  const app = boot({})48 49  const plugin = new Plugin(fastq(app, app._loadPluginNextTick, 1), async function (instance, opts) { }, false, 0)50 51  app._loadPlugin(plugin, function (err) {52    t.equal(err, undefined)53  })54})55 56test('catch an error when loading a plugin with async function', (t) => {57  t.plan(1)58  const app = boot({})59 60  const plugin = new Plugin(fastq(app, app._loadPluginNextTick, 1), async function (instance, opts) {61    throw Error('ArbitraryError')62  }, false, 0)63 64  app._loadPlugin(plugin, function (err) {65    t.equal(err.message, 'ArbitraryError')66  })67})68 69test('successfully load a plugin when function is a Promise, which resolves to a function', (t) => {70  t.plan(1)71  const app = boot({})72 73  const plugin = new Plugin(fastq(app, app._loadPluginNextTick, 1), new Promise(resolve => resolve(function (instance, opts, done) {74    done()75  })), false, 0)76 77  app._loadPlugin(plugin, function (err) {78    t.equal(err, undefined)79  })80})81 82test('catch an error when loading a plugin when function is a Promise, which resolves to a function', (t) => {83  t.plan(1)84  const app = boot({})85 86  const plugin = new Plugin(fastq(app, app._loadPluginNextTick, 1), new Promise(resolve => resolve(function (instance, opts, done) {87    done(Error('ArbitraryError'))88  })), false, 0)89 90  app._loadPlugin(plugin, function (err) {91    t.equal(err.message, 'ArbitraryError')92  })93})94 95test('successfully load a plugin when function is a Promise, which resolves to a function, which is wrapped in default', (t) => {96  t.plan(1)97  const app = boot({})98 99  const plugin = new Plugin(fastq(app, app._loadPluginNextTick, 1), new Promise(resolve => resolve({100    default: function (instance, opts, done) {101      done()102    }103  })), false, 0)104 105  app._loadPlugin(plugin, function (err) {106    t.equal(err, undefined)107  })108})109 110test('catch an error when loading a plugin when function is a Promise, which resolves to a function, which is wrapped in default', (t) => {111  t.plan(1)112  const app = boot({})113 114  const plugin = new Plugin(fastq(app, app._loadPluginNextTick, 1), new Promise(resolve => resolve({115    default: function (instance, opts, done) {116      done(Error('ArbitraryError'))117    }118  })), false, 0)119 120  app._loadPlugin(plugin, function (err) {121    t.equal(err.message, 'ArbitraryError')122  })123})124