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

chai-jscodeshift

v15.0.0

Published

Chai assertion utilities for writing JSCodeShift Codemods.

Downloads

10

Readme

chai-jscodeshift

chai-jscodeshift provides a custom assertion for jscodeshift to check whether a given input fixture matches an output fixture after being transformed by the transformer under test.

Setup

import chai from 'chai';
import chaiJSCodeShift from 'chai-jscodeshift';
chai.use(chaiJSCodeShift());

Usage

import myTransform from '../src/my-transform';

describe('myTransform', () => {
  it('transforms properly', () => {
    expect(myTransform).to.transform('my-fixture');

    // or

    assert.transforms(myTransform, 'my-fixture');
  });
});

Customization

By default, this plugin will look for fixtures in the fixtures in the working directory. You will probably want to customize this by setting the directory in which your fixtures appear:

import path from 'path';

chai.use(chaiJSCodeShift({
  fixtureDirectory: path.join(__dirname, 'fixtures')
}));

When you declare that you want a transformer to transform a particular fixture, this plugin will look for a file named <fixtureName>.input.js, relative to the fixtureDirectory declared above. It will read this file, transform the contents using your transformer, and compare it against a file named <fixtureName>.output.js relative to the fixture directory. You can customize either of these paths by passing a custom inputFixturePath or outputFixturePath in your options (both of which take two arguments, the fixture name and the root of the fixture directory):

chai.use(chaiJSCodeShift({
  fixtureDirectory: path.join(__dirname, 'fixtures'),
  inputFixturePath(fixtureName, fixtureDirectory) {
    return path.join(fixtureDirectory, 'input', `${fixtureName}.js`);
  },
  inputFixturePath(fixtureName, fixtureDirectory) {
    return path.join(fixtureDirectory, 'output', `${fixtureName}.js`);
  },
}));

You can also set custom options that will be passed as the third argument to your transformer on every call using the transformOptions configuration option:

chai.use(chaiJSCodeShift({
  transformOptions: {
    printOptions: {space: 'single'},
  },
}));