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

adonis-sink

v1.0.6

Published

Development kitchen sink for writing adonisjs providers

Downloads

4

Readme

Adonis Sink

Adonis sink contains fake implementations for commonly used AdonisJs providers. You can use this package to write tests for your own providers.

NPM Version Build Status Appveyor

It contains fake implmentations for

  1. Config provider
  2. Helpers provider
  3. Logger provider
  4. Env provider
  5. Setup adonis-fold resolver.

Config provider

If your provider has a dependency on Config provider, you must use a fake implementation to write tests.

const { Config } = require('adonis-sink')
const test = require('japa')

test.group('My Package', (group) => {
  group.beforeEach(() => {
    this.config = new Config()
  })


  test('test', () => {
    this.config.set('services.redis', {
      host: '',
      port: ''
    })

    const redis = new Redis(this.config)
  })

})

Then inside your Redis class you can make use of the Config.get method.

class Redis {
  constructor (config) {
    const redisConfig = config.get('services.redis')
  }
}

Helpers Provider

Helpers provider is used to get path to certain application directories. All the methods from the actual provider are available in the fake implementation.

const { Helpers } = require('adonis-sink')
const test = require('japa')
const path = require('path')

test.group('My Package', (group) => {
  group.beforeEach(() => {
    this.helpers = new Helpers(path.join(__dirname, './'))
  })
})

The Helpers provider needs the appRoot as the constructor argument.

Logger Provider

Logger provider is used to log messages. The fake implementation also let you verify whether a message for a given level was logged or not.

const { Logger } = require('adonis-sink')
const test = require('japa')
const path = require('path')

test.group('My Package', (group) => {
  group.beforeEach(() => {
    this.logger = new Logger()
  })

  test('my test', () => {
    const someModule = new SomeModule(this.logger)
    someModule.connect()

    assert.isTrue(this.logger.has('warn', 'Consider passing 127.0.0.1 over localhost'))
  })
})

And use it like this

class SomeModule {
  constructor (logger) {
    this.logger = logger
  }

  connect () {
    if (this.config.host = 'localhost') {
      this.logger.warn('Consider passing 127.0.0.1 over localhost')
    }
  }
}

For complex message, you may use logger.contains over logger.has, since logger.has checks the equality of 2 strings and logger.contains does a sub string check.

this.logger.debug('user profile %j', { name: 'virk' })
this.logger.contains('user profile')

Env Provider

Also env provider can be used to read environment variables. The fake implementation doesn't load any .env file, whereas you can set values manually before writing tests.

const { Env } = require('adonis-sink')

const env = new Env()

env.set('HOST', '127.0.0.1')

Resolver Setup

The resolver is an object to make namespaces and resolve values for a given namespace based upon the directory structure and autoloaded namespace.

Setup of resolver is done before AdonisJs application boots, but at the time of writing tests, there is no application and hence you can setup the resolver using a pre-configured method.

const { setupResolver } = require('adonis-sink')

test.group('My Package', (group) => {
  group.before(() => {
    setupResolver()
  })
})

Now your application code under the test can make use of the adonis-fold resolver to resolve dependencies.

const { resolver } = require('adonis-fold')
resolver.for('httpControllers').resolveFunc('HomeController.render')

// returns { instance: HomeController, isClosure: false, method: render }