🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

gengojs-wrappify

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gengojs-wrappify

An Express, Hapi, an Koa wrapper for the core of gengojs. This module should be used for test purposes only.

latest
Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

gengojs-wrappify

An Express, Hapi, an Koa wrapper for the core of gengojs. This module should be used when you need to test your gengojs plugins that need or use the request object.

The following is an example that shows you to:

  • Make sure the plugin has properly loaded
  • Make sure that the internal API is properly exposed.
  • Make sure that the internal API's API are exposed as well.

Note that there are two version of Wrappify. One is without es6 and the other is. The example below is with ES6. Therefore, make sure to use the --harmony flag when running your tests or use Babel to convert your ES6 code to ES5.

Also note that the wrapper for koa only supports Koa >= v2.0.0.

var assert = require('chai').assert;
var core = require('gengojs-core');
var header = require('your plugin path');
// Wrappify with harmony
// (without harmony would simply be require('gengojs-wrappify'))
var wrappify = require('gengojs-wrappify/es6');

describe('Header', function() {
  describe('load plugins', function() {
    it('should exist', function() {
     // Create an instance of the core.
      var gengo = core({}, header());
      gengo.plugins.headers.forEach(function(plugin) {
        assert.isDefined(plugin);
        assert.strictEqual(plugin.package.type, 'header');
        assert.strictEqual(plugin.package.name, 'gengojs-default-header');
      });
    });
  });
  describe('koa', function() {
    var gengo = core({}, header());
    var Koa = require('koa');
    var app = new Koa();
    // Use Koa wrapper
    app.use(wrappify(gengo).koa());
    var request = require('supertest');
    it('should have the api exposed internally', function() {
      request(app.listen()).get('/').end(function() {
        assert.isDefined(gengo.header);
        assert.isDefined(gengo.header.getLocale);
      });
    });
  });

  describe('express', function() {
    var gengo = core({}, header());
    var express = require('express');
    var app = express();
    var request = require('supertest');
    // Use Express wrapper
    app.use(wrappify(gengo).express());
    it('should have the api exposed internally', function() {
      request(app).get('/').end(function() {
        assert.isDefined(gengo.header);
        assert.isDefined(gengo.header.getLocale);
      })
    });
  });

  describe('hapi', function() {
    var gengo = core({}, header());
    var Hapi = require('hapi');
    var server = new Hapi.Server();
    server.connection({
      port: 3000
    });
    // Register Hapi wrapper
    server.register(wrappify(gengo).hapi(), function(err) {});

    it('should have the api exposed internally', function() {
      server.inject('/', function(res) {
        assert.isDefined(gengo.header);
        assert.isDefined(gengo.header.getLocale);
      })
    });
  });
});

FAQs

Package last updated on 10 Nov 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts