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

maineffect

v0.0.21

Published

Testing in javascript made easier.

Downloads

9

Readme

Maineffect - [Beta]

Testing so bold, it does not require anything.

Maineffect enables you to write tests faster by helping you easily isolate the test execution path. Instead of requiring modules and their dependencies, Maineffect "parses" the module to test into it's AST representation.

From there on it one can traverse the tree to find functions they intend to test. Private functions, class methods and just about anything can be tested this way.

Warning

This is not production ready at this point. Will be releasing a more stable version depending on feedback.

Currently expects you to bring @babel/core.

Demo

Watch the video

Installation

$ npm install maineffect

Quickstart - Example #1

Parse/Load the file (Do not require or import). Find the function you want to test by name and CallWith arguments.

math.js
import log from 'logger'

const add = (a,b) => a + b
math.test.js
const {load} = import 'maineffect'
const math = load(require.resolve('./math'))

describe ('math', () => {
  describe('add', () => {
    it('should return 2 when called with 1, 1', () => {
	const {result} = math.find('add').callWith(1, 1)
	expect(result).to.equal(2)
    })
  })
})

Explanation

Here, we wanted to test the add function of math.js. Generally we import the file into our test and call add. However with Maineffect, we parse the raw file, and find the add function. Just like finding a div element in the DOM. We then call it with our arguments.

Advantages

  • We can now test private functions. In math.js above we did not export add.
  • We dot care about dependencies in the test. Like above, we don't even have a logger module installed.

Quickstart - Example #2

Provide a variable with any value. Fold stuff you don't care about.

taxes.js
import log from 'Logger'
import getTaxeRate from 'irs'

const getAmountAfterTaxes = async (amount) => {
  log('Inside getTaxes')
  const taxRate = await getTaxeRate()
  return amount - amount * taxRate
}
taxes.test.js
import { expect } from 'chai'
import { load } from '../src/maineffect'

const taxes = load(require.resolve('./taxes'))

describe ('taxes', () => {
  describe('getTaxes', () => {
    it('should return 50 when called with 100 and a rate of 0.5', async () => {
      const {result} = taxes.find('getAmountAfterTaxes')
                        .provide('log', () => {})					
                        .fold('taxRate', 0.5)
                        .callWith(100)
      expect(await result).to.equal(50)
    })
  })
})

Explanation

Here, we want to test the getAmountAfterTaxes function of taxes.js. Once we find the function, we provide log as an empty function (stubs also work here). Then we fold the taxRate constant to the value 0.5 and call the function.

Advantages

  • All we care about is the value of taxRate. We are not here to test getTaxeRate. So we fold the right-hand-side of that assignment to a value we like.
  • We can mock dependencies like log

Development

Build

npx webpack --config webpack.config.js

Test

yarn run test

Test in Developer mode

yarn run test-dev

Contact

Reach out to me at @buzzarvind on Twitter for anything. I'll do my best to help out.

License

The MIT License

Copyright (c) 2019-2019 Arvind Naidu https://twitter.com/buzzarvind