npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ama-team/voxengine-stubs

v0.1.0

Published

VoxImplant application environment stubs for testing

Downloads

103

Readme

VoxEngine Stubs

npm CircleCI/Master Coveralls/Master Scrutinizer/Master Code Climate

This repository contains stubs for VoxEngine-specific global objects to help in testing VoxImplant applications.

Installation

npm i @ama-team/voxengine-stubs

Usage

Library has main entrypoint:

var Stubs = require('@ama-team/voxengine-stubs')

It exposes several methods: .setup(), .install(), .uninstall(), .reset() and .flush(). First three are terribly self-explanatory:

beforeEach(function() {
  Stubs.setup({global: {allure: {enabled: true}}})
  Stubs.install()
})
afterEach(function() {
  Stubs.uninstall()
})

Reset and flush are different things. When dealing with stubs like Logger, you'll want to a) save what's been in there (that's .flush() method) and b) clear that before every test (and that's .reset()). Reset method is a little bit redundant if you constantly call install and uninstall methods, but may come handy in hard cases. .uninstall() method calls .flush() automatically, so usually you won't need to call it either.

Configuration

There are four levels of configuration:

  • Stub defaults
  • Global defaults
  • Global configuration
  • Stub configuration

When it comes to work, all three levels are recursively merged into one, and lower level keys take precedence of upper ones. Defaults are hard-boiled inside library and can't be changed, while the latter two levels are configured as single object:

Stubs.setup({
  global: {
    allure: {
      enabled: true
    }
  },
  Logger: {
    allure: {
      filename: 'voxengine.log'
    }
  }
})

Sinon integration

Every stubbed function is wrapped in Sinon.spy, so you may call something like Logger.write.getCall(0).args[0] in your tests without any hassle.

Spies are recreated on every reset call, so calls don't accumulate.

Per-stub work

Sometimes you will need to work with stubs directly. Most of the stubs have corresponding ._setup(), ._reset() and ._flush() methods that practically do the same thing you expect.

Logger

Logger saves passed data to internal state and flushes it as voxengine.log Allure attachment.

It's configuration schema is:

allure:
  enabled: true
  filename: voxengine.log
  mimeType: text/plain

VoxEngine

VoxEngine stubs .terminate, .customData, .addEventListener and .removeEventListener functions. You can use ._emit(event) function to invoke event raise.

Configuration:

allure:
  enabled: true
  events:
    filename: events.yml
    mimeType: application/x-yaml
  listeners:
    filename: listeners.yml
    mimeType: application/x-yaml
  customData:
    filename: custom-data.yml
    mimeType: application/x-yaml
customData:
  default: ''
terminate:
  # Whether to throw on second VoxEngine.terminate call
  throwOnMultipleCalls: false
  # Whether to throw if `this` is lost. Such call may result in
  # undesired behavior in VoxEngine.
  throwOnLostContext: true

Net

Only HTTP part has been stubbed yet.

allure:
  enabled: true
  pattern: http-interaction-%d.yml
  mimeType: application/yaml
# list
http:
  # list of HttpRequestResult-alike structures
  # example:
  #   code: 200
  #   headers:
  #     - key: Server
  #       value: elasticsearch/5.5.2
  #   raw_headers: |
  #     Server: elasticsearch/5.5.2
  #   text: '{"acknowledged":true}'
  responses: []
  # whether to throw when last response have been reached or
  # just start from beginning
  roundRobin: false

AppEvents and CallEvents

Both of these namespace have been stubbed. You can create events yourself by just calling new AppEvents.Something({property: value}) constructor. Events come with some dumb defaults, so most of the time you will have correct types even if you don't feed constructor with anything.

Hey, i don't see X in that list!

That's probably because i had no time to implement it. Pull requests are appreciated.

Allure integration

Currently all flushing boils down to saving Allure attachments if it's turned on and is present as allure global object. Allure is a beautiful reporting tool made just for case like this: collect all data about tests and present it in beautiful view. If you haven't got a chance to get acquainted with it earlier, do it now, because it will save you tons of testing time.

License

MIT

Dev branch state

CircleCI/Dev Coveralls/Dev Scrutinizer/Dev